From 2fcf916f91434d1c18e943ad7b1f4c7af4f3d7f4 Mon Sep 17 00:00:00 2001 From: Patrick LaRocque Date: Wed, 31 Jan 2024 10:02:29 -0500 Subject: [PATCH 1/4] Update NewRx message to include all the required header information. --- src/util/buildScript.2017071.js | 43 +++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/util/buildScript.2017071.js b/src/util/buildScript.2017071.js index 0b0f8f91..463604cc 100644 --- a/src/util/buildScript.2017071.js +++ b/src/util/buildScript.2017071.js @@ -2,6 +2,8 @@ import { getDrugCodeableConceptFromMedicationRequest } from './fhir'; +var SCRIPT_VERSION='20170715'; + function xmlAddTextNode(xmlDoc, parent, sectionName, value) { var section = xmlDoc.createElement(sectionName); var textNode = xmlDoc.createTextNode(value); @@ -9,6 +11,14 @@ function xmlAddTextNode(xmlDoc, parent, sectionName, value) { parent.appendChild(section); } +function xmlAddTextNodeWithAttribute(xmlDoc, parent, sectionName, value, attrName, attrValue) { + var section = xmlDoc.createElement(sectionName); + section.setAttribute(attrName, attrValue); + var textNode = xmlDoc.createTextNode(value); + section.appendChild(textNode); + parent.appendChild(section); +} + function buildNewRxName(doc, nameResource) { var name = doc.createElement('Name'); xmlAddTextNode(doc, name, 'LastName', nameResource.family); @@ -62,6 +72,7 @@ function buildNewRxPatient(doc, patientResource) { function buildNewRxPrescriber(doc, practitionerResource) { var prescriber = doc.createElement('Prescriber'); var nonVeterinarian = doc.createElement('NonVeterinarian'); + var npi = null; // Prescriber Identifier for (let i = 0; i < practitionerResource.identifier.length; i++) { @@ -70,6 +81,7 @@ function buildNewRxPrescriber(doc, practitionerResource) { var identification = doc.createElement('Identification'); xmlAddTextNode(doc, identification, 'NPI', id.value); nonVeterinarian.appendChild(identification); + npi = id.value; } } @@ -96,7 +108,7 @@ function buildNewRxPrescriber(doc, practitionerResource) { nonVeterinarian.appendChild(communicationNumbers); prescriber.appendChild(nonVeterinarian); - return prescriber; + return [prescriber, npi]; } function quantityUnitOfMeasureFromDrugFormCode(dispenseRequest) { @@ -279,6 +291,15 @@ export default function buildNewRxRequest( ) { var doc = document.implementation.createDocument('', '', null); var message = doc.createElement('Message'); + // set the message attributes + message.setAttribute('DatatypesVersion', SCRIPT_VERSION); + message.setAttribute('TransportVersion', SCRIPT_VERSION); + message.setAttribute('TransactionDomain', 'SCRIPT'); + message.setAttribute('TransactionVersion', SCRIPT_VERSION); + message.setAttribute('StructuresVersion', SCRIPT_VERSION); + message.setAttribute('ECLVersion', SCRIPT_VERSION); + message.setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); + message.setAttribute('xsi:noNamespaceSchemaLocation', 'transport.xsd'); // Header var header = doc.createElement('Header'); @@ -286,6 +307,16 @@ export default function buildNewRxRequest( const d1 = new Date(); const messageIdValue = d1.getTime(); xmlAddTextNode(doc, header, 'MessageID', messageIdValue); + + // SentTime + xmlAddTextNode(doc, header, 'SentTime', d1.toISOString()); + + // PrescriberOrderNumber + xmlAddTextNode(doc, header, 'PrescriberOrderNumber', medicationRequestResource?.id); + + // To + xmlAddTextNodeWithAttribute(doc, header, 'To', 'Pharmacy 123', 'Qualifier', 'P'); + message.appendChild(header); // Body @@ -296,7 +327,15 @@ export default function buildNewRxRequest( newRx.appendChild(buildNewRxPatient(doc, patientResource)); // Prescriber - newRx.appendChild(buildNewRxPrescriber(doc, practitionerResource)); + const [prescriber, prescriberNPI] = buildNewRxPrescriber(doc, practitionerResource); + newRx.appendChild(prescriber); + if (prescriberNPI) { + // set the prescriber NPI in the header.from + xmlAddTextNodeWithAttribute(doc, header, 'From', prescriberNPI, 'Qualifier', 'C'); + } else { + // just set it to the request generator + xmlAddTextNodeWithAttribute(doc, header, 'From', 'Request Generator', 'Qualifier', 'C'); + } // Medication newRx.appendChild(buildNewRxMedication(doc, medicationRequestResource)); From 12f76d0840c873e2eff785b601f167feae5292ec Mon Sep 17 00:00:00 2001 From: Patrick LaRocque Date: Thu, 1 Feb 2024 15:07:36 -0500 Subject: [PATCH 2/4] updates from review --- src/util/buildScript.2017071.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/util/buildScript.2017071.js b/src/util/buildScript.2017071.js index 463604cc..20618446 100644 --- a/src/util/buildScript.2017071.js +++ b/src/util/buildScript.2017071.js @@ -2,7 +2,7 @@ import { getDrugCodeableConceptFromMedicationRequest } from './fhir'; -var SCRIPT_VERSION='20170715'; +var SCRIPT_VERSION = '20170715'; function xmlAddTextNode(xmlDoc, parent, sectionName, value) { var section = xmlDoc.createElement(sectionName); @@ -69,20 +69,26 @@ function buildNewRxPatient(doc, patientResource) { return patient; } +function getPractitionerNpi(practitionerResource) { + for (let i = 0; i < practitionerResource.identifier.length; i++) { + let id = practitionerResource.identifier[i]; + if (id.system && id.system.includes('us-npi')) { + return id.value; + } + } + return null; +} + function buildNewRxPrescriber(doc, practitionerResource) { var prescriber = doc.createElement('Prescriber'); var nonVeterinarian = doc.createElement('NonVeterinarian'); - var npi = null; + var npi = getPractitionerNpi(practitionerResource); // Prescriber Identifier - for (let i = 0; i < practitionerResource.identifier.length; i++) { - let id = practitionerResource.identifier[i]; - if (id.system && id.system.includes('us-npi')) { - var identification = doc.createElement('Identification'); - xmlAddTextNode(doc, identification, 'NPI', id.value); - nonVeterinarian.appendChild(identification); - npi = id.value; - } + if (npi) { + var identification = doc.createElement('Identification'); + xmlAddTextNode(doc, identification, 'NPI', npi); + nonVeterinarian.appendChild(identification); } // Prescriber Name @@ -108,7 +114,7 @@ function buildNewRxPrescriber(doc, practitionerResource) { nonVeterinarian.appendChild(communicationNumbers); prescriber.appendChild(nonVeterinarian); - return [prescriber, npi]; + return prescriber; } function quantityUnitOfMeasureFromDrugFormCode(dispenseRequest) { @@ -327,7 +333,8 @@ export default function buildNewRxRequest( newRx.appendChild(buildNewRxPatient(doc, patientResource)); // Prescriber - const [prescriber, prescriberNPI] = buildNewRxPrescriber(doc, practitionerResource); + const prescriber = buildNewRxPrescriber(doc, practitionerResource); + prescriberNPI = getPractitionerNpi(practitionerResource); newRx.appendChild(prescriber); if (prescriberNPI) { // set the prescriber NPI in the header.from From 6f5c4f7a637a9032f48545be0ec090590045df3a Mon Sep 17 00:00:00 2001 From: Joyce Quach Date: Thu, 1 Feb 2024 15:36:30 -0500 Subject: [PATCH 3/4] Only get npi once --- src/util/buildScript.2017071.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/buildScript.2017071.js b/src/util/buildScript.2017071.js index 20618446..06045fea 100644 --- a/src/util/buildScript.2017071.js +++ b/src/util/buildScript.2017071.js @@ -75,14 +75,13 @@ function getPractitionerNpi(practitionerResource) { if (id.system && id.system.includes('us-npi')) { return id.value; } - } + } return null; } -function buildNewRxPrescriber(doc, practitionerResource) { +function buildNewRxPrescriber(doc, practitionerResource, npi) { var prescriber = doc.createElement('Prescriber'); var nonVeterinarian = doc.createElement('NonVeterinarian'); - var npi = getPractitionerNpi(practitionerResource); // Prescriber Identifier if (npi) { @@ -226,7 +225,8 @@ function buildNewRxMedication(doc, medicationRequestResource) { var drugCoded = doc.createElement('DrugCoded'); // loop through the coding values and find the ndc code and the rxnorm code - let medicationCodingList = getDrugCodeableConceptFromMedicationRequest(medicationRequestResource)?.coding; + let medicationCodingList = + getDrugCodeableConceptFromMedicationRequest(medicationRequestResource)?.coding; for (let i = 0; i < medicationCodingList.length; i++) { const coding = medicationCodingList[i]; const system = coding.system.toLowerCase(); @@ -333,12 +333,12 @@ export default function buildNewRxRequest( newRx.appendChild(buildNewRxPatient(doc, patientResource)); // Prescriber - const prescriber = buildNewRxPrescriber(doc, practitionerResource); - prescriberNPI = getPractitionerNpi(practitionerResource); + const npi = getPractitionerNpi(practitionerResource); + const prescriber = buildNewRxPrescriber(doc, practitionerResource, npi); newRx.appendChild(prescriber); - if (prescriberNPI) { + if (npi) { // set the prescriber NPI in the header.from - xmlAddTextNodeWithAttribute(doc, header, 'From', prescriberNPI, 'Qualifier', 'C'); + xmlAddTextNodeWithAttribute(doc, header, 'From', npi, 'Qualifier', 'C'); } else { // just set it to the request generator xmlAddTextNodeWithAttribute(doc, header, 'From', 'Request Generator', 'Qualifier', 'C'); From d086705bc19c9763c6d1935a312c47bd89939553 Mon Sep 17 00:00:00 2001 From: Joyce Quach Date: Thu, 1 Feb 2024 15:36:43 -0500 Subject: [PATCH 4/4] Change use of var to const --- src/util/buildScript.2017071.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/buildScript.2017071.js b/src/util/buildScript.2017071.js index 06045fea..653b60e4 100644 --- a/src/util/buildScript.2017071.js +++ b/src/util/buildScript.2017071.js @@ -80,12 +80,12 @@ function getPractitionerNpi(practitionerResource) { } function buildNewRxPrescriber(doc, practitionerResource, npi) { - var prescriber = doc.createElement('Prescriber'); - var nonVeterinarian = doc.createElement('NonVeterinarian'); + const prescriber = doc.createElement('Prescriber'); + const nonVeterinarian = doc.createElement('NonVeterinarian'); // Prescriber Identifier if (npi) { - var identification = doc.createElement('Identification'); + const identification = doc.createElement('Identification'); xmlAddTextNode(doc, identification, 'NPI', npi); nonVeterinarian.appendChild(identification); } @@ -99,11 +99,11 @@ function buildNewRxPrescriber(doc, practitionerResource, npi) { nonVeterinarian.appendChild(buildNewRxAddress(doc, practitionerAddressResource)); // Prescriber Phone Number and Email - var communicationNumbers = doc.createElement('CommunicationNumbers'); + const communicationNumbers = doc.createElement('CommunicationNumbers'); for (let i = 0; i < practitionerResource.telecom.length; i++) { const telecom = practitionerResource.telecom[i]; if (telecom.system === 'phone') { - var primaryTelephone = doc.createElement('PrimaryTelephone'); + const primaryTelephone = doc.createElement('PrimaryTelephone'); xmlAddTextNode(doc, primaryTelephone, 'Number', telecom.value); communicationNumbers.appendChild(primaryTelephone); } else if (telecom.system === 'email') {