From 58bee0754aec4f6a0d995cb5c2ec273d53387adb Mon Sep 17 00:00:00 2001 From: Oliver Egger Date: Wed, 13 Nov 2019 19:29:17 +0100 Subject: [PATCH] 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) {