Skip to content

Commit

Permalink
Safe guard filter function and add mocked call to test reference retr…
Browse files Browse the repository at this point in the history
…ieval
  • Loading branch information
jafeltra committed Oct 16, 2019
1 parent 4adb3d6 commit a7c2733
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/__test__/backend/dataaccess/DataAccess.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ const mockSmartClient = {
};
return Promise.resolve({ data });
},
read: function(type, id) {
const data = {
entry: hardCodedFHIRPatient.entry.filter(e => e['resource']['resourceType'] === type && e['resource']['id'] === id)
};
return Promise.resolve({ data });
},
conformance: function(_options) {
const data = {
rest: [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const sampleObservationSearchData = {
entry: hardCodedFHIRPatient.entry.filter(e => e['resource']['resourceType'] === 'Observation')
};

const sampleReferenceResult = {
resourceType: 'Bundle',
entry: hardCodedFHIRPatient.entry.filter(e => e['resource']['resourceType'] === 'Condition')
}


describe('SMART on FHIR data source', function() {
const originalWindowFHIR = window.FHIR;
Expand Down Expand Up @@ -83,7 +88,9 @@ describe('SMART on FHIR data source', function() {
.get('/fhir/Patient?_id=1078857')
.reply(200, samplePatientSearchData)
.get('/fhir/Observation?patient=1078857')
.reply(200, sampleObservationSearchData);
.reply(200, sampleObservationSearchData)
.get('/fhir/Encounter/6a8bc97e-3ba1-4fb5-a478-4b5bd888c793') // reference retrieval
.reply(200, sampleReferenceResult);
// in this case it doesn't need to fetch the metadata since the resourceTypes are manually specified

const dataSource = new McodeV09SmartOnFhirDataSource({ resourceTypes: ['Patient', 'Observation'] });
Expand Down
8 changes: 4 additions & 4 deletions src/dataaccess/HardCodedFHIRPatient.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@
"text": "Prediabetes"
},
"patient": {
"reference": "urn:uuid:eb3cdde1-0f08-4ec3-b926-e071979ec7e1"
"reference": "Patient/eb3cdde1-0f08-4ec3-b926-e071979ec7e1"
},
"encounter": {
"reference": "urn:uuid:6a8bc97e-3ba1-4fb5-a478-4b5bd888c793"
"reference": "Encounter/6a8bc97e-3ba1-4fb5-a478-4b5bd888c793"
},
"onsetDateTime": "2011-07-12T11:19:32-04:00",
"dateRecorded": "2011-07-12T11:19:32-04:00",
Expand Down Expand Up @@ -175,10 +175,10 @@
"text": "Body Height"
},
"subject": {
"reference": "urn:uuid:eb3cdde1-0f08-4ec3-b926-e071979ec7e1"
"reference": "Patient/eb3cdde1-0f08-4ec3-b926-e071979ec7e1"
},
"encounter": {
"reference": "urn:uuid:6a8bc97e-3ba1-4fb5-a478-4b5bd888c793"
"reference": "Encounter/6a8bc97e-3ba1-4fb5-a478-4b5bd888c793"
},
"effectiveDateTime": "2011-07-12T11:19:32-04:00",
"issued": "2011-07-12T11:19:32.283-04:00",
Expand Down
5 changes: 4 additions & 1 deletion src/dataaccess/McodeV09SmartOnFhirDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ class McodeV09SmartOnFhirDataSource extends IDataSource {

// Filter out resources that can only support searching based on patient/subject. Also include the Patient resource type.
resourceTypeFilter = (res) => {
return res.searchInclude.includes(`${res.type}:patient`) || res.searchInclude.includes(`${res.type}:subject`) || res.type === 'Patient';
if (res && res.searchInclude) {
return res.searchInclude.includes(`${res.type}:patient`) || res.searchInclude.includes(`${res.type}:subject`) || res.type === 'Patient';
}
return true;
}

fetchResources() {
Expand Down

0 comments on commit a7c2733

Please sign in to comment.