-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pccm template backend #11490
Pccm template backend #11490
Conversation
export function getTemplateVersionByHash(reportType: ReportType, hash: string) { | ||
const queryParams: QueryInput = { | ||
TableName: process.env.FORM_TEMPLATE_TABLE_NAME!, | ||
IndexName: "HashIndex", | ||
KeyConditionExpression: "reportType = :reportType AND md5Hash = :md5Hash", | ||
Limit: 1, | ||
ExpressionAttributeValues: { | ||
":md5Hash": hash as AttributeValue, | ||
":reportType": reportType as unknown as AttributeValue, | ||
}, | ||
}; | ||
return dynamodbLib.query(queryParams); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved this to formTemplate.ts
const isProgramPCCM = | ||
unvalidatedMetadata?.programIsPCCM?.[0]?.value === "Yes"; | ||
|
||
try { | ||
({ formTemplate, formTemplateVersion } = await getOrCreateFormTemplate( | ||
reportBucket, | ||
reportType | ||
reportType, | ||
isProgramPCCM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
report create now checks for PCCM radio and generates a separate template if necessary – see below
const programIsPCCM = true; | ||
const programIsNotPCCM = false; | ||
|
||
global.structuredClone = (val: any) => JSON.parse(JSON.stringify(val)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test: had to mock structuredClone to its more primitive form because 🤷 I guess node environment isn't up to date enough to support it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that's sad. Mocking it here for tests isn't too painful imo, but hopefully something we can remove later.
mockDocumentClient.query.promise.mockReturnValueOnce({ | ||
Items: [], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test: added mocks to many tests because we now have two queries: one for matching hash, and one for latest version
const matchingTemplateMetadata = await getTemplateVersionByHash( | ||
reportType, | ||
currentTemplateHash | ||
); | ||
|
||
if (currentTemplateHash === mostRecentTemplateVersionHash) { | ||
if (matchingTemplateMetadata) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we now identify if there is a matching template by hash rather than latest. This way if we alternate creating PCCM and MCPAR forms it won't create duplicates in the table because the hash will be the same
versionNumber: newestTemplateMetadata?.versionNumber | ||
? (newestTemplateMetadata.versionNumber += 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still version off of the latest for simplicity. So whether you create a MCPAR or a PCCM, if it's new it will get a +1 to the latest version and save in the same table/bucket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, since PCCM form template versions are stored with reportType = MCPAR, we will have MCPAR version 17 (say) be a full MCPAR, and MCPAR version 18 be PCCM, and MCPAR version 19 be a full MCPAR again (with some differences compared to v17, such that the hash no longer matches). The only way for a developer browsing the form template version table to know whether a given entry for the MCPAR reportType is PCCM will be for them to pull the form template from S3.
I don't anticipate ever needing or wanting to do so myself, so I have no problem with that.
I also am not sure that this comment adds any clarity. Um, sorry. The code is good though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying, Ben! That helps.
Yes if we needed to find a PCCM template we could always look in the report table first, search for a report that selected "Yes" to PCCM, get the templateId from there, etc.
const routesToIncludeInPCCM = { | ||
"A: Program Information": [ | ||
"Point of Contact", | ||
"Reporting Period", | ||
"Add Plans", | ||
], | ||
"B: State-Level Indicators": ["I: Program Characteristics"], | ||
"C: Program-Level Indicators": ["I: Program Characteristics"], | ||
"D: Plan-Level Indicators": ["I: Program Characteristics", "VIII: Sanctions"], | ||
"Review & Submit": [], | ||
} as { [key: string]: string[] }; | ||
|
||
const entitiesToIncludeInPCCM = ["plans", "sanctions"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routes to include from ticket
Section A: Program Information
Point of Contact
Reporting Period
Add Plans
Section B: State-Level Indicators
Program Characteristics and Enrollment
Section C: Program-Level Indicators
Program Characteristics
Section D: Plan-Level Indicators
Program Characteristics and Enrollment
Sanctions
Review and Submit
entities inferred from same list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: I think that, strictly speaking, the entity inference could have been done in code rather than hardcoding plans
and sanctions
in this array. But that code would have been terribly complicated compared to this one-line declaration, so I completely agree with your approach.
const entitiesToIncludeInPCCM = ["plans", "sanctions"]; | ||
|
||
export const generatePCCMTemplate = (originalReportTemplate: any) => { | ||
const reportTemplate = structuredClone(originalReportTemplate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this structuredClone let's us copy the mcpar template without modifying it in memory, so that we can create MCPARs and PCCMs and they will always be based on the full MCPAR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work! My comments are all of the "idle musing" type.
const programIsPCCM = true; | ||
const programIsNotPCCM = false; | ||
|
||
global.structuredClone = (val: any) => JSON.parse(JSON.stringify(val)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that's sad. Mocking it here for tests isn't too painful imo, but hopefully something we can remove later.
versionNumber: newestTemplateMetadata?.versionNumber | ||
? (newestTemplateMetadata.versionNumber += 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, since PCCM form template versions are stored with reportType = MCPAR, we will have MCPAR version 17 (say) be a full MCPAR, and MCPAR version 18 be PCCM, and MCPAR version 19 be a full MCPAR again (with some differences compared to v17, such that the hash no longer matches). The only way for a developer browsing the form template version table to know whether a given entry for the MCPAR reportType is PCCM will be for them to pull the form template from S3.
I don't anticipate ever needing or wanting to do so myself, so I have no problem with that.
I also am not sure that this comment adds any clarity. Um, sorry. The code is good though.
const routesToIncludeInPCCM = { | ||
"A: Program Information": [ | ||
"Point of Contact", | ||
"Reporting Period", | ||
"Add Plans", | ||
], | ||
"B: State-Level Indicators": ["I: Program Characteristics"], | ||
"C: Program-Level Indicators": ["I: Program Characteristics"], | ||
"D: Plan-Level Indicators": ["I: Program Characteristics", "VIII: Sanctions"], | ||
"Review & Submit": [], | ||
} as { [key: string]: string[] }; | ||
|
||
const entitiesToIncludeInPCCM = ["plans", "sanctions"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: I think that, strictly speaking, the entity inference could have been done in code rather than hardcoding plans
and sanctions
in this array. But that code would have been terribly complicated compared to this one-line declaration, so I completely agree with your approach.
Description
Related ticket(s)
CMDCT-3028
How to test
Important updates
Author checklist
convert to a different template: test → val | val → prod