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

MR-3186: migrate indexhpp resolver #1890

Merged
merged 18 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 16 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
2 changes: 0 additions & 2 deletions services/app-api/src/domain-models/healthPlanPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ function packageSubmitters(pkg: HealthPlanPackageType): string[] {
function convertContractToUnlockedHealthPlanPackage(
contract: ContractType
): HealthPlanPackageType | Error {
console.info('Attempting to convert contract to health plan package')

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: file organization - this function takes parameter from the rates refactor (ContractType) whereas everything else in this file is about the domain model HPP and takes HPP related arguments. Should be separate file in domain models.

Copy link
Contributor Author

@JasonLin0991 JasonLin0991 Aug 29, 2023

Choose a reason for hiding this comment

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

Agreed, I could see this being in domain-models/contractAndRates in some file that contains all the converter functions we will have. I think though, I want to punt this to your ticket. I think you have to make converter functions for locked HPP. Maybe you could find a good home and name for this file.

// 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { PrismaTransactionType } from '../prismaTypes'
import type { ContractType } from '../../domain-models/contractAndRates'
import { NotFoundError } from '../storeError'
import { parseContractWithHistory } from './parseContractWithHistory'
import { includeFullContract } from './prismaSubmittedContractHelpers'

type ContractOrErrorType = {
contractID: string
contract: ContractType | Error
}

type ContractOrErrorArrayType = ContractOrErrorType[]

async function findAllContractsWithHistoryByState(
client: PrismaTransactionType,
stateCode: string
): Promise<ContractOrErrorArrayType | NotFoundError | Error> {
try {
const contracts = await client.contractTable.findMany({
where: {
stateCode: {
equals: stateCode,
},
},
include: includeFullContract,
})

if (!contracts) {
const err = `PRISMA ERROR: Cannot find contracts with state code: ${stateCode}`
console.error(err)
return new NotFoundError(err)
}

const parsedContractsOrErrors: ContractOrErrorArrayType = contracts.map(
(contract) => ({
contractID: contract.id,
contract: parseContractWithHistory(contract),
})
)

return parsedContractsOrErrors
} catch (err) {
console.error('PRISMA ERROR', err)
return err
}
}

export { findAllContractsWithHistoryByState }
export type { ContractOrErrorArrayType }
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { findAllContractsWithHistoryBySubmitInfo } from './findAllContractsWithHistoryBySubmitInfo'
import { sharedTestPrismaClient } from '../../testHelpers/storeHelpers'
import { createInsertContractData, must } from '../../testHelpers'
import { v4 as uuidv4 } from 'uuid'
import { insertDraftContract } from './insertContract'
import { submitContract } from './submitContract'
import { unlockContract } from './unlockContract'

describe('findAllContractsWithHistoryBySubmittedInfo', () => {
it('returns only contracts that have been submitted or unlocked', async () => {
const client = await sharedTestPrismaClient()
const stateUser = await client.user.create({
data: {
id: uuidv4(),
givenName: 'Aang',
familyName: 'Avatar',
email: 'aang@example.com',
role: 'STATE_USER',
stateCode: 'NM',
},
})

const cmsUser = await client.user.create({
data: {
id: uuidv4(),
givenName: 'Zuko',
familyName: 'Hotman',
email: 'zuko@example.com',
role: 'CMS_USER',
},
})

const draftContractData = createInsertContractData({
submissionDescription: 'one contract',
})

// make two submitted contracts and submit them
const contractOne = must(
await insertDraftContract(client, draftContractData)
)
const contractTwo = must(
await insertDraftContract(client, draftContractData)
)
const submittedContractOne = must(
await submitContract(
client,
contractOne.id,
stateUser.id,
'contractOne submit'
)
)
const submittedContractTwo = must(
await submitContract(
client,
contractTwo.id,
stateUser.id,
'contractTwo submit'
)
)

// make two draft contracts
const draftContractOne = must(
await insertDraftContract(client, draftContractData)
)
const draftContractTwo = must(
await insertDraftContract(client, draftContractData)
)

// make one unlocked contract
const contractThree = must(
await insertDraftContract(client, draftContractData)
)
must(
await submitContract(
client,
contractThree.id,
stateUser.id,
'unlockContractOne submit'
)
)
const unlockedContract = must(
await unlockContract(
client,
contractThree.id,
cmsUser.id,
'unlock unlockContractOne'
)
)

// call the find by submit info function
const contracts = must(
await findAllContractsWithHistoryBySubmitInfo(client)
)

// expect our two submitted contracts
expect(contracts).toEqual(
expect.arrayContaining([
expect.objectContaining({
contractID: submittedContractOne.id,
}),
expect.objectContaining({
contractID: submittedContractTwo.id,
}),
])
)

// expect our one unlocked contract
expect(contracts).toEqual(
expect.arrayContaining([
expect.objectContaining({
contractID: unlockedContract.id,
}),
])
)

// expect our two draft contracts to not be in the results
expect(contracts).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
contractID: draftContractOne.id,
}),
expect.objectContaining({
contractID: draftContractTwo.id,
}),
])
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { PrismaTransactionType } from '../prismaTypes'
import { NotFoundError } from '../storeError'
import { parseContractWithHistory } from './parseContractWithHistory'
import { includeFullContract } from './prismaSubmittedContractHelpers'
import type { ContractOrErrorArrayType } from './findAllContractsWithHistoryByState'

async function findAllContractsWithHistoryBySubmitInfo(
client: PrismaTransactionType
): Promise<ContractOrErrorArrayType | NotFoundError | Error> {
try {
const contracts = await client.contractTable.findMany({
where: {
revisions: {
some: {
submitInfo: {
isNot: null,
},
},
},
stateCode: {
not: 'AS', // exclude test state as per ADR 019
},
},
include: includeFullContract,
})

if (!contracts) {
const err = `PRISMA ERROR: Cannot find all contracts by submit info`
console.error(err)
return new NotFoundError(err)
}

const parsedContracts: ContractOrErrorArrayType = contracts.map(
(contract) => ({
contractID: contract.id,
contract: parseContractWithHistory(contract),
})
)

return parsedContracts
} catch (err) {
console.error('PRISMA ERROR', err)
return err
}
}

export { findAllContractsWithHistoryBySubmitInfo }
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ describe('findRate', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'a.1 body',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
},
Expand Down Expand Up @@ -491,7 +491,7 @@ describe('findRate', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'a.2 body',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
},
Expand Down Expand Up @@ -532,7 +532,7 @@ describe('findRate', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'one contract',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
})
Expand All @@ -549,7 +549,7 @@ describe('findRate', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'one contract',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
})
Expand All @@ -567,7 +567,7 @@ describe('findRate', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'a.1 body',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
})
Expand Down
3 changes: 3 additions & 0 deletions services/app-api/src/postgres/contractAndRates/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export type { InsertContractArgsType } from './insertContract'
export type { UpdateContractArgsType } from './updateDraftContract'
export type { ContractOrErrorArrayType } from './findAllContractsWithHistoryByState'
export { insertDraftContract } from './insertContract'
export { findContractWithHistory } from './findContractWithHistory'
export { updateDraftContract } from './updateDraftContract'
export { findAllContractsWithHistoryByState } from './findAllContractsWithHistoryByState'
export { findAllContractsWithHistoryBySubmitInfo } from './findAllContractsWithHistoryBySubmitInfo'
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('insertContract', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'Contract 1.0',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
}),
Expand Down Expand Up @@ -83,6 +83,7 @@ describe('insertContract', () => {

const draftContractData = createInsertContractData({
stateCode: 'CANADA' as StateCodeType,
programIDs: [],
})
const draftContract = await insertDraftContract(
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('submitContract', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'one contract',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
}),
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('submitContract', () => {
submissionType: 'CONTRACT_AND_RATES',
submissionDescription: 'second contract revision',
contractType: 'BASE',
programIDs: ['PMAP'],
programIDs: draftContractData.programIDs,
populationCovered: 'MEDICAID',
riskBasedContract: false,
},
Expand Down
15 changes: 15 additions & 0 deletions services/app-api/src/postgres/postgresStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ import {
insertDraftContract,
findContractWithHistory,
updateDraftContract,
findAllContractsWithHistoryByState,
findAllContractsWithHistoryBySubmitInfo,
} from './contractAndRates'
import type {
InsertContractArgsType,
UpdateContractArgsType,
ContractOrErrorArrayType,
} from './contractAndRates'

type Store = {
Expand Down Expand Up @@ -145,6 +148,14 @@ type Store = {
updateDraftContract: (
args: UpdateContractArgsType
) => Promise<ContractType | Error>

findAllContractsWithHistoryByState: (
stateCode: string
) => Promise<ContractOrErrorArrayType | Error>

findAllContractsWithHistoryBySubmitInfo: () => Promise<
ContractOrErrorArrayType | Error
>
}

function NewPostgresStore(client: PrismaClient): Store {
Expand Down Expand Up @@ -206,6 +217,10 @@ function NewPostgresStore(client: PrismaClient): Store {
findContractWithHistory: (args) =>
findContractWithHistory(client, args),
updateDraftContract: (args) => updateDraftContract(client, args),
findAllContractsWithHistoryByState: (args) =>
findAllContractsWithHistoryByState(client, args),
findAllContractsWithHistoryBySubmitInfo: () =>
findAllContractsWithHistoryBySubmitInfo(client),
}
}

Expand Down
5 changes: 4 additions & 1 deletion services/app-api/src/resolvers/configureResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export function configureResolvers(
store,
launchDarkly
),
indexHealthPlanPackages: indexHealthPlanPackagesResolver(store),
indexHealthPlanPackages: indexHealthPlanPackagesResolver(
store,
launchDarkly
),
indexUsers: indexUsersResolver(store),
indexQuestions: indexQuestionsResolver(store),
fetchEmailSettings: fetchEmailSettingsResolver(
Expand Down
Loading
Loading