From 58bee0754aec4f6a0d995cb5c2ec273d53387adb Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Wed, 13 Nov 2019 19:29:17 +0100 Subject: [PATCH 1/2] fml: validator change transform to elementmodel --- .../hl7/fhir/r5/validation/ValidationEngine.java | 13 ++++++------- .../java/org/hl7/fhir/r5/validation/Validator.java | 7 +++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java index c69a663c8..ab43c4207 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java @@ -1210,12 +1210,12 @@ public class ValidationEngine implements IValidatorResourceFetcher { return issue.getSeverity().toString()+" @ "+issue.getLocation() + " " +issue.getDetails().getText() +(source != null ? " (src = "+source+")" : ""); } - public Resource transform(String source, String map) throws Exception { + public org.hl7.fhir.r5.elementmodel.Element transform(String source, String map) throws Exception { Content cnt = loadContent(source, "validate"); return transform(cnt.focus, cnt.cntType, map); } - public Resource transform(byte[] source, FhirFormat cntType, String mapUri) throws Exception { + public org.hl7.fhir.r5.elementmodel.Element transform(byte[] source, FhirFormat cntType, String mapUri) throws Exception { List outputs = new ArrayList(); StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs)); @@ -1224,13 +1224,12 @@ public class ValidationEngine implements IValidatorResourceFetcher { if (map == null) throw new Error("Unable to find map "+mapUri+" (Known Maps = "+context.listMapUrls()+")"); - Resource resource = getTargetResourceFromStructureMap(map); - + org.hl7.fhir.r5.elementmodel.Element resource = getTargetResourceFromStructureMap(map); scu.transform(null, src, map, resource); return resource; } - private Resource getTargetResourceFromStructureMap(StructureMap map) { + private org.hl7.fhir.r5.elementmodel.Element getTargetResourceFromStructureMap(StructureMap map) { String targetTypeUrl = null; for(StructureMap.StructureMapStructureComponent component: map.getStructure()) { if(component.getMode() == StructureMap.StructureMapModelMode.TARGET) { @@ -1252,8 +1251,8 @@ public class ValidationEngine implements IValidatorResourceFetcher { if(structureDefinition == null) throw new FHIRException("Unable to determine StructureDefinition for target type"); - - return ResourceFactory.createResource(structureDefinition.getName()); + + return Manager.build(getContext(), structureDefinition); } public DomainResource generate(String source, String version) throws Exception { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/Validator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/Validator.java index 4a77c56dd..b175d8762 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/Validator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/Validator.java @@ -537,11 +537,14 @@ public class Validator { throw new Exception("Must provide a map when doing a transform"); try { validator.setMapLog(mapLog); - Resource r = validator.transform(sources.get(0), map); + org.hl7.fhir.r5.elementmodel.Element r = validator.transform(sources.get(0), map); System.out.println(" ...success"); if (output != null) { FileOutputStream s = new FileOutputStream(output); - x.compose(s, r); + if (output != null && output.endsWith(".json")) + new org.hl7.fhir.r5.elementmodel.JsonParser(validator.getContext()).compose(r, s, OutputStyle.PRETTY, null); + else + new org.hl7.fhir.r5.elementmodel.XmlParser(validator.getContext()).compose(r, s, OutputStyle.PRETTY, null); s.close(); } } catch (Exception e) { From b86f5a5ac883903c9916c3ba1a6fa28631313541 Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Fri, 15 Nov 2019 16:27:38 +0100 Subject: [PATCH 2/2] use ElementModel for FML in create --- .../hl7/fhir/r5/validation/ValidationEngine.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java index ab43c4207..e39231d8f 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java @@ -250,9 +250,9 @@ public class ValidationEngine implements IValidatorResourceFetcher { public class TransformSupportServices implements ITransformerServices { - private List outputs; + private List outputs; - public TransformSupportServices(List outputs) { + public TransformSupportServices(List outputs) { this.outputs = outputs; } @@ -266,19 +266,13 @@ public class ValidationEngine implements IValidatorResourceFetcher { @Override public Base createType(Object appInfo, String name) throws FHIRException { StructureDefinition sd = context.fetchResource(StructureDefinition.class, name); - if (sd != null && sd.getKind() == StructureDefinitionKind.LOGICAL) { - return Manager.build(context, sd); - } else { - if (name.startsWith("http://hl7.org/fhir/StructureDefinition/")) - name = name.substring("http://hl7.org/fhir/StructureDefinition/".length()); - return ResourceFactory.createResourceOrType(name); - } + return Manager.build(context, sd); } @Override public Base createResource(Object appInfo, Base res, boolean atRootofTransform) { if (atRootofTransform) - outputs.add((Resource) res); + outputs.add(res); return res; } @@ -1216,7 +1210,7 @@ public class ValidationEngine implements IValidatorResourceFetcher { } public org.hl7.fhir.r5.elementmodel.Element transform(byte[] source, FhirFormat cntType, String mapUri) throws Exception { - List outputs = new ArrayList(); + List outputs = new ArrayList(); StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs)); org.hl7.fhir.r5.elementmodel.Element src = Manager.parse(context, new ByteArrayInputStream(source), cntType);