-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add implicit merge for if block instead of merge
Closes #7
- Loading branch information
Showing
3 changed files
with
401 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { QuestionnaireResponse } from 'fhir/r4b'; | ||
import { resolveTemplate } from './extract'; | ||
import * as fhirpath_r4_model from 'fhirpath/fhir-context/r4'; | ||
|
||
const qr: QuestionnaireResponse = { | ||
resourceType: 'QuestionnaireResponse', | ||
status: 'completed', | ||
item: [ | ||
{ | ||
linkId: 'name', | ||
item: [ | ||
{ | ||
linkId: 'last-name', | ||
answer: [ | ||
{ | ||
valueString: 'Beda', | ||
}, | ||
], | ||
}, | ||
{ | ||
linkId: 'first-name', | ||
answer: [ | ||
{ | ||
valueString: 'Ilya', | ||
}, | ||
], | ||
}, | ||
{ | ||
linkId: 'middle-name', | ||
answer: [ | ||
{ | ||
valueString: 'Alekseevich', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
linkId: 'birth-date', | ||
answer: [ | ||
{ | ||
valueDate: '2023-05-01', | ||
}, | ||
], | ||
}, | ||
{ | ||
linkId: 'gender', | ||
answer: [ | ||
{ | ||
valueCoding: { code: 'male' }, | ||
}, | ||
], | ||
}, | ||
{ | ||
linkId: 'ssn', | ||
answer: [ | ||
{ | ||
valueString: '123', | ||
}, | ||
], | ||
}, | ||
{ | ||
linkId: 'mobile', | ||
answer: [ | ||
{ | ||
valueString: '11231231231', | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const template1 = { | ||
resourceType: 'Patient', | ||
name: [ | ||
{ | ||
family: "{{ QuestionnaireResponse.repeat(item).where(linkId='last-name').answer.value }}", | ||
given: [ | ||
"{{ QuestionnaireResponse.repeat(item).where(linkId='first-name').answer.value }}", | ||
"{{ QuestionnaireResponse.repeat(item).where(linkId='middle-name').answer.value }}", | ||
], | ||
}, | ||
], | ||
birthDate: "{{ QuestionnaireResponse.item.where(linkId='birth-date').answer.value }}", | ||
gender: "{{ QuestionnaireResponse.item.where(linkId='gender').answer.valueCoding.code }}", | ||
telecom: [ | ||
{ | ||
system: 'phone', | ||
value: "{{ QuestionnaireResponse.item.where(linkId='mobile').answer.value }}", | ||
}, | ||
], | ||
identifier: [ | ||
{ | ||
system: 'http://hl7.org/fhir/sid/us-ssn', | ||
value: "{{ QuestionnaireResponse.item.where(linkId='ssn').answer.value }}", | ||
}, | ||
], | ||
}; | ||
|
||
|
||
const template2 = { | ||
resourceType: 'Patient', | ||
name: { | ||
"{{ QuestionnaireResponse.item.where(linkId='name') }}": { | ||
family: "{{ item.where(linkId='last-name').answer.valueString }}", | ||
given: [ | ||
"{{ item.where(linkId='first-name').answer.valueString }}", | ||
"{{ item.where(linkId='middle-name').answer.valueString }}", | ||
], | ||
}, | ||
}, | ||
birthDate: "{{ QuestionnaireResponse.item.where(linkId='birth-date').answer.value }}", | ||
gender: "{{ QuestionnaireResponse.item.where(linkId='gender').answer.valueCoding.code }}", | ||
telecom: [ | ||
{ | ||
system: 'phone', | ||
value: "{{ QuestionnaireResponse.item.where(linkId='mobile').answer.value }}", | ||
}, | ||
], | ||
identifier: [ | ||
{ | ||
system: 'http://hl7.org/fhir/sid/us-ssn', | ||
value: "{{ QuestionnaireResponse.item.where(linkId='ssn').answer.value }}", | ||
}, | ||
], | ||
}; | ||
|
||
const result = { | ||
birthDate: '2023-05-01', | ||
gender: 'male', | ||
identifier: [ | ||
{ | ||
system: 'http://hl7.org/fhir/sid/us-ssn', | ||
value: '123', | ||
}, | ||
], | ||
name: [ | ||
{ | ||
family: 'Beda', | ||
given: ['Ilya', 'Alekseevich'], | ||
}, | ||
], | ||
resourceType: 'Patient', | ||
telecom: [ | ||
{ | ||
system: 'phone', | ||
value: '11231231231', | ||
}, | ||
], | ||
}; | ||
|
||
describe('Extraction', () => { | ||
test('Simple transformation', () => { | ||
expect(resolveTemplate(qr, template1, {}, fhirpath_r4_model)).toStrictEqual(result); | ||
}); | ||
|
||
test('List transformation', () => { | ||
expect(resolveTemplate(qr, template2, {}, fhirpath_r4_model)).toStrictEqual(result); | ||
}); | ||
}); | ||
|
Oops, something went wrong.