diff --git a/backend/src/database/data.js b/backend/src/database/data.js index 873fb05..5a395ce 100644 --- a/backend/src/database/data.js +++ b/backend/src/database/data.js @@ -1,21 +1,25 @@ export const medicationRequestToRemsAdmins = Object.freeze([ { rxnorm: 2183126, + ndc: '65597-407-20', display: 'Turalio 200 MG Oral Capsule', remsAdminFhirUrl: process.env.REMS_ADMIN_FHIR_URL || 'http://localhost:8090/4_0_0' }, { rxnorm: 6064, + ndc: '0245-0571-01', display: 'Isotretinoin 20 MG Oral Capsule', remsAdminFhirUrl: process.env.REMS_ADMIN_FHIR_URL || 'http://localhost:8090/4_0_0' }, { rxnorm: 1237051, + ndc: '63459-502-30', display: 'TIRF 200 UG Oral Transmucosal Lozenge', remsAdminFhirUrl: process.env.REMS_ADMIN_FHIR_URL || 'http://localhost:8090/4_0_0' }, { rxnorm: 1666386, + ndc: '58604-214-30', display: 'Addyi 100 MG Oral Tablet', remsAdminFhirUrl: process.env.REMS_ADMIN_FHIR_URL || 'http://localhost:8090/4_0_0' } diff --git a/backend/src/routes/doctorOrders.js b/backend/src/routes/doctorOrders.js index c0f46b7..a7d101e 100644 --- a/backend/src/routes/doctorOrders.js +++ b/backend/src/routes/doctorOrders.js @@ -249,9 +249,17 @@ router.delete('/api/deleteAll', async (req, res) => { }); const isRemsDrug = order => { - return medicationRequestToRemsAdmins.some( - entry => Number(order.drugRxnormCode) === Number(entry.rxnorm) - ); + return medicationRequestToRemsAdmins.some(entry => { + if (order.drugNdcCode && entry.ndc) { + return order.drugNdcCode === entry.ndc; + } + + if (order.drugRxnormCode && entry.rxnorm) { + return Number(order.drugRxnormCode) === Number(entry.rxnorm); + } + + return false; + }); }; const getEtasuUrl = order => { @@ -260,9 +268,16 @@ const getEtasuUrl = order => { if (env.USE_INTERMEDIARY) { baseUrl = env.INTERMEDIARY_FHIR_URL; } else { - const rxnorm = order.drugRxnormCode; const remsDrug = medicationRequestToRemsAdmins.find(entry => { - return Number(rxnorm) === Number(entry.rxnorm); + if (order.drugNdcCode && entry.ndc) { + return order.drugNdcCode === entry.ndc; + } + + if (order.drugRxnormCode && entry.rxnorm) { + return Number(order.drugRxnormCode) === Number(entry.rxnorm); + } + + return false; }); baseUrl = remsDrug?.remsAdminFhirUrl; } @@ -291,6 +306,36 @@ const getGuidanceResponse = async order => { ] }; } else { + let medicationCoding = []; + + if (order.drugNdcCode) { + medicationCoding.push({ + system: 'http://hl7.org/fhir/sid/ndc', + code: order.drugNdcCode, + display: order.drugNames + }); + } + + if (order.drugRxnormCode) { + medicationCoding.push({ + system: 'http://www.nlm.nih.gov/research/umls/rxnorm', + code: order.drugRxnormCode, + display: order.drugNames + }); + } else { + const remsDrug = medicationRequestToRemsAdmins.find(entry => { + return order.drugNdcCode && entry.ndc && order.drugNdcCode === entry.ndc; + }); + + if (remsDrug && remsDrug.rxnorm) { + medicationCoding.push({ + system: 'http://www.nlm.nih.gov/research/umls/rxnorm', + code: remsDrug.rxnorm.toString(), + display: order.drugNames + }); + } + } + body = { resourceType: 'Parameters', parameter: [ @@ -315,13 +360,7 @@ const getGuidanceResponse = async order => { resourceType: 'Medication', id: order.prescriberOrderNumber, code: { - coding: [ - { - system: 'http://www.nlm.nih.gov/research/umls/rxnorm', - code: order.drugRxnormCode, - display: order.drugNames - } - ] + coding: medicationCoding } } } @@ -356,7 +395,7 @@ const getDispenseStatus = (order, guidanceResponse) => { * Return : Mongoose schema of a newOrder */ async function parseNCPDPScript(newRx) { - // Parsing XML NCPDP SCRIPT from EHR + // Parsing XML NCPDP SCRIPT from EHR const incompleteOrder = { orderId: newRx.Message.Header.MessageID.toString(), // Will need to return to this and use actual pt identifier or uuid caseNumber: newRx.Message.Header.AuthorizationNumber, @@ -385,8 +424,15 @@ async function parseNCPDPScript(newRx) { newRx.Message.Body.NewRx.Prescriber.NonVeterinarian.CommunicationNumbers.ElectronicMail, drugNames: newRx.Message.Body.NewRx.MedicationPrescribed.DrugDescription, simpleDrugName: newRx.Message.Body.NewRx.MedicationPrescribed.DrugDescription.split(' ')[0], - drugNdcCode: newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.ProductCode.Code, - drugRxnormCode: newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.DrugDBCode.Code, + + drugNdcCode: + newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.ProductCode?.Code || + newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.NDC || + null, + + drugRxnormCode: + newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.DrugDBCode?.Code || null, + rxDate: newRx.Message.Body.NewRx.MedicationPrescribed.WrittenDate.Date, drugPrice: 200, // Add later? quantities: newRx.Message.Body.NewRx.MedicationPrescribed.Quantity.Value,