use of org.hl7.fhir.dstu2016may.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class CompartmentDefinition 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("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((CompartmentDefinitionContactComponent) value);
else if (name.equals("date"))
// DateTimeType
this.date = castToDateTime(value);
else if (name.equals("description"))
// StringType
this.description = castToString(value);
else if (name.equals("requirements"))
// StringType
this.requirements = castToString(value);
else if (name.equals("code"))
// Enumeration<CompartmentType>
this.code = new CompartmentTypeEnumFactory().fromType(value);
else if (name.equals("search"))
// BooleanType
this.search = castToBoolean(value);
else if (name.equals("resource"))
this.getResource().add((CompartmentDefinitionResourceComponent) value);
else
super.setProperty(name, value);
}
use of org.hl7.fhir.dstu2016may.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class ConceptMap 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"))
// Identifier
this.identifier = 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((ConceptMapContactComponent) value);
else if (name.equals("date"))
// DateTimeType
this.date = castToDateTime(value);
else if (name.equals("description"))
// StringType
this.description = castToString(value);
else if (name.equals("useContext"))
this.getUseContext().add(castToCodeableConcept(value));
else if (name.equals("requirements"))
// StringType
this.requirements = castToString(value);
else if (name.equals("copyright"))
// StringType
this.copyright = castToString(value);
else if (name.equals("source[x]"))
// Type
this.source = (Type) value;
else if (name.equals("target[x]"))
// Type
this.target = (Type) value;
else if (name.equals("element"))
this.getElement().add((SourceElementComponent) value);
else
super.setProperty(name, value);
}
use of org.hl7.fhir.dstu2016may.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaResourceGenerator method generateEnum.
private void generateEnum(EnumInfo e) throws Exception {
String tn = e.getName();
String tns = tn;
if (tn.startsWith("Enumeration<")) {
tns = tn.substring(tn.indexOf("<") + 1);
tns = tns.substring(0, tns.length() - 1);
} else {
tn = "Enumeration<" + tn + ">";
}
ValueSet vs = e.getValueSet();
ValueSet vse = (ValueSet) vs.getUserData("expansion");
if (vs.hasUserData("shared")) {
return;
}
if (vse == null) {
return;
}
List<ValueSetExpansionContainsComponent> codes = vse.getExpansion().getContains();
String url = vs.getUrl();
CommaSeparatedStringBuilder el = new CommaSeparatedStringBuilder();
write(" public enum " + tns + " {\r\n");
int l = codes.size();
int i = 0;
for (ValueSetExpansionContainsComponent c : codes) {
i++;
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
el.append(cc);
String definition = definitions.getCodeDefinition(c.getSystem(), c.getCode());
write(" /**\r\n");
write(" * " + Utilities.escapeJava(definition) + "\r\n");
write(" */\r\n");
write(" " + cc.toUpperCase() + ", \r\n");
}
write(" /**\r\n");
write(" * added to help the parsers with the generic types\r\n");
write(" */\r\n");
write(" NULL;\r\n");
el.append("NULL");
write(" public static " + tns + " fromCode(String codeString) throws FHIRException {\r\n");
write(" if (codeString == null || \"\".equals(codeString))\r\n");
write(" return null;\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return " + cc + ";\r\n");
}
write(" if (Configuration.isAcceptInvalidEnums())\r\n");
write(" return null;\r\n");
write(" else\r\n");
write(" throw new FHIRException(\"Unknown " + tns + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public String toCode() {\r\n");
write(" switch (this) {\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
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 : codes) {
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 : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
String definition = definitions.getCodeDefinition(c.getSystem(), c.getCode());
write(" case " + cc + ": return \"" + Utilities.escapeJava(definition) + "\";\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 : codes) {
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");
write(" }\r\n");
write("\r\n");
write(" public static class " + tns + "EnumFactory implements EnumFactory<" + tns + "> {\r\n");
write(" public " + tns + " 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 : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return " + tns + "." + cc + ";\r\n");
}
write(" throw new IllegalArgumentException(\"Unknown " + tns + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public Enumeration<" + tns + "> 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<" + tns + ">(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 : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (\"" + c.getCode() + "\".equals(codeString))\r\n");
write(" return new Enumeration<" + tns + ">(this, " + tns + "." + cc + ");\r\n");
}
write(" throw new FHIRException(\"Unknown " + tns + " code '\"+codeString+\"'\");\r\n");
write(" }\r\n");
write(" public String toCode(" + tns + " code) {\r\n");
for (ValueSetExpansionContainsComponent c : codes) {
String cc = Utilities.camelCase(c.getCode());
cc = makeConst(cc);
write(" if (code == " + tns + "." + cc + ")\r\n return \"" + c.getCode() + "\";\r\n");
}
write(" return \"?\";\r\n");
write(" }\r\n");
write(" public String toSystem(" + tns + " code) {\r\n");
write(" return code.getSystem();\r\n");
write(" }\r\n");
write(" }\r\n");
write("\r\n");
// enumInfo.put("org.hl7.fhir."+jid+".model."+name+"."+tns, url+"|"+el.toString());
}
use of org.hl7.fhir.dstu2016may.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaResourceGenerator method generateConstructor.
private void generateConstructor(String className, List<ElementDefinition> params, String indent) throws IOException {
write(indent + "/**\r\n");
write(indent + " * Constructor\r\n");
write(indent + " */\r\n");
write(indent + " public " + className + "(");
boolean first = true;
for (ElementDefinition e : params) {
if (!first)
write(", ");
first = false;
String tn = e.getUserString("java.type");
if (definitions.hasPrimitiveType(e.typeSummary()) && !e.hasUserData("java.enum")) {
if ("xhtml".equals(e.typeSummary())) {
tn = "XhtmlNode";
} else {
tn = getSimpleType(tn);
}
} else if (tn.startsWith("Enumeration<")) {
tn = tn.substring(12, tn.length() - 1);
}
String en = getElementName(e.getName(), true);
write(tn + " " + en);
}
write(") {\r\n");
write(indent + " super();\r\n");
for (ElementDefinition e : params) {
String en = getElementName(e.getName(), true);
if (e.unbounded()) {
write(indent + " this.add" + Utilities.capitalize(en) + "(" + en + ");\r\n");
} else {
write(indent + " this.set" + Utilities.capitalize(en).replace("Abstract_", "Abstract") + "(" + en + ");\r\n");
}
}
write(indent + " }\r\n\r\n");
}
use of org.hl7.fhir.dstu2016may.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaParserJsonGenerator method genElementComposer.
private void genElementComposer(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(en) + "()) {\r\n");
composer.append(" composeType(\"" + pfx + "\", element.get" + upFirst(en) + "());\r\n");
composer.append(" }\r\n");
} else {
String tn = ed.getUserString("java.type");
String comp = null;
String en = null;
boolean enShared = false;
if (ed.hasUserData("java.enum")) {
// getCodeListType(cd.getBinding());
EnumInfo ei = (EnumInfo) ed.getUserData("java.enum");
ValueSet vs = ei.getValueSet();
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 (tn.equals("code")) {
tn = "Code";
comp = "composeCode";
} else if (tn.equals("instant")) {
tn = "Instant";
} 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 (tn.startsWith(analysis.getName()) && !tn.equals(analysis.getClassName())) {
comp = "compose" + leaf(tn);
} else if (isPrimitive(ed)) {
comp = "compose" + leaf(tn);
// remove Type"
comp = comp.substring(0, comp.length() - 4);
} else {
comp = "compose" + leaf(tn);
}
}
if (ed.unbounded()) {
tn = ed.getUserString("java.type");
if (tn.contains("Reference(")) {
comp = "composeReference";
tn = "Reference";
} else if (tn.contains("canonical(")) {
comp = "composeCanonical";
tn = "CanonicalType";
}
String stn = tn;
if (ed.isInlineType() || ed.hasContentReference()) {
stn = analysis.getClassName() + "." + tn;
}
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
if (en == null) {
if (tn.equals("String"))
tn = "StringType";
if (definitions.hasPrimitiveType(tn)) {
tn = upFirst(tn) + "Type";
}
if (isPrimitive(ed) || ed.typeSummary().startsWith("canonical(")) {
composer.append(" if (anyHasValue(element.get" + upFirst(getElementName(name, false)) + "())) {\r\n");
composer.append(" openArray(\"" + name + "\");\r\n");
composer.append(" for (" + (tn.contains("(") ? stn : upFirst(tn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" " + comp + "Core(null, e, e != element.get" + upFirst(getElementName(name, false)) + "().get(element.get" + upFirst(getElementName(name, false)) + "().size()-1));\r\n");
composer.append(" closeArray();\r\n");
composer.append(" }\r\n");
composer.append(" if (anyHasExtras(element.get" + upFirst(getElementName(name, false)) + "())) {\r\n");
composer.append(" openArray(\"_" + name + "\");\r\n");
composer.append(" for (" + (stn.contains("(") ? stn : upFirst(stn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" " + comp + "Extras(null, e, true);\r\n");
composer.append(" closeArray();\r\n");
composer.append(" }\r\n");
} else if (ed.typeSummary().equals("Resource")) {
composer.append(" openArray(\"" + name + "\");\r\n");
composer.append(" for (" + (stn.contains("(") ? tn : upFirst(tn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" open(null);\r\n");
composer.append(" " + comp + "(e);\r\n");
composer.append(" close();\r\n");
composer.append(" }\r\n");
composer.append(" closeArray();\r\n");
} else {
composer.append(" openArray(\"" + name + "\");\r\n");
composer.append(" for (" + (stn.contains("(") ? stn : upFirst(stn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" " + comp + "(null, e);\r\n");
composer.append(" closeArray();\r\n");
}
} else {
composer.append(" openArray(\"" + name + "\");\r\n");
composer.append(" for (Enumeration<" + prepEnumName(en) + "> e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" composeEnumerationCore(null, e, new " + prepEnumName(en) + "EnumFactory(), true);\r\n");
composer.append(" closeArray();\r\n");
composer.append(" if (anyHasExtras(element.get" + upFirst(getElementName(name, false)) + "())) {\r\n");
composer.append(" openArray(\"_" + name + "\");\r\n");
composer.append(" for (Enumeration<" + prepEnumName(en) + "> e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" composeEnumerationExtras(null, e, new " + prepEnumName(en) + "EnumFactory(), true);\r\n");
composer.append(" closeArray();\r\n");
composer.append(" }\r\n");
}
composer.append(" };\r\n");
} else if (en != null) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "Element()) {\r\n");
if (enShared) {
composer.append(" composeEnumerationCore(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
composer.append(" composeEnumerationExtras(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
} else {
composer.append(" composeEnumerationCore(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
composer.append(" composeEnumerationExtras(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
}
composer.append(" }\r\n");
// composer.append(" composeString(\""+name+"\", element.get"+upFirst(getElementName(name, false))+"().toCode());\r\n");
} else if (ed.typeSummary().equals("Resource")) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" open(\"" + name + "\");\r\n");
composer.append(" " + comp + "(element.get" + upFirst(getElementName(name, false)) + "());\r\n");
composer.append(" close();\r\n");
composer.append(" }\r\n");
} else if (!"xhtml".equals(ed.typeSummary()) && (isPrimitive(ed) || ed.typeSummary().startsWith("canonical("))) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "Element()) {\r\n");
composer.append(" " + comp + "Core(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), false);\r\n");
composer.append(" " + comp + "Extras(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), false);\r\n");
composer.append(" }\r\n");
} else if (tn.equals("xhtml")) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" XhtmlNode node = element.getDiv();\r\n");
composer.append(" if (node.getNsDecl() == null) {\r\n");
composer.append(" node.attribute(\"xmlns\", XHTML_NS);\r\n");
composer.append(" }\r\n");
composer.append(" " + comp + "(\"" + name + "\", node);\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");
}
}
}
Aggregations