From 335e93648362a5c428194399d7a6d85d9fe4eeb3 Mon Sep 17 00:00:00 2001 From: Patrick LaRocque Date: Thu, 19 Jun 2025 17:01:42 -0400 Subject: [PATCH 1/2] Handle the case where there is no DrugDescription in the NewRx message. --- backend/src/routes/doctorOrders.js | 51 ++++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/backend/src/routes/doctorOrders.js b/backend/src/routes/doctorOrders.js index a7d101e..8646ae0 100644 --- a/backend/src/routes/doctorOrders.js +++ b/backend/src/routes/doctorOrders.js @@ -396,51 +396,60 @@ const getDispenseStatus = (order, guidanceResponse) => { */ async function parseNCPDPScript(newRx) { // Parsing XML NCPDP SCRIPT from EHR + const patient = newRx.Message.Body.NewRx.Patient; + const prescriber = newRx.Message.Body.NewRx.Prescriber; + const medicationPrescribed = newRx.Message.Body.NewRx.MedicationPrescribed; + 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, prescriberOrderNumber: newRx.Message.Header.PrescriberOrderNumber, patientName: - newRx.Message.Body.NewRx.Patient.HumanPatient.Name.FirstName + + patient.HumanPatient.Name.FirstName + ' ' + - newRx.Message.Body.NewRx.Patient.HumanPatient.Name.LastName, - patientFirstName: newRx.Message.Body.NewRx.Patient.HumanPatient.Name.FirstName, - patientLastName: newRx.Message.Body.NewRx.Patient.HumanPatient.Name.LastName, - patientDOB: newRx.Message.Body.NewRx.Patient.HumanPatient.DateOfBirth.Date, - patientCity: newRx.Message.Body.NewRx.Patient.HumanPatient.Address.City, - patientStateProvince: newRx.Message.Body.NewRx.Patient.HumanPatient.Address.StateProvince, - patientPostalCode: newRx.Message.Body.NewRx.Patient.HumanPatient.Address.PostalCode, - patientCountry: newRx.Message.Body.NewRx.Patient.HumanPatient.Address.Country, + patient.HumanPatient.Name.LastName, + patientFirstName: patient.HumanPatient.Name.FirstName, + patientLastName: patient.HumanPatient.Name.LastName, + patientDOB: patient.HumanPatient.DateOfBirth.Date, + patientCity: patient.HumanPatient.Address.City, + patientStateProvince: patient.HumanPatient.Address.StateProvince, + patientPostalCode: patient.HumanPatient.Address.PostalCode, + patientCountry: patient.HumanPatient.Address.Country, doctorName: 'Dr. ' + - newRx.Message.Body.NewRx.Prescriber.NonVeterinarian.Name.FirstName + + prescriber.NonVeterinarian.Name.FirstName + ' ' + - newRx.Message.Body.NewRx.Prescriber.NonVeterinarian.Name.LastName, + prescriber.NonVeterinarian.Name.LastName, doctorContact: - newRx.Message.Body.NewRx.Prescriber.NonVeterinarian.CommunicationNumbers.PrimaryTelephone + prescriber.NonVeterinarian.CommunicationNumbers.PrimaryTelephone ?.Number, - doctorID: newRx.Message.Body.NewRx.Prescriber.NonVeterinarian.Identification.NPI, + doctorID: prescriber.NonVeterinarian.Identification.NPI, doctorEmail: - newRx.Message.Body.NewRx.Prescriber.NonVeterinarian.CommunicationNumbers.ElectronicMail, - drugNames: newRx.Message.Body.NewRx.MedicationPrescribed.DrugDescription, - simpleDrugName: newRx.Message.Body.NewRx.MedicationPrescribed.DrugDescription.split(' ')[0], + prescriber.NonVeterinarian.CommunicationNumbers.ElectronicMail, + drugNames: medicationPrescribed.DrugDescription, + simpleDrugName: medicationPrescribed.DrugDescription?.split(' ')[0], drugNdcCode: - newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.ProductCode?.Code || - newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.NDC || + medicationPrescribed.DrugCoded.ProductCode?.Code || + medicationPrescribed.DrugCoded.NDC || null, drugRxnormCode: - newRx.Message.Body.NewRx.MedicationPrescribed.DrugCoded.DrugDBCode?.Code || null, + medicationPrescribed.DrugCoded.DrugDBCode?.Code || null, - rxDate: newRx.Message.Body.NewRx.MedicationPrescribed.WrittenDate.Date, + rxDate: medicationPrescribed.WrittenDate.Date, drugPrice: 200, // Add later? - quantities: newRx.Message.Body.NewRx.MedicationPrescribed.Quantity.Value, + quantities: medicationPrescribed.Quantity.Value, total: 1800, pickupDate: 'Tue Dec 13 2022', // Add later? dispenseStatus: 'Pending' }; + if (incompleteOrder.drugNames === undefined || incompleteOrder.drugNames === 'undefined') { + incompleteOrder.drugNames = incompleteOrder.drugNdcCode; + incompleteOrder.simpleDrugName = incompleteOrder.drugNdcCode; + } + const metRequirements = isRemsDrug(incompleteOrder) ? [] : null; const order = new doctorOrder({ ...incompleteOrder, metRequirements }); return order; From 270a7e482a7b5cbaddbb830a658e6ce313c85abc Mon Sep 17 00:00:00 2001 From: Patrick LaRocque Date: Tue, 1 Jul 2025 14:41:43 -0400 Subject: [PATCH 2/2] run prettier --- backend/src/routes/doctorOrders.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/backend/src/routes/doctorOrders.js b/backend/src/routes/doctorOrders.js index 8646ae0..9af2b78 100644 --- a/backend/src/routes/doctorOrders.js +++ b/backend/src/routes/doctorOrders.js @@ -404,10 +404,7 @@ async function parseNCPDPScript(newRx) { orderId: newRx.Message.Header.MessageID.toString(), // Will need to return to this and use actual pt identifier or uuid caseNumber: newRx.Message.Header.AuthorizationNumber, prescriberOrderNumber: newRx.Message.Header.PrescriberOrderNumber, - patientName: - patient.HumanPatient.Name.FirstName + - ' ' + - patient.HumanPatient.Name.LastName, + patientName: patient.HumanPatient.Name.FirstName + ' ' + patient.HumanPatient.Name.LastName, patientFirstName: patient.HumanPatient.Name.FirstName, patientLastName: patient.HumanPatient.Name.LastName, patientDOB: patient.HumanPatient.DateOfBirth.Date, @@ -420,12 +417,9 @@ async function parseNCPDPScript(newRx) { prescriber.NonVeterinarian.Name.FirstName + ' ' + prescriber.NonVeterinarian.Name.LastName, - doctorContact: - prescriber.NonVeterinarian.CommunicationNumbers.PrimaryTelephone - ?.Number, + doctorContact: prescriber.NonVeterinarian.CommunicationNumbers.PrimaryTelephone?.Number, doctorID: prescriber.NonVeterinarian.Identification.NPI, - doctorEmail: - prescriber.NonVeterinarian.CommunicationNumbers.ElectronicMail, + doctorEmail: prescriber.NonVeterinarian.CommunicationNumbers.ElectronicMail, drugNames: medicationPrescribed.DrugDescription, simpleDrugName: medicationPrescribed.DrugDescription?.split(' ')[0], @@ -434,8 +428,7 @@ async function parseNCPDPScript(newRx) { medicationPrescribed.DrugCoded.NDC || null, - drugRxnormCode: - medicationPrescribed.DrugCoded.DrugDBCode?.Code || null, + drugRxnormCode: medicationPrescribed.DrugCoded.DrugDBCode?.Code || null, rxDate: medicationPrescribed.WrittenDate.Date, drugPrice: 200, // Add later?