From 4da8ce6e7dc232a44925cf1febad73c167cd008d Mon Sep 17 00:00:00 2001 From: oliveregger Date: Fri, 13 Sep 2024 17:40:12 +0200 Subject: [PATCH] #265 --- .vscode/launch.json | 4 ++-- docs/changelog.md | 3 ++- matchbox-server/api.http | 3 +-- matchbox-server/fml.http | 1 - .../StructureMapTransformProvider.java | 20 ++---------------- .../test/resources/application-test-r4.yaml | 5 +++++ matchbox-server/xver.http | 21 +++++++++++++++++++ 7 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 matchbox-server/xver.http diff --git a/.vscode/launch.json b/.vscode/launch.json index d087178f99d..271d57e4f07 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -106,11 +106,11 @@ }, { "type": "java", - "name": "Launch Matchbox-Server (test)", + "name": "Launch Matchbox-Server (test r4)", "request": "launch", "mainClass": "ca.uhn.fhir.jpa.starter.Application", "projectName": "matchbox-server", - "vmArgs": "-Dspring.config.additional-location=file:/Users/oegger/Documents/github/matchbox/matchbox-server/target/test-classes/application-test-r5onr4.yaml", + "vmArgs": "-Dspring.config.additional-location=file:/Users/oegger/Documents/github/matchbox/matchbox-server/target/test-classes/application-test-r4.yaml", "cwd": "${workspaceFolder}/matchbox-server" }, { diff --git a/docs/changelog.md b/docs/changelog.md index 1ef787786c1..d00c1ab3dd5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,6 @@ -2024/09/ Release 3.9.x +2024/09/ Release 3.9.1 - Make CORS configurable, default not activated make cors configurable (now activated) [#271](https://github.com/ahdis/matchbox/issues/271) +- server API FML transforms between different FHIR versions (R4, R4B, R5) [#265](https://github.com/ahdis/matchbox/issues/265), set flag xVersion 2024/09/10 Release 3.9.0 diff --git a/matchbox-server/api.http b/matchbox-server/api.http index edf1f8560cd..cfebebd5931 100644 --- a/matchbox-server/api.http +++ b/matchbox-server/api.http @@ -1,4 +1,4 @@ -@host = http://localhost:8082/matchboxv3 +@host = http://localhost:8080/matchboxv3 ### @host = https://test.ahdis.ch/matchbox ### @host = https://test.ahdis.ch/matchboxv3 @@ -23,6 +23,5 @@ Accept: application/fhir+json GET {{host}}/fhir/OperationDefinition/-s-validate HTTP/1.1 Accept: application/fhir+json - ### $validate OperationDefinition GET {{host}}/tx-reg/resolve HTTP/1.1 diff --git a/matchbox-server/fml.http b/matchbox-server/fml.http index 85c817ca84d..fc94b736640 100644 --- a/matchbox-server/fml.http +++ b/matchbox-server/fml.http @@ -5,7 +5,6 @@ ### returns metadata configuration for server, verify that you have in implementation description "Development Mode" GET {{host}}/metadata HTTP/1.1 Accept: application/fhir+xml;fhirVersion=4.0 -Origin: http://localhost ### Convert Textual representation of a FHIR Mapping Language to StructureMap resource diff --git a/matchbox-server/src/main/java/ch/ahdis/matchbox/mappinglanguage/StructureMapTransformProvider.java b/matchbox-server/src/main/java/ch/ahdis/matchbox/mappinglanguage/StructureMapTransformProvider.java index ca8c4f36c2e..4e54bee336c 100644 --- a/matchbox-server/src/main/java/ch/ahdis/matchbox/mappinglanguage/StructureMapTransformProvider.java +++ b/matchbox-server/src/main/java/ch/ahdis/matchbox/mappinglanguage/StructureMapTransformProvider.java @@ -122,11 +122,6 @@ public void manualInputAndOutput(HttpServletRequest theServletRequest, HttpServl if (map == null) { throw new UnprocessableEntityException("Map not available with canonical url "+source[0]); } - for (StructureMapStructureComponent component : map.getStructure()) { - if (component.getUrl() != null && matchboxEngine.getStructureDefinitionR5(component.getUrl()) == null) { - throw new UnprocessableEntityException("matchbox engine could not be initialized with canonical url required for transform for "+source[0]+ " component "+component.getUrl()); - } - } transform(map, theServletRequest, theServletResponse, matchboxEngine); } else { throw new UnprocessableEntityException("No source parameter provided"); @@ -147,24 +142,13 @@ public void transform(org.hl7.fhir.r5.model.StructureMap map, HttpServletRequest if (highestRankedAcceptValues.contains(Constants.CT_FHIR_JSON)) { responseContentType = Constants.CT_FHIR_JSON_NEW; } + String result = matchboxEngine.transform(new String(theServletRequest.getInputStream().readAllBytes()), contentType.contains("json"), map.getUrl(), responseContentType.contains("json")); - org.hl7.fhir.r5.elementmodel.Element r = matchboxEngine.transform(ByteProvider.forBytes(theServletRequest.getInputStream().readAllBytes()), contentType.contains("xml") ? FhirFormat.XML : FhirFormat.JSON, map.getUrl()); - theServletResponse.setContentType(responseContentType); theServletResponse.setCharacterEncoding("UTF-8"); ServletOutputStream output = theServletResponse.getOutputStream(); - try { - if (output != null) { - if (responseContentType.equals(Constants.CT_FHIR_JSON_NEW)) - new org.hl7.fhir.r5.elementmodel.JsonParser(matchboxEngine.getContext()).compose(r, output, OutputStyle.PRETTY, null); - else - new org.hl7.fhir.r5.elementmodel.XmlParser(matchboxEngine.getContext()).compose(r, output, OutputStyle.PRETTY, null); - } - } catch(org.hl7.fhir.exceptions.FHIRException e) { - log.error("Transform exception", e); - output.write("Exception during Transform".getBytes()); - } + output.write(result.getBytes("UTF-8")); theServletResponse.getOutputStream().close(); } diff --git a/matchbox-server/src/test/resources/application-test-r4.yaml b/matchbox-server/src/test/resources/application-test-r4.yaml index 06950d3caf6..92e4d49c167 100644 --- a/matchbox-server/src/test/resources/application-test-r4.yaml +++ b/matchbox-server/src/test/resources/application-test-r4.yaml @@ -21,6 +21,10 @@ hapi: name: matchbox.health.test.ig.r4 version: 0.1.0 url: classpath:/matchbox.health.test.ig.r4-0.1.0.tgz + xver: + name: hl7.fhir.uv.xver + version: 0.1.0 + url: classpath:/hl7.fhir.uv.xver#0.1.0@mb.tgz matchbox: fhir: context: @@ -29,6 +33,7 @@ matchbox: hl7.fhir.r4.core#4.0.1: - "Constraint failed: dom-6:" - "regex:Entry '(.+)' isn't reachable by traversing forwards from the Composition" + xVersion: true spring: datasource: url: "jdbc:h2:mem:test-r4" diff --git a/matchbox-server/xver.http b/matchbox-server/xver.http new file mode 100644 index 00000000000..f34e19ec4bd --- /dev/null +++ b/matchbox-server/xver.http @@ -0,0 +1,21 @@ +@host = http://localhost:8081/matchboxv3/fhir +### @host = https://test.ahdis.ch/matchbox/fhir + +### returns metadata configuration for server, verify that you have in implementation description "Development Mode" +GET {{host}}/metadata HTTP/1.1 +Accept: application/fhir+xml;fhirVersion=4.0 + +### transform the r4 provided medication to r5 medication +POST {{host}}/StructureMap/$transform?source=http://hl7.org/fhir/uv/xver/StructureMap/Medication4to5 +Accept: application/fhir+json +Content-Type: application/fhir+json + +< ./matchbox-engine/src/test/resources/xvers/medication-r4-med0301.json + + +### ### transform the r5 medication to r4 medication +POST {{host}}/StructureMap/$transform?source=http://hl7.org/fhir/uv/xver/StructureMap/Medication5to4 +Accept: application/fhir+json +Content-Type: application/fhir+json + +< ./matchbox-engine/src/test/resources/xvers/medication-r5-med0301.json \ No newline at end of file