From 7cb5f7bb21d9802dd6405c057ab04229a40de537 Mon Sep 17 00:00:00 2001 From: KeeyanGhoreshi Date: Thu, 4 Apr 2024 13:40:11 -0400 Subject: [PATCH 1/4] update controller to handle medrequest --- src/services/guidanceresponse.service.ts | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/services/guidanceresponse.service.ts b/src/services/guidanceresponse.service.ts index d16f372b..3c548920 100644 --- a/src/services/guidanceresponse.service.ts +++ b/src/services/guidanceresponse.service.ts @@ -1,7 +1,7 @@ import { FhirUtilities } from '../fhir/utilities'; import { GuidanceResponseUtilities } from '../fhir/guidanceResponseUtilities'; import GuidanceResponseModel from '../lib/schemas/resources/GuidanceResponse'; -import { Parameters, Medication, Patient } from 'fhir/r4'; +import { Parameters, Medication, Patient, MedicationRequest } from 'fhir/r4'; import { getCaseInfo } from '../lib/etasu'; module.exports.searchById = async (args: any) => { @@ -17,14 +17,22 @@ module.exports.create = async (args: any, req: any) => { return await FhirUtilities.store(resource, GuidanceResponseModel, base_version); }; -const getMedicationCode = (medication: Medication | undefined) => { +const getMedicationCode = (medication: Medication | MedicationRequest | undefined) => { // grab the medication drug code from the Medication resource let drugCode = null; - medication?.code?.coding?.forEach(medCode => { - if (medCode?.system?.endsWith('rxnorm')) { - drugCode = medCode?.code; - } - }); + if(medication?.resourceType == 'Medication') { + medication?.code?.coding?.forEach(medCode => { + if (medCode?.system?.endsWith('rxnorm')) { + drugCode = medCode?.code; + } + }); + } else { + medication?.medicationCodeableConcept?.coding?.forEach(medCode => { + if (medCode.system?.endsWith('rxnorm')) { + drugCode = medCode.code; + } + }); + } return drugCode; }; @@ -33,12 +41,12 @@ module.exports.remsEtasu = async (args: any, context: any, logger: any) => { const parameters: Parameters = args?.resource; let patient: Patient | undefined; - let medication: Medication | undefined; + let medication: Medication | MedicationRequest | undefined; parameters?.parameter?.forEach(param => { if (param?.name === 'patient' && param?.resource?.resourceType === 'Patient') { patient = param.resource; - } else if (param?.name === 'medication' && param?.resource?.resourceType === 'Medication') { + } else if (param?.name === 'medication' && (param?.resource?.resourceType === 'Medication' || param.resource?.resourceType === 'MedicationRequest')) { medication = param.resource; } }); From f41cf944dfc2541db828bf8eff1645625a64ce49 Mon Sep 17 00:00:00 2001 From: KeeyanGhoreshi Date: Fri, 5 Apr 2024 11:15:05 -0400 Subject: [PATCH 2/4] lint --- src/services/guidanceresponse.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/services/guidanceresponse.service.ts b/src/services/guidanceresponse.service.ts index 3c548920..a888b20b 100644 --- a/src/services/guidanceresponse.service.ts +++ b/src/services/guidanceresponse.service.ts @@ -20,7 +20,7 @@ module.exports.create = async (args: any, req: any) => { const getMedicationCode = (medication: Medication | MedicationRequest | undefined) => { // grab the medication drug code from the Medication resource let drugCode = null; - if(medication?.resourceType == 'Medication') { + if (medication?.resourceType == 'Medication') { medication?.code?.coding?.forEach(medCode => { if (medCode?.system?.endsWith('rxnorm')) { drugCode = medCode?.code; @@ -46,7 +46,11 @@ module.exports.remsEtasu = async (args: any, context: any, logger: any) => { parameters?.parameter?.forEach(param => { if (param?.name === 'patient' && param?.resource?.resourceType === 'Patient') { patient = param.resource; - } else if (param?.name === 'medication' && (param?.resource?.resourceType === 'Medication' || param.resource?.resourceType === 'MedicationRequest')) { + } else if ( + param?.name === 'medication' && + (param?.resource?.resourceType === 'Medication' || + param.resource?.resourceType === 'MedicationRequest') + ) { medication = param.resource; } }); From c6861d689200a370e1d33e0dc915e4cf4efce2b9 Mon Sep 17 00:00:00 2001 From: KeeyanGhoreshi Date: Fri, 5 Apr 2024 13:24:42 -0400 Subject: [PATCH 3/4] accomodate ref --- src/services/guidanceresponse.service.ts | 29 ++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/services/guidanceresponse.service.ts b/src/services/guidanceresponse.service.ts index a888b20b..6770c507 100644 --- a/src/services/guidanceresponse.service.ts +++ b/src/services/guidanceresponse.service.ts @@ -1,7 +1,7 @@ import { FhirUtilities } from '../fhir/utilities'; import { GuidanceResponseUtilities } from '../fhir/guidanceResponseUtilities'; import GuidanceResponseModel from '../lib/schemas/resources/GuidanceResponse'; -import { Parameters, Medication, Patient, MedicationRequest } from 'fhir/r4'; +import { Parameters, Medication, Patient, MedicationRequest, FhirResource } from 'fhir/r4'; import { getCaseInfo } from '../lib/etasu'; module.exports.searchById = async (args: any) => { @@ -17,9 +17,9 @@ module.exports.create = async (args: any, req: any) => { return await FhirUtilities.store(resource, GuidanceResponseModel, base_version); }; -const getMedicationCode = (medication: Medication | MedicationRequest | undefined) => { +const getMedicationCode = (medication: Medication | MedicationRequest | undefined): string | undefined => { // grab the medication drug code from the Medication resource - let drugCode = null; + let drugCode; if (medication?.resourceType == 'Medication') { medication?.code?.coding?.forEach(medCode => { if (medCode?.system?.endsWith('rxnorm')) { @@ -27,11 +27,26 @@ const getMedicationCode = (medication: Medication | MedicationRequest | undefine } }); } else { - medication?.medicationCodeableConcept?.coding?.forEach(medCode => { - if (medCode.system?.endsWith('rxnorm')) { - drugCode = medCode.code; + if(medication?.medicationCodeableConcept){ + medication?.medicationCodeableConcept?.coding?.forEach(medCode => { + if (medCode.system?.endsWith('rxnorm')) { + drugCode = medCode.code; + } + }); + } else if(medication?.medicationReference){ + const ref = medication.medicationReference.reference + if(ref?.startsWith('#')){ + const containedRef = ref.slice(1); + const match = medication.contained?.find((res) => { + return res.id === containedRef; + }); + if(match?.resourceType === 'Medication'){ + return getMedicationCode(match); + } + } - }); + } + } return drugCode; }; From 11acc8a413dd8f74e897e26031eba220689fefad Mon Sep 17 00:00:00 2001 From: KeeyanGhoreshi Date: Fri, 5 Apr 2024 13:51:15 -0400 Subject: [PATCH 4/4] linting --- src/services/guidanceresponse.service.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/services/guidanceresponse.service.ts b/src/services/guidanceresponse.service.ts index 6770c507..2ee16646 100644 --- a/src/services/guidanceresponse.service.ts +++ b/src/services/guidanceresponse.service.ts @@ -17,7 +17,9 @@ module.exports.create = async (args: any, req: any) => { return await FhirUtilities.store(resource, GuidanceResponseModel, base_version); }; -const getMedicationCode = (medication: Medication | MedicationRequest | undefined): string | undefined => { +const getMedicationCode = ( + medication: Medication | MedicationRequest | undefined +): string | undefined => { // grab the medication drug code from the Medication resource let drugCode; if (medication?.resourceType == 'Medication') { @@ -27,26 +29,24 @@ const getMedicationCode = (medication: Medication | MedicationRequest | undefine } }); } else { - if(medication?.medicationCodeableConcept){ + if (medication?.medicationCodeableConcept) { medication?.medicationCodeableConcept?.coding?.forEach(medCode => { if (medCode.system?.endsWith('rxnorm')) { drugCode = medCode.code; } }); - } else if(medication?.medicationReference){ - const ref = medication.medicationReference.reference - if(ref?.startsWith('#')){ + } else if (medication?.medicationReference) { + const ref = medication.medicationReference.reference; + if (ref?.startsWith('#')) { const containedRef = ref.slice(1); - const match = medication.contained?.find((res) => { + const match = medication.contained?.find(res => { return res.id === containedRef; }); - if(match?.resourceType === 'Medication'){ + if (match?.resourceType === 'Medication') { return getMedicationCode(match); } - } } - } return drugCode; };