From c51b41b70199696cfd7b9392e8fdbbf9ef3f75a9 Mon Sep 17 00:00:00 2001 From: Ilya Beda Date: Tue, 4 Jul 2023 14:56:34 +0400 Subject: [PATCH] Add extensions data tests --- tests/cases/extensions.yaml | 108 +++++++++++++++++++++++++ tests/resources/patient-example-2.json | 26 ++++++ 2 files changed, 134 insertions(+) create mode 100644 tests/cases/extensions.yaml create mode 100644 tests/resources/patient-example-2.json diff --git a/tests/cases/extensions.yaml b/tests/cases/extensions.yaml new file mode 100644 index 0000000..e309c79 --- /dev/null +++ b/tests/cases/extensions.yaml @@ -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 diff --git a/tests/resources/patient-example-2.json b/tests/resources/patient-example-2.json new file mode 100644 index 0000000..1947ac1 --- /dev/null +++ b/tests/resources/patient-example-2.json @@ -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" + } + } + ] + } + } + ] +}