Skip to content
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

Merged
merged 5 commits into from
Oct 18, 2023
Merged

Pccm template backend #11490

merged 5 commits into from
Oct 18, 2023

Conversation

gmrabian
Copy link
Contributor

@gmrabian gmrabian commented Oct 17, 2023

Description

Related ticket(s)

CMDCT-3028


How to test

Important updates


Author checklist

  • I have performed a self-review of my code
  • I have added thorough tests, if necessary
  • I have updated relevant documentation, if necessary

convert to a different template: test → val | val → prod

@gmrabian gmrabian changed the title [WIP] - Pccm template backend (option 2) [WIP] - Pccm template backend Oct 17, 2023
Comment on lines -43 to -55
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);
}
Copy link
Contributor Author

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

Comment on lines +86 to +93
const isProgramPCCM =
unvalidatedMetadata?.programIsPCCM?.[0]?.value === "Yes";

try {
({ formTemplate, formTemplateVersion } = await getOrCreateFormTemplate(
reportBucket,
reportType
reportType,
isProgramPCCM
Copy link
Contributor Author

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));
Copy link
Contributor Author

@gmrabian gmrabian Oct 17, 2023

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

info here

Copy link
Contributor

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.

Comment on lines +43 to +45
mockDocumentClient.query.promise.mockReturnValueOnce({
Items: [],
});
Copy link
Contributor Author

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

Comment on lines +88 to +93
const matchingTemplateMetadata = await getTemplateVersionByHash(
reportType,
currentTemplateHash
);

if (currentTemplateHash === mostRecentTemplateVersionHash) {
if (matchingTemplateMetadata) {
Copy link
Contributor Author

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

Comment on lines +123 to +124
versionNumber: newestTemplateMetadata?.versionNumber
? (newestTemplateMetadata.versionNumber += 1)
Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +274 to +286
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"];
Copy link
Contributor Author

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

Copy link
Contributor

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);
Copy link
Contributor Author

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

@gmrabian gmrabian added the ready for review Ready for all the reviews! label Oct 17, 2023
@gmrabian gmrabian changed the title [WIP] - Pccm template backend Pccm template backend Oct 17, 2023
@gmrabian gmrabian marked this pull request as ready for review October 17, 2023 20:45
Copy link
Contributor

@benmartin-coforma benmartin-coforma left a 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));
Copy link
Contributor

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.

Comment on lines +123 to +124
versionNumber: newestTemplateMetadata?.versionNumber
? (newestTemplateMetadata.versionNumber += 1)
Copy link
Contributor

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.

Comment on lines +274 to +286
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"];
Copy link
Contributor

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.

@gmrabian gmrabian merged commit 69297dc into add-pccm-radio-3027 Oct 18, 2023
9 checks passed
@gmrabian gmrabian deleted the pccm-template-backend branch October 18, 2023 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Ready for all the reviews!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants