fix: use proper target object

This commit is contained in:
I325048 2019-09-17 21:17:00 +05:30
parent d857d546e5
commit 4f9118e9da
3 changed files with 35 additions and 9 deletions

View File

@ -499,6 +499,10 @@ private Map<String, Object> userData;
CodeableConcept cc = new CodeableConcept();
cc.addCoding().setCode(((CodeType) b).asStringValue());
return cc;
} else if(b instanceof StringType) {
CodeableConcept cc = new CodeableConcept();
cc.addCoding().setCode(((StringType) b).asStringValue());
return cc;
} else
throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a CodeableConcept");
}

View File

@ -1888,7 +1888,7 @@ public class StructureMapUtilities {
case EVALUATE :
ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
if (expr == null) {
expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString()));
expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(0), tgt.toString()));
tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
}
List<Base> v = fpe.evaluate(vars, null, null, tgt.getParameter().size() == 2 ? getParam(vars, tgt.getParameter().get(0)) : new BooleanType(false), expr);

View File

@ -1185,19 +1185,41 @@ public class ValidationEngine {
List<Resource> outputs = new ArrayList<Resource>();
StructureMapUtilities scu = new StructureMapUtilities(context, new TransformSupportServices(outputs));
org.hl7.fhir.r5.elementmodel.Element src = Manager.parse(context, new ByteArrayInputStream(source), cntType);
StructureMap map = context.getTransform(mapUri);
if (map == null)
throw new Error("Unable to find map "+mapUri+" (Known Maps = "+context.listMapUrls()+")");
scu.transform(null, src, map, null);
if (outputs.size() == 0)
throw new Exception("This transform did not produce an output");
if (outputs.size() > 1)
throw new Exception("This transform did produced multiple outputs which is not supported in this context");
return outputs.get(0);
Resource resource = getTargetResourceFromStructureMap(map);
scu.transform(null, src, map, resource);
return resource;
}
private Resource getTargetResourceFromStructureMap(StructureMap map) {
String targetTypeUrl = null;
for(StructureMap.StructureMapStructureComponent component: map.getStructure()) {
if(component.getMode() == StructureMap.StructureMapModelMode.TARGET) {
targetTypeUrl = component.getUrl();
break;
}
}
if(targetTypeUrl == null)
throw new FHIRException("Unable to determine resource URL for target type");
StructureDefinition structureDefinition = null;
for(StructureDefinition sd:this.context.getStructures()) {
if(sd.getUrl().equalsIgnoreCase(targetTypeUrl)) {
structureDefinition = sd;
break;
}
}
if(structureDefinition == null)
throw new FHIRException("Unable to determine StructureDefinition for target type");
return ResourceFactory.createResource(structureDefinition.getName());
}
public DomainResource generate(String source) throws Exception {