Handle scope on TestScript R4 <-> r5 conversion

This commit is contained in:
Grahame Grieve 2022-05-19 17:05:37 +10:00
parent d39ed690f8
commit 7432b40c84
5 changed files with 511 additions and 0 deletions

View File

@ -1,13 +1,33 @@
package org.hl7.fhir.convertors.advisors.impl;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nonnull;
import org.hl7.fhir.convertors.advisors.interfaces.BaseAdvisor50;
import org.hl7.fhir.exceptions.FHIRException;
public class BaseAdvisor_40_50 extends BaseAdvisor50<org.hl7.fhir.r4.model.Extension> {
private static final List<String> TestScriptIgnoredUrls = Arrays.asList("http://hl7.org/fhir/5.0/StructureDefinition/extension-TestScript.scope");
public BaseAdvisor_40_50() {
}
public BaseAdvisor_40_50(Boolean failFast) {
this.failFast = failFast;
}
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) throws FHIRException {
List<String> paths = Arrays.asList(path.split(","));
if ((paths.get(paths.size() - 1).equals("TestScript")) && (TestScriptIgnoredUrls.contains(url))) {
return true;
} else
return false;
}
}

View File

@ -9,6 +9,8 @@ import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.UsageConte
import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.*;
import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.utils.ToolingExtensions;
import org.hl7.fhir.r5.model.TestScript.TestScriptScopeComponent;
/*
Copyright (c) 2011+, HL7, Inc.
@ -46,6 +48,19 @@ public class TestScript40_50 {
return null;
org.hl7.fhir.r5.model.TestScript tgt = new org.hl7.fhir.r5.model.TestScript();
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
for (org.hl7.fhir.r4.model.Extension ext : src.getExtensionsByUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-TestScript.scope")) {
// the advisor will get this ignored.
TestScriptScopeComponent scope = tgt.addScope();
scope.setArtifact(ext.getExtensionString("artifact"));
org.hl7.fhir.r4.model.Extension se = ext.getExtensionByUrl("conformance");
if (se != null) {
scope.setConformance(CodeableConcept40_50.convertCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) se.getValue()));
}
se = ext.getExtensionByUrl("phase");
if (se != null) {
scope.setPhase(CodeableConcept40_50.convertCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) se.getValue()));
}
}
if (src.hasUrl())
tgt.setUrlElement(Uri40_50.convertUri(src.getUrlElement()));
if (src.hasIdentifier())
@ -148,6 +163,25 @@ public class TestScript40_50 {
tgt.addTest(convertTestScriptTestComponent(t));
if (src.hasTeardown())
tgt.setTeardown(convertTestScriptTeardownComponent(src.getTeardown()));
for (TestScriptScopeComponent scope : src.getScope()) {
org.hl7.fhir.r4.model.Extension ext = tgt.addExtension();
ext.setUrl("http://hl7.org/fhir/5.0/StructureDefinition/extension-TestScript.scope");
if (scope.hasArtifact()) {
org.hl7.fhir.r4.model.Extension se = ext.addExtension();
se.setUrl("artifact");
se.setValue(Canonical40_50.convertCanonical(scope.getArtifactElement()));
}
if (scope.hasConformance()) {
org.hl7.fhir.r4.model.Extension se = ext.addExtension();
se.setUrl("conformance");
se.setValue(CodeableConcept40_50.convertCodeableConcept(scope.getConformance()));
}
if (scope.hasPhase()) {
org.hl7.fhir.r4.model.Extension se = ext.addExtension();
se.setUrl("phase");
se.setValue(CodeableConcept40_50.convertCodeableConcept(scope.getPhase()));
}
}
return tgt;
}

View File

@ -0,0 +1,47 @@
package org.hl7.fhir.convertors.conv40_50;
import java.io.IOException;
import java.io.InputStream;
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class TestScript40_50Test {
@Test
@DisplayName("Test TestScript R4 <-> R5 with resoutce scope extension")
public void testValueExpressionConversion40_10() throws IOException {
InputStream r4_stream = this.getClass().getResourceAsStream("/test_script_r4.json");
org.hl7.fhir.r4.model.TestScript r4_input = (org.hl7.fhir.r4.model.TestScript) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_stream);
InputStream r5_stream = this.getClass().getResourceAsStream("/test_script_r5.json");
org.hl7.fhir.r5.model.TestScript r5_input = (org.hl7.fhir.r5.model.TestScript) new org.hl7.fhir.r5.formats.JsonParser().parse(r5_stream);
org.hl7.fhir.r5.model.TestScript r5_output = (org.hl7.fhir.r5.model.TestScript) VersionConvertorFactory_40_50.convertResource(r4_input);
org.hl7.fhir.r4.model.TestScript r4_output = (org.hl7.fhir.r4.model.TestScript) VersionConvertorFactory_40_50.convertResource(r5_input);
org.hl7.fhir.r5.formats.JsonParser r5_parser = new org.hl7.fhir.r5.formats.JsonParser();
String r5_in = r5_parser.setOutputStyle(OutputStyle.PRETTY).composeString(r5_input);
String r5_out = r5_parser.composeString(r5_output);
boolean pass = r5_input.equalsDeep(r5_output);
if (!pass) {
System.out.println("R5. Expected out ->\n"+ r5_in + "\n\nActual out ->\n" + r5_out);
}
Assertions.assertTrue(pass);
org.hl7.fhir.r4.formats.JsonParser r4_parser = new org.hl7.fhir.r4.formats.JsonParser();
String r4_in = r4_parser.composeString(r4_input);
String r4_out = r4_parser.composeString(r4_output);
pass = r4_input.equalsDeep(r4_output);
if (!pass) {
System.out.println("R4. Expected out ->\n"+ r4_in + "\n\nActual out ->\n" + r4_out);
}
Assertions.assertTrue(pass);
}
}

View File

@ -0,0 +1,208 @@
{
"resourceType": "TestScript",
"extension" : [{
"url" : "http://hl7.org/fhir/5.0/StructureDefinition/extension-TestScript.scope",
"extension" : [{
"url" : "artifact",
"valueCanonical" : "http://somewhere.org/fhir/uv/myig/StructureDefinition/mypatient"
},{
"url" : "conformance",
"valueCodeableConcept" : {
"coding" : [
{
"system" : "http://terminology.hl7.org/CodeSystem/testscript-scope-conformance-codes",
"code" : "required",
"display" : "Required"
}
]
}
}]
}],
"id": "testscript-example-readtest",
"version": "1.0",
"name": "TestScript Example Read Test",
"status": "draft",
"experimental": true,
"date": "2017-01-18",
"publisher": "HL7",
"contact": [
{
"name": "Support",
"telecom": [
{
"system": "email",
"value": "support@HL7.org",
"use": "work"
}
]
}
],
"description": "TestScript example resource for simple read test.",
"purpose": "Patient Read Operation",
"copyright": "© HL7.org 2011+",
"metadata": {
"link": [
{
"url": "http://hl7.org/fhir/patient.html",
"description": "Demographics and other administrative information about an individual or animal receiving care or other health-related services."
}
]
},
"profile": [
{
"id": "patient-profile",
"reference": "http://hl7.org/fhir/StructureDefinition/Patient"
}
],
"variable": [
{
"name": "KnownPatientResourceId",
"defaultValue": "example"
},
{
"name": "NonExistsPatientResourceId",
"defaultValue": "does-not-exist"
}
],
"test": [
{
"id": "R001",
"name": "Sprinkler Read Test R001",
"description": "Read a known Patient and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Read the known Patient resource on the destination test system using the user defined dynamic variable ${KnownPatientResourceId}.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/${KnownPatientResourceId}"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 200(OK).",
"response": "okay",
"warningOnly": false
}
},
{
"assert": {
"description": "Confirm that the returned format is XML.",
"contentType": "xml",
"warningOnly": false
}
},
{
"assert": {
"description": "Confirm that the returned HTTP Header Last-Modified is present. Warning only as the server might not support versioning.",
"headerField": "Last-Modified",
"operator": "notEmpty",
"warningOnly": true
}
},
{
"assert": {
"description": "Confirm that the returned resource type is Patient.",
"resource": "Patient",
"warningOnly": false
}
},
{
"assert": {
"description": "Confirm that the returned Patient conforms to the base FHIR specification.",
"validateProfileId": "patient-profile",
"warningOnly": false
}
}
]
},
{
"id": "R002",
"name": "Sprinkler Read Test R002",
"description": "Read an unknown Resource Type and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Attempt to read the Parameters resource type. What we really want here is an illegal type but the build process won't allow that. Parameters is a valid resource which doesn't have an end-point so, this should fail.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/1"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 404(Not Found).",
"response": "notFound",
"warningOnly": false
}
}
]
},
{
"id": "R003",
"name": "Sprinkler Read Test R003",
"description": "Read a known, non-existing Patient and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Attempt to read the non-existing Patient resource on the destination test system using the user defined dynamic variable ${NonExistsPatientResourceId}.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/${NonExistsPatientResourceId}"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 404(Not Found).",
"response": "notFound",
"warningOnly": false
}
}
]
},
{
"id": "R004",
"name": "Sprinkler Read Test R004",
"description": "Read a Patient using a known bad formatted resource id and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Attempt to read a Patient resource on the destination test system using known bad formatted resource id.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/ID-may-not-contain-CAPITALS"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 400(Bad Request).",
"response": "bad",
"warningOnly": false
}
}
]
}
]
}

View File

@ -0,0 +1,202 @@
{
"resourceType": "TestScript",
"id": "testscript-example-readtest",
"scope": [
{
"artifact": "http://somewhere.org/fhir/uv/myig/StructureDefinition/mypatient",
"conformance": {
"coding": [
{
"system" : "http://terminology.hl7.org/CodeSystem/testscript-scope-conformance-codes",
"code" : "required",
"display" : "Required"
}
]
}
}
],
"version": "1.0",
"name": "TestScript Example Read Test",
"status": "draft",
"experimental": true,
"date": "2017-01-18",
"publisher": "HL7",
"contact": [
{
"name": "Support",
"telecom": [
{
"system": "email",
"value": "support@HL7.org",
"use": "work"
}
]
}
],
"description": "TestScript example resource for simple read test.",
"purpose": "Patient Read Operation",
"copyright": "© HL7.org 2011+",
"metadata": {
"link": [
{
"url": "http://hl7.org/fhir/patient.html",
"description": "Demographics and other administrative information about an individual or animal receiving care or other health-related services."
}
]
},
"profile": [
{
"id": "patient-profile",
"reference": "http://hl7.org/fhir/StructureDefinition/Patient"
}
],
"variable": [
{
"name": "KnownPatientResourceId",
"defaultValue": "example"
},
{
"name": "NonExistsPatientResourceId",
"defaultValue": "does-not-exist"
}
],
"test": [
{
"id": "R001",
"name": "Sprinkler Read Test R001",
"description": "Read a known Patient and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Read the known Patient resource on the destination test system using the user defined dynamic variable ${KnownPatientResourceId}.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/${KnownPatientResourceId}"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 200(OK).",
"response": "okay",
"warningOnly": false
}
},
{
"assert": {
"description": "Confirm that the returned format is XML.",
"contentType": "xml",
"warningOnly": false
}
},
{
"assert": {
"description": "Confirm that the returned HTTP Header Last-Modified is present. Warning only as the server might not support versioning.",
"headerField": "Last-Modified",
"operator": "notEmpty",
"warningOnly": true
}
},
{
"assert": {
"description": "Confirm that the returned resource type is Patient.",
"resource": "Patient",
"warningOnly": false
}
},
{
"assert": {
"description": "Confirm that the returned Patient conforms to the base FHIR specification.",
"validateProfileId": "patient-profile",
"warningOnly": false
}
}
]
},
{
"id": "R002",
"name": "Sprinkler Read Test R002",
"description": "Read an unknown Resource Type and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Attempt to read the Parameters resource type. What we really want here is an illegal type but the build process won't allow that. Parameters is a valid resource which doesn't have an end-point so, this should fail.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/1"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 404(Not Found).",
"response": "notFound",
"warningOnly": false
}
}
]
},
{
"id": "R003",
"name": "Sprinkler Read Test R003",
"description": "Read a known, non-existing Patient and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Attempt to read the non-existing Patient resource on the destination test system using the user defined dynamic variable ${NonExistsPatientResourceId}.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/${NonExistsPatientResourceId}"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 404(Not Found).",
"response": "notFound",
"warningOnly": false
}
}
]
},
{
"id": "R004",
"name": "Sprinkler Read Test R004",
"description": "Read a Patient using a known bad formatted resource id and validate response.",
"action": [
{
"operation": {
"type": {
"system": "http://terminology.hl7.org/CodeSystem/testscript-operation-codes",
"code": "read"
},
"resource": "Patient",
"description": "Attempt to read a Patient resource on the destination test system using known bad formatted resource id.",
"accept": "xml",
"encodeRequestUrl": true,
"params": "/ID-may-not-contain-CAPITALS"
}
},
{
"assert": {
"description": "Confirm that the returned HTTP status is 400(Bad Request).",
"response": "bad",
"warningOnly": false
}
}
]
}
]
}