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 af2758d1c..7b95b1653 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; } @@ -1210,13 +1204,13 @@ 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 { - List outputs = new ArrayList(); + 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)); org.hl7.fhir.r5.elementmodel.Element src = Manager.parse(context, new ByteArrayInputStream(source), cntType); @@ -1224,13 +1218,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 +1245,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) {