Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Timing to Medication Request Extractor #204

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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)) {
Expand All @@ -53,6 +56,8 @@ function formatData(medicationData, patientId) {
doseRateType,
doseQuantityValue,
doseQuantityUnit,
timingCode,
timingEvent: !timingEvent ? null : formatDateTime(timingEvent),
};
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/schemas/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ const CSVCancerRelatedMedicationRequestSchema = {
{ name: 'doseRateType' },
{ name: 'doseQuantityValue' },
{ name: 'doseQuantityUnit' },
{ name: 'timingCode' },
{ name: 'timingEvent' },
],
};

Expand Down
16 changes: 14 additions & 2 deletions src/templates/CancerRelatedMedicationRequestTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,24 @@ function doseAndRateTemplate({ doseRateType, doseQuantityValue, doseQuantityUnit
};
}

function timingTemplate({ timingCode, timingEvent }) {
return {
timing: {
...(timingEvent && { 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 }),
}],
};
}
Expand All @@ -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; ';
Expand All @@ -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 }),
Expand Down
15 changes: 14 additions & 1 deletion test/extractors/fixtures/csv-medication-request-bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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,,,,,,,
15 changes: 14 additions & 1 deletion test/templates/fixtures/maximal-medication-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 8 additions & 0 deletions test/templates/medicationRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -43,6 +45,8 @@ const REQUEST_MINIMAL_DATA = {
doseRateType: null,
doseQuantityValue: null,
doseQuantityUnit: null,
timingEvent: null,
timingCode: null,
};


Expand All @@ -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', () => {
Expand Down Expand Up @@ -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 = {
Expand Down
Loading