@@ -249,9 +249,17 @@ router.delete('/api/deleteAll', async (req, res) => {
249249} ) ;
250250
251251const isRemsDrug = order => {
252- return medicationRequestToRemsAdmins . some (
253- entry => Number ( order . drugRxnormCode ) === Number ( entry . rxnorm )
254- ) ;
252+ return medicationRequestToRemsAdmins . some ( entry => {
253+ if ( order . drugNdcCode && entry . ndc ) {
254+ return order . drugNdcCode === entry . ndc ;
255+ }
256+
257+ if ( order . drugRxnormCode && entry . rxnorm ) {
258+ return Number ( order . drugRxnormCode ) === Number ( entry . rxnorm ) ;
259+ }
260+
261+ return false ;
262+ } ) ;
255263} ;
256264
257265const getEtasuUrl = order => {
@@ -260,9 +268,16 @@ const getEtasuUrl = order => {
260268 if ( env . USE_INTERMEDIARY ) {
261269 baseUrl = env . INTERMEDIARY_FHIR_URL ;
262270 } else {
263- const rxnorm = order . drugRxnormCode ;
264271 const remsDrug = medicationRequestToRemsAdmins . find ( entry => {
265- return Number ( rxnorm ) === Number ( entry . rxnorm ) ;
272+ if ( order . drugNdcCode && entry . ndc ) {
273+ return order . drugNdcCode === entry . ndc ;
274+ }
275+
276+ if ( order . drugRxnormCode && entry . rxnorm ) {
277+ return Number ( order . drugRxnormCode ) === Number ( entry . rxnorm ) ;
278+ }
279+
280+ return false ;
266281 } ) ;
267282 baseUrl = remsDrug ?. remsAdminFhirUrl ;
268283 }
@@ -291,6 +306,36 @@ const getGuidanceResponse = async order => {
291306 ]
292307 } ;
293308 } else {
309+ let medicationCoding = [ ] ;
310+
311+ if ( order . drugNdcCode ) {
312+ medicationCoding . push ( {
313+ system : 'http://hl7.org/fhir/sid/ndc' ,
314+ code : order . drugNdcCode ,
315+ display : order . drugNames
316+ } ) ;
317+ }
318+
319+ if ( order . drugRxnormCode ) {
320+ medicationCoding . push ( {
321+ system : 'http://www.nlm.nih.gov/research/umls/rxnorm' ,
322+ code : order . drugRxnormCode ,
323+ display : order . drugNames
324+ } ) ;
325+ } else {
326+ const remsDrug = medicationRequestToRemsAdmins . find ( entry => {
327+ return order . drugNdcCode && entry . ndc && order . drugNdcCode === entry . ndc ;
328+ } ) ;
329+
330+ if ( remsDrug && remsDrug . rxnorm ) {
331+ medicationCoding . push ( {
332+ system : 'http://www.nlm.nih.gov/research/umls/rxnorm' ,
333+ code : remsDrug . rxnorm . toString ( ) ,
334+ display : order . drugNames
335+ } ) ;
336+ }
337+ }
338+
294339 body = {
295340 resourceType : 'Parameters' ,
296341 parameter : [
@@ -315,13 +360,7 @@ const getGuidanceResponse = async order => {
315360 resourceType : 'Medication' ,
316361 id : order . prescriberOrderNumber ,
317362 code : {
318- coding : [
319- {
320- system : 'http://www.nlm.nih.gov/research/umls/rxnorm' ,
321- code : order . drugRxnormCode ,
322- display : order . drugNames
323- }
324- ]
363+ coding : medicationCoding
325364 }
326365 }
327366 }
@@ -356,7 +395,7 @@ const getDispenseStatus = (order, guidanceResponse) => {
356395 * Return : Mongoose schema of a newOrder
357396 */
358397async function parseNCPDPScript ( newRx ) {
359- // Parsing XML NCPDP SCRIPT from EHR
398+ // Parsing XML NCPDP SCRIPT from EHR
360399 const incompleteOrder = {
361400 orderId : newRx . Message . Header . MessageID . toString ( ) , // Will need to return to this and use actual pt identifier or uuid
362401 caseNumber : newRx . Message . Header . AuthorizationNumber ,
@@ -385,8 +424,15 @@ async function parseNCPDPScript(newRx) {
385424 newRx . Message . Body . NewRx . Prescriber . NonVeterinarian . CommunicationNumbers . ElectronicMail ,
386425 drugNames : newRx . Message . Body . NewRx . MedicationPrescribed . DrugDescription ,
387426 simpleDrugName : newRx . Message . Body . NewRx . MedicationPrescribed . DrugDescription . split ( ' ' ) [ 0 ] ,
388- drugNdcCode : newRx . Message . Body . NewRx . MedicationPrescribed . DrugCoded . ProductCode . Code ,
389- drugRxnormCode : newRx . Message . Body . NewRx . MedicationPrescribed . DrugCoded . DrugDBCode . Code ,
427+
428+ drugNdcCode :
429+ newRx . Message . Body . NewRx . MedicationPrescribed . DrugCoded . ProductCode ?. Code ||
430+ newRx . Message . Body . NewRx . MedicationPrescribed . DrugCoded . NDC ||
431+ null ,
432+
433+ drugRxnormCode :
434+ newRx . Message . Body . NewRx . MedicationPrescribed . DrugCoded . DrugDBCode ?. Code || null ,
435+
390436 rxDate : newRx . Message . Body . NewRx . MedicationPrescribed . WrittenDate . Date ,
391437 drugPrice : 200 , // Add later?
392438 quantities : newRx . Message . Body . NewRx . MedicationPrescribed . Quantity . Value ,
0 commit comments