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

Drop contractRevision.rateRevisions and rateRevision.contractRevisions #2613

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import {
contractPackageSubmissionSchema,
ratePackageSubmissionSchema,
} from './packageSubmissions'
import {
contractRevisionSchema,
contractRevisionWithRatesSchema,
rateRevisionSchema,
rateRevisionWithContractsSchema,
} from './revisionTypes'
import { contractRevisionSchema, rateRevisionSchema } from './revisionTypes'
import { statusSchema } from './statusType'
import { updateInfoSchema } from './updateInfoType'

Expand All @@ -27,7 +22,7 @@ const contractWithoutDraftRatesSchema = z.object({
draftRevision: contractRevisionSchema.optional(),

// All revisions are submitted and in reverse chronological order
revisions: z.array(contractRevisionWithRatesSchema),
revisions: z.array(contractRevisionSchema),

packageSubmissions: z.array(contractPackageSubmissionSchema),
})
Expand All @@ -47,9 +42,8 @@ const rateWithoutDraftContractsSchema = z.object({
withdrawInfo: updateInfoSchema.optional(),
// If this rate is in a DRAFT or UNLOCKED status, there will be a draftRevision
draftRevision: rateRevisionSchema.optional(),
// draftContracts: rateDraftContracts,
// All revisions are submitted and in reverse chronological order
revisions: z.array(rateRevisionWithContractsSchema),
revisions: z.array(rateRevisionSchema),

packageSubmissions: z.array(ratePackageSubmissionSchema),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { z } from 'zod'
import {
contractRevisionSchema,
contractRevisionWithRatesSchema,
} from './revisionTypes'
import { contractRevisionSchema } from './revisionTypes'
import { unlockedContractStatusSchema } from './statusType'
import { pruneDuplicateEmails } from '../../emailer/formatters'
import {
Expand All @@ -23,8 +20,8 @@ const unlockedContractSchema = contractSchema.extend({

const draftContractSchema = contractSchema.extend({
status: z.literal('DRAFT'),
draftRevision: contractRevisionWithRatesSchema,
revisions: z.array(contractRevisionWithRatesSchema).min(1),
draftRevision: contractRevisionSchema,
revisions: z.array(contractRevisionSchema).min(1),
})

type ContractType = z.infer<typeof contractSchema>
Expand All @@ -43,7 +40,6 @@ function contractSubmitters(contract: ContractType): string[] {
}

export {
contractRevisionWithRatesSchema,
unlockedContractSchema,
draftContractSchema,
contractSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ function convertContractToDraftRateRevisions(contract: ContractType) {
function convertContractWithRatesToUnlockedHPP(
contract: ContractType
): HealthPlanPackageType | Error {
// Since drafts come in separate on the Contract type, we push it onto the revisions before converting below
if (contract.draftRevision) {
const rateRevisions = convertContractToDraftRateRevisions(contract)
contract.revisions.unshift({ ...contract.draftRevision, rateRevisions })
}

const healthPlanRevisions = convertContractWithRatesRevtoHPPRev(contract)

if (healthPlanRevisions instanceof Error) {
Expand All @@ -55,10 +49,51 @@ function convertContractWithRatesRevtoHPPRev(
contract: ContractType
): HealthPlanRevisionType[] | Error {
let healthPlanRevisions: HealthPlanRevisionType[] | Error = []
for (const contractRev of contract.revisions) {

if (contract.draftRevision && contract.draftRates) {
const contractRev = contract.draftRevision
const rateRevisions = convertContractToDraftRateRevisions(contract)

const unlockedHealthPlanFormData = convertContractWithRatesToFormData(
contractRev,
rateRevisions,
contract.id,
contract.stateCode,
contract.stateNumber
)

if (unlockedHealthPlanFormData instanceof Error) {
return unlockedHealthPlanFormData
}

const formDataProto = toProtoBuffer(unlockedHealthPlanFormData)

const healthPlanRevision: HealthPlanRevisionType = {
id: contractRev.id,
unlockInfo: contractRev.unlockInfo,
submitInfo: contractRev.submitInfo,
createdAt: contractRev.createdAt,
formDataProto,
}

healthPlanRevisions.push(healthPlanRevision)
}

// Convert a list of package submissions into a list of pkg revisions
let lastSeenContractRevID: string | undefined = undefined
for (const submission of contract.packageSubmissions) {
const contractRev = submission.contractRevision
if (contractRev.id === lastSeenContractRevID) {
continue
}

// otherwise, this is a new contract rev so we add a new rev to the history.
// this is lossy, our HPP revs don't map 1:1 to package submissions. Temporary.
lastSeenContractRevID = contractRev.id

const unlockedHealthPlanFormData = convertContractWithRatesToFormData(
contractRev,
contractRev.rateRevisions,
submission.rateRevisions,
contract.id,
contract.stateCode,
contract.stateNumber
Expand Down
14 changes: 2 additions & 12 deletions services/app-api/src/domain-models/contractAndRates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ export {

export { contractFormDataSchema, rateFormDataSchema } from './formDataTypes'

export {
rateRevisionWithContractsSchema,
contractRevisionWithRatesSchema,
contractRevisionSchema,
rateRevisionSchema,
} from './revisionTypes'
export { contractRevisionSchema, rateRevisionSchema } from './revisionTypes'

export { statusSchema } from './statusType'

Expand All @@ -37,12 +32,7 @@ export type {
ContractFormEditableType,
} from './formDataTypes'

export type {
ContractRevisionType,
RateRevisionType,
RateRevisionWithContractsType,
ContractRevisionWithRatesType,
} from './revisionTypes'
export type { ContractRevisionType, RateRevisionType } from './revisionTypes'

export type {
ContractPackageSubmissionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import {
contractWithoutDraftRatesSchema,
rateWithoutDraftContractsSchema,
} from './baseContractRateTypes'
import {
rateRevisionWithContractsSchema,
rateRevisionSchema,
} from './revisionTypes'
import { rateRevisionSchema } from './revisionTypes'

const rateSchema = rateWithoutDraftContractsSchema.extend({
draftContracts: z.array(contractWithoutDraftRatesSchema).optional(),
})

type RateType = z.infer<typeof rateSchema>

export { rateRevisionSchema, rateRevisionWithContractsSchema, rateSchema }
export { rateRevisionSchema, rateSchema }

export type { RateType }
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,9 @@ const rateRevisionSchema = z.object({
formData: rateFormDataSchema,
})

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

const contractRevisionWithRatesSchema = contractRevisionSchema.extend({
rateRevisions: z.array(rateRevisionSchema),
})

type ContractRevisionType = z.infer<typeof contractRevisionSchema>
type RateRevisionType = z.infer<typeof rateRevisionSchema>
type RateRevisionWithContractsType = z.infer<
typeof rateRevisionWithContractsSchema
>
type ContractRevisionWithRatesType = z.infer<
typeof contractRevisionWithRatesSchema
>

export {
rateRevisionWithContractsSchema,
contractRevisionWithRatesSchema,
contractRevisionSchema,
rateRevisionSchema,
}
export { contractRevisionSchema, rateRevisionSchema }

export type {
ContractRevisionType,
RateRevisionType,
RateRevisionWithContractsType,
ContractRevisionWithRatesType,
}
export type { ContractRevisionType, RateRevisionType }
2 changes: 0 additions & 2 deletions services/app-api/src/domain-models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ export {
export type {
ContractType,
ContractRevisionType,
ContractRevisionWithRatesType,
ContractFormDataType,
RateType,
RateRevisionType,
RateRevisionWithContractsType,
RateFormDataType,
PackageStatusType,
ContractPackageSubmissionType,
Expand Down
15 changes: 8 additions & 7 deletions services/app-api/src/emailer/emailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import type {
import type {
UpdateInfoType,
ProgramType,
ContractRevisionWithRatesType,
Question,
ContractRevisionType,
UnlockedContractType,
} from '../domain-models'
import { SESServiceException } from '@aws-sdk/client-ses'

Expand Down Expand Up @@ -84,13 +85,13 @@ type Emailer = {
statePrograms: ProgramType[]
) => Promise<void | Error>
sendUnlockContractCMSEmail: (
contractRev: ContractRevisionWithRatesType,
contract: UnlockedContractType,
updateInfo: UpdateInfoType,
stateAnalystsEmails: StateAnalystsEmails,
statePrograms: ProgramType[]
) => Promise<void | Error>
sendUnlockContractStateEmail: (
contractRev: ContractRevisionWithRatesType,
contract: UnlockedContractType,
updateInfo: UpdateInfoType,
statePrograms: ProgramType[],
submitterEmails: string[]
Expand Down Expand Up @@ -120,26 +121,26 @@ type Emailer = {
statePrograms: ProgramType[]
) => Promise<void | Error>
sendQuestionsStateEmail: (
contract: ContractRevisionWithRatesType,
contract: ContractRevisionType,
submitterEmails: string[],
statePrograms: ProgramType[],
question: Question
) => Promise<void | Error>
sendQuestionsCMSEmail: (
contract: ContractRevisionWithRatesType,
contract: ContractRevisionType,
stateAnalystsEmails: StateAnalystsEmails,
statePrograms: ProgramType[],
questions: Question[]
) => Promise<void | Error>
sendQuestionResponseCMSEmail: (
contractRevision: ContractRevisionWithRatesType,
contractRevision: ContractRevisionType,
statePrograms: ProgramType[],
stateAnalystsEmails: StateAnalystsEmails,
currentQuestion: Question,
allContractQuestions: Question[]
) => Promise<void | Error>
sendQuestionResponseStateEmail: (
contractRevision: ContractRevisionWithRatesType,
contractRevision: ContractRevisionType,
statePrograms: ProgramType[],
submitterEmails: string[],
currentQuestion: Question,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`unlockPackageCMSEmail renders overall email as expected 1`] = `
"Submission MCR-MN-0003-SNBC was unlocked<br />
"Submission MCR-MN-0004-SNBC was unlocked<br />
<br />
<b>Unlocked by:</b> leslie@example.com<br />
<b>Unlocked on:</b> 01/01/2022<br />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders overall email as expected 1`] = `
"Submission MCR-MN-0003-SNBC was unlocked by CMS<br />
"Submission MCR-MN-0004-SNBC was unlocked by CMS<br />
<br />
<b>Unlocked by:</b> josh@example.com<br />
<b>Unlocked on:</b> 02/01/2022<br />
Expand Down
4 changes: 2 additions & 2 deletions services/app-api/src/emailer/emails/sendQuestionCMSEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
getQuestionRound,
} from '../templateHelpers'
import { submissionQuestionResponseURL } from '../generateURLs'
import type { ContractRevisionWithRatesType } from '../../domain-models/contractAndRates'
import type { ContractRevisionType } from '../../domain-models/contractAndRates'

export const sendQuestionCMSEmail = async (
contractRev: ContractRevisionWithRatesType,
contractRev: ContractRevisionType,
stateAnalystsEmails: StateAnalystsEmails,
config: EmailConfiguration,
statePrograms: ProgramType[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
getQuestionRound,
} from '../templateHelpers'
import { submissionQuestionResponseURL } from '../generateURLs'
import type { ContractRevisionWithRatesType } from '../../domain-models/contractAndRates'
import type { ContractRevisionType } from '../../domain-models/contractAndRates'
import type { StateAnalystsEmails } from '..'

export const sendQuestionResponseCMSEmail = async (
contractRev: ContractRevisionWithRatesType,
contractRev: ContractRevisionType,
config: EmailConfiguration,
statePrograms: ProgramType[],
stateAnalystsEmails: StateAnalystsEmails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../../testHelpers/emailerHelpers'
import type {
CMSUserType,
ContractRevisionWithRatesType,
ContractRevisionType,
StateType,
} from '../../domain-models'
import type { ContractFormDataType, Question } from '../../domain-models'
Expand Down Expand Up @@ -126,7 +126,7 @@ test('to addresses list includes submitter emails', async () => {
})

test('to addresses list includes all state contacts on submission', async () => {
const sub: ContractRevisionWithRatesType = {
const sub: ContractRevisionType = {
...mockContractRev({ formData }),
}
const defaultStatePrograms = mockMNState().programs
Expand Down Expand Up @@ -169,7 +169,7 @@ test('to addresses list does not include duplicate state receiver emails on subm
],
}

const sub: ContractRevisionWithRatesType = mockContractRev({
const sub: ContractRevisionType = mockContractRev({
formData: formDataWithDuplicateStateContacts,
})
const defaultStatePrograms = mockMNState().programs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
getQuestionRound,
} from '../templateHelpers'
import { submissionQuestionResponseURL } from '../generateURLs'
import type { ContractRevisionWithRatesType } from '../../domain-models/contractAndRates'
import type { ContractRevisionType } from '../../domain-models/contractAndRates'

export const sendQuestionResponseStateEmail = async (
contractRev: ContractRevisionWithRatesType,
contractRev: ContractRevisionType,
config: EmailConfiguration,
submitterEmails: string[],
statePrograms: ProgramType[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../../testHelpers/emailerHelpers'
import type {
CMSUserType,
ContractRevisionWithRatesType,
ContractRevisionType,
StateType,
} from '../../domain-models'
import type { ContractFormDataType, Question } from '../../domain-models'
Expand Down Expand Up @@ -122,7 +122,7 @@ test('to addresses list includes submitter emails', async () => {
})

test('to addresses list includes all state contacts on submission', async () => {
const sub: ContractRevisionWithRatesType = {
const sub: ContractRevisionType = {
...mockContractRev({ formData }),
}
const defaultStatePrograms = mockMNState().programs
Expand Down Expand Up @@ -164,7 +164,7 @@ test('to addresses list does not include duplicate state receiver emails on subm
],
}

const sub: ContractRevisionWithRatesType = mockContractRev({
const sub: ContractRevisionType = mockContractRev({
formData: formDataWithDuplicateStateContacts,
})
const defaultStatePrograms = mockMNState().programs
Expand Down
Loading
Loading