Skip to content

Commit

Permalink
Add resourceType as a mandatory element for resources
Browse files Browse the repository at this point in the history
  • Loading branch information
elsaperelli committed Apr 12, 2024
1 parent 56e916c commit 060df2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/util/exportToNDJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ const getDocuments = async (collectionName, searchParameterQueries, valueSetQuer
mandatoryElements[collectionName].forEach(elem => {
projection[elem] = 1;
});

// add a projection of 1 for resourceType which we have determined to be a mandatory element for each FHIR resource even though
// it is not included in the StructureDefinition
projection['resourceType'] = 1;
}

if (searchParameterQueries) {
Expand Down
5 changes: 3 additions & 2 deletions test/util/exportToNDJson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ describe('check export logic', () => {
});

describe('_elements tests', () => {
test('returns Condition document with only the resourceType, subject (mandatory element for Condition), and the SUBSETTED tag when _elements=Condition.resourceType', async () => {
const docObj = await getDocuments('Condition', undefined, undefined, undefined, ['resourceType']);
test('returns Condition document with only the id, resourceType and subject (mandatory elements for Condition), and the SUBSETTED tag when _elements=Condition.resourceType', async () => {
const docObj = await getDocuments('Condition', undefined, undefined, undefined, ['id']);
expect(docObj.document.length).toEqual(1);
expect(docObj.document[0]).toEqual({
resourceType: 'Condition',
id: 'test-condition',
subject: {
reference: 'Patient/testPatient'
},
Expand Down

0 comments on commit 060df2e

Please sign in to comment.