Skip to content

Commit

Permalink
write contract
Browse files Browse the repository at this point in the history
  • Loading branch information
rswerve committed Jul 22, 2023
1 parent 3e27efc commit 9a23d3c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
22 changes: 19 additions & 3 deletions services/app-api/src/handlers/proto_to_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { NewPostgresStore } from '../postgres/postgresStore'
import { Store } from '../postgres'
import { HealthPlanRevisionTable } from '@prisma/client'
import { isStoreError, StoreError } from '../postgres/storeError'
import { PrismaClient } from '@prisma/client'
import { createContractRevision } from '../postgres/contractAndRates/migrateContractData'

export const getDatabaseConnection = async (): Promise<Store> => {
export const getDatabaseConnection = async (): Promise<{
store: Store
client: PrismaClient
}> => {
const dbURL = process.env.DATABASE_URL
const secretsManagerSecret = process.env.SECRETS_MANAGER_SECRET

Expand All @@ -28,8 +33,9 @@ export const getDatabaseConnection = async (): Promise<Store> => {
console.info('Postgres configured in data exporter')
}
const store = NewPostgresStore(pgResult)
const client = new PrismaClient()

return store
return { store, client }
}

export const getRevisions = async (
Expand Down Expand Up @@ -64,9 +70,19 @@ export const main: Handler = async (
}

initMeter(serviceName)
const store = await getDatabaseConnection()
const { store, client } = await getDatabaseConnection()

const revisions = await getRevisions(store)

// Process all revisions
for (const revision of revisions) {
const result = await createContractRevision(client, revision)
if (result instanceof Error) {
console.error(
`Error creating contract revision for ${revision.id}: ${result.message}`
)
}
}
// Get the pkgID from the first revision in the list
const pkgID = revisions[0].pkgID
if (!pkgID) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
PrismaClient,
ContractRevisionTable,
HealthPlanRevisionTable,
ManagedCareEntity,
} from '@prisma/client'
import { UnlockedHealthPlanFormDataType } from 'app-web/src/common-code/healthPlanFormDataType'
import { toDomain } from 'app-web/src/common-code/proto/healthPlanFormDataProto'

async function createContractRevision(
client: PrismaClient,
revision: HealthPlanRevisionTable
): Promise<ContractRevisionTable | Error> {
try {
// Decode the formDataProto
const decodedFormDataProto = toDomain(revision.formDataProto)
if (decodedFormDataProto instanceof Error) throw decodedFormDataProto
const formData = decodedFormDataProto as UnlockedHealthPlanFormDataType

// Create ContractRevisionTable entry from HealthPlanRevisionTable entry
const contractRevision: ContractRevisionTable = {
id: formData.id,
contractID: revision.id, // Set contractID as revision.id
unlockInfoID: null,
submitInfoID: null,
createdAt: formData.createdAt,
updatedAt: formData.updatedAt,
submissionType: formData.submissionType,
submissionDescription: formData.submissionDescription,
programIDs: formData.programIDs,
populationCovered: formData.populationCovered || null,
riskBasedContract: formData.riskBasedContract || null,
contractType: formData.contractType || 'BASE',
contractExecutionStatus: formData.contractExecutionStatus || null,
contractDateStart: formData.contractDateStart || null,
contractDateEnd: formData.contractDateEnd || null,
managedCareEntities:
formData.managedCareEntities as ManagedCareEntity[],
federalAuthorities: formData.federalAuthorities,
modifiedBenefitsProvided: null,
modifiedGeoAreaServed: null,
modifiedMedicaidBeneficiaries: null,
modifiedRiskSharingStrategy: null,
modifiedIncentiveArrangements: null,
modifiedWitholdAgreements: null,
modifiedStateDirectedPayments: null,
modifiedPassThroughPayments: null,
modifiedPaymentsForMentalDiseaseInstitutions: null,
modifiedMedicalLossRatioStandards: null,
modifiedOtherFinancialPaymentIncentive: null,
modifiedEnrollmentProcess: null,
modifiedGrevienceAndAppeal: null,
modifiedNetworkAdequacyStandards: null,
modifiedLengthOfContract: null,
modifiedNonRiskPaymentArrangements: null,
inLieuServicesAndSettings: null,
}

const createdContractRevision =
await client.contractRevisionTable.create({
data: contractRevision,
})

return createdContractRevision
} catch (error) {
console.error(
`Error creating contract revision ${JSON.stringify(error)}`
)
return new Error('Error creating contract revision')
}
}

export { createContractRevision }

0 comments on commit 9a23d3c

Please sign in to comment.