diff --git a/src/extractors/CSVCancerRelatedMedicationRequestExtractor.js b/src/extractors/CSVCancerRelatedMedicationRequestExtractor.js index 1ba76cf..74db58a 100644 --- a/src/extractors/CSVCancerRelatedMedicationRequestExtractor.js +++ b/src/extractors/CSVCancerRelatedMedicationRequestExtractor.js @@ -2,6 +2,7 @@ const { BaseCSVExtractor } = require('./BaseCSVExtractor'); const { generateMcodeResources } = require('../templates'); const { getPatientFromContext } = require('../helpers/contextUtils'); const { getEmptyBundle } = require('../helpers/fhirUtils'); +const { formatDateTime } = require('../helpers/dateUtils'); const logger = require('../helpers/logger'); const { CSVCancerRelatedMedicationRequestSchema } = require('../helpers/schemas/csv'); @@ -28,6 +29,8 @@ function formatData(medicationData, patientId) { doseratetype: doseRateType, dosequantityvalue: doseQuantityValue, dosequantityunit: doseQuantityUnit, + timingcode: timingCode, + timingevent: timingEvent, } = medication; if (!(code && codeSystem && status && intent && requesterId)) { @@ -53,6 +56,8 @@ function formatData(medicationData, patientId) { doseRateType, doseQuantityValue, doseQuantityUnit, + timingCode, + timingEvent: !timingEvent ? null : formatDateTime(timingEvent), }; }); } diff --git a/src/helpers/schemas/csv.js b/src/helpers/schemas/csv.js index e86570b..9845a49 100644 --- a/src/helpers/schemas/csv.js +++ b/src/helpers/schemas/csv.js @@ -122,6 +122,8 @@ const CSVCancerRelatedMedicationRequestSchema = { { name: 'doseRateType' }, { name: 'doseQuantityValue' }, { name: 'doseQuantityUnit' }, + { name: 'timingCode' }, + { name: 'timingEvent' }, ], }; diff --git a/src/templates/CancerRelatedMedicationRequestTemplate.js b/src/templates/CancerRelatedMedicationRequestTemplate.js index 9568a95..9e00cae 100644 --- a/src/templates/CancerRelatedMedicationRequestTemplate.js +++ b/src/templates/CancerRelatedMedicationRequestTemplate.js @@ -41,14 +41,24 @@ function doseAndRateTemplate({ doseRateType, doseQuantityValue, doseQuantityUnit }; } +function timingTemplate({ timingCode, timingEvent }) { + return { + timing: { + event: [timingEvent], + code: { coding: [coding({ code: timingCode, system: 'http://terminology.hl7.org/CodeSystem/v3-GTSAbbreviation' })] }, + }, + }; +} + function dosageInstructionTemplate({ - dosageRoute, asNeededCode, doseRateType, doseQuantityValue, doseQuantityUnit, + dosageRoute, asNeededCode, doseRateType, doseQuantityValue, doseQuantityUnit, timingCode, timingEvent, }) { return { dosageInstruction: [{ route: { coding: [coding({ code: dosageRoute, system: 'http://snomed.info/sct' })] }, asNeededCodeableConcept: { coding: [coding({ code: asNeededCode, system: 'http://snomed.info/sct' })] }, ...ifSomeArgsObj(doseAndRateTemplate)({ doseRateType, doseQuantityValue, doseQuantityUnit }), + ...ifSomeArgsObj(timingTemplate)({ timingCode, timingEvent }), }], }; } @@ -72,6 +82,8 @@ function cancerRelatedMedicationRequestTemplate({ doseRateType, doseQuantityValue, doseQuantityUnit, + timingCode, + timingEvent, }) { if (!(subjectId && code && codeSystem && status && intent && requesterId)) { const e1 = 'Trying to render a CancerRelatedMedicationRequestTemplate, but a required argument is missing; '; @@ -91,7 +103,7 @@ function cancerRelatedMedicationRequestTemplate({ status, intent, ...medicationTemplate({ code, codeSystem, displayText }), - ...ifSomeArgsObj(dosageInstructionTemplate)({ dosageRoute, asNeededCode, doseRateType, doseQuantityValue, doseQuantityUnit }), + ...ifSomeArgsObj(dosageInstructionTemplate)({ dosageRoute, asNeededCode, doseRateType, doseQuantityValue, doseQuantityUnit, timingCode, timingEvent }), ...ifAllArgsObj(subjectTemplate)({ id: subjectId }), ...(authoredOn && { authoredOn: formatDateTime(authoredOn) }), ...ifAllArgsObj(requesterTemplate)({ id: requesterId }), diff --git a/test/extractors/fixtures/csv-medication-request-bundle.json b/test/extractors/fixtures/csv-medication-request-bundle.json index 45be2f3..9908fdd 100644 --- a/test/extractors/fixtures/csv-medication-request-bundle.json +++ b/test/extractors/fixtures/csv-medication-request-bundle.json @@ -69,7 +69,20 @@ "unit": "example-unit" } } - ] + ], + "timing": { + "event": [ + "YYYY-MM-DD" + ], + "code": { + "coding": [ + { + "system": "http://terminology.hl7.org/CodeSystem/v3-GTSAbbreviation", + "code": "example-code" + } + ] + } + } } ], "subject": { diff --git a/test/extractors/fixtures/csv-medication-request-module-response.json b/test/extractors/fixtures/csv-medication-request-module-response.json index b470a49..bec0c8e 100644 --- a/test/extractors/fixtures/csv-medication-request-module-response.json +++ b/test/extractors/fixtures/csv-medication-request-module-response.json @@ -17,6 +17,8 @@ "asneededcode": "example-asneeded", "doseratetype": "example-type", "dosequantityvalue": "111", - "dosequantityunit": "example-unit" + "dosequantityunit": "example-unit", + "timingevent": "YYYY-MM-DD", + "timingcode": "example-code" } ] \ No newline at end of file diff --git a/test/sample-client-data/cancer-related-medication-request-information.csv b/test/sample-client-data/cancer-related-medication-request-information.csv index 36da576..7dd3be0 100644 --- a/test/sample-client-data/cancer-related-medication-request-information.csv +++ b/test/sample-client-data/cancer-related-medication-request-information.csv @@ -1,4 +1,4 @@ -mrn,requestId,code,codeSystem,displayText,treatmentReasonCode,treatmentReasonCodeSystem,treatmentReasonDisplayText,procedureIntent,status,intent,authoredOn,requesterId,dosageRoute,asNeededCode,doseRateType,doseQuantityValue,doseQuantityUnit -123,requestId-1,10760,http://www.nlm.nih.gov/research/umls/rxnorm,Triamcinolone Oral Paste,999000,http://snomed.info/sct,Mixed islet cell and exocrine adenocarcinoma,373808002,active,order,2020-01-01,requester-1,26643006,1152001,calculated,100,mg -456,requestId-2,91318,http://www.nlm.nih.gov/research/umls/rxnorm,Coal Tar Topical Solution,915007,http://snomed.info/sct,Malignant melanoma in junctional nevus,373808002,on-hold,proposal,2019-02-02,requester-2,46713006,1140008,ordered,50,mg -789,requestId-3,91833,http://www.nlm.nih.gov/research/umls/rxnorm,Vitamin K1 Injectable Solution [Aquamephyton],900006,http://snomed.info/sct,Mucin-producing adenocarcinoma,363676003,cancelled,plan,,requester-3,,,,, +mrn,requestId,code,codeSystem,displayText,treatmentReasonCode,treatmentReasonCodeSystem,treatmentReasonDisplayText,procedureIntent,status,intent,authoredOn,requesterId,dosageRoute,asNeededCode,doseRateType,doseQuantityValue,doseQuantityUnit,timingCode,timingEvent +123,requestId-1,10760,http://www.nlm.nih.gov/research/umls/rxnorm,Triamcinolone Oral Paste,999000,http://snomed.info/sct,Mixed islet cell and exocrine adenocarcinoma,373808002,active,order,2020-01-01,requester-1,26643006,1152001,calculated,100,mg,QD,2023-01-01 +456,requestId-2,91318,http://www.nlm.nih.gov/research/umls/rxnorm,Coal Tar Topical Solution,915007,http://snomed.info/sct,Malignant melanoma in junctional nevus,373808002,on-hold,proposal,2019-02-02,requester-2,46713006,1140008,ordered,50,mg,AM,2023-04-04 +789,requestId-3,91833,http://www.nlm.nih.gov/research/umls/rxnorm,Vitamin K1 Injectable Solution [Aquamephyton],900006,http://snomed.info/sct,Mucin-producing adenocarcinoma,363676003,cancelled,plan,,requester-3,,,,,,, diff --git a/test/templates/fixtures/maximal-medication-request.json b/test/templates/fixtures/maximal-medication-request.json index 5b52b76..988cac6 100644 --- a/test/templates/fixtures/maximal-medication-request.json +++ b/test/templates/fixtures/maximal-medication-request.json @@ -63,7 +63,20 @@ "unit": "example-unit" } } - ] + ], + "timing": { + "event": [ + "2020-01-01" + ], + "code": { + "coding": [ + { + "system": "http://terminology.hl7.org/CodeSystem/v3-GTSAbbreviation", + "code": "example-code" + } + ] + } + } } ], "subject": { diff --git a/test/templates/medicationRequest.test.js b/test/templates/medicationRequest.test.js index 768fb4d..6e622dc 100644 --- a/test/templates/medicationRequest.test.js +++ b/test/templates/medicationRequest.test.js @@ -23,6 +23,8 @@ const REQUEST_VALID_DATA = { doseRateType: 'example-type', doseQuantityValue: '111', doseQuantityUnit: 'example-unit', + timingEvent: '2020-01-01', + timingCode: 'example-code', }; const REQUEST_MINIMAL_DATA = { @@ -43,6 +45,8 @@ const REQUEST_MINIMAL_DATA = { doseRateType: null, doseQuantityValue: null, doseQuantityUnit: null, + timingEvent: null, + timingCode: null, }; @@ -65,6 +69,8 @@ const REQUEST_INVALID_DATA = { doseRateType: 'example-type', doseQuantityValue: '111', doseQuantityUnit: 'example-unit', + timingEvent: '2020-01-01', + timingCode: 'example-code', }; describe('test Medication Request template', () => { @@ -96,6 +102,8 @@ describe('test Medication Request template', () => { doseRateType: 'example-type', doseQuantityValue: '111', doseQuantityUnit: 'example-unit', + timingEvent: '2020-01-01', + timingCode: 'example-code', }; const NECESSARY_DATA = {