use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method convertType.
@SuppressWarnings("unchecked")
private DataType convertType(Base value, QuestionnaireItemType af, ValueSet vs, String path) throws FHIRException {
switch(af) {
// simple cases
case BOOLEAN:
if (value instanceof BooleanType)
return (DataType) value;
break;
case DECIMAL:
if (value instanceof DecimalType)
return (DataType) value;
break;
case INTEGER:
if (value instanceof IntegerType)
return (DataType) value;
break;
case DATE:
if (value instanceof DateType)
return (DataType) value;
break;
case DATETIME:
if (value instanceof DateTimeType)
return (DataType) value;
break;
case TIME:
if (value instanceof TimeType)
return (DataType) value;
break;
case STRING:
if (value instanceof StringType)
return (DataType) value;
else if (value instanceof UriType)
return new StringType(((UriType) value).asStringValue());
break;
case TEXT:
if (value instanceof StringType)
return (DataType) value;
break;
case QUANTITY:
if (value instanceof Quantity)
return (DataType) value;
break;
// ? QuestionnaireItemTypeAttachment: ...?
case CODING:
if (value instanceof Coding)
return (DataType) value;
else if (value instanceof Enumeration) {
Coding cc = new Coding();
cc.setCode(((Enumeration<Enum<?>>) value).asStringValue());
cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
return cc;
} else if (value instanceof StringType) {
Coding cc = new Coding();
cc.setCode(((StringType) value).asStringValue());
cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
return cc;
}
break;
case REFERENCE:
if (value instanceof Reference)
return (DataType) value;
else if (value instanceof StringType) {
Reference r = new Reference();
r.setReference(((StringType) value).asStringValue());
}
break;
default:
break;
}
throw new FHIRException("Unable to convert from '" + value.getClass().toString() + "' for Answer Format " + af.toCode() + ", path = " + path);
}
use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateFilters.
private void generateFilters(XhtmlNode x, CodeSystem cs) {
if (cs.hasFilter()) {
x.para().b().tx("Filters");
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx("Code");
tr.td().b().tx("Description");
tr.td().b().tx("operator");
tr.td().b().tx("Value");
for (CodeSystemFilterComponent f : cs.getFilter()) {
tr = tbl.tr();
tr.td().tx(f.getCode());
tr.td().tx(f.getDescription());
XhtmlNode td = tr.td();
for (Enumeration<org.hl7.fhir.dstu3.model.CodeSystem.FilterOperator> t : f.getOperator()) td.tx(t.asStringValue() + " ");
tr.td().tx(f.getValue());
}
}
}
use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method renderLeaf.
private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path) throws FHIRException, UnsupportedEncodingException, IOException {
if (ew == null)
return;
Base e = ew.getBase();
if (e instanceof StringType)
x.addText(((StringType) e).getValue());
else if (e instanceof CodeType)
x.addText(((CodeType) e).getValue());
else if (e instanceof IdType)
x.addText(((IdType) e).getValue());
else if (e instanceof Extension)
return;
else if (e instanceof InstantType)
x.addText(((InstantType) e).toHumanDisplay());
else if (e instanceof DateTimeType)
x.addText(((DateTimeType) e).toHumanDisplay());
else if (e instanceof Base64BinaryType)
x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
else if (e instanceof org.hl7.fhir.dstu3.model.DateType)
x.addText(((org.hl7.fhir.dstu3.model.DateType) e).toHumanDisplay());
else if (e instanceof Enumeration) {
Object ev = ((Enumeration<?>) e).getValue();
// todo: look up a display name if there is one
x.addText(ev == null ? "" : ev.toString());
} else if (e instanceof BooleanType)
x.addText(((BooleanType) e).getValue().toString());
else if (e instanceof CodeableConcept) {
renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
} else if (e instanceof Coding) {
renderCoding((Coding) e, x, showCodeDetails);
} else if (e instanceof Annotation) {
renderAnnotation((Annotation) e, x);
} else if (e instanceof Identifier) {
renderIdentifier((Identifier) e, x);
} else if (e instanceof org.hl7.fhir.dstu3.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.dstu3.model.IntegerType) e).getValue()));
} else if (e instanceof org.hl7.fhir.dstu3.model.DecimalType) {
x.addText(((org.hl7.fhir.dstu3.model.DecimalType) e).getValue().toString());
} else if (e instanceof HumanName) {
renderHumanName((HumanName) e, x);
} else if (e instanceof SampledData) {
renderSampledData((SampledData) e, x);
} else if (e instanceof Address) {
renderAddress((Address) e, x);
} else if (e instanceof ContactPoint) {
renderContactPoint((ContactPoint) e, x);
} else if (e instanceof UriType) {
renderUri((UriType) e, x);
} else if (e instanceof Timing) {
renderTiming((Timing) e, x);
} else if (e instanceof Range) {
renderRange((Range) e, x);
} else if (e instanceof Quantity) {
renderQuantity((Quantity) e, x, showCodeDetails);
} else if (e instanceof Ratio) {
renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
x.tx("/");
renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
} else if (e instanceof Period) {
Period p = (Period) e;
x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
x.tx(" --> ");
x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
} else if (e instanceof Reference) {
Reference r = (Reference) e;
XhtmlNode c = x;
ResourceWithReference tr = null;
if (r.hasReferenceElement()) {
tr = resolveReference(res, r.getReference());
if (!r.getReference().startsWith("#")) {
if (tr != null && tr.getReference() != null)
c = x.ah(tr.getReference());
else
c = x.ah(r.getReference());
}
}
// what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
if (r.hasDisplayElement()) {
c.addText(r.getDisplay());
if (tr != null && tr.getResource() != null) {
c.tx(". Generated Summary: ");
generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
}
} else if (tr != null && tr.getResource() != null) {
generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
} else {
c.addText(r.getReference());
}
} else if (e instanceof Resource) {
return;
} else if (e instanceof ElementDefinition) {
x.tx("todo-bundle");
} else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
if (sd == null)
throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
else
generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails);
}
}
use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method genTypes.
private Cell genTypes(HierarchicalTableGenerator gen, Row r, ElementDefinition e, String profileBaseFileName, StructureDefinition profile, String corePath, String imagePath) {
Cell c = gen.new Cell();
r.getCells().add(c);
List<TypeRefComponent> types = e.getType();
if (!e.hasType()) {
if (e.hasContentReference()) {
return c;
} else {
ElementDefinition d = (ElementDefinition) e.getUserData(DERIVATION_POINTER);
if (d != null && d.hasType()) {
types = new ArrayList<ElementDefinition.TypeRefComponent>();
for (TypeRefComponent tr : d.getType()) {
TypeRefComponent tt = tr.copy();
tt.setUserData(DERIVATION_EQUALS, true);
types.add(tt);
}
} else
return c;
}
}
boolean first = true;
TypeRefComponent tl = null;
for (TypeRefComponent t : types) {
if (first)
first = false;
else
c.addPiece(checkForNoChange(tl, gen.new Piece(null, ", ", null)));
tl = t;
if (t.hasTarget()) {
c.getPieces().add(gen.new Piece(corePath + "references.html", t.getWorkingCode(), null));
c.getPieces().add(gen.new Piece(null, "(", null));
boolean tfirst = true;
for (UriType u : t.getTargetProfile()) {
if (tfirst)
tfirst = false;
else
c.addPiece(gen.new Piece(null, " | ", null));
genTargetLink(gen, profileBaseFileName, corePath, c, t, u.getValue());
}
c.getPieces().add(gen.new Piece(null, ")", null));
if (t.getAggregation().size() > 0) {
c.getPieces().add(gen.new Piece(corePath + "valueset-resource-aggregation-mode.html", " {", null));
boolean firstA = true;
for (Enumeration<AggregationMode> a : t.getAggregation()) {
if (firstA = true)
firstA = false;
else
c.getPieces().add(gen.new Piece(corePath + "valueset-resource-aggregation-mode.html", ", ", null));
c.getPieces().add(gen.new Piece(corePath + "valueset-resource-aggregation-mode.html", codeForAggregation(a.getValue()), hintForAggregation(a.getValue())));
}
c.getPieces().add(gen.new Piece(corePath + "valueset-resource-aggregation-mode.html", "}", null));
}
} else if (t.hasProfile() && (!t.getWorkingCode().equals("Extension") || isProfiledType(t.getProfile()))) {
// a profiled type
String ref;
ref = pkp.getLinkForProfile(profile, t.getProfile().get(0).getValue());
if (ref != null) {
String[] parts = ref.split("\\|");
if (parts[0].startsWith("http:") || parts[0].startsWith("https:")) {
// c.addPiece(checkForNoChange(t, gen.new Piece(parts[0], "<" + parts[1] + ">", t.getCode()))); Lloyd
c.addPiece(checkForNoChange(t, gen.new Piece(parts[0], parts[1], t.getWorkingCode())));
} else {
// c.addPiece(checkForNoChange(t, gen.new Piece((t.getProfile().startsWith(corePath)? corePath: "")+parts[0], "<" + parts[1] + ">", t.getCode())));
c.addPiece(checkForNoChange(t, gen.new Piece((t.getProfile().get(0).getValue().startsWith(corePath + "StructureDefinition") ? corePath : "") + parts[0], parts[1], t.getWorkingCode())));
}
} else
c.addPiece(checkForNoChange(t, gen.new Piece((t.getProfile().get(0).getValue().startsWith(corePath) ? corePath : "") + ref, t.getWorkingCode(), null)));
} else {
String tc = t.getWorkingCode();
if (pkp != null && pkp.hasLinkFor(tc)) {
c.addPiece(checkForNoChange(t, gen.new Piece(pkp.getLinkFor(corePath, tc), tc, null)));
} else
c.addPiece(checkForNoChange(t, gen.new Piece(null, tc, null)));
}
}
return c;
}
use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method renderTarget.
private static void renderTarget(StringBuilder b, StructureMapGroupRuleTargetComponent rt, boolean abbreviate) {
if (rt.hasContext()) {
if (rt.getContextType() == StructureMapContextType.TYPE)
b.append("@");
b.append(rt.getContext());
if (rt.hasElement()) {
b.append('.');
b.append(rt.getElement());
}
}
if (!abbreviate && rt.hasTransform()) {
if (rt.hasContext())
b.append(" = ");
if (rt.getTransform() == StructureMapTransform.COPY && rt.getParameter().size() == 1) {
renderTransformParam(b, rt.getParameter().get(0));
} else if (rt.getTransform() == StructureMapTransform.EVALUATE && rt.getParameter().size() == 1) {
b.append("(");
b.append("\"" + ((StringType) rt.getParameter().get(0).getValue()).asStringValue() + "\"");
b.append(")");
} else if (rt.getTransform() == StructureMapTransform.EVALUATE && rt.getParameter().size() == 2) {
b.append(rt.getTransform().toCode());
b.append("(");
b.append(((IdType) rt.getParameter().get(0).getValue()).asStringValue());
b.append("\"" + ((StringType) rt.getParameter().get(1).getValue()).asStringValue() + "\"");
b.append(")");
} else {
b.append(rt.getTransform().toCode());
b.append("(");
boolean first = true;
for (StructureMapGroupRuleTargetParameterComponent rtp : rt.getParameter()) {
if (first)
first = false;
else
b.append(", ");
renderTransformParam(b, rtp);
}
b.append(")");
}
}
if (!abbreviate && rt.hasVariable()) {
b.append(" as ");
b.append(rt.getVariable());
}
for (Enumeration<StructureMapTargetListMode> lm : rt.getListMode()) {
b.append(" ");
b.append(lm.getValue().toCode());
if (lm.getValue() == StructureMapTargetListMode.SHARE) {
b.append(" ");
b.append(rt.getListRuleId());
}
}
}
Aggregations