use of org.hl7.fhir.dstu2.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;
// either all types are the same, or we don't consider any of them the same
Element source = types.get(0);
int aggMode = AGG_NONE;
boolean allReference = !types.isEmpty();
Set<AggregationMode> aggs = new HashSet<ElementDefinition.AggregationMode>();
for (TypeRefComponent t : types) {
if (t.getCode() != null && t.getCode().equals("Reference") && t.hasProfile()) {
for (Enumeration<AggregationMode> en : t.getAggregation()) aggs.add(en.getValue());
} else
allReference = false;
}
if (allReference) {
if (aggs.size() > 0) {
boolean allSame = true;
for (TypeRefComponent t : types) {
for (AggregationMode agg : aggs) {
boolean found = false;
for (Enumeration<AggregationMode> en : t.getAggregation()) if (en.getValue() == agg)
found = true;
if (!found)
allSame = false;
}
}
aggMode = allSame ? AGG_GR : AGG_IND;
if (aggMode != AGG_GR)
allReference = false;
}
} else
aggMode = aggs.size() == 0 ? AGG_NONE : AGG_IND;
if (allReference) {
c.getPieces().add(gen.new Piece(corePath + "references.html", "Reference", null));
c.getPieces().add(gen.new Piece(null, "(", null));
}
TypeRefComponent tl = null;
for (TypeRefComponent t : types) {
if (first)
first = false;
else if (allReference)
c.addPiece(checkForNoChange(tl, gen.new Piece(null, " | ", null)));
else
c.addPiece(checkForNoChange(tl, gen.new Piece(null, ", ", null)));
tl = t;
if (t.getCode() != null && t.getCode().equals("Reference")) {
if (!allReference) {
c.getPieces().add(gen.new Piece(corePath + "references.html", "Reference", null));
c.getPieces().add(gen.new Piece(null, "(", null));
}
if (t.hasTargetProfile() && t.getTargetProfile().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getTargetProfile());
if (sd != null) {
String disp = sd.hasTitle() ? sd.getTitle() : sd.getName();
c.addPiece(checkForNoChange(t, gen.new Piece(checkPrepend(corePath, sd.getUserString("path")), disp, null)));
} else {
String rn = t.getTargetProfile().substring(40);
c.addPiece(checkForNoChange(t, gen.new Piece(pkp.getLinkFor(corePath, rn), rn, null)));
}
} else if (t.hasTargetProfile() && Utilities.isAbsoluteUrl(t.getTargetProfile())) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getTargetProfile());
if (sd != null) {
String disp = sd.hasTitle() ? sd.getTitle() : sd.getName();
String ref = pkp.getLinkForProfile(null, sd.getUrl());
if (ref.contains("|"))
ref = ref.substring(0, ref.indexOf("|"));
c.addPiece(checkForNoChange(t, gen.new Piece(ref, disp, null)));
} else
c.addPiece(checkForNoChange(t, gen.new Piece(null, t.getTargetProfile(), null)));
} else if (t.hasTargetProfile() && t.getTargetProfile().startsWith("#"))
c.addPiece(checkForNoChange(t, gen.new Piece(corePath + profileBaseFileName + "." + t.getTargetProfile().substring(1).toLowerCase() + ".html", t.getTargetProfile(), null)));
else if (t.hasTargetProfile())
c.addPiece(checkForNoChange(t, gen.new Piece(corePath + t.getTargetProfile(), t.getTargetProfile(), null)));
if (!allReference) {
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()), null));
}
c.getPieces().add(gen.new Piece(corePath + "valueset-resource-aggregation-mode.html", "}", null));
}
}
} else if (t.hasProfile() && (!t.getCode().equals("Extension") || t.getProfile().contains(":"))) {
// a profiled type
String ref;
ref = pkp.getLinkForProfile(profile, t.getProfile());
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())));
else
c.addPiece(checkForNoChange(t, gen.new Piece((t.getProfile().startsWith(corePath) ? corePath : "") + parts[0], parts[1], t.getCode())));
} else
c.addPiece(checkForNoChange(t, gen.new Piece((t.getProfile().startsWith(corePath) ? corePath : "") + ref, t.getCode(), null)));
} else if (pkp.hasLinkFor(t.getCode())) {
c.addPiece(checkForNoChange(t, gen.new Piece(pkp.getLinkFor(corePath, t.getCode()), t.getCode(), null)));
} else
c.addPiece(checkForNoChange(t, gen.new Piece(null, t.getCode(), null)));
}
if (allReference) {
c.getPieces().add(gen.new Piece(null, ")", null));
if (aggs.size() > 0) {
c.getPieces().add(gen.new Piece(corePath + "valueset-resource-aggregation-mode.html", " {", null));
boolean firstA = true;
for (AggregationMode a : aggs) {
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), null));
}
c.getPieces().add(gen.new Piece(corePath + "valueset-resource-aggregation-mode.html", "}", null));
}
}
return c;
}
use of org.hl7.fhir.dstu2.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, int indent, ResourceContext rc) 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) {
if (e.hasPrimitiveValue())
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.r4.model.DateType)
x.addText(((org.hl7.fhir.r4.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.r4.model.IntegerType) {
x.addText(Integer.toString(((org.hl7.fhir.r4.model.IntegerType) e).getValue()));
} else if (e instanceof org.hl7.fhir.r4.model.DecimalType) {
x.addText(((org.hl7.fhir.r4.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, defn.getPath(), rc != null && rc.resourceResource != null ? rc.resourceResource.getId() : null);
} 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(), rc);
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("#"), rc);
}
} else if (tr != null && tr.getResource() != null) {
generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"), rc);
} 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, indent + 1, rc);
}
}
use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class ImplementationGuide10_50 method convertImplementationGuide.
public static org.hl7.fhir.dstu2.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.ImplementationGuide tgt = new org.hl7.fhir.dstu2.model.ImplementationGuide();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_50.convertUri(src.getUrlElement()));
if (src.hasVersionElement())
tgt.setVersionElement(String10_50.convertString(src.getVersionElement()));
if (src.hasNameElement())
tgt.setNameElement(String10_50.convertString(src.getNameElement()));
if (src.hasStatus())
tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement()));
if (src.hasExperimental())
tgt.setExperimentalElement(Boolean10_50.convertBoolean(src.getExperimentalElement()));
if (src.hasPublisherElement())
tgt.setPublisherElement(String10_50.convertString(src.getPublisherElement()));
for (org.hl7.fhir.r5.model.ContactDetail t : src.getContact()) tgt.addContact(convertImplementationGuideContactComponent(t));
if (src.hasDate())
tgt.setDateElement(DateTime10_50.convertDateTime(src.getDateElement()));
if (src.hasDescription())
tgt.setDescription(src.getDescription());
for (org.hl7.fhir.r5.model.UsageContext t : src.getUseContext()) if (t.hasValueCodeableConcept())
tgt.addUseContext(CodeableConcept10_50.convertCodeableConcept(t.getValueCodeableConcept()));
for (org.hl7.fhir.r5.model.CodeableConcept t : src.getJurisdiction()) tgt.addUseContext(CodeableConcept10_50.convertCodeableConcept(t));
if (src.hasCopyright())
tgt.setCopyright(src.getCopyright());
for (Enumeration<org.hl7.fhir.r5.model.Enumerations.FHIRVersion> v : src.getFhirVersion()) {
tgt.setFhirVersion(v.asStringValue());
}
for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDependsOnComponent t : src.getDependsOn()) tgt.addDependency(convertImplementationGuideDependencyComponent(t));
for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent t : src.getDefinition().getGrouping()) tgt.addPackage(convertImplementationGuidePackageComponent(t));
for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent t : src.getDefinition().getResource()) findPackage(tgt.getPackage(), t.getGroupingId()).addResource(convertImplementationGuidePackageResourceComponent(t));
for (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent t : src.getGlobal()) tgt.addGlobal(convertImplementationGuideGlobalComponent(t));
tgt.setPage(convertImplementationGuidePageComponent(src.getDefinition().getPage()));
return tgt;
}
use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaResourceGenerator method generatePropertySetterName.
private void generatePropertySetterName(Analysis analysis, TypeInfo ti, String indent) throws Exception {
List<ElementDefinition> children = ti.getChildren();
boolean isInterface = analysis.isInterface();
write(indent + " @Override\r\n");
write(indent + " public Base setProperty(String name, Base value) throws FHIRException {\r\n");
boolean first = true;
for (ElementDefinition e : children) {
if (!isInterface) {
String tn = e.getUserString("java.type");
if (first)
write(indent + " ");
else
write(indent + " } else ");
first = false;
write("if (name.equals(\"" + e.getName() + "\")) {\r\n");
String name = e.getName().replace("[x]", "");
String cn = "(" + tn + ") value";
if (!Utilities.existsInList(e.typeSummary(), "Element", "BackboneElement")) {
if (e.typeSummary().equals("xhtml")) {
cn = "TypeConvertor.castToXhtml(value)";
} else if (tn.contains("Enumeration<")) {
// enumeration
write(indent + " value = new " + tn.substring(tn.indexOf("<") + 1, tn.length() - 1) + "EnumFactory().fromType(TypeConvertor.castToCode(value));\r\n");
cn = "(Enumeration) value";
} else if (e.getType().size() == 1 && !e.typeSummary().equals("*") && !e.getType().get(0).getCode().startsWith("@")) {
cn = "TypeConvertor.castTo" + upFirst(checkConstraint(e.getType().get(0).getWorkingCode())) + "(value)";
} else if (e.getType().size() > 0 && !e.getType().get(0).getCode().startsWith("@")) {
cn = "TypeConvertor.castToType(value)";
}
}
if (e.unbounded()) {
write(indent + " this.get" + upFirst(getElementName(name, false)) + "().add(" + cn + ");\r\n");
} else {
write(indent + " this." + getElementName(name, true) + " = " + cn + "; // " + tn + "\r\n");
}
}
}
if (!first)
write(indent + " } else\r\n");
write(indent + " return super.setProperty(name, value);\r\n");
if (!first)
write(indent + " return value;\r\n");
write(indent + " }\r\n\r\n");
}
use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaResourceGenerator method generatePropertySetterId.
private void generatePropertySetterId(Analysis analysis, TypeInfo ti, String indent) throws Exception {
List<ElementDefinition> children = ti.getChildren();
boolean isInterface = analysis.isInterface();
write(indent + " @Override\r\n");
write(indent + " public Base setProperty(int hash, String name, Base value) throws FHIRException {\r\n");
write(indent + " switch (hash) {\r\n");
for (ElementDefinition e : children) {
if (!isInterface) {
String tn = e.getUserString("java.type");
String name = e.getName().replace("[x]", "");
write(indent + " case " + propId(name) + ": // " + name + "\r\n");
String cn = "(" + tn + ") value";
if (!Utilities.existsInList(e.typeSummary(), "Element", "BackboneElement")) {
if (e.typeSummary().equals("xhtml")) {
cn = "TypeConvertor.castToXhtml(value)";
}
if (tn.contains("Enumeration<")) {
// enumeration
write(indent + " value = new " + tn.substring(tn.indexOf("<") + 1, tn.length() - 1) + "EnumFactory().fromType(TypeConvertor.castToCode(value));\r\n");
cn = "(Enumeration) value";
} else if (e.getType().size() == 1 && !e.typeSummary().equals("*") && !e.getType().get(0).getName().startsWith("@")) {
cn = "TypeConvertor.castTo" + upFirst(checkConstraint(e.getType().get(0).getWorkingCode())) + "(value)";
} else if (e.getType().size() > 0 && !e.getType().get(0).getCode().startsWith("@")) {
cn = "TypeConvertor.castToType(value)";
}
}
if (e.unbounded()) {
write(indent + " this.get" + upFirst(getElementName(name, false)) + "().add(" + cn + "); // " + tn + "\r\n");
} else {
write(indent + " this." + getElementName(name, true) + " = " + cn + "; // " + tn + "\r\n");
}
write(indent + " return value;\r\n");
}
}
write(indent + " default: return super.setProperty(hash, name, value);\r\n");
write(indent + " }\r\n\r\n");
write(indent + " }\r\n\r\n");
}
Aggregations