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

Connect QA to Contracts #2027

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,17 @@
BEGIN;

ALTER TABLE "Question" ADD COLUMN "contractID" TEXT;

-- AddForeignKey
ALTER TABLE "Question" ADD CONSTRAINT "Question_contractID_fkey" FOREIGN KEY ("contractID") REFERENCES "ContractTable"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- migrate data over
UPDATE "Question" SET "contractID"="pkgID";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where we copy all the pkgIDs into contractIDs

The way this works is that we don't add the NOT NULL constraint until after we copy this over.
then we can safely drop the pkgID column


-- make not nullable, drop pkgID
ALTER TABLE "Question"
ALTER COLUMN "contractID" SET NOT NULL,
DROP CONSTRAINT "Question_pkgID_fkey",
DROP COLUMN "pkgID";

COMMIT;
55 changes: 28 additions & 27 deletions services/app-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ model HealthPlanPackageTable {
stateCode String
state State @relation(fields: [stateCode], references: [stateCode])
revisions HealthPlanRevisionTable[]
questions Question[]
}

model ProtoMigrationsTable {
Expand Down Expand Up @@ -41,9 +40,11 @@ model ContractTable {

mccrsID String?
stateCode String
state State @relation(fields: [stateCode], references: [stateCode])
state State @relation(fields: [stateCode], references: [stateCode])
stateNumber Int

questions Question[]

revisions ContractRevisionTable[]
// This relationship is a scam. We never call it in our code but Prisma
// requires that there be an inverse to RateRevision.draftContracts which we do use
Expand Down Expand Up @@ -72,8 +73,8 @@ model ContractRevisionTable {
contractID String
contract ContractTable @relation(fields: [contractID], references: [id])

rateRevisions RateRevisionsOnContractRevisionsTable[]
draftRates RateTable[]
rateRevisions RateRevisionsOnContractRevisionsTable[]
draftRates RateTable[]

unlockInfoID String?
unlockInfo UpdateInfoTable? @relation("unlockContractInfo", fields: [unlockInfoID], references: [id])
Expand Down Expand Up @@ -130,21 +131,21 @@ model RateRevisionTable {
submitInfoID String?
submitInfo UpdateInfoTable? @relation("submitRateInfo", fields: [submitInfoID], references: [id], onDelete: Cascade)

rateType RateType?
rateCapitationType RateCapitationType?
rateDocuments RateDocument[]
supportingDocuments RateSupportingDocument[]
rateDateStart DateTime? @db.Date
rateDateEnd DateTime? @db.Date
rateDateCertified DateTime? @db.Date
amendmentEffectiveDateStart DateTime? @db.Date
amendmentEffectiveDateEnd DateTime? @db.Date
rateProgramIDs String[]
rateCertificationName String?
certifyingActuaryContacts ActuaryContact[] @relation(name: "CertifyingActuaryOnRateRevision")
addtlActuaryContacts ActuaryContact[] @relation(name: "AddtlActuaryOnRateRevision")
actuaryCommunicationPreference ActuaryCommunication?
contractsWithSharedRateRevision ContractTable[] @relation(name: "SharedRateRevisions")
rateType RateType?
rateCapitationType RateCapitationType?
rateDocuments RateDocument[]
supportingDocuments RateSupportingDocument[]
rateDateStart DateTime? @db.Date
rateDateEnd DateTime? @db.Date
rateDateCertified DateTime? @db.Date
amendmentEffectiveDateStart DateTime? @db.Date
amendmentEffectiveDateEnd DateTime? @db.Date
rateProgramIDs String[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm maybe we need to build in prisma formatting into our precommit scripts. I've been noticing these kind of formatting difff on our prisma PRs over the last few months

rateCertificationName String?
certifyingActuaryContacts ActuaryContact[] @relation(name: "CertifyingActuaryOnRateRevision")
addtlActuaryContacts ActuaryContact[] @relation(name: "AddtlActuaryOnRateRevision")
actuaryCommunicationPreference ActuaryCommunication?
contractsWithSharedRateRevision ContractTable[] @relation(name: "SharedRateRevisions")
}

model RateRevisionsOnContractRevisionsTable {
Expand Down Expand Up @@ -291,12 +292,12 @@ model UserAudit {
}

model Question {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
pkgID String
pkg HealthPlanPackageTable @relation(fields: [pkgID], references: [id])
Copy link
Contributor

Choose a reason for hiding this comment

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

With these changes to Question and HealthPlanPackageTable, would we want to make a migration or drop the Q&A tables? I think this only applies to Val since it is the only environment that has existing Q&A records.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Take a closer look at that migration! All the Questions that were associated with HPP should now be associated with Contracts

addedBy User @relation(fields: [addedByUserID], references: [id])
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
contractID String
contract ContractTable @relation(fields: [contractID], references: [id])
addedBy User @relation(fields: [addedByUserID], references: [id])
addedByUserID String
division Division
documents QuestionDocument[]
Expand Down Expand Up @@ -327,10 +328,10 @@ model QuestionResponse {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
question Question @relation(fields: [questionID], references: [id])
addedBy User @relation(fields: [addedByUserID], references: [id])
questionID String
question Question @relation(fields: [questionID], references: [id])
addedByUserID String
addedBy User @relation(fields: [addedByUserID], references: [id])
documents QuestionResponseDocument[]
}

Expand Down
4 changes: 2 additions & 2 deletions services/app-api/src/domain-models/QuestionsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Document = {

type Question = {
id: string
pkgID: string
contractID: string
createdAt: Date
addedBy: CMSUserType
documents: Document[]
Expand Down Expand Up @@ -40,7 +40,7 @@ type CreateQuestionPayload = {
}

type CreateQuestionInput = {
pkgID: string
contractID: string
documents: Document[]
}

Expand Down
10 changes: 4 additions & 6 deletions services/app-api/src/postgres/postgresStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
insertManyUsers,
} from './user'
import {
findAllQuestionsByHealthPlanPackage,
findAllQuestionsByContract,
insertQuestion,
insertQuestionResponse,
} from './questionResponse'
Expand Down Expand Up @@ -139,9 +139,7 @@ type Store = {
user: CMSUserType
) => Promise<Question | StoreError>

findAllQuestionsByHealthPlanPackage: (
pkgID: string
) => Promise<Question[] | StoreError>
findAllQuestionsByContract: (pkgID: string) => Promise<Question[] | Error>

insertQuestionResponse: (
questionInput: InsertQuestionResponseArgs,
Expand Down Expand Up @@ -240,8 +238,8 @@ function NewPostgresStore(client: PrismaClient): Store {
findAllUsers: () => findAllUsers(client),
insertQuestion: (questionInput, user) =>
insertQuestion(client, questionInput, user),
findAllQuestionsByHealthPlanPackage: (pkgID) =>
findAllQuestionsByHealthPlanPackage(client, pkgID),
findAllQuestionsByContract: (pkgID) =>
findAllQuestionsByContract(client, pkgID),
insertQuestionResponse: (questionInput, user) =>
insertQuestionResponse(client, questionInput, user),
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import type {
Question,
QuestionResponseType,
} from '../../domain-models'
import type { StoreError } from '../storeError'
import { convertPrismaErrorToStoreError } from '../storeError'

export async function findAllQuestionsByHealthPlanPackage(
export async function findAllQuestionsByContract(
client: PrismaClient,
pkgID: string
): Promise<Question[] | StoreError> {
contractID: string
): Promise<Question[] | Error> {
try {
const findResult = await client.question.findMany({
where: {
pkgID: pkgID,
contractID: contractID,
},
include: {
documents: {
Expand Down Expand Up @@ -49,6 +47,10 @@ export async function findAllQuestionsByHealthPlanPackage(

return questions
} catch (e: unknown) {
return convertPrismaErrorToStoreError(e)
if (e instanceof Error) {
return e
}
console.error('Unknown object thrown by Prisma', e)
return new Error('Unknown object thrown by Prisma')
}
}
2 changes: 1 addition & 1 deletion services/app-api/src/postgres/questionResponse/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { findAllQuestionsByHealthPlanPackage } from './findAllQuestionsByHealthPlanPackage'
export { findAllQuestionsByContract } from './findAllQuestionsByContract'
export { insertQuestion } from './insertQuestion'
export { convertToIndexQuestionsPayload } from './questionHelpers'
export { insertQuestionResponse } from './insertQuestionResponse'
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export async function insertQuestion(
const result = await client.question.create({
data: {
id: uuidv4(),
pkg: {
contract: {
connect: {
id: questionInput.pkgID,
id: questionInput.contractID,
},
},
addedBy: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { protoToBase64 } from '../../../../app-web/src/common-code/proto/healthP
import statePrograms from '../../../../app-web/src/common-code/data/statePrograms.json'
import type { Resolvers } from '../../gen/gqlServer'
import type { Store } from '../../postgres'
import { isStoreError } from '../../postgres'
import { convertToIndexQuestionsPayload } from '../../postgres/questionResponse'
import { logError } from '../../logger'
import { setErrorAttributesOnActiveSpan } from '../attributeHelper'
Expand Down Expand Up @@ -59,15 +58,13 @@ export function healthPlanPackageResolver(
}
return state
},
questions: async (parent, args, context) => {
questions: async (parent, _args, context) => {
const { span } = context
const pkgID = parent.id
const result = await store.findAllQuestionsByHealthPlanPackage(
pkgID
)
const result = await store.findAllQuestionsByContract(pkgID)

if (isStoreError(result)) {
const errMessage = `Issue finding questions of type ${result.code} for package with id: ${pkgID}. Message: ${result.message}`
if (result instanceof Error) {
const errMessage = `Issue finding questions for package with id: ${pkgID}. Message: ${result.message}`
logError('indexQuestions', errMessage)
setErrorAttributesOnActiveSpan(errMessage, span)
throw new GraphQLError(errMessage, {
Expand Down
Loading
Loading