use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class JavaParserJsonGenerator method genElementParser.
private void genElementParser(Analysis analysis, TypeInfo ti, ElementDefinition ed, boolean bUseOwner, ElementDefinition inh) throws Exception {
String name = ed.getName();
String tn = ed.getUserString("java.type");
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]", "") : "";
parser.append(" DataType " + getElementName(en, false) + " = parseType(\"" + en + "\", json);\r\n");
parser.append(" if (" + getElementName(en, false) + " != null)\r\n");
parser.append(" res.set" + upFirst(getElementName(en, false)) + "(" + getElementName(en, false) + ");\r\n");
} else {
String prsr = null;
String aprsr = null;
String anprsr = null;
EnumInfo ei = null;
String en = null;
if (ed.hasUserData("java.enum")) {
// getCodeListType(cd.getBinding());
ei = (EnumInfo) ed.getUserData("java.enum");
ValueSet vs = ei.getValueSet();
if (vs.hasUserData("shared")) {
en = "Enumerations." + ei.getName();
} else {
en = analysis.getClassName() + "." + ei.getName();
}
// en+".fromCode(parseString(xpp))";
prsr = "parseEnumeration(json.get(\"" + name + "\").getAsString(), " + en + ".NULL, new " + en.substring(0, en.indexOf(".")) + "." + en.substring(en.indexOf(".") + 1) + "EnumFactory())";
// en+".fromCode(parseString(xpp))";
aprsr = "parseEnumeration(array.get(i).getAsString(), " + en + ".NULL, new " + en.substring(0, en.indexOf(".")) + "." + en.substring(en.indexOf(".") + 1) + "EnumFactory())";
// en+".fromCode(parseString(xpp))";
anprsr = "parseEnumeration(null, " + en + ".NULL, new " + en.substring(0, en.indexOf(".")) + "." + en.substring(en.indexOf(".") + 1) + "EnumFactory())";
// parseEnumeration(xpp, Narratived.NarrativeStatus.additional, new Narratived.NarrativeStatusEnumFactory())
} else {
if (name.equals("extension")) {
name = "extension";
tn = "Extension";
}
if (tn.equals("XhtmlNode")) {
prsr = "parseXhtml(json.get(\"" + name + "\").getAsString())";
} else if (tn.contains("Reference(")) {
prsr = "parseReference(getJObject(json, \"" + name + "\"))";
aprsr = "parseReference(array.get(i).getAsJsonObject())";
anprsr = "parseReference(null)";
} else if (tn.contains("canonical(")) {
prsr = "parseCanonical(json.get(\"" + name + "\").getAsString())";
aprsr = "parseCanonical(array.get(i).getAsString())";
anprsr = "parseCanonical(null)";
} else if (isPrimitive(ed.typeSummary())) {
if (tn.endsWith("Type")) {
tn = tn.substring(0, tn.length() - 4);
}
prsr = "parse" + upFirst(tn) + "(json.get(\"" + name + "\").getAs" + getAsJsonPrimitive(ed.typeSummary(), true) + "())";
aprsr = "parse" + upFirst(tn) + "(array.get(i).getAs" + getAsJsonPrimitive(ed.typeSummary(), true) + "())";
anprsr = "parse" + upFirst(tn) + "(null)";
} else {
String pn = tn;
if ((ed.isInlineType() || ed.hasContentReference()) && !pn.startsWith(analysis.getClassName())) {
pn = analysis.getClassName() + pn;
}
prsr = "parse" + pn + "(getJObject(json, \"" + name + "\"))";
aprsr = "parse" + pn + "(array.get(i).getAsJsonObject())";
anprsr = "parse" + pn + "(null)";
}
}
if (ed.unbounded()) {
if (isPrimitive(ed.typeSummary()) || ed.typeSummary().startsWith("canonical(")) {
parser.append(" if (json.has(\"" + name + "\")) {\r\n");
parser.append(" JsonArray array = getJArray(json, \"" + name + "\");\r\n");
parser.append(" for (int i = 0; i < array.size(); i++) {\r\n");
parser.append(" if (array.get(i).isJsonNull()) {\r\n");
if (en == null) {
parser.append(" res.get" + upFirst(name) + "().add(new " + tn + "Type());\r\n");
} else {
parser.append(" res.get" + upFirst(name) + "().add(new Enumeration<" + en + ">(new " + en + "EnumFactory(), " + en + ".NULL));\r\n");
}
parser.append(" } else {;\r\n");
parser.append(" res.get" + upFirst(name) + "().add(" + aprsr + ");\r\n");
parser.append(" }\r\n");
parser.append(" }\r\n");
parser.append(" };\r\n");
parser.append(" if (json.has(\"_" + name + "\")) {\r\n");
parser.append(" JsonArray array = getJArray(json, \"_" + name + "\");\r\n");
parser.append(" for (int i = 0; i < array.size(); i++) {\r\n");
parser.append(" if (i == res.get" + upFirst(name) + "().size())\r\n");
parser.append(" res.get" + upFirst(name) + "().add(" + anprsr + ");\r\n");
parser.append(" if (array.get(i) instanceof JsonObject) \r\n");
parser.append(" parseElementProperties(array.get(i).getAsJsonObject(), res.get" + upFirst(name) + "().get(i));\r\n");
parser.append(" }\r\n");
parser.append(" };\r\n");
} else {
parser.append(" if (json.has(\"" + name + "\")) {\r\n");
parser.append(" JsonArray array = getJArray(json, \"" + name + "\");\r\n");
parser.append(" for (int i = 0; i < array.size(); i++) {\r\n");
parser.append(" res.get" + upFirst(getElementName(name, false)) + "().add(" + aprsr + ");\r\n");
parser.append(" }\r\n");
parser.append(" };\r\n");
}
} else if (inh != null && inh.unbounded()) {
parser.append(" if (json.has(\"" + name + "\"))\r\n");
if ((isPrimitive(ed.typeSummary()) || ed.typeSummary().startsWith("canonical(")) && !tn.equals("XhtmlNode")) {
parser.append(" res.add" + upFirst(getElementName(name, false)) + "Element(" + prsr + ");\r\n");
parser.append(" if (json.has(\"_" + name + "\"))\r\n");
parser.append(" parseElementProperties(getJObject(json, \"_" + name + "\"), res.get" + upFirst(getElementName(name, false)) + "ElementFirstRep());\r\n");
} else {
parser.append(" res.add" + upFirst(getElementName(name, false)) + "(" + prsr + ");\r\n");
}
} else {
parser.append(" if (json.has(\"" + name + "\"))\r\n");
if ((isPrimitive(ed.typeSummary()) || ed.typeSummary().startsWith("canonical(")) && !tn.equals("XhtmlNode")) {
parser.append(" res.set" + upFirst(getElementName(name, false)) + "Element(" + prsr + ");\r\n");
parser.append(" if (json.has(\"_" + name + "\"))\r\n");
parser.append(" parseElementProperties(getJObject(json, \"_" + name + "\"), res.get" + upFirst(getElementName(name, false)) + "Element());\r\n");
} else {
parser.append(" res.set" + upFirst(getElementName(name, false)) + "(" + prsr + ");\r\n");
}
}
}
}
use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class StructureMap 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((StructureMapContactComponent) 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("structure"))
this.getStructure().add((StructureMapStructureComponent) value);
else if (name.equals("import"))
this.getImport().add(castToUri(value));
else if (name.equals("group"))
this.getGroup().add((StructureMapGroupComponent) value);
else
super.setProperty(name, value);
}
use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class NamingSystem method setProperty.
@Override
public Base setProperty(String name, Base value) throws FHIRException {
if (name.equals("name")) {
// StringType
this.name = castToString(value);
} else if (name.equals("status")) {
value = new PublicationStatusEnumFactory().fromType(castToCode(value));
// Enumeration<PublicationStatus>
this.status = (Enumeration) value;
} else if (name.equals("kind")) {
value = new NamingSystemTypeEnumFactory().fromType(castToCode(value));
// Enumeration<NamingSystemType>
this.kind = (Enumeration) value;
} else if (name.equals("date")) {
// DateTimeType
this.date = castToDateTime(value);
} else if (name.equals("publisher")) {
// StringType
this.publisher = castToString(value);
} else if (name.equals("contact")) {
this.getContact().add(castToContactDetail(value));
} else if (name.equals("responsible")) {
// StringType
this.responsible = castToString(value);
} else if (name.equals("type")) {
// CodeableConcept
this.type = castToCodeableConcept(value);
} else if (name.equals("description")) {
// MarkdownType
this.description = castToMarkdown(value);
} else if (name.equals("useContext")) {
this.getUseContext().add(castToUsageContext(value));
} else if (name.equals("jurisdiction")) {
this.getJurisdiction().add(castToCodeableConcept(value));
} else if (name.equals("usage")) {
// StringType
this.usage = castToString(value);
} else if (name.equals("uniqueId")) {
this.getUniqueId().add((NamingSystemUniqueIdComponent) value);
} else if (name.equals("replacedBy")) {
// Reference
this.replacedBy = castToReference(value);
} else
return super.setProperty(name, value);
return value;
}
use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class OperationDefinition method setProperty.
@Override
public Base setProperty(String name, Base value) throws FHIRException {
if (name.equals("url")) {
// UriType
this.url = castToUri(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")) {
value = new PublicationStatusEnumFactory().fromType(castToCode(value));
// Enumeration<PublicationStatus>
this.status = (Enumeration) value;
} else if (name.equals("kind")) {
value = new OperationKindEnumFactory().fromType(castToCode(value));
// Enumeration<OperationKind>
this.kind = (Enumeration) value;
} else if (name.equals("experimental")) {
// BooleanType
this.experimental = castToBoolean(value);
} else if (name.equals("date")) {
// DateTimeType
this.date = castToDateTime(value);
} else if (name.equals("publisher")) {
// StringType
this.publisher = castToString(value);
} else if (name.equals("contact")) {
this.getContact().add(castToContactDetail(value));
} else if (name.equals("description")) {
// MarkdownType
this.description = castToMarkdown(value);
} else if (name.equals("useContext")) {
this.getUseContext().add(castToUsageContext(value));
} else if (name.equals("jurisdiction")) {
this.getJurisdiction().add(castToCodeableConcept(value));
} else if (name.equals("purpose")) {
// MarkdownType
this.purpose = castToMarkdown(value);
} else if (name.equals("idempotent")) {
// BooleanType
this.idempotent = castToBoolean(value);
} else if (name.equals("code")) {
// CodeType
this.code = castToCode(value);
} else if (name.equals("comment")) {
// StringType
this.comment = castToString(value);
} else if (name.equals("base")) {
// Reference
this.base = castToReference(value);
} else if (name.equals("resource")) {
this.getResource().add(castToCode(value));
} else if (name.equals("system")) {
// BooleanType
this.system = castToBoolean(value);
} else if (name.equals("type")) {
// BooleanType
this.type = castToBoolean(value);
} else if (name.equals("instance")) {
// BooleanType
this.instance = castToBoolean(value);
} else if (name.equals("parameter")) {
this.getParameter().add((OperationDefinitionParameterComponent) value);
} else if (name.equals("overload")) {
this.getOverload().add((OperationDefinitionOverloadComponent) value);
} else
return super.setProperty(name, value);
return value;
}
use of org.hl7.fhir.dstu2.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class StructureDefinition method setProperty.
@Override
public Base 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("title")) {
// StringType
this.title = castToString(value);
} else if (name.equals("status")) {
value = new PublicationStatusEnumFactory().fromType(castToCode(value));
// Enumeration<PublicationStatus>
this.status = (Enumeration) value;
} else if (name.equals("experimental")) {
// BooleanType
this.experimental = castToBoolean(value);
} else if (name.equals("date")) {
// DateTimeType
this.date = castToDateTime(value);
} else if (name.equals("publisher")) {
// StringType
this.publisher = castToString(value);
} else if (name.equals("contact")) {
this.getContact().add(castToContactDetail(value));
} else if (name.equals("description")) {
// MarkdownType
this.description = castToMarkdown(value);
} else if (name.equals("useContext")) {
this.getUseContext().add(castToUsageContext(value));
} else if (name.equals("jurisdiction")) {
this.getJurisdiction().add(castToCodeableConcept(value));
} else if (name.equals("purpose")) {
// MarkdownType
this.purpose = castToMarkdown(value);
} else if (name.equals("copyright")) {
// MarkdownType
this.copyright = castToMarkdown(value);
} else if (name.equals("keyword")) {
this.getKeyword().add(castToCoding(value));
} else if (name.equals("fhirVersion")) {
// IdType
this.fhirVersion = castToId(value);
} else if (name.equals("mapping")) {
this.getMapping().add((StructureDefinitionMappingComponent) value);
} else if (name.equals("kind")) {
value = new StructureDefinitionKindEnumFactory().fromType(castToCode(value));
// Enumeration<StructureDefinitionKind>
this.kind = (Enumeration) value;
} else if (name.equals("abstract")) {
// BooleanType
this.abstract_ = castToBoolean(value);
} else if (name.equals("contextType")) {
value = new ExtensionContextEnumFactory().fromType(castToCode(value));
// Enumeration<ExtensionContext>
this.contextType = (Enumeration) value;
} else if (name.equals("context")) {
this.getContext().add(castToString(value));
} else if (name.equals("contextInvariant")) {
this.getContextInvariant().add(castToString(value));
} else if (name.equals("type")) {
// CodeType
this.type = castToCode(value);
} else if (name.equals("baseDefinition")) {
// UriType
this.baseDefinition = castToUri(value);
} else if (name.equals("derivation")) {
value = new TypeDerivationRuleEnumFactory().fromType(castToCode(value));
// Enumeration<TypeDerivationRule>
this.derivation = (Enumeration) value;
} else if (name.equals("snapshot")) {
// StructureDefinitionSnapshotComponent
this.snapshot = (StructureDefinitionSnapshotComponent) value;
} else if (name.equals("differential")) {
// StructureDefinitionDifferentialComponent
this.differential = (StructureDefinitionDifferentialComponent) value;
} else
return super.setProperty(name, value);
return value;
}
Aggregations