Stream: mapping-framework
Topic: Explicit names for rules in map files.
Anthony Rocco (Dec 02 2021 at 15:06):
I'm using HAPI FHIR r4 and trying to perform a transform with the StructureMapUtilities class, however the FHIRLexer is throwing this exception when parsing my map:
org.hl7.fhir.r4.utils.FHIRLexer$FHIRLexerException: Error in ?? at 9, 7: Complex rules must have an explicit name
What makes something a complex rule? I've seen examples of maps where there's to explicit rule names at all, and some where every rule has an explicit name. For reference, here is my map:
map "http://hl7.org/fhir/StructureMap/LabResultToDiagnosticReport" = "LabResultToDiagnosticReport"
uses "http://hl7.org/fhir/StructureDefinition/LabResult" alias LabResult as source
uses "http://hl7.org/fhir/StructureDefinition/DiagnosticReport" alias DiagnosticReport as target
uses "http://hl7.org/fhir/StructureDefinition/Observation" alias Observation as target
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target
group makeBundle(source src : LabResult, target bundle : Bundle) {
src -> bundle.id = uuid();
src -> bundle.type = 'collection';
src -> bundle.entry as entry, entry.resource = create('DiagnosticReport') as report then
TransformDiagnosticReport(src, report), TransformDiagnosticReportPostHandler(src, report, bundle);
}
group TransformDiagnosticReport(source src : LabResult, target report : DiagnosticReport) {
src -> report.id = uuid();
src -> report.status = 'final';
src.facilitycode as ordercode -> report.code = cc("http://loinc.org", ordercode, ordercode)
src.observationdatetime as odt -> report.effectiveDateTime = dateOp(odt, 'dateTime');
src.labresultid as labid -> report.identifier = id('https://xxx', labid);
}
group TransformDiagnosticReportPostHandler(source src : LabResult, source report : DiagnosticReport, target bundle : Bundle) {
src.observations as obs -> bundle.entry as entry, entry.resource = create('Observation') as observation
then TransformObservation(src, report, observation);
}
group TransformObservation(source lab_obs, source report : DiagnosticReport, target observation: Observation) {
lab_obs -> observation.id = uuid();
lab_obs -> observation.status = 'final';
lab_obs.observationidentifier as o_identifier -> observation.identifier = id('https://xxx', o_identifier);
lab_obs.loinc as loinc -> observation.code = cc("http://loinc.org", loinc, loinc);
observation.id as o_id log "$this" -> report.result = create('Reference') as result,
result.reference = evaluate(o_id, '\'Observation/\' + $this');
}
Anthony Rocco (Dec 02 2021 at 15:15):
@Vadim Peretokin
Vadim Peretokin (Dec 02 2021 at 15:23):
I'm not sure off the top of my head, and that name is not called out in the spec. Maybe it means the 'then' statement? I'd try to debug this by cutting everything out and building it back up again until you get the error.
Vadim Peretokin (Dec 02 2021 at 15:27):
src.facilitycode as ordercode -> report.code = cc("http://loinc.org", ordercode, ordercode)
is missing a semicolon - check this @Anthony Rocco
Anthony Rocco (Dec 02 2021 at 17:18):
Vadim Peretokin said:
I'm not sure off the top of my head, and that name is not called out in the spec. Maybe it means the 'then' statement? I'd try to debug this by cutting everything out and building it back up again until you get the error.
Thanks Vadim, and also thank you for your great presentation on FHIR mapping language - it was a big help. I ended up resolving this error by naming all my rules, like so:
src -> bundle.id = uuid() "bundle.id";
src -> bundle.type = 'collection' "bundle.type";
Even those two rules were causing an exception without it.
I'm now encountering this error:
[java] org.hl7.fhir.exceptions.FHIRException: Cannot set property resource on entry - value is not a primitive type (DiagnosticReport) or an ElementModel type
I followed how you constructed the bundle in your video, but maybe the spec has changed since then.
Edit: That error seems to have been an issue with how I was loading the structure definition for DiagnosticReport - has since been resolved. Some of the transformed you used like id
are throwing an Exception saying the transform is unknown, which mapping engine did you use in your presentation?
Vadim Peretokin (Dec 06 2021 at 07:07):
Same one actually! But it was a couple of years ago so things have moved on since then it would seem.
Vadim Peretokin (Dec 06 2021 at 07:08):
It would be good to figure out all the new changes and publish an update :thinking:
Vadim Peretokin (Dec 06 2021 at 07:12):
@Oliver Egger is naming every single rule really required now? It seems a bit unnecessary. Maybe this is not intended?
Declan Kieran (Dec 07 2021 at 09:32):
Anthony Rocco said:
Edit: That error seems to have been an issue with how I was loading the structure definition for DiagnosticReport - has since been resolved. Some of the transformed you used like
id
are throwing an Exception saying the transform is unknown, which mapping engine did you use in your presentation?
I've noticed the unknown map error being thrown because of another error higher up, even when the transform parameter is set to the correct value from the FML map, i.e. in your example the transform=http://hl7.org/fhir/StructureMap/LabResultToDiagnosticReport. It had me looking in the wrong place a few times. This was when using the validator_cli and looking at the output on the terminal, not sure about errors coming back in an OperationOutcome...
Last updated: Apr 12 2022 at 19:14 UTC