Skip to content

Commit

Permalink
Adding Period to ResearchSubjects in CSVClinicalTrialInformationExtra…
Browse files Browse the repository at this point in the history
…ctor
  • Loading branch information
dmendelowitz committed Sep 26, 2023
1 parent 9e96594 commit f87a8f5
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 11 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
8 changes: 4 additions & 4 deletions src/templates/EncounterTemplate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { ifAllArgsObj } = require('../helpers/templateUtils');
const { ifAllArgsObj, ifSomeArgsObj } = require('../helpers/templateUtils');
const { coding, reference } = require('./snippets');

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

Expand Down
13 changes: 13 additions & 0 deletions 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 { ifSomeArgsObj } = require('../helpers/templateUtils');

function studyTemplate(trialResearchID, trialResearchSystem) {
return {
Expand Down Expand Up @@ -31,13 +32,24 @@ function researchSubjectIdentifiersTemplate(trialSubjectID) {
);
}

function periodTemplate({ startDate, endDate }) {
return {
period: {
...(startDate && { start: startDate }),
...(endDate && { end: endDate }),
},
};
}

function researchSubjectTemplate({
id,
enrollmentStatus,
trialSubjectID,
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 +62,7 @@ function researchSubjectTemplate({
...studyTemplate(trialResearchID, trialResearchSystem),
...individualTemplate(patientId),
...researchSubjectIdentifiersTemplate(trialSubjectID),
...ifSomeArgsObj(periodTemplate)({ startDate, endDate }),
};
}

Expand Down
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 f87a8f5

Please sign in to comment.