@@ -19,7 +19,7 @@ import path from 'path';
1919import { Connection } from './lib/schemas/Phonebook' ;
2020import { EHRWhitelist , loadPhonebook } from './hooks/hookProxy' ;
2121import cookieParser from 'cookie-parser' ;
22- import { extractDrugFromNcpdp , ndcToCoding , getMessageType } from './lib/ncpdpHelpers' ;
22+ import { extractDrugFromNcpdp , ndcToCoding , getMessageType , Qualifier , getToQualifier } from './lib/ncpdpHelpers' ;
2323import { getServiceConnection } from './hooks/hookProxy' ;
2424import { HookSession } from './lib/schemas/HookSession' ;
2525import { Communication } from 'fhir/r4' ;
@@ -305,14 +305,15 @@ class REMSIntermediary extends Server {
305305 return this ;
306306 }
307307
308- registerNcpdpScript ( { ncpdpScriptForwardUrl, ehrUrl } : Config [ 'general' ] ) {
308+
309+ registerNcpdpScript ( { ncpdpScriptForwardUrl, ehrBaseUrl } : Config [ 'general' ] ) {
309310 console . log ( 'Registering NCPDP SCRIPT endpoint with intelligent routing' ) ;
310311
311312 this . app . post ( '/ncpdp/script' , async ( req : any , res : any ) => {
312313 try {
313314 console . log ( 'Processing NCPDP SCRIPT message' ) ;
314315
315- const ehrEndpoint = ehrUrl + '/script'
316+ const ehrEndpoint = ehrBaseUrl + '/ncpdp /script'
316317
317318 // Determine message type
318319 const messageType = getMessageType ( req . body ) ;
@@ -368,38 +369,35 @@ class REMSIntermediary extends Server {
368369 console . log ( 'Processing RxFill message' ) ;
369370
370371 const drugInfo = extractDrugFromNcpdp ( req . body ) ;
371- const promises = [ ] ;
372372
373- // Send to EHR
374-
375- console . log ( `Sending RxFill to EHR: ${ ehrEndpoint } ` ) ;
376- promises . push (
377- axios . post ( ehrEndpoint , req . body , { headers : req . headers } )
378- . then ( ( ) => console . log ( '✓ RxFill sent to EHR' ) )
379- . catch ( err => console . error ( '✗ Error sending RxFill to EHR:' , err . message ) )
380- ) ;
381-
373+ // grab the qualifier from the to
374+ const qualifier = getToQualifier ( req . body ) ;
382375
383- // Send to REMS Admin if REMS drug
384- if ( drugInfo && drugInfo . ndc ) {
385- const coding = ndcToCoding ( drugInfo . ndc ) ;
386- const serviceConnection = await getServiceConnection ( coding , undefined ) ;
387-
388- if ( serviceConnection && serviceConnection . toNcpdp ) {
389- console . log ( `Sending RxFill to REMS Admin: ${ serviceConnection . toNcpdp } ` ) ;
390- console . log ( ` Drug: ${ drugInfo . description || 'Unknown' } (${ drugInfo . ndc } )` ) ;
376+ if ( qualifier == Qualifier . Clinic || qualifier == Qualifier . Prescriber ) {
377+ // Send to EHR
378+ console . log ( `Sending RxFill to EHR: ${ ehrEndpoint } ` ) ;
379+
380+ await axios . post ( ehrEndpoint , req . body , { headers : req . headers } )
381+ . then ( ( ) => console . log ( '✓ RxFill sent to EHR' ) )
382+ . catch ( err => console . error ( '✗ Error sending RxFill to EHR:' , err . message ) ) ;
383+
384+ } else if ( qualifier == Qualifier . REMSAdministrator ) {
385+ // Send to REMS Admin if REMS drug
386+ if ( drugInfo && drugInfo . ndc ) {
387+ const coding = ndcToCoding ( drugInfo . ndc ) ;
388+ const serviceConnection = await getServiceConnection ( coding , undefined ) ;
391389
392- promises . push (
393- axios . post ( serviceConnection . toNcpdp , req . body , { headers : req . headers } )
394- . then ( ( ) => console . log ( '✓ RxFill sent to REMS Admin' ) )
395- . catch ( err => console . error ( '✗ Error sending RxFill to REMS Admin:' , err . message ) )
396- ) ;
390+ if ( serviceConnection && serviceConnection . toNcpdp ) {
391+ console . log ( `Sending RxFill to REMS Admin: ${ serviceConnection . toNcpdp } ` ) ;
392+ console . log ( ` Drug: ${ drugInfo . description || 'Unknown' } (${ drugInfo . ndc } )` ) ;
393+
394+ await axios . post ( serviceConnection . toNcpdp , req . body , { headers : req . headers } )
395+ . then ( ( ) => console . log ( '✓ RxFill sent to REMS Admin' ) )
396+ . catch ( err => console . error ( '✗ Error sending RxFill to REMS Admin:' , err . message ) ) ;
397+ }
397398 }
398399 }
399400
400- // Wait for all sends to complete
401- await Promise . all ( promises ) ;
402-
403401 // Return success status
404402 return res . send ( { status : 'success' , message : 'RxFill processed' } ) ;
405403 }
0 commit comments