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

Consolidate contract and rate types #1872

Merged
merged 5 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ submitContract
unlockContract
```

Plus a couple functions for inspecting them:
Plus a function for inspecting them:

```
findContractWithHistory
findDraftContract
```

The life cycle functions are used as follows:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const contractSchema = z.object({
status: z.union([z.literal('SUBMITTED'), z.literal('DRAFT')]),
stateCode: z.string(),
stateNumber: z.number().min(1),
// If this contract is in a DRAFT or UNLOCKED status, there will be a draftRevision
draftRevision: contractRevisionWithRatesSchema.optional(),
// All revisions are submitted and in reverse chronological order
revisions: z.array(contractRevisionWithRatesSchema),
})

Expand Down
5 changes: 5 additions & 0 deletions services/app-api/src/domain-models/healthPlanPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function convertContractToUnlockedHealthPlanPackage(
): HealthPlanPackageType | Error {
console.info('Attempting to convert contract to health plan package')

// Since drafts come in separate on the Contract type, we push it onto the revisions before converting below
if (contract.draftRevision) {
contract.revisions.unshift(contract.draftRevision)
Copy link
Contributor

@haworku haworku Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 should we do anything else to verify that the first revision is indeed a draft here or can we be confident?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're good here, a draft should be a draft if we put it on draftRevision

}

const healthPlanRevisions =
convertContractRevisionToHealthPlanRevision(contract)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ describe('findContract', () => {
)
)

// Unlock A, but don't resubmit it yet.
// Unlock contract A, but don't resubmit it yet.
must(
await unlockContract(
client,
Expand All @@ -598,16 +598,51 @@ describe('findContract', () => {
)
)

// Draft should pull revision 2.0 out
const draftPreRateUnlock = must(
await findContractWithHistory(client, contractA.id)
)
expect(draftPreRateUnlock.draftRevision).toBeDefined()
expect(
draftPreRateUnlock.draftRevision?.rateRevisions.map(
(rr) => rr.formData.rateCertificationName
)
).toEqual(['onepoint0', 'twopointo'])

// unlock and submit second rate rev
must(await unlockRate(client, rate2.id, cmsUser.id, 'unlock for 2.1'))
must(
await updateDraftRate(client, rate2.id, 'twopointone', [
contractA.id,
])
)

// Draft should now pull draft revision 2.1 out, even though its unsubmitted
const draftPreRateSubmit = must(
await findContractWithHistory(client, contractA.id)
)
expect(draftPreRateSubmit.draftRevision).toBeDefined()
expect(
draftPreRateSubmit.draftRevision?.rateRevisions.map(
(rr) => rr.formData.rateCertificationName
)
).toEqual(['onepoint0', 'twopointone'])

// Submit Rate 2.1
must(await submitRate(client, rate2.id, stateUser.id, '2.1 update'))

// submit A1, now, should show up as a single new rev and have the latest rates
// raft should still pull revision 2.1 out
const draftPostRateSubmit = must(
await findContractWithHistory(client, contractA.id)
)
expect(draftPostRateSubmit.draftRevision).toBeDefined()
expect(
draftPostRateSubmit.draftRevision?.rateRevisions.map(
(rr) => rr.formData.rateCertificationName
)
).toEqual(['onepoint0', 'twopointone'])

// submit contract A1, now, should show up as a single new rev and have the latest rates
must(
await submitContract(
client,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PrismaTransactionType } from '../prismaTypes'
import type { ContractType } from '../../domain-models/contractAndRates'
import { NotFoundError } from '../storeError'
import { includeUpdateInfo } from './prismaSharedContractRateHelpers'
import { parseContractWithHistory } from './parseContractWithHistory'
import { includeFullContract } from './prismaSubmittedContractHelpers'

// findContractWithHistory returns a ContractType with a full set of
// ContractRevisions in reverse chronological order. Each revision is a change to this
Expand All @@ -17,38 +17,7 @@ async function findContractWithHistory(
where: {
id: contractID,
},
include: {
revisions: {
orderBy: {
createdAt: 'asc',
},
include: {
submitInfo: includeUpdateInfo,
unlockInfo: includeUpdateInfo,
rateRevisions: {
include: {
rateRevision: {
include: {
rateDocuments: true,
supportingDocuments: true,
certifyingActuaryContacts: true,
addtlActuaryContacts: true,
submitInfo: includeUpdateInfo,
unlockInfo: includeUpdateInfo,
draftContracts: true,
},
},
},
orderBy: {
validAfter: 'asc',
},
},
stateContacts: true,
contractDocuments: true,
supportingDocuments: true,
},
},
},
include: includeFullContract,
})

if (!contract) {
Expand Down
Loading
Loading