Skip to content

Commit ccc3412

Browse files
committed
Get ResearchStudy resources from context
1 parent fac2f08 commit ccc3412

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

src/helpers/contextUtils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,20 @@ function getEncountersFromContext(context) {
6262
return encounterResourcesInContext;
6363
}
6464

65+
function getResearchStudiesFromContext(context) {
66+
logger.debug('Getting ResearchStudy resources from context');
67+
const researchStudyResourcesInContext = getBundleResourcesByType(context, 'ResearchStudy', {}, false);
68+
if (researchStudyResourcesInContext.length === 0) {
69+
throw Error('Could not find any ResearchStudy resources in context; ensure that a ClinicalTrialInformationExtractor or ResearchStudyExtractor is used earlier in your extraction configuration');
70+
}
71+
logger.debug(`ResearchStudy resources found in context. Found ${researchStudyResourcesInContext.length} ResearchStudy resources.`);
72+
return researchStudyResourcesInContext;
73+
}
74+
6575
module.exports = {
6676
getConditionEntriesFromContext,
6777
getConditionsFromContext,
6878
getEncountersFromContext,
6979
getPatientFromContext,
80+
getResearchStudiesFromContext,
7081
};

test/helpers/contextUtils.test.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
const { getConditionEntriesFromContext, getConditionsFromContext, getEncountersFromContext, getPatientFromContext } = require('../../src/helpers/contextUtils');
2-
3-
const MOCK_PATIENT_MRN = '123';
1+
const {
2+
getConditionEntriesFromContext,
3+
getConditionsFromContext,
4+
getEncountersFromContext,
5+
getPatientFromContext,
6+
getResearchStudiesFromContext,
7+
} = require('../../src/helpers/contextUtils');
48

59
describe('getPatientFromContext', () => {
610
const patientResource = {
@@ -124,7 +128,39 @@ describe('getEncountersFromContext', () => {
124128
});
125129

126130
test('Should throw an error if there are no encounters in context', () => {
127-
expect(() => getEncountersFromContext(MOCK_PATIENT_MRN, {}))
131+
expect(() => getEncountersFromContext({}))
128132
.toThrow('Could not find any encounter resources in context; ensure that an EncounterExtractor is used earlier in your extraction configuration');
129133
});
130134
});
135+
136+
describe('getResearchStudyFromContext', () => {
137+
const researchStudyResource = {
138+
resourceType: 'ResearchStudy',
139+
id: 'ResearchStudyExample01',
140+
};
141+
const researchStudyContext = {
142+
resourceType: 'Bundle',
143+
type: 'collection',
144+
entry: [
145+
{
146+
fullUrl: 'context-url-1',
147+
resource: researchStudyResource,
148+
},
149+
{
150+
fullUrl: 'context-url-2',
151+
resource: { ...researchStudyResource, id: 'ResearchStudyExample02' },
152+
},
153+
],
154+
};
155+
156+
test('Should return all ResearchStudy resources in context', () => {
157+
const researchStudyResources = getResearchStudiesFromContext(researchStudyContext);
158+
expect(researchStudyResources).toHaveLength(2);
159+
expect(researchStudyResources[0]).toEqual(researchStudyResource);
160+
});
161+
162+
test('Should throw an error if there are no research studies in context', () => {
163+
expect(() => getResearchStudiesFromContext({}))
164+
.toThrow('Could not find any ResearchStudy resources in context; ensure that a ClinicalTrialInformationExtractor or ResearchStudyExtractor is used earlier in your extraction configuration');
165+
});
166+
});

0 commit comments

Comments
 (0)