use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class DiagnosticReportRenderer method addObservationToTable.
private void addObservationToTable(XhtmlNode tbl, ObservationNode o, int i, String cs, boolean refRange, boolean flags, boolean note, boolean effectiveTime, boolean issued, DataType eff, DataType iss) throws UnsupportedEncodingException, FHIRException, IOException {
XhtmlNode tr = tbl.tr();
if (o.obs != null && o.obs.getReference() == null) {
XhtmlNode td = tr.td().colspan(cs);
td.i().tx("This Observation could not be resolved");
} else {
if (o.obs != null && o.obs.getResource() != null) {
addObservationToTable(tr, o.obs.getResource(), i, o.obs.getReference(), refRange, flags, note, effectiveTime, issued, eff, iss);
} else {
XhtmlNode td = tr.td().colspan(cs);
td.i().tx("Observation");
}
if (o.contained != null) {
for (ObservationNode c : o.contained) {
addObservationToTable(tbl, c, i + 1, cs, refRange, flags, note, effectiveTime, issued, eff, iss);
}
}
}
}
use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method getParam.
private Base getParam(Variables vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
DataType p = parameter.getValue();
if (!(p instanceof IdType))
return p;
else {
String n = ((IdType) p).asStringValue();
Base b = vars.get(VariableMode.INPUT, n);
if (b == null)
b = vars.get(VariableMode.OUTPUT, n);
if (b == null)
throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
return b;
}
}
use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method analyseTarget.
private void analyseTarget(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt, String tv, TargetWriter tw, List<StructureDefinition> profiles, String sliceName) throws FHIRException {
VariableForProfiling var = null;
if (tgt.hasContext()) {
var = vars.get(VariableMode.OUTPUT, tgt.getContext());
if (var == null)
throw new FHIRException("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
if (!tgt.hasElement())
throw new FHIRException("Rule \"" + ruleId + "\": Not supported yet");
}
TypeDetails type = null;
if (tgt.hasTransform()) {
type = analyseTransform(context, map, tgt, var, vars);
} else {
Property vp = var.getProperty().getBaseProperty().getChild(tgt.getElement(), tgt.getElement());
if (vp == null)
throw new FHIRException("Unknown Property " + tgt.getElement() + " on " + var.getProperty().getPath());
type = new TypeDetails(CollectionStatus.SINGLETON, vp.getType(tgt.getElement()));
}
if (tgt.getTransform() == StructureMapTransform.CREATE) {
String s = getParamString(vars, tgt.getParameter().get(0));
if (worker.getResourceNames().contains(s))
tw.newResource(tgt.getVariable(), s);
} else {
boolean mapsSrc = false;
for (StructureMapGroupRuleTargetParameterComponent p : tgt.getParameter()) {
DataType pr = p.getValue();
if (pr instanceof IdType && ((IdType) pr).asStringValue().equals(tv))
mapsSrc = true;
}
if (mapsSrc) {
if (var == null)
throw new Error("Rule \"" + ruleId + "\": Attempt to assign with no context");
tw.valueAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + getTransformSuffix(tgt.getTransform()));
} else if (tgt.hasContext()) {
if (isSignificantElement(var.getProperty(), tgt.getElement())) {
String td = describeTransform(tgt);
if (td != null)
tw.keyAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + " = " + td);
}
}
}
DataType fixed = generateFixedValue(tgt);
PropertyWithType prop = updateProfile(var, tgt.getElement(), type, map, profiles, sliceName, fixed, tgt);
if (tgt.hasVariable())
if (tgt.hasElement())
vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
else
vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
}
use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method getParam.
private TypeDetails getParam(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
DataType p = parameter.getValue();
if (!(p instanceof IdType))
return new TypeDetails(CollectionStatus.SINGLETON, ProfileUtilities.sdNs(p.fhirType(), worker.getOverrideVersionNs()));
else {
String n = ((IdType) p).asStringValue();
VariableForProfiling b = vars.get(VariableMode.INPUT, n);
if (b == null)
b = vars.get(VariableMode.OUTPUT, n);
if (b == null)
throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
return b.getProperty().getTypes();
}
}
use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method updateProfile.
private PropertyWithType updateProfile(VariableForProfiling var, String element, TypeDetails type, StructureMap map, List<StructureDefinition> profiles, String sliceName, DataType fixed, StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
if (var == null) {
assert (Utilities.noString(element));
// 1. start the new structure definition
StructureDefinition sdn = worker.fetchResource(StructureDefinition.class, type.getType());
if (sdn == null)
throw new FHIRException("Unable to find definition for " + type.getType());
ElementDefinition edn = sdn.getSnapshot().getElementFirstRep();
PropertyWithType pn = createProfile(map, profiles, new PropertyWithType(sdn.getId(), new Property(worker, edn, sdn), null, type), sliceName, tgt);
return pn;
} else {
assert (!Utilities.noString(element));
Property pvb = var.getProperty().getBaseProperty();
Property pvd = var.getProperty().getProfileProperty();
Property pc = pvb.getChild(element, var.getProperty().getTypes());
if (pc == null)
throw new DefinitionException("Unable to find a definition for " + pvb.getDefinition().getPath() + "." + element);
// the profile structure definition (derived)
StructureDefinition sd = var.getProperty().getProfileProperty().getStructure();
ElementDefinition ednew = sd.getDifferential().addElement();
ednew.setPath(var.getProperty().getProfileProperty().getDefinition().getPath() + "." + pc.getName());
ednew.setUserData("slice-name", sliceName);
ednew.setFixed(fixed);
for (ProfiledType pt : type.getProfiledTypes()) {
if (pt.hasBindings())
ednew.setBinding(pt.getBindings().get(0));
if (pt.getUri().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
String t = pt.getUri().substring(40);
t = checkType(t, pc, pt.getProfiles());
if (t != null) {
if (pt.hasProfiles()) {
for (String p : pt.getProfiles()) if (t.equals("Reference"))
ednew.getType(t).addTargetProfile(p);
else
ednew.getType(t).addProfile(p);
} else
ednew.getType(t);
}
}
}
return new PropertyWithType(var.getProperty().getPath() + "." + element, pc, new Property(worker, ednew, sd), type);
}
}
Aggregations