-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b824331
commit cc9e551
Showing
38 changed files
with
562 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/common-code/src/proto/healthPlanFormDataProto/healthPlanFormDataEncoding.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/common-code/src/proto/healthPlanFormDataProto/protoBase64.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@mc-review/document-helpers", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "build/index.js", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"@mc-review/common-code": "workspace:*", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { HealthPlanFormDataType } from '../common-code/healthPlanFormDataType' | ||
|
||
const getAllDocuments = (pkg: HealthPlanFormDataType) => { | ||
let allDocuments = [...pkg.contractDocuments, ...pkg.documents] | ||
if (pkg.rateInfos.length > 0) { | ||
pkg.rateInfos.forEach((rateInfo) => { | ||
allDocuments = allDocuments.concat(rateInfo.rateDocuments) | ||
allDocuments = allDocuments.concat(rateInfo.supportingDocuments) | ||
}) | ||
} | ||
return allDocuments | ||
} | ||
|
||
export { getAllDocuments } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { makeDocumentDateTable } from './makeDocumentDateLookupTable' | ||
export { makeDocumentS3KeyLookup } from './makeDocumentKeyLookupList' |
120 changes: 120 additions & 0 deletions
120
packages/document-helpers/src/makeDocumentDateLookupTable.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { makeDocumentDateTable } from './makeDocumentDateLookupTable' | ||
import { | ||
mockDraftHealthPlanPackage, | ||
mockSubmittedHealthPlanPackageWithRevision, | ||
} from '@mc-review/test-helpers' | ||
import { UnlockedHealthPlanFormDataType } from '../common-code/healthPlanFormDataType' | ||
import { TextEncoder, TextDecoder } from 'util' | ||
import { buildRevisionsLookup } from '../gqlHelpers/fetchHealthPlanPackageWrapper' | ||
|
||
Object.assign(global, { TextDecoder, TextEncoder }) | ||
|
||
describe('makeDocumentDateTable', () => { | ||
it('should make a proper lookup table', () => { | ||
const submission = mockSubmittedHealthPlanPackageWithRevision({ | ||
currentSubmitInfo: { | ||
updatedAt: new Date('2022-03-28T17:56:32.953Z'), | ||
}, | ||
previousSubmitInfo: { | ||
updatedAt: new Date('2022-03-25T21:14:43.057Z'), | ||
}, | ||
initialSubmitInfo: { | ||
updatedAt: new Date('2022-03-25T21:13:20.420Z'), | ||
}, | ||
}) | ||
const revisionsLookup = buildRevisionsLookup(submission) | ||
if (revisionsLookup instanceof Error) { | ||
throw revisionsLookup | ||
} | ||
const lookupTable = makeDocumentDateTable(revisionsLookup) | ||
expect(lookupTable).toEqual({ | ||
fakesha: new Date('2022-03-25T21:13:20.420Z'), | ||
fakesha1: new Date('2022-03-28T17:56:32.953Z'), | ||
fakesha2: new Date('2022-03-25T21:13:20.420Z'), | ||
fakesha3: new Date('2022-03-25T21:13:20.420Z'), | ||
fakesha4: new Date('2022-03-25T21:13:20.420Z'), | ||
fakesha5: new Date('2022-03-25T21:13:20.420Z'), | ||
previousSubmissionDate: new Date('2022-03-25T21:14:43.057Z'), | ||
}) | ||
}) | ||
|
||
it('should return no document dates for submission still in initial draft', () => { | ||
const submission = mockDraftHealthPlanPackage() | ||
const revisionsLookup = buildRevisionsLookup(submission) | ||
if (revisionsLookup instanceof Error) { | ||
throw revisionsLookup | ||
} | ||
const lookupTable = makeDocumentDateTable(revisionsLookup) | ||
|
||
expect(lookupTable).toEqual({ | ||
previousSubmissionDate: null, | ||
}) | ||
}) | ||
|
||
it('should use earliest document added date based that revisions submit date', () => { | ||
const docs: Partial<UnlockedHealthPlanFormDataType> = { | ||
documents: [ | ||
{ | ||
s3URL: 's3://bucketname/testDateDoc/testDateDoc.pdf', | ||
name: 'Test Date Doc', | ||
sha256: 'fakesha', | ||
}, | ||
], | ||
contractDocuments: [ | ||
{ | ||
s3URL: 's3://bucketname/key/replaced-contract.pdf', | ||
name: 'replaced contract', | ||
sha256: 'fakesha1', | ||
}, | ||
], | ||
rateInfos: [ | ||
{ | ||
rateDocuments: [], | ||
supportingDocuments: [], | ||
actuaryContacts: [], | ||
packagesWithSharedRateCerts: [], | ||
}, | ||
], | ||
} | ||
const submission = mockSubmittedHealthPlanPackageWithRevision({ | ||
currentSubmissionData: { | ||
...docs, | ||
}, | ||
currentSubmitInfo: { | ||
updatedAt: new Date('2022-03-10T00:00:00.000Z'), | ||
}, | ||
previousSubmissionData: { | ||
...docs, | ||
}, | ||
previousSubmitInfo: { | ||
updatedAt: new Date('2022-02-10T00:00:00.000Z'), | ||
}, | ||
initialSubmissionData: { | ||
...docs, | ||
contractDocuments: [ | ||
{ | ||
s3URL: 's3://bucketname/key/original-contract.pdf', | ||
name: 'original contract', | ||
sha256: 'fakesha2', | ||
}, | ||
], | ||
}, | ||
initialSubmitInfo: { | ||
updatedAt: new Date('2022-01-10T00:00:00.000Z'), | ||
}, | ||
}) | ||
|
||
const revisionsLookup = buildRevisionsLookup(submission) | ||
if (revisionsLookup instanceof Error) { | ||
throw revisionsLookup | ||
} | ||
const lookupTable = makeDocumentDateTable(revisionsLookup) | ||
|
||
expect(lookupTable).toEqual({ | ||
fakesha: new Date('2022-01-10T00:00:00.000Z'), | ||
fakesha1: new Date('2022-02-10T00:00:00.000Z'), | ||
fakesha2: new Date('2022-01-10T00:00:00.00'), | ||
previousSubmissionDate: new Date('2022-02-10T00:00:00.000Z'), | ||
}) | ||
}) | ||
}) |
52 changes: 52 additions & 0 deletions
52
packages/document-helpers/src/makeDocumentDateLookupTable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
ExpandedRevisionsType, | ||
RevisionsLookupType, | ||
} from '../gqlHelpers/fetchHealthPlanPackageWrapper' | ||
import { getAllDocuments } from './getAllDocuments' | ||
|
||
// DocumentDateLookupTableType - { document lookup key string : date string for "date added" } | ||
type DocumentDateLookupTableType = { | ||
previousSubmissionDate: string | null | ||
[key: string]: string | null | ||
} | ||
|
||
// getDateAdded - picks out the submit info updatedAt date for a revision | ||
// value is undefined if document not yet submitted | ||
const getDateAdded = ( | ||
revisionData: ExpandedRevisionsType | ||
): string | undefined => { | ||
return revisionData.submitInfo?.updatedAt | ||
} | ||
// makeDateTable - generates unique document keys and their "date added" | ||
// used for date added column on UploadedDocumentsTable displayed in SubmissionSummary and ReviewSubmit | ||
// documents without a submitted date are excluded from list | ||
// logic for unique document keys comes from getDocumentKey - This can be simplified once we have doc.sha everywhere | ||
function makeDocumentDateTable( | ||
revisionsLookup: RevisionsLookupType | ||
): DocumentDateLookupTableType { | ||
const lookupTable: DocumentDateLookupTableType = { | ||
previousSubmissionDate: null, // the last time there was a submission on this package | ||
} | ||
const listOfRevisionLookups = Object.keys(revisionsLookup) | ||
listOfRevisionLookups.forEach( | ||
(revisionId: string, index) => { | ||
const revision = revisionsLookup[revisionId] | ||
|
||
const submitDate = revision.submitInfo?.updatedAt | ||
if (submitDate && (listOfRevisionLookups.length === 1 || index === 1)) { // if we have a package with only one submitted revision, use that - otherwise use whatever in is the 1 index because thats the last submitted | ||
lookupTable['previousSubmissionDate'] = submitDate | ||
} | ||
|
||
const allDocuments = getAllDocuments(revision.formData) | ||
allDocuments.forEach((doc) => { | ||
const documentKey = doc.sha256 ? doc.sha256 : doc.s3URL | ||
const dateAdded = getDateAdded(revision) | ||
if (dateAdded) lookupTable[documentKey] = dateAdded | ||
}) | ||
} | ||
) | ||
return lookupTable | ||
} | ||
|
||
export { makeDocumentDateTable } | ||
export type { DocumentDateLookupTableType } |
Oops, something went wrong.