@@ -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' ;
2424
2525const logger = container . get ( 'application' ) ;
@@ -131,14 +131,14 @@ class REMSIntermediary extends Server {
131131 return this ;
132132 }
133133
134- registerNcpdpScript ( { ncpdpScriptForwardUrl, ehrUrl } : Config [ 'general' ] ) {
134+ registerNcpdpScript ( { ncpdpScriptForwardUrl, ehrBaseUrl } : Config [ 'general' ] ) {
135135 console . log ( 'Registering NCPDP SCRIPT endpoint with intelligent routing' ) ;
136136
137137 this . app . post ( '/ncpdp/script' , async ( req : any , res : any ) => {
138138 try {
139139 console . log ( 'Processing NCPDP SCRIPT message' ) ;
140140
141- const ehrEndpoint = ehrUrl + '/script'
141+ const ehrEndpoint = ehrBaseUrl + '/ncpdp /script'
142142
143143 // Determine message type
144144 const messageType = getMessageType ( req . body ) ;
@@ -195,38 +195,35 @@ class REMSIntermediary extends Server {
195195 console . log ( 'Processing RxFill message' ) ;
196196
197197 const drugInfo = extractDrugFromNcpdp ( req . body ) ;
198- const promises = [ ] ;
199198
200- // Send to EHR
201-
202- console . log ( `Sending RxFill to EHR: ${ ehrEndpoint } ` ) ;
203- promises . push (
204- axios . post ( ehrEndpoint , req . body , { headers : req . headers } )
205- . then ( ( ) => console . log ( '✓ RxFill sent to EHR' ) )
206- . catch ( err => console . error ( '✗ Error sending RxFill to EHR:' , err . message ) )
207- ) ;
208-
199+ // grab the qualifier from the to
200+ const qualifier = getToQualifier ( req . body ) ;
209201
210- // Send to REMS Admin if REMS drug
211- if ( drugInfo && drugInfo . ndc ) {
212- const coding = ndcToCoding ( drugInfo . ndc ) ;
213- const serviceConnection = await getServiceConnection ( coding , undefined ) ;
214-
215- if ( serviceConnection && serviceConnection . toNcpdp ) {
216- console . log ( `Sending RxFill to REMS Admin: ${ serviceConnection . toNcpdp } ` ) ;
217- console . log ( ` Drug: ${ drugInfo . description || 'Unknown' } (${ drugInfo . ndc } )` ) ;
202+ if ( qualifier == Qualifier . Clinic || qualifier == Qualifier . Prescriber ) {
203+ // Send to EHR
204+ console . log ( `Sending RxFill to EHR: ${ ehrEndpoint } ` ) ;
205+
206+ await axios . post ( ehrEndpoint , req . body , { headers : req . headers } )
207+ . then ( ( ) => console . log ( '✓ RxFill sent to EHR' ) )
208+ . catch ( err => console . error ( '✗ Error sending RxFill to EHR:' , err . message ) ) ;
209+
210+ } else if ( qualifier == Qualifier . REMSAdministrator ) {
211+ // Send to REMS Admin if REMS drug
212+ if ( drugInfo && drugInfo . ndc ) {
213+ const coding = ndcToCoding ( drugInfo . ndc ) ;
214+ const serviceConnection = await getServiceConnection ( coding , undefined ) ;
218215
219- promises . push (
220- axios . post ( serviceConnection . toNcpdp , req . body , { headers : req . headers } )
221- . then ( ( ) => console . log ( '✓ RxFill sent to REMS Admin' ) )
222- . catch ( err => console . error ( '✗ Error sending RxFill to REMS Admin:' , err . message ) )
223- ) ;
216+ if ( serviceConnection && serviceConnection . toNcpdp ) {
217+ console . log ( `Sending RxFill to REMS Admin: ${ serviceConnection . toNcpdp } ` ) ;
218+ console . log ( ` Drug: ${ drugInfo . description || 'Unknown' } (${ drugInfo . ndc } )` ) ;
219+
220+ await axios . post ( serviceConnection . toNcpdp , req . body , { headers : req . headers } )
221+ . then ( ( ) => console . log ( '✓ RxFill sent to REMS Admin' ) )
222+ . catch ( err => console . error ( '✗ Error sending RxFill to REMS Admin:' , err . message ) ) ;
223+ }
224224 }
225225 }
226226
227- // Wait for all sends to complete
228- await Promise . all ( promises ) ;
229-
230227 // Return success status
231228 return res . send ( { status : 'success' , message : 'RxFill processed' } ) ;
232229 }
0 commit comments