@@ -35,6 +35,7 @@ interface DrugInfo {
3535const REMSAdminWhitelist = {
3636 standardRemsAdmin : config ?. general ?. remsAdminHookPath ,
3737 standardRemsAdminEtasu : config ?. general ?. remsAdminFhirEtasuPath ,
38+ standardRemsAdminNcpdp : config ?. general ?. remsAdminNcpdpPath ,
3839 discoveryUrlBase : config ?. general ?. discoveryBaseUrl ,
3940 discoveryApiEndpoint : config ?. general ?. discoveryApiUrl ,
4041 discoverySplZipEndpoint : config ?. general ?. discoverySplZipUrl ,
@@ -407,15 +408,17 @@ async function saveOrUpdateEntry(entryToSave: any, model: any): Promise<{ action
407408
408409 if ( existingEntry ) {
409410 const hasChanges = existingEntry . to !== entryToSave . to ||
410- existingEntry . toEtasu !== entryToSave . toEtasu ;
411+ existingEntry . toEtasu !== entryToSave . toEtasu ||
412+ existingEntry . toNcpdp !== entryToSave . toNcpdp ;
411413
412414 if ( hasChanges ) {
413415 await model . updateOne (
414416 { code : entryToSave . code , system : entryToSave . system } ,
415417 {
416418 $set : {
417419 to : entryToSave . to ,
418- toEtasu : entryToSave . toEtasu
420+ toEtasu : entryToSave . toEtasu ,
421+ toNcpdp : entryToSave . toNcpdp
419422 }
420423 }
421424 ) ;
@@ -624,13 +627,19 @@ function createDrugEntry(drug: DrugInfo, cdsEndpoint?: string, fhirBaseUrl?: str
624627 ? finalFhirBaseUrl + '4_0_0/GuidanceResponse/$rems-etasu'
625628 : finalFhirBaseUrl + '/4_0_0/GuidanceResponse/$rems-etasu' ;
626629
630+ // Add NCPDP endpoint
631+ const ncpdpUrl = finalFhirBaseUrl . endsWith ( '/' )
632+ ? finalFhirBaseUrl + 'ncpdp/script'
633+ : finalFhirBaseUrl + '/ncpdp/script' ;
634+
627635 return {
628636 code : code ,
629637 system : system ,
630638 brand_name : drug . brandName ,
631639 generic_name : drug . genericName ,
632640 to : cdsUrl ,
633641 toEtasu : etasuUrl ,
642+ toNcpdp : ncpdpUrl ,
634643 from : [ EHRWhitelist . any ]
635644 } ;
636645}
@@ -678,12 +687,26 @@ async function processPhonebookEntries(splDrugs: any[]): Promise<{ drugs: any[],
678687 ? apiResult . rems_fhir_base_url + '4_0_0/GuidanceResponse/$rems-etasu'
679688 : apiResult . rems_fhir_base_url + '/4_0_0/GuidanceResponse/$rems-etasu' ;
680689
690+ entryToSave . toNcpdp = apiResult . rems_fhir_base_url . endsWith ( '/' )
691+ ? apiResult . rems_fhir_base_url + 'ncpdp/script'
692+ : apiResult . rems_fhir_base_url + '/ncpdp/script' ;
693+
681694 phonebookApiCount ++ ;
682695 } else {
683696 console . log ( ` ⚙️ PHONEBOOK DEFAULT USED: ${ entry . brand_name } (${ entry . code } )` ) ;
684697 console . log ( ` 🔗 Using fallback endpoints` ) ;
685698 entryToSave . to = REMSAdminWhitelist . standardRemsAdmin ;
686699 entryToSave . toEtasu = REMSAdminWhitelist . standardRemsAdminEtasu ;
700+ entryToSave . toNcpdp = REMSAdminWhitelist . standardRemsAdminNcpdp ;
701+
702+ // Add default NCPDP endpoint if we have a base URL
703+ if ( REMSAdminWhitelist . standardRemsAdminEtasu ) {
704+ const baseUrl = REMSAdminWhitelist . standardRemsAdminEtasu . split ( '/4_0_0' ) [ 0 ] ;
705+ entryToSave . toNcpdp = baseUrl . endsWith ( '/' )
706+ ? baseUrl + 'ncpdp/script'
707+ : baseUrl + '/ncpdp/script' ;
708+ }
709+
687710 phonebookDefaultCount ++ ;
688711 }
689712
@@ -803,6 +826,7 @@ export async function getServiceConnection(coding: Coding, requester: string | u
803826 const connectionModel = Connection ;
804827 if ( coding . system && coding . code ) {
805828 const connection = await connectionModel . findOne ( { code : coding . code , system : coding . system } ) ;
829+ console . log ( connection )
806830 if ( ! connection ) {
807831 return undefined ;
808832 }
0 commit comments