use of org.hl7.fhir.r5.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaParserXmlGenerator method genElementCompose.
private void genElementCompose(Analysis analysis, TypeInfo ti, ElementDefinition ed, ElementDefinition inh) throws Exception {
String name = ed.getName();
if (name.endsWith("[x]") || name.equals("[type]")) {
String en = name.endsWith("[x]") && !name.equals("[x]") ? name.replace("[x]", "") : "value";
String pfx = name.endsWith("[x]") ? name.replace("[x]", "") : "";
composer.append(" if (element.has" + upFirst(getElementName(en, false)) + "()) {\r\n");
composer.append(" composeType(\"" + pfx + "\", element.get" + upFirst(getElementName(en, false)) + "());\r\n");
composer.append(" }");
} else {
String comp = null;
String en = null;
String tn = ed.getUserString("java.type");
if (ed.hasUserData("java.enum")) {
EnumInfo ei = (EnumInfo) ed.getUserData("java.enum");
ValueSet vs = ei.getValueSet();
boolean enShared = vs.hasUserData("shared");
if (enShared) {
en = "Enumerations." + ei.getName();
} else {
en = analysis.getClassName() + "." + ei.getName();
}
} else {
if (name.equals("extension")) {
name = "extension";
tn = "Extension";
}
if (tn.equals("XhtmlNode")) {
tn = "xhtml";
comp = "composeXhtml";
} else if (isPrimitive(ed)) {
comp = "compose" + tn.substring(0, tn.length() - 4);
} else if (tn.contains("Reference(")) {
comp = "composeReference";
tn = "Reference";
} else if (tn.contains("canonical(")) {
comp = "composeCanonical";
tn = "CanonicalType";
} else if (tn.contains("(")) {
comp = "compose" + tn;
} else if ((ed.hasContentReference() || ed.isInlineType()) && !tn.startsWith(analysis.getClassName())) {
comp = "compose" + analysis.getClassName() + tn;
} else {
comp = "compose" + tn;
}
}
if (ed.unbounded()) {
if (en != null) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" for (Enumeration<" + en + "> e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" composeEnumeration(\"" + name + "\", e, new " + en + "EnumFactory());\r\n");
} else {
String stn = ed.isInlineType() || ed.hasContentReference() ? analysis.getClassName() + "." + tn : tn;
// String pfx = ed.isInlineType() || ed.hasContentReference() ? analysis.getClassName() : "";
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) { \r\n");
composer.append(" for (" + stn + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
if (ed.typeSummary().equals("Resource")) {
composer.append(" {\r\n");
composer.append(" xml.enter(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" " + comp + "(e);\r\n");
composer.append(" xml.exit(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" }\r\n");
} else {
composer.append(" " + comp + "(\"" + name + "\", e);\r\n");
}
composer.append(" }\r\n");
}
} else if (en != null) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "Element())\r\n");
composer.append(" composeEnumeration(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + en + "EnumFactory());\r\n");
} else if (!"xhtml".equals(ed.typeSummary()) && (isJavaPrimitive(ed) || ed.typeSummary().startsWith("canonical("))) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "Element()) {\r\n");
composer.append(" " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element());\r\n");
composer.append(" }\r\n");
} else if (ed.typeSummary().equals("Resource")) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" xml.enter(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" " + comp + "(element.get" + upFirst(getElementName(name, false)) + "());\r\n");
composer.append(" xml.exit(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" }\r\n");
} else if (inh != null && inh.unbounded()) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "FirstRep());\r\n");
composer.append(" }\r\n");
} else {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "());\r\n");
composer.append(" }\r\n");
}
}
}
use of org.hl7.fhir.r5.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaEnumerationsGenerator method generateEnum.
private void generateEnum(String name, ValueSet vs) throws Exception {
String url = vs.getUrl();
CommaSeparatedStringBuilder el = new CommaSeparatedStringBuilder();
write(" public enum " + name + " {\r\n");
int l = vs.getExpansion().getContains().size();
int i = 0;
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
i++;
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
el.append(cc);
write(" /**\r\n");
write(" * " + definitions.getCodeDefinition(c.getSystem(), c.getCode()) + "\r\n");
write(" */\r\n");
write(" " + cc.toUpperCase() + ", \r\n");
}
write(" /**\r\n");
write(" * added to help the parsers\r\n");
write(" */\r\n");
write(" NULL;\r\n");
el.append("NULL");
write(" public static " + name + " fromCode(String codeString) throws FHIRException {\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" return null;\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return " + cc + ";\r\n");
}
write(" throw new FHIRException(\"Unknown " + name + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public String toCode() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" case " + cc + ": return \"" + c.getCode() + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
write(" public String getSystem() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" case " + cc + ": return \"" + c.getSystem() + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
write(" public String getDefinition() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" case " + cc + ": return \"" + Utilities.escapeJava(definitions.getCodeDefinition(c.getSystem(), c.getCode())) + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
write(" public String getDisplay() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" case " + cc + ": return \"" + Utilities.escapeJava(Utilities.noString(c.getDisplay()) ? c.getCode() : c.getDisplay()) + "\";\r\n");
}
write(" case NULL: return null;\r\n");
write(" default: return \"?\";\r\n");
write(" }\r\n");
write(" }\r\n");
if (config.getAdornments().containsKey(name)) {
write("// manual code from configuration.txt:\r\n");
write(config.getAdornments().get(name) + "\r\n");
write("// end addition\r\n");
}
write(" }\r\n");
write("\r\n");
write(" public static class " + name + "EnumFactory implements EnumFactory<" + name + "> {\r\n");
write(" public " + name + " fromCode(String codeString) throws IllegalArgumentException {\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" return null;\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return " + name + "." + cc + ";\r\n");
}
write(" throw new IllegalArgumentException(\"Unknown " + name + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public Enumeration<" + name + "> fromType(Base code) throws FHIRException {\r\n");
write(" if (code == null)\r\n");
write(" return null;\r\n");
write(" if (code.isEmpty())\r\n");
write(" return new Enumeration<" + name + ">(this);\r\n");
write(" String codeString = ((PrimitiveType) code).asStringValue();\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" return null;\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return new Enumeration<" + name + ">(this, " + name + "." + cc + ");\r\n");
}
write(" throw new FHIRException(\"Unknown " + name + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public String toCode(" + name + " code) {\r\n");
for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (code == " + name + "." + cc + ")\r\n return \"" + c.getCode() + "\";\r\n");
}
write(" return \"?\";\r\n");
write(" }\r\n");
write(" public String toSystem(" + name + " code) {\r\n");
write(" return code.getSystem();\r\n");
write(" }\r\n");
write(" }\r\n");
write("\r\n");
}
use of org.hl7.fhir.r5.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class Analyser method scanNestedTypes.
private void scanNestedTypes(Analysis analysis, TypeInfo type, String path, ElementDefinition e) throws Exception {
String tn = null;
if (e.typeSummary().equals("code") && e.hasBinding()) {
ElementDefinitionBindingComponent cd = e.getBinding();
if (isEnum(cd)) {
ValueSet vs = definitions.getValuesets().get(cd.getValueSet());
if (vs != null) {
tn = getCodeListType(vs.getName());
EnumInfo ei = analysis.getEnums().get(tn);
if (ei == null) {
ei = new EnumInfo(tn);
analysis.getEnums().put(tn, ei);
ei.setValueSet(vs);
}
if (tn.equals("SubscriptionStatus")) {
// work around cause there's a Resource with the same name
tn = "org.hl7.fhir.r4b.model.Enumerations." + tn;
}
e.setUserData("java.type", "Enumeration<" + tn + ">");
e.setUserData("java.enum", ei);
}
}
}
if (tn == null) {
if (e.getType().size() > 0 && !e.hasContentReference() && (!Utilities.existsInList(e.getType().get(0).getCode(), "Element", "BackboneElement"))) {
tn = getTypeName(e);
if (e.typeSummary().equals("xml:lang"))
tn = "CodeType";
if (e.typeSummary().equals("xhtml"))
tn = "XhtmlNode";
else if (e.getType().size() > 1)
tn = "DataType";
else if (definitions.hasPrimitiveType(tn))
tn = upFirst(tn) + "Type";
e.setUserData("java.type", tn);
} else {
if (e.hasContentReference()) {
ElementDefinition er = getElementForPath(analysis.getStructure(), e.getContentReference().substring(1));
tn = er.getUserString("java.type");
if (Utilities.noString(tn)) {
// have to resolve this later
e.setUserData("java.type", "@" + er.getPath());
} else {
e.setUserData("java.type", tn);
}
} else {
String cpath;
if (e.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
tn = upFirst(e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) + "Component";
cpath = e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name");
} else if (config.getIni().hasProperty("typenames", e.getPath())) {
tn = upFirst(config.getIni().getStringProperty("typenames", e.getPath())) + "Component";
cpath = config.getIni().getStringProperty("typenames", e.getPath());
} else {
tn = path + upFirst(getTitle(e.getName())) + "Component";
cpath = path + getTitle(e.getName());
}
if (tn.equals("Element"))
tn = "Element_";
if (analysis.getTypes().containsKey(tn)) {
char i = 'A';
while (analysis.getTypes().containsKey(tn + i)) {
i++;
}
tn = tn + i;
}
e.setUserData("java.type", tn);
tn = upFirst(tn);
TypeInfo ctype = new TypeInfo();
ctype.setName(tn);
analysis.getTypes().put(ctype.getName(), ctype);
analysis.getTypeList().add(ctype);
ctype.setDefn(e);
ctype.setAncestorName(e.typeSummary());
ctype.setChildren(filterChildren(new ProfileUtilities(null, null, null).getChildList(analysis.getStructure(), ctype.getDefn())));
for (ElementDefinition c : ctype.getChildren()) {
scanNestedTypes(analysis, ctype, cpath, c);
}
}
}
}
}
use of org.hl7.fhir.r5.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class DataElement method setProperty.
@Override
public void setProperty(String name, Base value) throws FHIRException {
if (name.equals("url"))
// UriType
this.url = castToUri(value);
else if (name.equals("identifier"))
this.getIdentifier().add(castToIdentifier(value));
else if (name.equals("version"))
// StringType
this.version = castToString(value);
else if (name.equals("name"))
// StringType
this.name = castToString(value);
else if (name.equals("status"))
// Enumeration<ConformanceResourceStatus>
this.status = new ConformanceResourceStatusEnumFactory().fromType(value);
else if (name.equals("experimental"))
// BooleanType
this.experimental = castToBoolean(value);
else if (name.equals("publisher"))
// StringType
this.publisher = castToString(value);
else if (name.equals("contact"))
this.getContact().add((DataElementContactComponent) value);
else if (name.equals("date"))
// DateTimeType
this.date = castToDateTime(value);
else if (name.equals("useContext"))
this.getUseContext().add(castToCodeableConcept(value));
else if (name.equals("copyright"))
// StringType
this.copyright = castToString(value);
else if (name.equals("stringency"))
// Enumeration<DataElementStringency>
this.stringency = new DataElementStringencyEnumFactory().fromType(value);
else if (name.equals("mapping"))
this.getMapping().add((DataElementMappingComponent) value);
else if (name.equals("element"))
this.getElement().add(castToElementDefinition(value));
else
super.setProperty(name, value);
}
use of org.hl7.fhir.r5.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class ExplanationOfBenefit method setProperty.
@Override
public void setProperty(String name, Base value) throws FHIRException {
if (name.equals("identifier"))
this.getIdentifier().add(castToIdentifier(value));
else if (name.equals("request"))
// Reference
this.request = castToReference(value);
else if (name.equals("outcome"))
// Enumeration<RemittanceOutcome>
this.outcome = new RemittanceOutcomeEnumFactory().fromType(value);
else if (name.equals("disposition"))
// StringType
this.disposition = castToString(value);
else if (name.equals("ruleset"))
// Coding
this.ruleset = castToCoding(value);
else if (name.equals("originalRuleset"))
// Coding
this.originalRuleset = castToCoding(value);
else if (name.equals("created"))
// DateTimeType
this.created = castToDateTime(value);
else if (name.equals("organization"))
// Reference
this.organization = castToReference(value);
else if (name.equals("requestProvider"))
// Reference
this.requestProvider = castToReference(value);
else if (name.equals("requestOrganization"))
// Reference
this.requestOrganization = castToReference(value);
else
super.setProperty(name, value);
}
Aggregations