Merge pull request #106 from ahdis/oliveregger_validator_transform_r4
fml: validator change transform to elementmodel
This commit is contained in:
commit
bd8df9ba90
|
@ -250,9 +250,9 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||||
|
|
||||||
public class TransformSupportServices implements ITransformerServices {
|
public class TransformSupportServices implements ITransformerServices {
|
||||||
|
|
||||||
private List<Resource> outputs;
|
private List<Base> outputs;
|
||||||
|
|
||||||
public TransformSupportServices(List<Resource> outputs) {
|
public TransformSupportServices(List<Base> outputs) {
|
||||||
this.outputs = outputs;
|
this.outputs = outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,19 +266,13 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||||
@Override
|
@Override
|
||||||
public Base createType(Object appInfo, String name) throws FHIRException {
|
public Base createType(Object appInfo, String name) throws FHIRException {
|
||||||
StructureDefinition sd = context.fetchResource(StructureDefinition.class, name);
|
StructureDefinition sd = context.fetchResource(StructureDefinition.class, name);
|
||||||
if (sd != null && sd.getKind() == StructureDefinitionKind.LOGICAL) {
|
|
||||||
return Manager.build(context, sd);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Base createResource(Object appInfo, Base res, boolean atRootofTransform) {
|
public Base createResource(Object appInfo, Base res, boolean atRootofTransform) {
|
||||||
if (atRootofTransform)
|
if (atRootofTransform)
|
||||||
outputs.add((Resource) res);
|
outputs.add(res);
|
||||||
return 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+")" : "");
|
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");
|
Content cnt = loadContent(source, "validate");
|
||||||
return transform(cnt.focus, cnt.cntType, map);
|
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<Resource> outputs = new ArrayList<Resource>();
|
List<Base> outputs = new ArrayList<Base>();
|
||||||
|
|
||||||
StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs));
|
StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs));
|
||||||
org.hl7.fhir.r5.elementmodel.Element src = Manager.parse(context, new ByteArrayInputStream(source), cntType);
|
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)
|
if (map == null)
|
||||||
throw new Error("Unable to find map "+mapUri+" (Known Maps = "+context.listMapUrls()+")");
|
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);
|
scu.transform(null, src, map, resource);
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Resource getTargetResourceFromStructureMap(StructureMap map) {
|
private org.hl7.fhir.r5.elementmodel.Element getTargetResourceFromStructureMap(StructureMap map) {
|
||||||
String targetTypeUrl = null;
|
String targetTypeUrl = null;
|
||||||
for(StructureMap.StructureMapStructureComponent component: map.getStructure()) {
|
for(StructureMap.StructureMapStructureComponent component: map.getStructure()) {
|
||||||
if(component.getMode() == StructureMap.StructureMapModelMode.TARGET) {
|
if(component.getMode() == StructureMap.StructureMapModelMode.TARGET) {
|
||||||
|
@ -1253,7 +1246,7 @@ public class ValidationEngine implements IValidatorResourceFetcher {
|
||||||
if(structureDefinition == null)
|
if(structureDefinition == null)
|
||||||
throw new FHIRException("Unable to determine StructureDefinition for target type");
|
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 {
|
public DomainResource generate(String source, String version) throws Exception {
|
||||||
|
|
|
@ -537,11 +537,14 @@ public class Validator {
|
||||||
throw new Exception("Must provide a map when doing a transform");
|
throw new Exception("Must provide a map when doing a transform");
|
||||||
try {
|
try {
|
||||||
validator.setMapLog(mapLog);
|
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");
|
System.out.println(" ...success");
|
||||||
if (output != null) {
|
if (output != null) {
|
||||||
FileOutputStream s = new FileOutputStream(output);
|
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();
|
s.close();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue