Skip to content

Commit

Permalink
Add extensions data tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Jul 4, 2023
1 parent 7de0ad4 commit c51b41b
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
108 changes: 108 additions & 0 deletions tests/cases/extensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
tests:
# https://www.hl7.org/fhir/fhirpath.html#types
- 'group: Extension and id for primitive types':

- desc: '** id for primitive type'
expression: Functions.attrtrue.id = 'someid'
result:
- true

- desc: '** expression with extension for primitive type 1'
inputfile: patient-example.json
expression: Patient.birthDate.extension.where(url = '').empty()
result:
- true

- desc: '** expression with extension for primitive type 2'
inputfile: patient-example.json
expression: >-
Patient.birthDate.extension
.where(url = 'http://hl7.org/fhir/StructureDefinition/patient-birthTime')
.valueDateTime.toDateTime() = @1974-12-25T14:35:45-05:00
result:
- true

- desc: '** expression with extension for primitive type 3'
inputfile: patient-example.json
model: r4
expression: >-
Patient.birthDate.extension
.where(url = 'http://hl7.org/fhir/StructureDefinition/patient-birthTime')
.value = @1974-12-25T14:35:45-05:00
result:
- true

# https://www.hl7.org/fhir/fhirpath.html#functions
- 'group: Additional functions':
- desc: 'extension(url : string) : collection'

# If the url is empty ({ }), the result is empty.
- desc: '** empty url'
inputfile: patient-example.json
expression: Patient.birthDate.extension('').empty()
result:
- true

# If the input collection is empty ({ }), the result is empty.
- desc: '** empty input collection'
inputfile: patient-example.json
expression: >-
Patient.birthDate1
.extension('http://hl7.org/fhir/StructureDefinition/patient-birthTime').empty()
result:
- true

- desc: '** expression with extension() for primitive type (without using FHIR model data)'
inputfile: patient-example.json
expression: >-
Patient.birthDate.extension('http://hl7.org/fhir/StructureDefinition/patient-birthTime')
.valueDateTime.toDateTime() = @1974-12-25T14:35:45-05:00
result:
- true

- desc: '** expression with extension() for primitive type (without using FHIR model data) when only extension is present'
inputfile: patient-example-2.json
expression: >-
Patient.communication.preferred.extension('test').exists()
result:
- true

- desc: '** expression with extension() for primitive type (using FHIR model data) when only extension is present'
inputfile: patient-example-2.json
model: r4
expression: >-
Patient.communication.preferred.extension('test').value.id
result:
- testing

- desc: '** expression with extension() for primitive type (using FHIR model data)'
inputfile: patient-example.json
model: r4
expression: >-
Patient.birthDate.extension('http://hl7.org/fhir/StructureDefinition/patient-birthTime')
.value = @1974-12-25T14:35:45-05:00
result:
- true

- desc: '** value of extension of extension (using FHIR model data)'
model: r4
expression: Functions.attrtrue.extension('url1').extension('url2').value = 'someuri'
result:
- true

- desc: '** id of extension of extension'
expression: Functions.attrtrue.extension('url1').extension('url2').id = 'someid2'
result:
- true

subject:
resourceType: Functions
attrtrue: true
_attrtrue:
id: someid
extension:
- url: url1
extension:
- url: url2
id: someid2
valueUri: someuri
26 changes: 26 additions & 0 deletions tests/resources/patient-example-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"resourceType": "Patient",
"communication": [
{
"language": {
"coding": [
{
"system": "urn:ietf:bcp:47",
"code": "nl",
"display": "Dutch"
}
]
},
"_preferred": {
"extension": [
{
"url": "test",
"_valueString": {
"id": "testing"
}
}
]
}
}
]
}

0 comments on commit c51b41b

Please sign in to comment.