Stream: implementers
Topic: transforms
Sufyan Patel (Jul 28 2021 at 11:10):
Hi, here in the UK we are looking at creating a transform capability to allow a FHIR message to be sent/received to/from an endpoint that is built to accept a different version of FHIR. I understand there are many options from developing the FHIR Mapping files to using the HAPI FHIR library. Is there anyone trying this or any other option?
Declan Kieran (Nov 08 2021 at 17:10):
Hi
I was looking for an example for how to carry out a transform and found an example on the old wiki at
https://wiki.hl7.org/Using_the_FHIR_Validator_to_transform_content
The new wiki page on the new wiki seems to still need migrated
https://confluence.hl7.org/display/FHIR/R3-R4+Transformations
I took an example from the STU3 AllergyIntolerance resource and tried using the example in the wiki to convert it to R4.
When I ran the validator_cli.jar with the following parameters.
java -jar validator_cli.jar r4_allergyintolerance-example.json -output r3_allergyintolerance-transformed.json -transform http://hl7.org/fhir/StructureMap/*4to3 -ig hl7.fhir.transforms.v4v3
I got the error
Exception in thread "main" java.lang.Error: Unable to find map http://hl7.org/fhir/StructureMap/*4to3 (Known Maps = [http://hl7.org/fhir/StructureMap/supplyrequest-transform, http://hl7.org/fhir/StructureMap/example|0.1, http://hl7.org/fhir/StructureMap/example, supplyrequest-transform, http://hl7.org/fhir/StructureMap/supplyrequest-transform|#0, example])
at org.hl7.fhir.validation.ValidationEngine.transform(ValidationEngine.java:405)
at org.hl7.fhir.validation.ValidationEngine.transform(ValidationEngine.java:397)
at org.hl7.fhir.validation.cli.services.ValidationService.transform(ValidationService.java:218)
at org.hl7.fhir.validation.ValidatorCli.doValidation(ValidatorCli.java:241)
at org.hl7.fhir.validation.ValidatorCli.main(ValidatorCli.java:163)
A search of https://packages2.fhir.org/packages shows no packages with transforms as part of the title, so I tried changing the IG to just the r3 and r4 core packages, but then got the error
Exception in thread "main" java.lang.Error: Unable to find map http://hl7.org/fhir/StructureMap/*4to3 (Known Maps = [http://hl7.org/fhir/StructureMap/supplyrequest-transform, http://hl7.org/fhir/StructureMap/example|0.1, http://hl7.org/fhir/StructureMap/example, supplyrequest-transform, http://hl7.org/fhir/StructureMap/supplyrequest-transform|#0, example])
at org.hl7.fhir.validation.ValidationEngine.transform(ValidationEngine.java:405)
at org.hl7.fhir.validation.ValidationEngine.transform(ValidationEngine.java:397)
at org.hl7.fhir.validation.cli.services.ValidationService.transform(ValidationService.java:218)
at org.hl7.fhir.validation.ValidatorCli.doValidation(ValidatorCli.java:241)
at org.hl7.fhir.validation.ValidatorCli.main(ValidatorCli.java:163)
I also changed http://hl7.org/fhir/StructureMap/*4to3 to http://hl7.org/fhir/StructureMap/AllergyIntolerance4to3 based on the instructions in the wiki, but got the same error.
Is there other documentation or examples I could refer to? Is it possible to use the latest pre-built validator_cli.jar to run transforms in this way?
Thanks
René Spronk (Nov 09 2021 at 07:24):
AFAIK FHIR only comes with the transforms for the various Profiling resources, but not for all resource types. You can define your own mapping and subsequently use the validator to execute the transformations.
Declan Kieran (Nov 10 2021 at 09:54):
Thanks, that's good to know. I've been able to make some progress following the tutorial implementation by @Oliver Egger (Thanks, really helpful!) here https://github.com/ahdis/fhir-mapping-tutorial, based on https://www.hl7.org/fhir/mapping-tutorial.html.
Using the instructions for using the validator_cli.jar in java.md, allowed me to run the validator_cli.jar successfully and with a few modifications to the tleft StructureDefinition, StructureMap and FML in the maps directory, I was able to add a new element to the source and remap the simple example in step1 to change the value in the output transform.
I'm going to use this to see if I can now transform the AllergyIntolerance using the FML given here https://www.hl7.org/fhir/allergyintolerance-version-maps.html, as I think either the $convert or $transform operation in the StructureMap resource should generate a StructureMap from the FML (I think...), otherwise I'll try to handcraft it based on the FML.
Oliver Egger (Nov 10 2021 at 10:35):
@Declan Kieran using the maps to transform from R3 to R4 needs special setup because the transform needs to be aware of the different versions. There is java test code available which demonstrates it, see https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/R3R4ConversionTests.java.
Antje Borgmann (Nov 10 2021 at 20:01):
Hello,
I am new to the transform topic. I tried a transformation with an own mapping file, but it failed. Does anyone have an answer to that error?
Exception in thread "main" java.lang.Error: Unable to find map http://example.org/fhir/StructureMap/TestPatientPractioner (Known Maps = [http://hl7.org/fhir/StructureMap/supplyrequest-transform, http://hl7.org/fhir/StructureMap/example|0.1, http://hl7.org/fhir/StructureMap/example, supplyrequest-transform, http://hl7.org/fhir/StructureMap/supplyrequest-transform|#0, example])
at org.hl7.fhir.validation.ValidationEngine.transform(ValidationEngine.java:401)
at org.hl7.fhir.validation.ValidationEngine.transform(ValidationEngine.java:393)
at org.hl7.fhir.validation.cli.services.ValidationService.transform(ValidationService.java:218)
at org.hl7.fhir.validation.ValidatorCli.doValidation(ValidatorCli.java:241)
at org.hl7.fhir.validation.ValidatorCli.main(ValidatorCli.java:163)
I tried it with the direct location of the map file "c:\...\TestPatientPractioner.map, with the URL of the map http://example.org/fhir/StructureMap/TestPatientPractioner, inside and outside of my little IG. But the error ist still the same and -allow-example-urls true was always in the command for the validator.
I use VS Code with the FHIR tools extension, which includes the validator.
So I looked through all DevDay Youtube Videos, FHIR Mapping Language and validator documentation and all Tutorials. The Tutorial of @Oliver Egger worked fine, thanks a lot.
Thanks to all your ideas.
Oliver Egger (Nov 10 2021 at 20:21):
@Antje Borgmann did you provide the map file in a directory and specified the directory with the ig parameter? here an example form the tutorial:
java -jar validator_cli.jar ./maptutorial/step1/source/source1.xml -transform http://hl7.org/fhir/StructureMap/tutorial -version 4.0.1 -ig ./maptutorial/step1/logical -ig ./maptutorial/step1/map -log test.txt -output ./maptutorial/step1/output.xml
if you say your map is within your ig. Did you add there the xml or json StructureMap in the ig? can you confirm that the StructureMap is available in the ig (e.g. artifacts.html)?
Antje Borgmann (Nov 11 2021 at 07:31):
Thanks for your quick reply.
Yes, the map file is within the ig and I used the ig parameter like in step 1.
But there is no StructureMap resource in my ig. In the most github projects were only maps but no StructureMap resources. So I thought the validator doesn't need a StructureMap resource.
That's the next problem. I can't find something in the validator documentation to convert a map into a StructureMap resource.
Is it possible to have core resources e.g. Patient as source, Practioner as target (no profiling) and a map file to copy the name of Patient to Practioner with the validator, only with these three things?
Oliver Egger (Nov 11 2021 at 08:55):
Antje Borgmann said:
Is it possible to have core resources e.g. Patient as source, Practioner as target (no profiling) and a map file to copy the name of Patient to Practioner with the validator, only with these three things?
yes, i uploaded a minimal example here from QuestionnaireResponse to a Patient here, you can use the validator like this:
java -jar validator_cli.jar ./qr.json -transform http://ahdis.ch/matchbox/fml/qr2patgender -version 4.0.1 -ig ./map -output ./output.xml
Oliver Egger (Nov 11 2021 at 08:57):
Antje Borgmann said:
In the most github projects were only maps but no StructureMap resources.
for our projects we always include the StructureMap resource, e.g. see http://fhir.ch/ig/ch-orf/artifacts.html#terminology-structure-maps
Oliver Egger (Nov 11 2021 at 09:06):
Antje Borgmann said:
I can't find something in the validator documentation to convert a map into a StructureMap resource.
I thought it functionality was once included, but cannot find it anymore. Feel free to use the transformation service on our test server, it uses also the java implementation internally, you need do a POST call to https://test.ahdis.ch/matchbox/fhir/StructureMap, see example with REST Client
Antje Borgmann (Nov 11 2021 at 13:00):
Thanks this was very helpful.
Declan Kieran (Nov 19 2021 at 17:06):
Oliver Egger said:
Declan Kieran using the maps to transform from R3 to R4 needs special setup because the transform needs to be aware of the different versions. There is java test code available which demonstrates it, see https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.validation/src/test/java/org/hl7/fhir/conversion/tests/R3R4ConversionTests.java.
Hi Oliver Egger I've got the unit tests running, but they are all failing. It seems the structure definitions are not being added to the context, and this seems to be causing a failure in the parsing of the example files. i.e. after
StructureMapUtilities smu3 = new StructureMapUtilities(contextR3, this);
contextR3.structures is empty, which seems to be something to do with the SimpleWorkerContext being null. When the xml is being parsed, the StructureDefintion is not found and the following error is thrown
This does not appear to be a FHIR resource (unknown namespace/name...
I'm using the example file from the https://github.com/HL7/fhir.git repo, at commit 4cf6f3c0dad1f3691a36c13ce2b0c09a0cf814b6, with the files placed at "C:\work\org.hl7.fhir\build". I running test() in R3R4ConversionTests at whatever version was there when I cloned the org.hl7.fhir.core repo and when that didn't work, I used the code at commit 992f870cb42395938eaf5f38f127ee0a708016f8 (unit test conversions r3r4), which seems to be when the unit tests were merged into the main.
You mentioned that there needs to be some setup done, is there something I'm missing here to load in the structure defintions maybe?
Here is the console output for the first test, including a stack trace.
loading R3
loading R4
loading Maps
loaded
org.hl7.fhir.exceptions.FHIRFormatError: This does not appear to be a FHIR resource (unknown namespace/name 'http://hl7.org/fhir::Account') at line 0 col 0
at org.hl7.fhir.r4.elementmodel.ParserBase.logError(ParserBase.java:88)
at org.hl7.fhir.r4.elementmodel.ParserBase.getDefinition(ParserBase.java:110)
at org.hl7.fhir.r4.elementmodel.XmlParser.parse(XmlParser.java:170)
at org.hl7.fhir.r4.elementmodel.XmlParser.parse(XmlParser.java:162)
at org.hl7.fhir.r4.elementmodel.XmlParser.parse(XmlParser.java:134)
at org.hl7.fhir.conversion.tests.R3R4ConversionTests.test(R3R4ConversionTests.java:145)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Last updated: Apr 12 2022 at 19:14 UTC