Skip to content

Commit

Permalink
Merge pull request #197 from mcode/research-subject-period
Browse files Browse the repository at this point in the history
Adding Period to ResearchSubjects in CSVClinicalTrialInformationExtractor
  • Loading branch information
rdingwell authored Sep 28, 2023
2 parents 9e96594 + dde33b6 commit c8902b9
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/extractors/CSVClinicalTrialInformationExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { firstEntryInBundle, getEmptyBundle } = require('../helpers/fhirUtils');
const { getPatientFromContext } = require('../helpers/contextUtils');
const { generateMcodeResources } = require('../templates');
const logger = require('../helpers/logger');
const { formatDateTime } = require('../helpers/dateUtils');
const { CSVClinicalTrialInformationSchema } = require('../helpers/schemas/csv');


Expand All @@ -25,6 +26,8 @@ class CSVClinicalTrialInformationExtractor extends BaseCSVExtractor {
trialresearchid: trialResearchID,
trialstatus: trialStatus,
trialresearchsystem: trialResearchSystem,
startdate: startDate,
enddate: endDate,
} = clinicalTrialData;
const { clinicalSiteID, clinicalSiteSystem } = this;

Expand All @@ -40,6 +43,8 @@ class CSVClinicalTrialInformationExtractor extends BaseCSVExtractor {
trialResearchID,
patientId,
trialResearchSystem,
startDate: !startDate ? null : formatDateTime(startDate),
endDate: !endDate ? null : formatDateTime(endDate),
},
formattedDataStudy: {
trialStatus,
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 @@ -54,6 +54,8 @@ const CSVClinicalTrialInformationSchema = {
{ name: 'trialResearchID', required: true },
{ name: 'trialStatus', required: true },
{ name: 'trialResearchSystem' },
{ name: 'startDate' },
{ name: 'endDate' },
],
};

Expand Down
15 changes: 3 additions & 12 deletions src/templates/EncounterTemplate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
const { ifAllArgsObj } = require('../helpers/templateUtils');
const { coding, reference } = require('./snippets');

function periodTemplate({ startDate, endDate }) {
return {
period: {
start: startDate,
end: endDate,
},
};
}
const { ifAllArgsObj, ifSomeArgsObj } = require('../helpers/templateUtils');
const { coding, reference, periodTemplate } = require('./snippets');

function classTemplate({ classCode, classSystem }) {
return {
Expand Down Expand Up @@ -42,7 +33,7 @@ function encounterTemplate({
...classTemplate({ classCode, classSystem }),
...subjectTemplate({ subject }),
...ifAllArgsObj(typeTemplate)({ typeCode, typeSystem }),
...ifAllArgsObj(periodTemplate)({ startDate, endDate }),
...ifSomeArgsObj(periodTemplate)({ startDate, endDate }),
};
}

Expand Down
6 changes: 5 additions & 1 deletion src/templates/ResearchSubjectTemplate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { reference, identifier, identifierArr } = require('./snippets');
const { reference, identifier, identifierArr, periodTemplate } = require('./snippets');
const { ifSomeArgsObj } = require('../helpers/templateUtils');

function studyTemplate(trialResearchID, trialResearchSystem) {
return {
Expand Down Expand Up @@ -38,6 +39,8 @@ function researchSubjectTemplate({
trialResearchID,
patientId,
trialResearchSystem,
startDate,
endDate,
}) {
if (!(id && enrollmentStatus && trialSubjectID && trialResearchID && patientId)) {
throw Error('Trying to render a ResearchStudyTemplate, but a required argument is missing; ensure that id, trialStatus, trialResearchID, clinicalSiteID are all present');
Expand All @@ -50,6 +53,7 @@ function researchSubjectTemplate({
...studyTemplate(trialResearchID, trialResearchSystem),
...individualTemplate(patientId),
...researchSubjectIdentifiersTemplate(trialSubjectID),
...ifSomeArgsObj(periodTemplate)({ startDate, endDate }),
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/templates/snippets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { stagingMethodTemplate } = require('./cancerStaging');
const { medicationTemplate } = require('./medication');
const { subjectTemplate } = require('./subject');
const { treatmentReasonTemplate } = require('./treatmentReason');
const { periodTemplate } = require('./period');

module.exports = {
bodySiteTemplate,
Expand All @@ -22,6 +23,7 @@ module.exports = {
medicationTemplate,
meta,
narrative,
periodTemplate,
reference,
stagingMethodTemplate,
subjectTemplate,
Expand Down
12 changes: 12 additions & 0 deletions src/templates/snippets/period.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function periodTemplate({ startDate, endDate }) {
return {
period: {
...(startDate && { start: startDate }),
...(endDate && { end: endDate }),
},
};
}

module.exports = {
periodTemplate,
};
4 changes: 4 additions & 0 deletions test/extractors/CSVClinicalTrialInformationExtractor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('CSVClinicalTrialInformationExtractor', () => {
expect(csvClinicalTrialInformationExtractor.joinClinicalTrialData(clonedData, patientId)).toEqual(expect.anything());
if (key === 'patientId') return; // MRN is optional
if (key === 'trialresearchsystem') return; // trialResearchSystem is optional
if (key === 'startdate') return; // startDate is optional
if (key === 'enddate') return; // endDate is optional
delete clonedData[key];
expect(() => csvClinicalTrialInformationExtractor.joinClinicalTrialData(clonedData, patientId)).toThrow(new Error(expectedErrorString));
});
Expand All @@ -52,6 +54,8 @@ describe('CSVClinicalTrialInformationExtractor', () => {
trialResearchID: firstClinicalTrialInfoResponse.trialresearchid,
patientId,
trialResearchSystem: firstClinicalTrialInfoResponse.trialresearchsystem,
startDate: firstClinicalTrialInfoResponse.startdate,
endDate: firstClinicalTrialInfoResponse.enddate,
},
formattedDataStudy: {
trialStatus: firstClinicalTrialInfoResponse.trialstatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"type": "collection",
"entry": [
{
"fullUrl": "urn:uuid:a9235b06dfe8c24b40b938c7a1265ed3087cf0fa43ef0f11375effbb25ecca25",
"fullUrl": "urn:uuid:aea78e13731d4b105b3a731a48ce77602f159d46299bb02aaaf80e49530115bd",
"resource": {
"resourceType": "ResearchSubject",
"id": "a9235b06dfe8c24b40b938c7a1265ed3087cf0fa43ef0f11375effbb25ecca25",
"id": "aea78e13731d4b105b3a731a48ce77602f159d46299bb02aaaf80e49530115bd",
"identifier": [
{
"system": "http://example.com/clinicaltrialsubjectids",
Expand All @@ -26,6 +26,10 @@
"individual": {
"reference": "urn:uuid:mrn-1",
"type": "Patient"
},
"period": {
"start": "2020-01-01",
"end": "2021-01-01"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"enrollmentstatus": "example-enrollment-status",
"trialresearchid": "example-researchId",
"trialstatus": "example-trialStatus",
"trialresearchsystem":"example-system"
"trialresearchsystem":"example-system",
"startdate": "2020-01-01",
"enddate": "2021-01-01"
}
]
8 changes: 4 additions & 4 deletions test/sample-client-data/clinical-trial-information.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mrn,trialSubjectID,enrollmentStatus,trialResearchID,trialStatus,trialResearchSystem
123,subjectId-1,potential-candidate,researchId-1,approved,system-1
456,subjectId-2,on-study-intervention,researchId-1,completed,system-2
789,subjectId-3,on-study-observation,researchId-2,active,
mrn,trialSubjectID,enrollmentStatus,trialResearchID,trialStatus,trialResearchSystem,startDate,endDate
123,subjectId-1,potential-candidate,researchId-1,approved,system-1,2020-01-01,2021-01-03
456,subjectId-2,on-study-intervention,researchId-1,completed,system-2,2023-05-03,
789,subjectId-3,on-study-observation,researchId-2,active,,,
4 changes: 4 additions & 0 deletions test/templates/fixtures/research-subject-resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
},
"individual": {
"reference": "urn:uuid:mCODEPatient1"
},
"period": {
"start": "2020-01-01",
"end": "2021-01-01"
}
}
6 changes: 6 additions & 0 deletions test/templates/researchSubject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const VALID_DATA = {
trialSubjectID: 'trial-123',
trialResearchID: 'rs1',
patientId: 'mCODEPatient1',
startDate: '2020-01-01',
endDate: '2021-01-01',
};

const INVALID_DATA = {
Expand All @@ -16,6 +18,8 @@ const INVALID_DATA = {
trialResearchID: 'rs1',
patientId: 'mCODEPatient1',
trialSubjectID: null,
startDate: '2020-01-01',
endDate: '2021-01-01',
};

describe('test ResearchSubject template', () => {
Expand All @@ -25,6 +29,8 @@ describe('test ResearchSubject template', () => {
expect(generatedResearchSubject.id).toEqual(validResearchSubject.id);
expect(generatedResearchSubject.trialStatus).toEqual(validResearchSubject.trialStatus);
expect(generatedResearchSubject.trialResearchID).toEqual(validResearchSubject.trialResearchID);
expect(generatedResearchSubject.period.start).toEqual(validResearchSubject.period.start);
expect(generatedResearchSubject.period.end).toEqual(validResearchSubject.period.end);
expect(isValidFHIR(generatedResearchSubject)).toBeTruthy();
});

Expand Down

0 comments on commit c8902b9

Please sign in to comment.