Skip to content

Commit

Permalink
piece together working rate stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
macrael committed Aug 8, 2023
1 parent 0d23a7f commit 522b030
Show file tree
Hide file tree
Showing 28 changed files with 433 additions and 221 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN;
/*
Warnings:
- You are about to drop the column `name` on the `RateRevisionTable` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "RateRevisionTable" DROP COLUMN "name";
COMMIT;
1 change: 0 additions & 1 deletion services/app-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ model RateRevisionTable {
submitInfoID String?
submitInfo UpdateInfoTable? @relation("submitRateInfo", fields: [submitInfoID], references: [id])
name String
rateType RateType?
rateCapitationType RateCapitationType?
rateDocuments RateDocument[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { z } from 'zod'
import {
actuaryCommunicationTypeSchema,
actuaryContactSchema,
contractExecutionStatusSchema,
contractTypeSchema,
federalAuthoritySchema,
populationCoveredSchema,
rateCapitationTypeSchema,
rateTypeSchema,
sharedRateCertDisplay,
stateContactSchema,
submissionDocumentSchema,
submissionTypeSchema,
Expand Down Expand Up @@ -58,21 +63,50 @@ const contractRevisionSchema = z.object({
formData: contractFormDataSchema,
})

// The rate form data is the form filled out by state users submitting rates for review
const rateFormDataSchema = z.object({
id: z.string().optional(),
rateType: rateTypeSchema.optional(),
rateCapitationType: rateCapitationTypeSchema.optional(),
rateDocuments: z.array(submissionDocumentSchema).optional(),
supportingDocuments: z.array(submissionDocumentSchema).optional(),
rateDateStart: z.date().optional(),
rateDateEnd: z.date().optional(),
rateDateCertified: z.date().optional(),
amendmentEffectiveDateStart: z.date().optional(),
amendmentEffectiveDateEnd: z.date().optional(),
rateProgramIDs: z.array(z.string()).optional(),
rateCertificationName: z.string().optional(),
certifyingActuaryContacts: z.array(actuaryContactSchema).optional(),
addtlActuaryContacts: z.array(actuaryContactSchema).optional(),
actuaryCommunicationPreference: actuaryCommunicationTypeSchema.optional(),
packagesWithSharedRateCerts: z.array(sharedRateCertDisplay).optional(),
})

// A Rate represents all the data associated with a single rate certification over time.
// The rate's revisions field hold the array of rate revisions that show change history of specific rate data
// The first revision (array index 0) is the current revision
const ratesRevisionSchema = z.object({
id: z.string().uuid(),
submitInfo: updateInfoSchema.optional(),
unlockInfo: updateInfoSchema.optional(),
revisionFormData: z.string(),
createdAt: z.date(),
updatedAt: z.date(),
revisionFormData: rateFormDataSchema,
})

// ContractRevision has all the information in a single submission of this contract.
// If a revision has been submitted it will have submitInfo (otherwise it will be a draft)
// if a revision was unlocked, it will have unlock info, otherwise it was an initial submission
// The set of rateRevisions hold exactly what rate data was present at the time this contract was submitted.
const contractRevisionZodSchema = contractRevisionSchema.extend({
const contractRevisionWithRatesSchema = contractRevisionSchema.extend({
rateRevisions: z.array(ratesRevisionSchema),
})

const rateRevisionWithContractsSchema = ratesRevisionSchema.extend({
contractRevisions: z.array(contractRevisionSchema),
})

// Contract represents the contract specific information in a submission package
// All that data is contained in revisions, each revision represents the data in a single submission
// submissions are kept intact here across time
Expand All @@ -81,58 +115,54 @@ const contractZodSchema = z.object({
status: z.union([z.literal('SUBMITTED'), z.literal('DRAFT')]),
stateCode: z.string(),
stateNumber: z.number().min(1),
revisions: z.array(contractRevisionZodSchema),
revisions: z.array(contractRevisionWithRatesSchema),
})

const draftContractZodSchema = contractZodSchema.extend({
status: z.literal('DRAFT'),
revisions: z.array(contractRevisionZodSchema).min(1),
revisions: z.array(contractRevisionWithRatesSchema).min(1),
})

const rateZodSchema = z.object({
id: z.string().uuid(),
status: z.union([z.literal('SUBMITTED'), z.literal('DRAFT')]),
stateCode: z.string(),
stateNumber: z.number().min(1),
revisions: z.array(rateRevisionWithContractsSchema),
})

type ContractFormDataType = z.infer<typeof contractFormDataSchema>
type ContractType = z.infer<typeof contractZodSchema>
type ContractRevisionType = z.infer<typeof contractRevisionZodSchema>
type ContractRevisionType = z.infer<typeof contractRevisionSchema>
type ContractRevisionWithRatesType = z.infer<
typeof contractRevisionWithRatesSchema
>
type ContractFormDataType = z.infer<typeof contractFormDataSchema>

type RateType = z.infer<typeof rateZodSchema>
type RateRevisionType = z.infer<typeof ratesRevisionSchema>
type RateRevisionWithContractsType = z.infer<
typeof rateRevisionWithContractsSchema
>
type RateFormDataType = z.infer<typeof rateFormDataSchema>

type UpdateInfoType = z.infer<typeof updateInfoSchema>
type ContractStatusType = z.infer<typeof contractZodSchema.shape.status>

export { contractRevisionZodSchema, draftContractZodSchema, contractZodSchema }
export {
contractRevisionWithRatesSchema,
draftContractZodSchema,
contractZodSchema,
}

export type {
ContractFormDataType,
ContractType,
ContractRevisionType,
ContractRevisionWithRatesType,
ContractFormDataType,
RateType,
RateRevisionType,
RateRevisionWithContractsType,
RateFormDataType,
UpdateInfoType,
ContractStatusType,
}

/// Returned By FindWithHistory, Submit
// ContractWithRevisionsType
// - ContractType
// - revisions: ContractRevisionWithRateRevisionsType
// -- ContractRevisionType
// -- ContractFormDataType
// -- rateRevisions: RateRevisionType
// ---RateFormDataType
// --- rate: RateType

// returned by insertContract, unlockContract?, updateContract,
// DraftContractType
// - ContractType
// - draftRevision: DraftContractRevisionType
// -- ContractRevisionType
// -- ContractFormDataType
// -- rateRevisions: RateRevisionType
// --- RateFormDataType
// --- rate: RateType

// ContractType
// ContractWithRevisionsType
// ContractRevisionType
// ContractRevisionWithRateRevisionsType
// ContractFormDataType

// RateType
// RateWithRevisionsType
// RateRevisonType
// RateRevisionWithContractRevisionsType
// RateFormDataType
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
DraftContractTableWithRelations,
DraftContractRevisionTableWithRelations,
ContractTableWithRelations,
ContractRevisionTableWithRelations,
ContractRevisionTableWithRates,
} from '../../postgres/prismaTypes'
import {
parseDraftContract,
Expand Down Expand Up @@ -177,12 +177,15 @@ describe('parseDomainData', () => {
submitInfo: null,
unlockInfo: null,
unlockInfoID: null,
name: 'some data',
rateType: null,
rateCapitationType: null,
rateDateStart: null,
rateDateEnd: null,
rateDateCertified: null,
rateDocuments: [],
certifyingActuaryContacts: [],
addtlActuaryContacts: [],
supportingDocuments: [],
amendmentEffectiveDateStart: null,
amendmentEffectiveDateEnd: null,
rateProgramIDs: [],
Expand All @@ -191,7 +194,7 @@ describe('parseDomainData', () => {
},
},
],
}) as ContractRevisionTableWithRelations,
}) as ContractRevisionTableWithRates,
],
}),
testDescription: 'unsubmitted rate',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
} from '../../postgres/prismaTypes'
import {
ContractType,
ContractRevisionType,
contractRevisionZodSchema,
draftContractZodSchema,
contractRevisionWithRatesSchema,
ContractRevisionWithRatesType,
} from './contractAndRatesZodSchema'
import {
draftContractToDomainModel,
Expand All @@ -15,9 +15,9 @@ import {

function parseDraftContractRevision(
revision: DraftContractRevisionTableWithRelations
): ContractRevisionType | Error {
): ContractRevisionWithRatesType | Error {
const draftContractRevision = draftContractRevToDomainModel(revision)
const parseDraft = contractRevisionZodSchema.safeParse(
const parseDraft = contractRevisionWithRatesSchema.safeParse(
draftContractRevision
)

Expand Down
27 changes: 0 additions & 27 deletions services/app-api/src/domain-models/contractAndRates/rateType.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('findContract', () => {
const rate1 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'someurle.en',
rateCertificationName: 'someurle.en',
})
)
must(
Expand All @@ -70,7 +70,7 @@ describe('findContract', () => {
const rate2 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'twopointo',
rateCertificationName: 'twopointo',
})
)
must(
Expand All @@ -81,7 +81,7 @@ describe('findContract', () => {
const rate3 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'threepointo',
rateCertificationName: 'threepointo',
})
)
must(
Expand Down Expand Up @@ -263,9 +263,10 @@ describe('findContract', () => {
)

expect(revisionsInTimeOrder[5].rateRevisions).toHaveLength(2)
expect(revisionsInTimeOrder[5].rateRevisions[1].revisionFormData).toBe(
'onepointone'
)
expect(
revisionsInTimeOrder[5].rateRevisions[1].revisionFormData
.rateCertificationName
).toBe('onepointone')
expect(revisionsInTimeOrder[5].unlockInfo?.updatedReason).toBe(
'unlock for 1.1'
)
Expand Down Expand Up @@ -346,7 +347,7 @@ describe('findContract', () => {
const rate1 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'someurle.en',
rateCertificationName: 'someurle.en',
})
)
must(
Expand All @@ -359,7 +360,7 @@ describe('findContract', () => {
const rate2 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'twopointo',
rateCertificationName: 'twopointo',
})
)
must(
Expand All @@ -370,7 +371,7 @@ describe('findContract', () => {
const rate3 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'threepointo',
rateCertificationName: 'threepointo',
})
)
must(
Expand Down Expand Up @@ -483,9 +484,9 @@ describe('findContract', () => {
expect(revisions[4].rateRevisions).toHaveLength(2)

expect(revisions[5].rateRevisions).toHaveLength(2)
expect(revisions[5].rateRevisions[1].revisionFormData).toBe(
'onepointone'
)
expect(
revisions[5].rateRevisions[1].revisionFormData.rateCertificationName
).toBe('onepointone')
expect(revisions[5].submitInfo?.updatedReason).toBe('1.1 new name')

expect(revisions[6].rateRevisions).toHaveLength(2)
Expand Down Expand Up @@ -541,7 +542,7 @@ describe('findContract', () => {
const rate1 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'onepoint0',
rateCertificationName: 'onepoint0',
})
)
must(await updateDraftRate(client, rate1.id, 'onepoint0', []))
Expand All @@ -550,7 +551,7 @@ describe('findContract', () => {
const rate2 = must(
await insertDraftRate(client, {
stateCode: 'MN',
name: 'twopointo',
rateCertificationName: 'twopointo',
})
)
must(await updateDraftRate(client, rate2.id, 'twopointo', []))
Expand Down Expand Up @@ -648,7 +649,9 @@ describe('findContract', () => {

// these revisions can be in any order because they were saved at the same time
const revisionFormDatas = new Set(
revisions[2].rateRevisions.map((rr) => rr.revisionFormData)
revisions[2].rateRevisions.map(
(rr) => rr.revisionFormData.rateCertificationName
)
)
const expectedFormDatas = new Set(['onepoint0', 'twopointone'])
expect(revisionFormDatas).toStrictEqual(expectedFormDatas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PrismaTransactionType } from '../prismaTypes'
import { ContractType } from '../../domain-models/contractAndRates/contractAndRatesZodSchema'
import { updateInfoIncludeUpdater } from '../prismaHelpers'
import { NotFoundError } from '../storeError'
import { parseContractWithHistory } from './prismaContractWithHistoryConverter'

// findContractWithHistory returns a ContractType with a full set of
// ContractRevisions in reverse chronological order. Each revision is a change to this
Expand All @@ -28,8 +29,13 @@ async function findContractWithHistory(
include: {
rateRevision: {
include: {
rateDocuments: true,
supportingDocuments: true,
certifyingActuaryContacts: true,
addtlActuaryContacts: true,
submitInfo: updateInfoIncludeUpdater,
unlockInfo: updateInfoIncludeUpdater,
draftContracts: true,
},
},
},
Expand Down
Loading

0 comments on commit 522b030

Please sign in to comment.