first complete generator
This commit is contained in:
parent
193e61999e
commit
1131ac236e
|
@ -0,0 +1,7 @@
|
|||
|
||||
public void checkNoModifiers(String noun, String verb) throws FHIRException {
|
||||
if (hasModifierExtension()) {
|
||||
throw new FHIRException("Found unknown Modifier Exceptions on "+noun+" doing "+verb);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
public void checkNoModifiers(String noun, String verb) throws FHIRException {
|
||||
if (hasModifierExtension()) {
|
||||
throw new FHIRException("Found unknown Modifier Exceptions on "+noun+" doing "+verb);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getUrl();
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
@Override
|
||||
public byte[] getContent() {
|
||||
return getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaseBinary setContent(byte[] arg0) {
|
||||
return setData(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Base64BinaryType getContentElement() {
|
||||
return getDataElement();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Returns the {@link #getLink() link} which matches a given {@link BundleLinkComponent#getRelation() relation}.
|
||||
* If no link is found which matches the given relation, returns <code>null</code>. If more than one
|
||||
* link is found which matches the given relation, returns the first matching BundleLinkComponent.
|
||||
*
|
||||
* @param theRelation
|
||||
* The relation, such as \"next\", or \"self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}.
|
||||
* @return Returns a matching BundleLinkComponent, or <code>null</code>
|
||||
* @see IBaseBundle#LINK_NEXT
|
||||
* @see IBaseBundle#LINK_PREV
|
||||
* @see IBaseBundle#LINK_SELF
|
||||
*/
|
||||
public BundleLinkComponent getLink(String theRelation) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty");
|
||||
for (BundleLinkComponent next : getLink()) {
|
||||
if (theRelation.equals(next.getRelation())) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link #getLink() link} which matches a given {@link BundleLinkComponent#getRelation() relation}.
|
||||
* If no link is found which matches the given relation, creates a new BundleLinkComponent with the
|
||||
* given relation and adds it to this Bundle. If more than one
|
||||
* link is found which matches the given relation, returns the first matching BundleLinkComponent.
|
||||
*
|
||||
* @param theRelation
|
||||
* The relation, such as \"next\", or \"self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}.
|
||||
* @return Returns a matching BundleLinkComponent, or <code>null</code>
|
||||
* @see IBaseBundle#LINK_NEXT
|
||||
* @see IBaseBundle#LINK_PREV
|
||||
* @see IBaseBundle#LINK_SELF
|
||||
*/
|
||||
public BundleLinkComponent getLinkOrCreate(String theRelation) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty");
|
||||
for (BundleLinkComponent next : getLink()) {
|
||||
if (theRelation.equals(next.getRelation())) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
BundleLinkComponent retVal = new BundleLinkComponent();
|
||||
retVal.setRelation(theRelation);
|
||||
getLink().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Returns the {@link #getLink() link} which matches a given {@link BundleLinkComponent#getRelation() relation}.
|
||||
* If no link is found which matches the given relation, returns <code>null</code>. If more than one
|
||||
* link is found which matches the given relation, returns the first matching BundleLinkComponent.
|
||||
*
|
||||
* @param theRelation
|
||||
* The relation, such as \"next\", or \"self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}.
|
||||
* @return Returns a matching BundleLinkComponent, or <code>null</code>
|
||||
* @see IBaseBundle#LINK_NEXT
|
||||
* @see IBaseBundle#LINK_PREV
|
||||
* @see IBaseBundle#LINK_SELF
|
||||
*/
|
||||
public BundleLinkComponent getLink(String theRelation) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty");
|
||||
for (BundleLinkComponent next : getLink()) {
|
||||
if (theRelation.equals(next.getRelation())) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link #getLink() link} which matches a given {@link BundleLinkComponent#getRelation() relation}.
|
||||
* If no link is found which matches the given relation, creates a new BundleLinkComponent with the
|
||||
* given relation and adds it to this Bundle. If more than one
|
||||
* link is found which matches the given relation, returns the first matching BundleLinkComponent.
|
||||
*
|
||||
* @param theRelation
|
||||
* The relation, such as \"next\", or \"self. See the constants such as {@link IBaseBundle#LINK_SELF} and {@link IBaseBundle#LINK_NEXT}.
|
||||
* @return Returns a matching BundleLinkComponent, or <code>null</code>
|
||||
* @see IBaseBundle#LINK_NEXT
|
||||
* @see IBaseBundle#LINK_PREV
|
||||
* @see IBaseBundle#LINK_SELF
|
||||
*/
|
||||
public BundleLinkComponent getLinkOrCreate(String theRelation) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theRelation, "theRelation may not be null or empty");
|
||||
for (BundleLinkComponent next : getLink()) {
|
||||
if (theRelation.equals(next.getRelation())) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
BundleLinkComponent retVal = new BundleLinkComponent();
|
||||
retVal.setRelation(theRelation);
|
||||
getLink().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
@Override
|
||||
public String toString() {
|
||||
return fhirType()+"["+getUrl()+"]";
|
||||
}
|
||||
|
||||
public String present() {
|
||||
if (hasTitle())
|
||||
return getTitle();
|
||||
if (hasName())
|
||||
return getName();
|
||||
return toString();
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
public PropertyComponent getProperty(String code) {
|
||||
for (PropertyComponent pd : getProperty()) {
|
||||
if (pd.getCode().equalsIgnoreCase(code))
|
||||
return pd;
|
||||
}
|
||||
return null;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
private String system;
|
||||
|
||||
@Override
|
||||
public String getSystem() {
|
||||
return system;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSystem() {
|
||||
return system != null;
|
||||
}
|
||||
|
||||
public CodeType setSystem(String system) {
|
||||
this.system = system;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasVersion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDisplay() {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
public boolean hasCoding(String system, String code) {
|
||||
for (Coding c : getCoding()) {
|
||||
if (system.equals(c.getSystem()) && code.equals(c.getCode()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CodeableConcept(Coding code) {
|
||||
super();
|
||||
addCoding(code);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
@Override
|
||||
public boolean supportsVersion() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsDisplay() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean is(String system, String code) {
|
||||
return hasSystem() && hasCode() && this.getSystem().equals(system) && this.getCode().equals(code);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String base = getSystem();
|
||||
if (hasVersion())
|
||||
base = base+"|"+getVersion();
|
||||
base = base + "#"+getCode();
|
||||
if (hasDisplay())
|
||||
base = base+": "+getDisplay();
|
||||
return base;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getCode()+": "+getDisplay();
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
public void checkNoModifiers(String noun, String verb) throws FHIRException {
|
||||
if (hasModifierExtension()) {
|
||||
throw new FHIRException("Found unknown Modifier Exceptions on "+noun+" doing "+verb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addExtension(String url, DataType value) {
|
||||
Extension ex = new Extension();
|
||||
ex.setUrl(url);
|
||||
ex.setValue(value);
|
||||
getExtension().add(ex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean hasExtension(String url) {
|
||||
for (Extension e : getExtension())
|
||||
if (url.equals(e.getUrl()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Extension getExtensionByUrl(String theUrl) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
|
||||
ArrayList<Extension> retVal = new ArrayList<Extension>();
|
||||
for (Extension next : getExtension()) {
|
||||
if (theUrl.equals(next.getUrl())) {
|
||||
retVal.add(next);
|
||||
}
|
||||
}
|
||||
if (retVal.size() == 0)
|
||||
return null;
|
||||
else {
|
||||
org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match");
|
||||
return retVal.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public Resource getContained(String ref) {
|
||||
if (ref == null)
|
||||
return null;
|
||||
|
||||
if (ref.startsWith("#"))
|
||||
ref = ref.substring(1);
|
||||
for (Resource r : getContained()) {
|
||||
if (r.getId().equals(ref))
|
||||
return r;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of extensions from this element which have the given URL. Note that
|
||||
* this list may not be modified (you can not add or remove elements from it)
|
||||
*/
|
||||
public List<Extension> getExtensionsByUrl(String theUrl) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
|
||||
ArrayList<Extension> retVal = new ArrayList<Extension>();
|
||||
for (Extension next : getExtension()) {
|
||||
if (theUrl.equals(next.getUrl())) {
|
||||
retVal.add(next);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(retVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of modifier extensions from this element which have the given URL. Note that
|
||||
* this list may not be modified (you can not add or remove elements from it)
|
||||
*/
|
||||
public List<Extension> getModifierExtensionsByUrl(String theUrl) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must be provided with a value");
|
||||
ArrayList<Extension> retVal = new ArrayList<Extension>();
|
||||
for (Extension next : getModifierExtension()) {
|
||||
if (theUrl.equals(next.getUrl())) {
|
||||
retVal.add(next);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(retVal);
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
@Override
|
||||
public String getIdBase() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdBase(String value) {
|
||||
setId(value);
|
||||
}
|
||||
|
||||
public void addExtension(String url, DataType value) {
|
||||
if (disallowExtensions)
|
||||
throw new Error("Extensions are not allowed in this context");
|
||||
Extension ex = new Extension();
|
||||
ex.setUrl(url);
|
||||
ex.setValue(value);
|
||||
getExtension().add(ex);
|
||||
}
|
||||
|
||||
|
||||
public Extension getExtensionByUrl(String theUrl) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
|
||||
ArrayList<Extension> retVal = new ArrayList<Extension>();
|
||||
for (Extension next : getExtension()) {
|
||||
if (theUrl.equals(next.getUrl())) {
|
||||
retVal.add(next);
|
||||
}
|
||||
}
|
||||
if (retVal.size() == 0)
|
||||
return null;
|
||||
else {
|
||||
org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match");
|
||||
return retVal.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeExtension(String theUrl) {
|
||||
for (int i = getExtension().size()-1; i >= 0; i--) {
|
||||
if (theUrl.equals(getExtension().get(i).getUrl()))
|
||||
getExtension().remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used in the FHIRPath engine to record that no extensions are allowed for this item in the context in which it is used.
|
||||
* todo: enforce this....
|
||||
*/
|
||||
private boolean disallowExtensions;
|
||||
|
||||
public boolean isDisallowExtensions() {
|
||||
return disallowExtensions;
|
||||
}
|
||||
|
||||
public Element setDisallowExtensions(boolean disallowExtensions) {
|
||||
this.disallowExtensions = disallowExtensions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Element noExtensions() {
|
||||
this.disallowExtensions = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list containing all extensions on this element which
|
||||
* match the given URL.
|
||||
*
|
||||
* @param theUrl The URL. Must not be blank or null.
|
||||
* @return an unmodifiable list containing all extensions on this element which
|
||||
* match the given URL
|
||||
*/
|
||||
public List<Extension> getExtensionsByUrl(String theUrl) {
|
||||
org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
|
||||
ArrayList<Extension> retVal = new ArrayList<Extension>();
|
||||
for (Extension next : getExtension()) {
|
||||
if (theUrl.equals(next.getUrl())) {
|
||||
retVal.add(next);
|
||||
}
|
||||
}
|
||||
return java.util.Collections.unmodifiableList(retVal);
|
||||
}
|
||||
|
||||
public boolean hasExtension(String theUrl) {
|
||||
return !getExtensionsByUrl(theUrl).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
public String getExtensionString(String theUrl) throws FHIRException {
|
||||
List<Extension> ext = getExtensionsByUrl(theUrl);
|
||||
if (ext.isEmpty())
|
||||
return null;
|
||||
if (ext.size() > 1)
|
||||
throw new FHIRException("Multiple matching extensions found");
|
||||
if (!ext.get(0).getValue().isPrimitive())
|
||||
throw new FHIRException("Extension could not be converted to a string");
|
||||
return ext.get(0).getValue().primitiveValue();
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
|
||||
public String toString() {
|
||||
if (hasId())
|
||||
return getId();
|
||||
if (hasSliceName())
|
||||
return getPath()+":"+getSliceName();
|
||||
else
|
||||
return getPath();
|
||||
}
|
||||
|
||||
public void makeBase(String path, int min, String max) {
|
||||
ElementDefinitionBaseComponent self = getBase();
|
||||
self.setPath(path);
|
||||
self.setMin(min);
|
||||
self.setMax(max);
|
||||
}
|
||||
|
||||
public void makeBase() {
|
||||
ElementDefinitionBaseComponent self = getBase();
|
||||
self.setPath(getPath());
|
||||
self.setMin(getMin());
|
||||
self.setMax(getMax());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String typeSummary() {
|
||||
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
|
||||
for (TypeRefComponent tr : type) {
|
||||
if (tr.hasCode())
|
||||
b.append(tr.getCode());
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public TypeRefComponent getType(String code) {
|
||||
for (TypeRefComponent tr : getType())
|
||||
if (tr.getCode().equals(code))
|
||||
return tr;
|
||||
TypeRefComponent tr = new TypeRefComponent();
|
||||
tr.setCode(code);
|
||||
type.add(tr);
|
||||
return tr;
|
||||
}
|
||||
|
||||
public static final boolean NOT_MODIFIER = false;
|
||||
public static final boolean NOT_IN_SUMMARY = false;
|
||||
public static final boolean IS_MODIFIER = true;
|
||||
public static final boolean IS_IN_SUMMARY = true;
|
||||
public ElementDefinition(boolean defaults, boolean modifier, boolean inSummary) {
|
||||
super();
|
||||
if (defaults) {
|
||||
setIsModifier(modifier);
|
||||
setIsSummary(inSummary);
|
||||
}
|
||||
}
|
||||
|
||||
public String present() {
|
||||
return hasId() ? getId() : getPath();
|
||||
}
|
||||
|
||||
public boolean hasCondition(IdType id) {
|
||||
for (IdType c : getCondition()) {
|
||||
if (c.primitiveValue().equals(id.primitiveValue()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasConstraint(String key) {
|
||||
for (ElementDefinitionConstraintComponent c : getConstraint()) {
|
||||
if (c.getKey().equals(key))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasCode(Coding c) {
|
||||
for (Coding t : getCode()) {
|
||||
if (t.getSystem().equals(c.getSystem()) && t.getCode().equals(c.getCode()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isChoice() {
|
||||
return getPath().endsWith("[x]");
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
public String toCode(int len) {
|
||||
return toCode().substring(0, len);
|
||||
}
|
||||
|
||||
public static boolean isR4Plus(String version) {
|
||||
return version != null && (version.startsWith("4.") || version.startsWith("5.") || "current".equals(version));
|
||||
}
|
||||
|
||||
public static boolean isValidCode(String codeString) {
|
||||
if (codeString == null || "".equals(codeString))
|
||||
return false;
|
||||
if ("0.01".equals(codeString))
|
||||
return true;
|
||||
if ("0.05".equals(codeString))
|
||||
return true;
|
||||
if ("0.06".equals(codeString))
|
||||
return true;
|
||||
if ("0.11".equals(codeString))
|
||||
return true;
|
||||
if ("0.0.80".equals(codeString))
|
||||
return true;
|
||||
if ("0.0.81".equals(codeString))
|
||||
return true;
|
||||
if ("0.0.82".equals(codeString))
|
||||
return true;
|
||||
if ("0.4.0".equals(codeString))
|
||||
return true;
|
||||
if ("0.5.0".equals(codeString))
|
||||
return true;
|
||||
if ("1.0.0".equals(codeString))
|
||||
return true;
|
||||
if ("1.0.1".equals(codeString))
|
||||
return true;
|
||||
if ("1.0.2".equals(codeString))
|
||||
return true;
|
||||
if ("1.1.0".equals(codeString))
|
||||
return true;
|
||||
if ("1.4.0".equals(codeString))
|
||||
return true;
|
||||
if ("1.6.0".equals(codeString))
|
||||
return true;
|
||||
if ("1.8.0".equals(codeString))
|
||||
return true;
|
||||
if ("3.0.0".equals(codeString))
|
||||
return true;
|
||||
if ("3.0.1".equals(codeString))
|
||||
return true;
|
||||
if ("3.3.0".equals(codeString))
|
||||
return true;
|
||||
if ("3.5.0".equals(codeString))
|
||||
return true;
|
||||
if ("4.0.0".equals(codeString))
|
||||
return true;
|
||||
if ("4.1.0".equals(codeString))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toCode();
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
/**
|
||||
* Returns all repetitions of {@link #getGiven() given name} as a space separated string
|
||||
*
|
||||
* @see DatatypeUtil#joinStringsSpaceSeparated(List)
|
||||
*/
|
||||
public String getGivenAsSingleString() {
|
||||
return joinStringsSpaceSeparated(getGiven());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all repetitions of {@link #getPrefix() prefix name} as a space separated string
|
||||
*
|
||||
* @see DatatypeUtil#joinStringsSpaceSeparated(List)
|
||||
*/
|
||||
public String getPrefixAsSingleString() {
|
||||
return joinStringsSpaceSeparated(getPrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all repetitions of {@link #getSuffix() suffix} as a space separated string
|
||||
*
|
||||
* @see DatatypeUtil#joinStringsSpaceSeparated(List)
|
||||
*/
|
||||
public String getSuffixAsSingleString() {
|
||||
return joinStringsSpaceSeparated(getSuffix());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced
|
||||
* string separating each part.
|
||||
* <p>
|
||||
* If none of the parts are populated, returns the {@link #getTextElement() text} element value instead.
|
||||
* </p>
|
||||
*/
|
||||
public String getNameAsSingleString() {
|
||||
List<StringType> nameParts = new ArrayList<StringType>();
|
||||
nameParts.addAll(getPrefix());
|
||||
nameParts.addAll(getGiven());
|
||||
nameParts.add(getFamilyElement());
|
||||
nameParts.addAll(getSuffix());
|
||||
if (nameParts.size() > 0) {
|
||||
return joinStringsSpaceSeparated(nameParts);
|
||||
} else {
|
||||
return getTextElement().getValue();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins a list of strings with a single space (' ') between each string
|
||||
*
|
||||
* TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
|
||||
*/
|
||||
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (IPrimitiveType<String> next : theStrings) {
|
||||
if (next.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append(' ');
|
||||
}
|
||||
b.append(next.getValue());
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
|
|
@ -0,0 +1,844 @@
|
|||
package org.hl7.fhir.r5.formats;
|
||||
|
||||
// generated
|
||||
|
||||
{{license}}
|
||||
|
||||
{{startMark}}
|
||||
|
||||
import org.hl7.fhir.r5.model.*;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.utilities.json.JsonTrackingParser.PresentedBigDecimal;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import java.io.IOException;
|
||||
|
||||
public class JsonParser extends JsonParserBase {
|
||||
|
||||
public JsonParser() {
|
||||
super();
|
||||
}
|
||||
|
||||
public JsonParser(boolean allowUnknownContent) {
|
||||
super();
|
||||
setAllowUnknownContent(allowUnknownContent);
|
||||
}
|
||||
|
||||
protected void parseBaseProperties(JsonObject json, Base res) throws IOException, FHIRFormatError {
|
||||
// nothing
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <E extends Enum<E>> Enumeration<E> parseEnumeration(String s, E item, EnumFactory e) throws IOException, FHIRFormatError {
|
||||
Enumeration<E> res = new Enumeration<E>(e);
|
||||
if (s != null)
|
||||
res.setValue((E) e.fromCode(s));
|
||||
return res;
|
||||
}
|
||||
|
||||
protected DateType parseDate(String v) throws IOException, FHIRFormatError {
|
||||
DateType res = new DateType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected DateTimeType parseDateTime(String v) throws IOException, FHIRFormatError {
|
||||
DateTimeType res = new DateTimeType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected CodeType parseCode(String v) throws IOException, FHIRFormatError {
|
||||
CodeType res = new CodeType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected StringType parseString(String v) throws IOException, FHIRFormatError {
|
||||
StringType res = new StringType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected IntegerType parseInteger(java.lang.Long v) throws IOException, FHIRFormatError {
|
||||
IntegerType res = new IntegerType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected Integer64Type parseInteger64(java.lang.Long v) throws IOException, FHIRFormatError {
|
||||
Integer64Type res = new Integer64Type(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected OidType parseOid(String v) throws IOException, FHIRFormatError {
|
||||
OidType res = new OidType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected CanonicalType parseCanonical(String v) throws IOException, FHIRFormatError {
|
||||
CanonicalType res = new CanonicalType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UriType parseUri(String v) throws IOException, FHIRFormatError {
|
||||
UriType res = new UriType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UuidType parseUuid(String v) throws IOException, FHIRFormatError {
|
||||
UuidType res = new UuidType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UrlType parseUrl(String v) throws IOException, FHIRFormatError {
|
||||
UrlType res = new UrlType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected InstantType parseInstant(String v) throws IOException, FHIRFormatError {
|
||||
InstantType res = new InstantType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected BooleanType parseBoolean(java.lang.Boolean v) throws IOException, FHIRFormatError {
|
||||
BooleanType res = new BooleanType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected Base64BinaryType parseBase64Binary(String v) throws IOException, FHIRFormatError {
|
||||
Base64BinaryType res = new Base64BinaryType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UnsignedIntType parseUnsignedInt(String v) throws IOException, FHIRFormatError {
|
||||
UnsignedIntType res = new UnsignedIntType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected MarkdownType parseMarkdown(String v) throws IOException, FHIRFormatError {
|
||||
MarkdownType res = new MarkdownType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected TimeType parseTime(String v) throws IOException, FHIRFormatError {
|
||||
TimeType res = new TimeType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected IdType parseId(String v) throws IOException, FHIRFormatError {
|
||||
IdType res = new IdType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected PositiveIntType parsePositiveInt(String v) throws IOException, FHIRFormatError {
|
||||
PositiveIntType res = new PositiveIntType(v);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected DecimalType parseDecimal(java.math.BigDecimal v) throws IOException, FHIRFormatError {
|
||||
DecimalType res = new DecimalType(v);
|
||||
if (v instanceof PresentedBigDecimal)
|
||||
res.setRepresentation(((PresentedBigDecimal) v).getPresentation());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
{{parser}}
|
||||
|
||||
@Override
|
||||
protected Resource parseResource(JsonObject json) throws IOException, FHIRFormatError {
|
||||
if (!json.has("resourceType")) {
|
||||
throw new FHIRFormatError("Unable to find resource type - maybe not a FHIR resource?");
|
||||
}
|
||||
String t = json.get("resourceType").getAsString();
|
||||
if (Utilities.noString(t)) {
|
||||
throw new FHIRFormatError("Unable to find resource type - maybe not a FHIR resource?");
|
||||
{{parse-resource}}
|
||||
} else {
|
||||
throw new FHIRFormatError("Unknown.Unrecognised resource type '"+t+"' (in property 'resourceType')");
|
||||
}
|
||||
}
|
||||
|
||||
protected DataType parseType(String prefix, JsonObject json) throws IOException, FHIRFormatError {
|
||||
if (json.has(prefix+"Date") || json.has("_"+prefix+"Date")) {
|
||||
DataType t = json.has(prefix+"Date") ? parseDate(json.get(prefix+"Date").getAsString()) : new DateType();
|
||||
if (json.has("_"+prefix+"Date"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Date"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"DateTime") || json.has("_"+prefix+"DateTime")) {
|
||||
DataType t = json.has(prefix+"DateTime") ? parseDateTime(json.get(prefix+"DateTime").getAsString()) : new DateTimeType();
|
||||
if (json.has("_"+prefix+"DateTime"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"DateTime"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Code") || json.has("_"+prefix+"Code")) {
|
||||
DataType t = json.has(prefix+"Code") ? parseCode(json.get(prefix+"Code").getAsString()) : new CodeType();
|
||||
if (json.has("_"+prefix+"Code"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Code"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"String") || json.has("_"+prefix+"String")) {
|
||||
DataType t = json.has(prefix+"String") ? parseString(json.get(prefix+"String").getAsString()) : new StringType();
|
||||
if (json.has("_"+prefix+"String"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"String"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Integer") || json.has("_"+prefix+"Integer")) {
|
||||
DataType t = json.has(prefix+"Integer") ? parseInteger(json.get(prefix+"Integer").getAsLong()) : new IntegerType();
|
||||
if (json.has("_"+prefix+"Integer"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Integer"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Integer64") || json.has("_"+prefix+"Integer64")) {
|
||||
DataType t = json.has(prefix+"Integer64") ? parseInteger64(json.get(prefix+"Integer64").getAsLong()) : new Integer64Type();
|
||||
if (json.has("_"+prefix+"Integer64"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Integer64"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Oid") || json.has("_"+prefix+"Oid")) {
|
||||
DataType t = json.has(prefix+"Oid") ? parseOid(json.get(prefix+"Oid").getAsString()) : new OidType();
|
||||
if (json.has("_"+prefix+"Oid"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Oid"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Canonical") || json.has("_"+prefix+"Canonical")) {
|
||||
DataType t = json.has(prefix+"Canonical") ? parseCanonical(json.get(prefix+"Canonical").getAsString()) : new CanonicalType();
|
||||
if (json.has("_"+prefix+"Canonical"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Canonical"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Uri") || json.has("_"+prefix+"Uri")) {
|
||||
DataType t = json.has(prefix+"Uri") ? parseUri(json.get(prefix+"Uri").getAsString()) : new UriType();
|
||||
if (json.has("_"+prefix+"Uri"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Uri"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Uuid") || json.has("_"+prefix+"Uuid")) {
|
||||
DataType t = json.has(prefix+"Uuid") ? parseUuid(json.get(prefix+"Uuid").getAsString()) : new UuidType();
|
||||
if (json.has("_"+prefix+"Uuid"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Uuid"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Url") || json.has("_"+prefix+"Url")) {
|
||||
DataType t = json.has(prefix+"Url") ? parseUrl(json.get(prefix+"Url").getAsString()) : new UrlType();
|
||||
if (json.has("_"+prefix+"Url"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Url"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Instant") || json.has("_"+prefix+"Instant")) {
|
||||
DataType t = json.has(prefix+"Instant") ? parseInstant(json.get(prefix+"Instant").getAsString()) : new InstantType();
|
||||
if (json.has("_"+prefix+"Instant"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Instant"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Boolean") || json.has("_"+prefix+"Boolean")) {
|
||||
DataType t = json.has(prefix+"Boolean") ? parseBoolean(json.get(prefix+"Boolean").getAsBoolean()) : new BooleanType();
|
||||
if (json.has("_"+prefix+"Boolean"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Boolean"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Base64Binary") || json.has("_"+prefix+"Base64Binary")) {
|
||||
DataType t = json.has(prefix+"Base64Binary") ? parseBase64Binary(json.get(prefix+"Base64Binary").getAsString()) : new Base64BinaryType();
|
||||
if (json.has("_"+prefix+"Base64Binary"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Base64Binary"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"UnsignedInt") || json.has("_"+prefix+"UnsignedInt")) {
|
||||
DataType t = json.has(prefix+"UnsignedInt") ? parseUnsignedInt(json.get(prefix+"UnsignedInt").getAsString()) : new UnsignedIntType();
|
||||
if (json.has("_"+prefix+"UnsignedInt"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"UnsignedInt"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Markdown") || json.has("_"+prefix+"Markdown")) {
|
||||
DataType t = json.has(prefix+"Markdown") ? parseMarkdown(json.get(prefix+"Markdown").getAsString()) : new MarkdownType();
|
||||
if (json.has("_"+prefix+"Markdown"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Markdown"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Time") || json.has("_"+prefix+"Time")) {
|
||||
DataType t = json.has(prefix+"Time") ? parseTime(json.get(prefix+"Time").getAsString()) : new TimeType();
|
||||
if (json.has("_"+prefix+"Time"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Time"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Id") || json.has("_"+prefix+"Id")) {
|
||||
DataType t = json.has(prefix+"Id") ? parseId(json.get(prefix+"Id").getAsString()) : new IdType();
|
||||
if (json.has("_"+prefix+"Id"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Id"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"PositiveInt") || json.has("_"+prefix+"PositiveInt")) {
|
||||
DataType t = json.has(prefix+"PositiveInt") ? parsePositiveInt(json.get(prefix+"PositiveInt").getAsString()) : new PositiveIntType();
|
||||
if (json.has("_"+prefix+"PositiveInt"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"PositiveInt"), t);
|
||||
return t;
|
||||
}
|
||||
else if (json.has(prefix+"Decimal") || json.has("_"+prefix+"Decimal")) {
|
||||
DataType t = json.has(prefix+"Decimal") ? parseDecimal(json.get(prefix+"Decimal").getAsBigDecimal()) : new DecimalType();
|
||||
if (json.has("_"+prefix+"Decimal"))
|
||||
parseElementProperties(json.getAsJsonObject("_"+prefix+"Decimal"), t);
|
||||
return t;
|
||||
{{parse-type-pfx}}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected DataType parseAnyType(JsonObject json, String type) throws IOException, FHIRFormatError {
|
||||
return parseType(json, type);
|
||||
}
|
||||
|
||||
protected DataType parseType(JsonObject json, String type) throws IOException, FHIRFormatError {
|
||||
if (Utilities.noString(type)) {
|
||||
throw new FHIRFormatError("Unable to parse type - type not specified");
|
||||
{{parse-type}}
|
||||
} else {
|
||||
throw new FHIRFormatError("Unknown Type "+type);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean hasTypeName(JsonObject json, String prefix) {
|
||||
{{parse-has-type}}
|
||||
if (json.has(prefix+"Date") || json.has("_"+prefix+"Date"))
|
||||
return true;
|
||||
if (json.has(prefix+"DateTime") || json.has("_"+prefix+"DateTime"))
|
||||
return true;
|
||||
if (json.has(prefix+"Code") || json.has("_"+prefix+"Code"))
|
||||
return true;
|
||||
if (json.has(prefix+"String") || json.has("_"+prefix+"String"))
|
||||
return true;
|
||||
if (json.has(prefix+"Integer") || json.has("_"+prefix+"Integer"))
|
||||
return true;
|
||||
if (json.has(prefix+"Integer64") || json.has("_"+prefix+"Integer64"))
|
||||
return true;
|
||||
if (json.has(prefix+"Oid") || json.has("_"+prefix+"Oid"))
|
||||
return true;
|
||||
if (json.has(prefix+"Canonical") || json.has("_"+prefix+"Canonical"))
|
||||
return true;
|
||||
if (json.has(prefix+"Uri") || json.has("_"+prefix+"Uri"))
|
||||
return true;
|
||||
if (json.has(prefix+"Uuid") || json.has("_"+prefix+"Uuid"))
|
||||
return true;
|
||||
if (json.has(prefix+"Url") || json.has("_"+prefix+"Url"))
|
||||
return true;
|
||||
if (json.has(prefix+"Instant") || json.has("_"+prefix+"Instant"))
|
||||
return true;
|
||||
if (json.has(prefix+"Boolean") || json.has("_"+prefix+"Boolean"))
|
||||
return true;
|
||||
if (json.has(prefix+"Base64Binary") || json.has("_"+prefix+"Base64Binary"))
|
||||
return true;
|
||||
if (json.has(prefix+"UnsignedInt") || json.has("_"+prefix+"UnsignedInt"))
|
||||
return true;
|
||||
if (json.has(prefix+"Markdown") || json.has("_"+prefix+"Markdown"))
|
||||
return true;
|
||||
if (json.has(prefix+"Time") || json.has("_"+prefix+"Time"))
|
||||
return true;
|
||||
if (json.has(prefix+"Id") || json.has("_"+prefix+"Id"))
|
||||
return true;
|
||||
if (json.has(prefix+"PositiveInt") || json.has("_"+prefix+"PositiveInt"))
|
||||
return true;
|
||||
if (json.has(prefix+"Decimal") || json.has("_"+prefix+"Decimal"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// -- compose ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
protected void composeBaseProperties(Base element) throws IOException {
|
||||
}
|
||||
|
||||
|
||||
protected <E extends Enum<E>> void composeEnumerationCore(String name, Enumeration<E> value, EnumFactory e, boolean inArray) throws IOException {
|
||||
if (value != null && value.getValue() != null) {
|
||||
prop(name, e.toCode(value.getValue()));
|
||||
} else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected <E extends Enum<E>> void composeEnumerationExtras(String name, Enumeration<E> value, EnumFactory e, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
} else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeDateCore(String name, DateType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, value.asStringValue());
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeDateExtras(String name, DateType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeDateTimeCore(String name, DateTimeType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, value.asStringValue());
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeDateTimeExtras(String name, DateTimeType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeCodeCore(String name, CodeType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeCodeExtras(String name, CodeType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeStringCore(String name, StringType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeStringExtras(String name, StringType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeIntegerCore(String name, IntegerType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, Integer.valueOf(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeIntegerExtras(String name, IntegerType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeInteger64Core(String name, Integer64Type value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, value.getValue().toString());
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeInteger64Extras(String name, Integer64Type value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeOidCore(String name, OidType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeOidExtras(String name, OidType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeCanonicalCore(String name, CanonicalType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeCanonicalExtras(String name, CanonicalType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUriCore(String name, UriType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUriExtras(String name, UriType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUuidCore(String name, UuidType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUuidExtras(String name, UuidType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUrlCore(String name, UrlType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUrlExtras(String name, UrlType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeInstantCore(String name, InstantType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, value.asStringValue());
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeInstantExtras(String name, InstantType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeBooleanCore(String name, BooleanType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, value.getValue());
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeBooleanExtras(String name, BooleanType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeBase64BinaryCore(String name, Base64BinaryType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeBase64BinaryExtras(String name, Base64BinaryType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUnsignedIntCore(String name, UnsignedIntType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, Integer.valueOf(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeUnsignedIntExtras(String name, UnsignedIntType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeMarkdownCore(String name, MarkdownType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeMarkdownExtras(String name, MarkdownType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeTimeCore(String name, TimeType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, value.asStringValue());
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeTimeExtras(String name, TimeType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeIdCore(String name, IdType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, toString(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeIdExtras(String name, IdType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composePositiveIntCore(String name, PositiveIntType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, Integer.valueOf(value.getValue()));
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composePositiveIntExtras(String name, PositiveIntType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeDecimalCore(String name, DecimalType value, boolean inArray) throws IOException {
|
||||
if (value != null && value.hasValue()) {
|
||||
prop(name, value.getValue());
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
protected void composeDecimalExtras(String name, DecimalType value, boolean inArray) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || makeComments(value))) {
|
||||
open(inArray ? null : "_"+name);
|
||||
composeElementProperties(value);
|
||||
close();
|
||||
}
|
||||
else if (inArray)
|
||||
writeNull(name);
|
||||
}
|
||||
|
||||
{{composer}}
|
||||
|
||||
@Override
|
||||
protected void composeResource(Resource resource) throws IOException {
|
||||
if (resource == null) {
|
||||
throw new Error("Unhandled resource type "+resource.getClass().getName());
|
||||
{{compose-resource}}
|
||||
} else
|
||||
throw new Error("Unhandled resource type "+resource.getClass().getName());
|
||||
}
|
||||
|
||||
protected void composeNamedReference(String name, Resource resource) throws IOException {
|
||||
if (resource == null) {
|
||||
throw new Error("Unhandled resource type "+resource.getClass().getName());
|
||||
{{compose-resource-named}}
|
||||
} else
|
||||
throw new Error("Unhandled resource type "+resource.getClass().getName());
|
||||
}
|
||||
|
||||
protected void composeType(String prefix, DataType type) throws IOException {
|
||||
if (type == null) {
|
||||
;
|
||||
{{compose-type}}
|
||||
} else if (type instanceof CodeType) {
|
||||
composeCodeCore(prefix+"Code", (CodeType) type, false);
|
||||
composeCodeExtras(prefix+"Code", (CodeType) type, false);
|
||||
}
|
||||
else if (type instanceof OidType) {
|
||||
composeOidCore(prefix+"Oid", (OidType) type, false);
|
||||
composeOidExtras(prefix+"Oid", (OidType) type, false);
|
||||
}
|
||||
else if (type instanceof CanonicalType) {
|
||||
composeCanonicalCore(prefix+"Canonical", (CanonicalType) type, false);
|
||||
composeCanonicalExtras(prefix+"Canonical", (CanonicalType) type, false);
|
||||
}
|
||||
else if (type instanceof UuidType) {
|
||||
composeUuidCore(prefix+"Uuid", (UuidType) type, false);
|
||||
composeUuidExtras(prefix+"Uuid", (UuidType) type, false);
|
||||
}
|
||||
else if (type instanceof UrlType) {
|
||||
composeUrlCore(prefix+"Url", (UrlType) type, false);
|
||||
composeUrlExtras(prefix+"Url", (UrlType) type, false);
|
||||
}
|
||||
else if (type instanceof UnsignedIntType) {
|
||||
composeUnsignedIntCore(prefix+"UnsignedInt", (UnsignedIntType) type, false);
|
||||
composeUnsignedIntExtras(prefix+"UnsignedInt", (UnsignedIntType) type, false);
|
||||
}
|
||||
else if (type instanceof MarkdownType) {
|
||||
composeMarkdownCore(prefix+"Markdown", (MarkdownType) type, false);
|
||||
composeMarkdownExtras(prefix+"Markdown", (MarkdownType) type, false);
|
||||
}
|
||||
else if (type instanceof IdType) {
|
||||
composeIdCore(prefix+"Id", (IdType) type, false);
|
||||
composeIdExtras(prefix+"Id", (IdType) type, false);
|
||||
}
|
||||
else if (type instanceof PositiveIntType) {
|
||||
composePositiveIntCore(prefix+"PositiveInt", (PositiveIntType) type, false);
|
||||
composePositiveIntExtras(prefix+"PositiveInt", (PositiveIntType) type, false);
|
||||
}
|
||||
else if (type instanceof DateType) {
|
||||
composeDateCore(prefix+"Date", (DateType) type, false);
|
||||
composeDateExtras(prefix+"Date", (DateType) type, false);
|
||||
}
|
||||
else if (type instanceof DateTimeType) {
|
||||
composeDateTimeCore(prefix+"DateTime", (DateTimeType) type, false);
|
||||
composeDateTimeExtras(prefix+"DateTime", (DateTimeType) type, false);
|
||||
}
|
||||
else if (type instanceof StringType) {
|
||||
composeStringCore(prefix+"String", (StringType) type, false);
|
||||
composeStringExtras(prefix+"String", (StringType) type, false);
|
||||
}
|
||||
else if (type instanceof IntegerType) {
|
||||
composeIntegerCore(prefix+"Integer", (IntegerType) type, false);
|
||||
composeIntegerExtras(prefix+"Integer", (IntegerType) type, false);
|
||||
}
|
||||
else if (type instanceof Integer64Type) {
|
||||
composeInteger64Core(prefix+"Integer64", (Integer64Type) type, false);
|
||||
composeInteger64Extras(prefix+"Integer64", (Integer64Type) type, false);
|
||||
}
|
||||
else if (type instanceof UriType) {
|
||||
composeUriCore(prefix+"Uri", (UriType) type, false);
|
||||
composeUriExtras(prefix+"Uri", (UriType) type, false);
|
||||
}
|
||||
else if (type instanceof InstantType) {
|
||||
composeInstantCore(prefix+"Instant", (InstantType) type, false);
|
||||
composeInstantExtras(prefix+"Instant", (InstantType) type, false);
|
||||
}
|
||||
else if (type instanceof BooleanType) {
|
||||
composeBooleanCore(prefix+"Boolean", (BooleanType) type, false);
|
||||
composeBooleanExtras(prefix+"Boolean", (BooleanType) type, false);
|
||||
}
|
||||
else if (type instanceof Base64BinaryType) {
|
||||
composeBase64BinaryCore(prefix+"Base64Binary", (Base64BinaryType) type, false);
|
||||
composeBase64BinaryExtras(prefix+"Base64Binary", (Base64BinaryType) type, false);
|
||||
}
|
||||
else if (type instanceof TimeType) {
|
||||
composeTimeCore(prefix+"Time", (TimeType) type, false);
|
||||
composeTimeExtras(prefix+"Time", (TimeType) type, false);
|
||||
}
|
||||
else if (type instanceof DecimalType) {
|
||||
composeDecimalCore(prefix+"Decimal", (DecimalType) type, false);
|
||||
composeDecimalExtras(prefix+"Decimal", (DecimalType) type, false);
|
||||
} else
|
||||
throw new Error("Unhandled type");
|
||||
}
|
||||
|
||||
protected void composeTypeInner(DataType type) throws IOException {
|
||||
if (type == null) {
|
||||
;
|
||||
{{compose-type-inner}}
|
||||
} else
|
||||
throw new Error("Unhandled type: "+type.fhirType());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Convenience method which adds a tag
|
||||
*
|
||||
* @param theSystem The code system
|
||||
* @param theCode The code
|
||||
* @param theDisplay The display name
|
||||
* @return Returns a reference to <code>this</code> for easy chaining
|
||||
*/
|
||||
public Meta addTag(String theSystem, String theCode, String theDisplay) {
|
||||
addTag().setSystem(theSystem).setCode(theCode).setDisplay(theDisplay);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first tag (if any) that has the given system and code, or returns
|
||||
* <code>null</code> if none
|
||||
*/
|
||||
public Coding getTag(String theSystem, String theCode) {
|
||||
for (Coding next : getTag()) {
|
||||
if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first security label (if any) that has the given system and code, or returns
|
||||
* <code>null</code> if none
|
||||
*/
|
||||
public Coding getSecurity(String theSystem, String theCode) {
|
||||
for (Coding next : getTag()) {
|
||||
if (ca.uhn.fhir.util.ObjectUtil.equals(next.getSystem(), theSystem) && ca.uhn.fhir.util.ObjectUtil.equals(next.getCode(), theCode)) {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
|
||||
public Parameters addParameter(String name, boolean b) {
|
||||
addParameter().setName(name).setValue(new BooleanType(b));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters addParameter(String name, String s) {
|
||||
if (s != null)
|
||||
addParameter().setName(name).setValue(new StringType(s));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters addParameter(String name, DataType v) {
|
||||
if (v != null)
|
||||
addParameter().setName(name).setValue(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters setParameter(String name, boolean b) {
|
||||
for (ParametersParameterComponent p : getParameter()) {
|
||||
if (p.getName().equals(name)) {
|
||||
p.setValue(new BooleanType(b));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
addParameter().setName(name).setValue(new BooleanType(b));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters setParameter(String name, String s) {
|
||||
if (s != null) {
|
||||
for (ParametersParameterComponent p : getParameter()) {
|
||||
if (p.getName().equals(name)) {
|
||||
p.setValue(new StringType(s));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
addParameter().setName(name).setValue(new StringType(s));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Parameters setParameter(String name, DataType v) {
|
||||
if (v != null) {
|
||||
for (ParametersParameterComponent p : getParameter() ) {
|
||||
if (p.getName().equals(name)) {
|
||||
p.setValue(v);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
addParameter().setName(name).setValue(v);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasParameter(String name) {
|
||||
for (ParametersParameterComponent p : getParameter()) {
|
||||
if (p.getName().equals(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public DataType getParameter(String name) {
|
||||
for (ParametersParameterComponent p : getParameter()) {
|
||||
if (p.getName().equals(name))
|
||||
return p.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<DataType> getParameters(String name) {
|
||||
List<DataType> res = new ArrayList<>();
|
||||
for (ParametersParameterComponent p : getParameter()) {
|
||||
if (p.getName().equals(name))
|
||||
res.add(p.getValue());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public boolean getParameterBool(String name) {
|
||||
for (ParametersParameterComponent p : getParameter()) {
|
||||
if (p.getName().equals(name)) {
|
||||
if (p.getValue() instanceof BooleanType)
|
||||
return ((BooleanType) p.getValue()).booleanValue();
|
||||
boolean ok = Boolean.getBoolean(p.getValue().primitiveValue());
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Sets the value for <b>start</b> ()
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* The start of the period. The boundary is inclusive.
|
||||
* </p>
|
||||
*/
|
||||
public Period setStart( Date theDate, TemporalPrecisionEnum thePrecision) {
|
||||
start = new DateTimeType(theDate, thePrecision);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for <b>end</b> ()
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* The end of the period. The boundary is inclusive.
|
||||
* </p>
|
||||
*/
|
||||
public Period setEnd( Date theDate, TemporalPrecisionEnum thePrecision) {
|
||||
end = new DateTimeType(theDate, thePrecision);
|
||||
return this;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasVersion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsVersion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDisplay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsDisplay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Quantity fromUcum(String v, String code) {
|
||||
Quantity res = new Quantity();
|
||||
res.setValue(new BigDecimal(v));
|
||||
res.setSystem("http://unitsofmeasure.org");
|
||||
res.setCode(code);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
public QuestionnaireItemComponent getQuestion(String linkId) {
|
||||
if (linkId == null)
|
||||
return null;
|
||||
for (QuestionnaireItemComponent i : getItem()) {
|
||||
if (i.getLinkId().equals(linkId))
|
||||
return i;
|
||||
QuestionnaireItemComponent t = i.getQuestion(linkId);
|
||||
if (t != null)
|
||||
return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public QuestionnaireItemComponent getCommonGroup(QuestionnaireItemComponent q1, QuestionnaireItemComponent q2) {
|
||||
for (QuestionnaireItemComponent i : getItem()) {
|
||||
QuestionnaireItemComponent t = i.getCommonGroup(q1, q2);
|
||||
if (t != null)
|
||||
return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
public QuestionnaireItemComponent getQuestion(String linkId) {
|
||||
if (linkId == null)
|
||||
return null;
|
||||
for (QuestionnaireItemComponent i : getItem()) {
|
||||
if (i.getLinkId().equals(linkId))
|
||||
return i;
|
||||
QuestionnaireItemComponent t = i.getQuestion(linkId);
|
||||
if (t != null)
|
||||
return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public QuestionnaireItemComponent getCommonGroup(QuestionnaireItemComponent q1, QuestionnaireItemComponent q2) {
|
||||
if (q1 == null || q2 == null)
|
||||
return null;
|
||||
for (QuestionnaireItemComponent i : getItem()) {
|
||||
QuestionnaireItemComponent t = i.getCommonGroup(q1, q2);
|
||||
if (t != null)
|
||||
return t;
|
||||
}
|
||||
if (containsQuestion(q1) && containsQuestion(q2))
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean containsQuestion(QuestionnaireItemComponent q) {
|
||||
if (q == this)
|
||||
return true;
|
||||
for (QuestionnaireItemComponent i : getItem()) {
|
||||
if (i.containsQuestion(q))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -0,0 +1,270 @@
|
|||
package org.hl7.fhir.r5.formats;
|
||||
|
||||
|
||||
// generated
|
||||
|
||||
{{license}}
|
||||
|
||||
{{startMark}}
|
||||
|
||||
import org.hl7.fhir.r5.model.*;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.r5.utils.formats.Turtle.Complex;
|
||||
import java.io.IOException;
|
||||
|
||||
public class RdfParser extends RdfParserBase {
|
||||
|
||||
public RdfParser() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RdfParser(boolean allowUnknownContent) {
|
||||
super();
|
||||
setAllowUnknownContent(allowUnknownContent);
|
||||
}
|
||||
|
||||
private void composeEnum(Complex parent, String parentType, String name, Enumeration<? extends Enum> value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
decorateCode(t, value);
|
||||
}
|
||||
|
||||
|
||||
protected void composeDate(Complex parent, String parentType, String name, DateType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeDateTime(Complex parent, String parentType, String name, DateTimeType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeCode(Complex parent, String parentType, String name, CodeType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
decorateCode(t, value);
|
||||
}
|
||||
|
||||
protected void composeString(Complex parent, String parentType, String name, StringType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeInteger(Complex parent, String parentType, String name, IntegerType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeInteger64(Complex parent, String parentType, String name, Integer64Type value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeOid(Complex parent, String parentType, String name, OidType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeCanonical(Complex parent, String parentType, String name, CanonicalType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeUri(Complex parent, String parentType, String name, UriType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeUuid(Complex parent, String parentType, String name, UuidType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeUrl(Complex parent, String parentType, String name, UrlType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeInstant(Complex parent, String parentType, String name, InstantType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeBoolean(Complex parent, String parentType, String name, BooleanType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeBase64Binary(Complex parent, String parentType, String name, Base64BinaryType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeUnsignedInt(Complex parent, String parentType, String name, UnsignedIntType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeMarkdown(Complex parent, String parentType, String name, MarkdownType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeTime(Complex parent, String parentType, String name, TimeType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeId(Complex parent, String parentType, String name, IdType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composePositiveInt(Complex parent, String parentType, String name, PositiveIntType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
protected void composeDecimal(Complex parent, String parentType, String name, DecimalType value, int index) {
|
||||
if (value == null)
|
||||
return;
|
||||
Complex t = parent.predicate("fhir:"+parentType+"."+name);
|
||||
t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
|
||||
composeElement(t, parentType, name, value, index);
|
||||
}
|
||||
|
||||
{{composer}}
|
||||
|
||||
|
||||
@Override
|
||||
protected void composeResource(Complex parent, Resource resource) {
|
||||
if (parent == null) {
|
||||
throw new Error("parent == null");
|
||||
} else if (resource == null) {
|
||||
throw new Error("resource == null");
|
||||
{{compose-resource}}
|
||||
} else {
|
||||
throw new Error("Unhandled resource type "+resource.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeType(Complex parent, String parentType, String name, DataType value, int index) {
|
||||
if (parent == null) {
|
||||
throw new Error("parent == null");
|
||||
} else if (parentType == null) {
|
||||
throw new Error("parentType == null");
|
||||
} else if (name == null) {
|
||||
throw new Error("name == null");
|
||||
} else if (value == null) {
|
||||
throw new Error("value == null");
|
||||
} else if (value instanceof DateType) {
|
||||
composeDate(parent, parentType, name, (DateType)value, index);
|
||||
} else if (value instanceof DateTimeType) {
|
||||
composeDateTime(parent, parentType, name, (DateTimeType)value, index);
|
||||
} else if (value instanceof CodeType) {
|
||||
composeCode(parent, parentType, name, (CodeType)value, index);
|
||||
} else if (value instanceof StringType) {
|
||||
composeString(parent, parentType, name, (StringType)value, index);
|
||||
} else if (value instanceof IntegerType) {
|
||||
composeInteger(parent, parentType, name, (IntegerType)value, index);
|
||||
} else if (value instanceof Integer64Type) {
|
||||
composeInteger64(parent, parentType, name, (Integer64Type)value, index);
|
||||
} else if (value instanceof OidType) {
|
||||
composeOid(parent, parentType, name, (OidType)value, index);
|
||||
} else if (value instanceof CanonicalType) {
|
||||
composeCanonical(parent, parentType, name, (CanonicalType)value, index);
|
||||
} else if (value instanceof UriType) {
|
||||
composeUri(parent, parentType, name, (UriType)value, index);
|
||||
} else if (value instanceof UuidType) {
|
||||
composeUuid(parent, parentType, name, (UuidType)value, index);
|
||||
} else if (value instanceof UrlType) {
|
||||
composeUrl(parent, parentType, name, (UrlType)value, index);
|
||||
} else if (value instanceof InstantType) {
|
||||
composeInstant(parent, parentType, name, (InstantType)value, index);
|
||||
} else if (value instanceof BooleanType) {
|
||||
composeBoolean(parent, parentType, name, (BooleanType)value, index);
|
||||
} else if (value instanceof Base64BinaryType) {
|
||||
composeBase64Binary(parent, parentType, name, (Base64BinaryType)value, index);
|
||||
} else if (value instanceof UnsignedIntType) {
|
||||
composeUnsignedInt(parent, parentType, name, (UnsignedIntType)value, index);
|
||||
} else if (value instanceof MarkdownType) {
|
||||
composeMarkdown(parent, parentType, name, (MarkdownType)value, index);
|
||||
} else if (value instanceof TimeType) {
|
||||
composeTime(parent, parentType, name, (TimeType)value, index);
|
||||
} else if (value instanceof IdType) {
|
||||
composeId(parent, parentType, name, (IdType)value, index);
|
||||
} else if (value instanceof PositiveIntType) {
|
||||
composePositiveInt(parent, parentType, name, (PositiveIntType)value, index);
|
||||
} else if (value instanceof DecimalType) {
|
||||
composeDecimal(parent, parentType, name, (DecimalType)value, index);
|
||||
{{compose-type}}
|
||||
} else {
|
||||
throw new Error("Unhandled type");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (hasReference())
|
||||
return "Reference["+getReference()+"]";
|
||||
if (hasIdentifier())
|
||||
return "Reference[id:"+getIdentifier()+"]";
|
||||
if (hasDisplay())
|
||||
return "Reference['"+getDisplay()+"']";
|
||||
return "Reference[??]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience setter which sets the reference to the complete {@link IIdType#getValue() value} of the given
|
||||
* reference.
|
||||
*
|
||||
* @param theReference The reference, or <code>null</code>
|
||||
* @return
|
||||
* @return Returns a reference to this
|
||||
*/
|
||||
public Reference setReferenceElement(IIdType theReference) {
|
||||
if (theReference != null) {
|
||||
setReference(theReference.getValue());
|
||||
} else {
|
||||
setReference(null);
|
||||
}
|
||||
return this;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
@Override
|
||||
public String getIdBase() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdBase(String value) {
|
||||
setId(value);
|
||||
}
|
||||
public abstract ResourceType getResourceType();
|
||||
|
||||
public String getLanguage(String defValue) {
|
||||
return hasLanguage() ? getLanguage() : defValue;
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package org.hl7.fhir.r5.model;
|
||||
|
||||
{{license}}
|
||||
|
||||
{{startMark}}
|
||||
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
|
||||
public class ResourceFactory extends Factory {
|
||||
|
||||
public static Resource createResource(String name) throws FHIRException {
|
||||
{{resource-factory}}
|
||||
else
|
||||
throw new FHIRException("Unknown Resource Name '"+name+"'");
|
||||
}
|
||||
|
||||
public static Element createType(String name) throws FHIRException {
|
||||
if ("base64Binary".equals(name))
|
||||
return new Base64BinaryType();
|
||||
if ("boolean".equals(name))
|
||||
return new BooleanType();
|
||||
if ("canonical".equals(name))
|
||||
return new CanonicalType();
|
||||
if ("code".equals(name))
|
||||
return new CodeType();
|
||||
if ("date".equals(name))
|
||||
return new DateType();
|
||||
if ("dateTime".equals(name))
|
||||
return new DateTimeType();
|
||||
if ("decimal".equals(name))
|
||||
return new DecimalType();
|
||||
if ("id".equals(name))
|
||||
return new IdType();
|
||||
if ("instant".equals(name))
|
||||
return new InstantType();
|
||||
if ("integer".equals(name))
|
||||
return new IntegerType();
|
||||
if ("integer64".equals(name))
|
||||
return new Integer64Type();
|
||||
if ("markdown".equals(name))
|
||||
return new MarkdownType();
|
||||
if ("oid".equals(name))
|
||||
return new OidType();
|
||||
if ("positiveInt".equals(name))
|
||||
return new PositiveIntType();
|
||||
if ("string".equals(name))
|
||||
return new StringType();
|
||||
if ("time".equals(name))
|
||||
return new TimeType();
|
||||
if ("unsignedInt".equals(name))
|
||||
return new UnsignedIntType();
|
||||
if ("uri".equals(name))
|
||||
return new UriType();
|
||||
if ("url".equals(name))
|
||||
return new UrlType();
|
||||
if ("uuid".equals(name))
|
||||
return new UuidType();
|
||||
{{type-factory}}
|
||||
else
|
||||
throw new FHIRException("Unknown Type Name '"+name+"'"); }
|
||||
|
||||
public static Base createResourceOrType(String name) throws FHIRException {
|
||||
switch (name.hashCode()) {
|
||||
case -1216012752: return new Base64BinaryType();
|
||||
case 64711720: return new BooleanType();
|
||||
case 828351732: return new CanonicalType();
|
||||
case 3059181: return new CodeType();
|
||||
case 3076014: return new DateType();
|
||||
case 1792749467: return new DateTimeType();
|
||||
case 1542263633: return new DecimalType();
|
||||
case 3355: return new IdType();
|
||||
case 1957570017: return new InstantType();
|
||||
case 1958052158: return new IntegerType();
|
||||
case 246938863: return new MarkdownType();
|
||||
case 110026: return new OidType();
|
||||
case -131262666: return new PositiveIntType();
|
||||
case -891985903: return new StringType();
|
||||
case 3560141: return new TimeType();
|
||||
case 1145198778: return new UnsignedIntType();
|
||||
case 116076: return new UriType();
|
||||
case 116079: return new UrlType();
|
||||
case 3601339: return new UuidType();
|
||||
{{case-factory}}
|
||||
default:
|
||||
throw new FHIRException("Unknown Resource or Type Name '"+name+"'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
public String describeType() {
|
||||
if ("Extension".equals(getType()))
|
||||
return "Extension" ;
|
||||
switch (getKind()) {
|
||||
case COMPLEXTYPE: return getDerivation() == TypeDerivationRule.CONSTRAINT ? "DataType Constraint" : "DataType" ;
|
||||
case LOGICAL: return getDerivation() == TypeDerivationRule.CONSTRAINT ? "Logical Model" : "Logical Model Profile";
|
||||
case PRIMITIVETYPE: return getDerivation() == TypeDerivationRule.CONSTRAINT ? "PrimitiveType Constraint" : "PrimitiveType";
|
||||
case RESOURCE: return getDerivation() == TypeDerivationRule.CONSTRAINT ? "Resource Profile" : "Resource";
|
||||
default:
|
||||
return "Definition";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
public String toString() {
|
||||
return StructureMapUtilities.render(this);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
public String toString() {
|
||||
return StructureMapUtilities.groupToString(this);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
public String toString() {
|
||||
return StructureMapUtilities.ruleToString(this);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
public String toString() {
|
||||
return StructureMapUtilities.sourceToString(this);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
public String toString() {
|
||||
return StructureMapUtilities.targetToString(this);
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
public String toString() {
|
||||
return value == null ? "null!" : value.toString();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
public boolean hasTarget() {
|
||||
return Utilities.existsInList(getCode(), "Reference", "canonical", "CodeableReference");
|
||||
}
|
||||
|
||||
/**
|
||||
* This code checks for the system prefix and returns the FHIR type
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getWorkingCode() {
|
||||
if (hasExtension(ToolingExtensions.EXT_FHIR_TYPE))
|
||||
return getExtensionString(ToolingExtensions.EXT_FHIR_TYPE);
|
||||
if (!hasCodeElement())
|
||||
return null;
|
||||
if (getCodeElement().hasExtension(ToolingExtensions.EXT_XML_TYPE)) {
|
||||
String s = getCodeElement().getExtensionString(ToolingExtensions.EXT_XML_TYPE);
|
||||
if ("xsd:gYear OR xsd:gYearMonth OR xsd:date OR xsd:dateTime".equalsIgnoreCase(s))
|
||||
return "dateTime";
|
||||
if ("xsd:gYear OR xsd:gYearMonth OR xsd:date".equalsIgnoreCase(s))
|
||||
return "date";
|
||||
if ("xsd:dateTime".equalsIgnoreCase(s))
|
||||
return "instant";
|
||||
if ("xsd:token".equals(s))
|
||||
return "code";
|
||||
if ("xsd:boolean".equals(s))
|
||||
return "boolean";
|
||||
if ("xsd:string".equals(s))
|
||||
return "string";
|
||||
if ("xsd:time".equals(s))
|
||||
return "time";
|
||||
if ("xsd:int".equals(s))
|
||||
return "integer";
|
||||
if ("xsd:decimal OR xsd:double".equals(s))
|
||||
return "decimal";
|
||||
if ("xsd:decimal".equalsIgnoreCase(s))
|
||||
return "decimal";
|
||||
if ("xsd:base64Binary".equalsIgnoreCase(s))
|
||||
return "base64Binary";
|
||||
if ("xsd:positiveInteger".equalsIgnoreCase(s))
|
||||
return "positiveInt";
|
||||
if ("xsd:nonNegativeInteger".equalsIgnoreCase(s))
|
||||
return "unsignedInt";
|
||||
if ("xsd:anyURI".equalsIgnoreCase(s))
|
||||
return "uri";
|
||||
|
||||
throw new Error("Unknown xml type '"+s+"'");
|
||||
}
|
||||
return getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = getCode();
|
||||
if (hasProfile()) {
|
||||
res = res + "{";
|
||||
boolean first = true;
|
||||
for (CanonicalType s : getProfile()) {
|
||||
if (first) first = false; else res = res + "|";
|
||||
res = res + s.getValue();
|
||||
}
|
||||
res = res + "}";
|
||||
}
|
||||
if (hasTargetProfile()) {
|
||||
res = res + "->(";
|
||||
boolean first = true;
|
||||
for (CanonicalType s : getProfile()) {
|
||||
if (first) first = false; else res = res + "|";
|
||||
res = res + s.getValue();
|
||||
}
|
||||
res = res + ")";
|
||||
}
|
||||
return res;
|
||||
}
|
|
@ -0,0 +1,922 @@
|
|||
package org.hl7.fhir.r5.formats;
|
||||
|
||||
|
||||
// generated
|
||||
|
||||
{{license}}
|
||||
|
||||
{{startMark}}
|
||||
|
||||
import org.hl7.fhir.r5.model.*;
|
||||
import org.hl7.fhir.r5.model.Enumerations.FHIRVersion;
|
||||
import org.xmlpull.v1.*;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class XmlParser extends XmlParserBase {
|
||||
|
||||
public XmlParser() {
|
||||
super();
|
||||
}
|
||||
|
||||
public XmlParser(boolean allowUnknownContent) {
|
||||
super();
|
||||
setAllowUnknownContent(allowUnknownContent);
|
||||
}
|
||||
|
||||
protected boolean parseBaseContent(int eventType, XmlPullParser xpp, Base res) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <E extends Enum<E>> Enumeration<E> parseEnumeration(XmlPullParser xpp, E item, EnumFactory e) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
Enumeration<E> res = new Enumeration<E>(e);
|
||||
parseElementAttributes(xpp, res);
|
||||
res.setValue((E) e.fromCode(xpp.getAttributeValue(null, "value")));
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected DateType parseDate(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
DateType res = new DateType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected DateTimeType parseDateTime(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
DateTimeType res = new DateTimeType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected CodeType parseCode(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
CodeType res = new CodeType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected StringType parseString(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
StringType res = new StringType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected IntegerType parseInteger(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
IntegerType res = new IntegerType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected Integer64Type parseInteger64(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
Integer64Type res = new Integer64Type(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected OidType parseOid(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
OidType res = new OidType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected CanonicalType parseCanonical(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
CanonicalType res = new CanonicalType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UriType parseUri(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
UriType res = new UriType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UuidType parseUuid(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
UuidType res = new UuidType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UrlType parseUrl(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
UrlType res = new UrlType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected InstantType parseInstant(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
InstantType res = new InstantType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected BooleanType parseBoolean(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
BooleanType res = new BooleanType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected Base64BinaryType parseBase64Binary(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
Base64BinaryType res = new Base64BinaryType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected UnsignedIntType parseUnsignedInt(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
UnsignedIntType res = new UnsignedIntType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected MarkdownType parseMarkdown(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
MarkdownType res = new MarkdownType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected TimeType parseTime(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
TimeType res = new TimeType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected IdType parseId(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
IdType res = new IdType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected PositiveIntType parsePositiveInt(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
PositiveIntType res = new PositiveIntType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
protected DecimalType parseDecimal(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
DecimalType res = new DecimalType(xpp.getAttributeValue(null, "value"));
|
||||
parseElementAttributes(xpp, res);
|
||||
next(xpp);
|
||||
int eventType = nextNoWhitespace(xpp);
|
||||
while (eventType != XmlPullParser.END_TAG) {
|
||||
if (!parseElementContent(eventType, xpp, res))
|
||||
unknownContent(xpp);
|
||||
eventType = nextNoWhitespace(xpp);
|
||||
}
|
||||
next(xpp);
|
||||
parseElementClose(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
{{parser}}
|
||||
|
||||
@Override
|
||||
protected Resource parseResource(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
if (xpp == null) {
|
||||
throw new IOException("xpp == null!");
|
||||
{{parse-resource}}
|
||||
} else {
|
||||
throw new FHIRFormatError("Unknown resource type "+xpp.getName()+"");
|
||||
}
|
||||
}
|
||||
|
||||
protected DataType parseType(String prefix, XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
if (prefix == null) {
|
||||
throw new IOException("prefix == null!");
|
||||
} else if (xpp == null) {
|
||||
throw new IOException("xpp == null!");
|
||||
} else if (xpp.getName().equals(prefix+"date")) {
|
||||
return parseDate(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"dateTime")) {
|
||||
return parseDateTime(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"code")) {
|
||||
return parseCode(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"string")) {
|
||||
return parseString(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"integer")) {
|
||||
return parseInteger(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"integer64")) {
|
||||
return parseInteger64(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"oid")) {
|
||||
return parseOid(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"canonical")) {
|
||||
return parseCanonical(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"uri")) {
|
||||
return parseUri(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"uuid")) {
|
||||
return parseUuid(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"url")) {
|
||||
return parseUrl(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"instant")) {
|
||||
return parseInstant(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"boolean")) {
|
||||
return parseBoolean(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"base64Binary")) {
|
||||
return parseBase64Binary(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"unsignedInt")) {
|
||||
return parseUnsignedInt(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"markdown")) {
|
||||
return parseMarkdown(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"time")) {
|
||||
return parseTime(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"id")) {
|
||||
return parseId(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"positiveInt")) {
|
||||
return parsePositiveInt(xpp);
|
||||
} else if (xpp.getName().equals(prefix+"decimal")) {
|
||||
return parseDecimal(xpp);
|
||||
{{parse-type-prefix}}
|
||||
} else {
|
||||
throw new FHIRFormatError("Unknown type "+xpp.getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected DataType parseType(XmlPullParser xpp, String type) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
if (type == null) {
|
||||
throw new IOException("type == null!");
|
||||
} else if (xpp == null) {
|
||||
throw new IOException("xpp == null!");
|
||||
} else if (type.equals("date")) {
|
||||
return parseDate(xpp);
|
||||
} else if (type.equals("dateTime")) {
|
||||
return parseDateTime(xpp);
|
||||
} else if (type.equals("code")) {
|
||||
return parseCode(xpp);
|
||||
} else if (type.equals("string")) {
|
||||
return parseString(xpp);
|
||||
} else if (type.equals("integer")) {
|
||||
return parseInteger(xpp);
|
||||
} else if (type.equals("integer64")) {
|
||||
return parseInteger64(xpp);
|
||||
} else if (type.equals("oid")) {
|
||||
return parseOid(xpp);
|
||||
} else if (type.equals("canonical")) {
|
||||
return parseCanonical(xpp);
|
||||
} else if (type.equals("uri")) {
|
||||
return parseUri(xpp);
|
||||
} else if (type.equals("uuid")) {
|
||||
return parseUuid(xpp);
|
||||
} else if (type.equals("url")) {
|
||||
return parseUrl(xpp);
|
||||
} else if (type.equals("instant")) {
|
||||
return parseInstant(xpp);
|
||||
} else if (type.equals("boolean")) {
|
||||
return parseBoolean(xpp);
|
||||
} else if (type.equals("base64Binary")) {
|
||||
return parseBase64Binary(xpp);
|
||||
} else if (type.equals("unsignedInt")) {
|
||||
return parseUnsignedInt(xpp);
|
||||
} else if (type.equals("markdown")) {
|
||||
return parseMarkdown(xpp);
|
||||
} else if (type.equals("time")) {
|
||||
return parseTime(xpp);
|
||||
} else if (type.equals("id")) {
|
||||
return parseId(xpp);
|
||||
} else if (type.equals("positiveInt")) {
|
||||
return parsePositiveInt(xpp);
|
||||
} else if (type.equals("decimal")) {
|
||||
return parseDecimal(xpp);
|
||||
{{parse-type}}
|
||||
} else {
|
||||
throw new FHIRFormatError("Unknown type "+type);
|
||||
}
|
||||
}
|
||||
|
||||
public Base parseFragment(XmlPullParser xpp, String type) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
if (type == null) {
|
||||
throw new IOException("type == null!");
|
||||
} else if (xpp == null) {
|
||||
throw new IOException("xpp == null!");
|
||||
{{parse-fragment}}
|
||||
} else if (type.equals("date")) {
|
||||
return parseDate(xpp);
|
||||
} else if (type.equals("dateTime")) {
|
||||
return parseDateTime(xpp);
|
||||
} else if (type.equals("code")) {
|
||||
return parseCode(xpp);
|
||||
} else if (type.equals("string")) {
|
||||
return parseString(xpp);
|
||||
} else if (type.equals("integer")) {
|
||||
return parseInteger(xpp);
|
||||
} else if (type.equals("integer64")) {
|
||||
return parseInteger64(xpp);
|
||||
} else if (type.equals("oid")) {
|
||||
return parseOid(xpp);
|
||||
} else if (type.equals("canonical")) {
|
||||
return parseCanonical(xpp);
|
||||
} else if (type.equals("uri")) {
|
||||
return parseUri(xpp);
|
||||
} else if (type.equals("uuid")) {
|
||||
return parseUuid(xpp);
|
||||
} else if (type.equals("url")) {
|
||||
return parseUrl(xpp);
|
||||
} else if (type.equals("instant")) {
|
||||
return parseInstant(xpp);
|
||||
} else if (type.equals("boolean")) {
|
||||
return parseBoolean(xpp);
|
||||
} else if (type.equals("base64Binary")) {
|
||||
return parseBase64Binary(xpp);
|
||||
} else if (type.equals("unsignedInt")) {
|
||||
return parseUnsignedInt(xpp);
|
||||
} else if (type.equals("markdown")) {
|
||||
return parseMarkdown(xpp);
|
||||
} else if (type.equals("time")) {
|
||||
return parseTime(xpp);
|
||||
} else if (type.equals("id")) {
|
||||
return parseId(xpp);
|
||||
} else if (type.equals("positiveInt")) {
|
||||
return parsePositiveInt(xpp);
|
||||
} else if (type.equals("decimal")) {
|
||||
return parseDecimal(xpp);
|
||||
} else {
|
||||
throw new FHIRFormatError("Unknown type "+type);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean nameIsTypeName(XmlPullParser xpp, String prefix) throws IOException {
|
||||
if (prefix == null) {
|
||||
throw new IOException("prefix == null!");
|
||||
} else if (xpp == null) {
|
||||
throw new IOException("xpp == null!");
|
||||
{{check-type}}
|
||||
} else if (xpp.getName().equals(prefix+"Date")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"DateTime")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Code")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"String")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Integer")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Integer64")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Oid")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Canonical")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Uri")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Uuid")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Url")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Instant")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Boolean")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Base64Binary")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"UnsignedInt")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Markdown")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Time")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Id")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"PositiveInt")) {
|
||||
return true;
|
||||
} else if (xpp.getName().equals(prefix+"Decimal")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataType parseAnyType(XmlPullParser xpp, String type) throws XmlPullParserException, IOException, FHIRFormatError {
|
||||
return parseType(xpp, type);
|
||||
}
|
||||
|
||||
|
||||
//----------------- Composer -------------------------------------------------------------------------------------------
|
||||
|
||||
protected <E extends Enum<E>> void composeEnumeration(String name, Enumeration<E> value, EnumFactory e) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || value.getValue() != null)) {
|
||||
composeElementAttributes(value);
|
||||
if (value.getValue() != null)
|
||||
xml.attribute("value", e.toCode(value.getValue()));
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeDate(String name, DateType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || value.getValue() != null)) {// date
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeDateTime(String name, DateTimeType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || value.getValue() != null)) {// dateTime
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeCode(String name, CodeType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// code
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeString(String name, StringType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// string
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeInteger(String name, IntegerType value) throws IOException {
|
||||
if (value != null) { // integer
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeInteger64(String name, Integer64Type value) throws IOException {
|
||||
if (value != null) { // integer
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeOid(String name, OidType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// oid
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeCanonical(String name, CanonicalType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// canonical
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeUri(String name, UriType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || value.getValue() != null)) {// uri
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeUuid(String name, UuidType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// uuid
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeUrl(String name, UrlType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// url
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeInstant(String name, InstantType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || value.getValue() != null)) {// instant
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeBoolean(String name, BooleanType value) throws IOException {
|
||||
if (value != null) { // boolean
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeBase64Binary(String name, Base64BinaryType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || value.getValue() != null)) {// base64Binary
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeUnsignedInt(String name, UnsignedIntType value) throws IOException {
|
||||
if (value != null) { // unsignedInt
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeMarkdown(String name, MarkdownType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// markdown
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeTime(String name, TimeType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// time
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeId(String name, IdType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || !Utilities.noString(value.getValue()))) {// id
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composePositiveInt(String name, PositiveIntType value) throws IOException {
|
||||
if (value != null) { // positiveInt
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeDecimal(String name, DecimalType value) throws IOException {
|
||||
if (value != null && (!Utilities.noString(value.getId()) || ExtensionHelper.hasExtensions(value) || value.getValue() != null)) {// decimal
|
||||
composeElementAttributes(value);
|
||||
if (value.asStringValue() != null)
|
||||
xml.attribute("value", value.asStringValue());
|
||||
|
||||
xml.enter(FHIR_NS, name);
|
||||
composeElementElements(value);
|
||||
composeElementClose(value);
|
||||
xml.exit(FHIR_NS, name);
|
||||
}
|
||||
}
|
||||
|
||||
{{composer}}
|
||||
|
||||
@Override
|
||||
protected void composeResource(Resource resource) throws IOException {
|
||||
if (resource == null) {
|
||||
throw new IOException("resource == null");
|
||||
{{compose-resource}}
|
||||
} else {
|
||||
throw new Error("Unhandled resource type "+resource.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeResource(String name, Resource resource) throws IOException {
|
||||
if (name == null) {
|
||||
throw new IOException("name == null");
|
||||
} else if (resource == null) {
|
||||
throw new IOException("resource == null");
|
||||
{{compose-resource-name}}
|
||||
} else {
|
||||
throw new Error("Unhandled resource type "+resource.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected void composeType(String prefix, DataType type) throws IOException {
|
||||
if (prefix == null) {
|
||||
throw new IOException("prefix == null");
|
||||
} else if (type == null) {
|
||||
throw new IOException("type == null");
|
||||
{{compose-type}}
|
||||
} else if (type instanceof CodeType) {
|
||||
composeCode(prefix+"Code", (CodeType) type);
|
||||
} else if (type instanceof OidType) {
|
||||
composeOid(prefix+"Oid", (OidType) type);
|
||||
} else if (type instanceof CanonicalType) {
|
||||
composeCanonical(prefix+"Canonical", (CanonicalType) type);
|
||||
} else if (type instanceof UuidType) {
|
||||
composeUuid(prefix+"Uuid", (UuidType) type);
|
||||
} else if (type instanceof UrlType) {
|
||||
composeUrl(prefix+"Url", (UrlType) type);
|
||||
} else if (type instanceof UnsignedIntType) {
|
||||
composeUnsignedInt(prefix+"UnsignedInt", (UnsignedIntType) type);
|
||||
} else if (type instanceof MarkdownType) {
|
||||
composeMarkdown(prefix+"Markdown", (MarkdownType) type);
|
||||
} else if (type instanceof IdType) {
|
||||
composeId(prefix+"Id", (IdType) type);
|
||||
} else if (type instanceof PositiveIntType) {
|
||||
composePositiveInt(prefix+"PositiveInt", (PositiveIntType) type);
|
||||
} else if (type instanceof DateType) {
|
||||
composeDate(prefix+"Date", (DateType) type);
|
||||
} else if (type instanceof DateTimeType) {
|
||||
composeDateTime(prefix+"DateTime", (DateTimeType) type);
|
||||
} else if (type instanceof StringType) {
|
||||
composeString(prefix+"String", (StringType) type);
|
||||
} else if (type instanceof IntegerType) {
|
||||
composeInteger(prefix+"Integer", (IntegerType) type);
|
||||
} else if (type instanceof Integer64Type) {
|
||||
composeInteger64(prefix+"Integer64", (Integer64Type) type);
|
||||
} else if (type instanceof UriType) {
|
||||
composeUri(prefix+"Uri", (UriType) type);
|
||||
} else if (type instanceof InstantType) {
|
||||
composeInstant(prefix+"Instant", (InstantType) type);
|
||||
} else if (type instanceof BooleanType) {
|
||||
composeBoolean(prefix+"Boolean", (BooleanType) type);
|
||||
} else if (type instanceof Base64BinaryType) {
|
||||
composeBase64Binary(prefix+"Base64Binary", (Base64BinaryType) type);
|
||||
} else if (type instanceof TimeType) {
|
||||
composeTime(prefix+"Time", (TimeType) type);
|
||||
} else if (type instanceof DecimalType) {
|
||||
composeDecimal(prefix+"Decimal", (DecimalType) type);
|
||||
} else {
|
||||
throw new Error("Unhandled type "+type.fhirType());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
[hierarchy]
|
||||
Meta = extends DataType implements IBaseMetaType
|
||||
Parameters = extends {{super}} implements IBaseParameters
|
||||
DomainResource = extends {{super}} implements IBaseHasExtensions, IBaseHasModifierExtensions, IDomainResource
|
||||
Bundle = extends {{super}} implements IBaseBundle
|
||||
Reference = extends BaseReference implements IBaseReference, ICompositeType
|
||||
Element = extends Base implements IBaseHasExtensions, IBaseElement
|
||||
Resource = extends BaseResource implements IAnyResource
|
||||
Quantity = extends {{super}} implements ICompositeType, ICoding
|
||||
BackboneType = extends {{super}} implements IBaseBackboneElement
|
||||
Extension = extends BaseExtension implements IBaseExtension<Extension, DataType>, IBaseHasExtensions
|
||||
BackboneElement = extends {{super}} implements IBaseBackboneElement
|
||||
Coding = extends {{super}} implements IBaseCoding, ICompositeType, ICoding
|
||||
Narrative = extends BaseNarrative implements INarrative
|
||||
Expression = extends DataType implements ICompositeType
|
||||
OperationOutcome = extends {{super}} implements IBaseOperationOutcome
|
||||
CapabilityStatement = extends {{super}} implements IBaseConformance
|
||||
CodeType = extends {{super}} implements ICoding
|
||||
DataType = extends Element implements IBaseDatatype, IElement
|
||||
Binary = extends BaseBinary implements IBaseBinary
|
||||
|
||||
[imports]
|
||||
Meta = org.hl7.fhir.instance.model.api.IBaseMetaType
|
||||
DomainResource = java.util.Collections, org.hl7.fhir.instance.model.api.IDomainResource, org.hl7.fhir.instance.model.api.IBaseDatatypeElement, org.hl7.fhir.instance.model.api.IBaseHasExtensions, org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions, org.hl7.fhir.instance.model.api.IBaseBackboneElement
|
||||
Parameters = org.hl7.fhir.instance.model.api.IBaseParameters
|
||||
Bundle = org.hl7.fhir.instance.model.api.IBaseBundle
|
||||
Reference = org.hl7.fhir.instance.model.api.IAnyResource, org.hl7.fhir.instance.model.api.IBaseReference, org.hl7.fhir.instance.model.api.ICompositeType, org.hl7.fhir.instance.model.api.IIdType
|
||||
Element = org.hl7.fhir.instance.model.api.IBaseElement, org.hl7.fhir.instance.model.api.IBaseHasExtensions
|
||||
Resource = org.hl7.fhir.instance.model.api.IAnyResource
|
||||
Period = ca.uhn.fhir.model.api.TemporalPrecisionEnum
|
||||
Extension = org.hl7.fhir.instance.model.api.IBaseExtension, org.hl7.fhir.instance.model.api.IBaseDatatype, org.hl7.fhir.instance.model.api.IBaseHasExtensions
|
||||
HumanName = ca.uhn.fhir.util.DatatypeUtil, org.hl7.fhir.instance.model.api.IPrimitiveType
|
||||
StructureMap = org.hl7.fhir.r5.utils.StructureMapUtilities
|
||||
Narrative = org.hl7.fhir.instance.model.api.INarrative
|
||||
Coding = org.hl7.fhir.instance.model.api.IBaseCoding
|
||||
OperationOutcome = org.hl7.fhir.instance.model.api.IBaseOperationOutcome
|
||||
CapabilityStatement = org.hl7.fhir.instance.model.api.IBaseConformance
|
||||
DataType = org.hl7.fhir.instance.model.api.IBaseDatatype, ca.uhn.fhir.model.api.IElement
|
||||
ElementDefinition = org.hl7.fhir.instance.model.api.ICompositeType, org.hl7.fhir.r5.model.Enumerations.BindingStrength, org.hl7.fhir.r5.model.Enumerations.BindingStrengthEnumFactory, org.hl7.fhir.r5.utils.ToolingExtensions, org.hl7.fhir.instance.model.api.IBaseDatatypeElement, org.hl7.fhir.utilities.CommaSeparatedStringBuilder
|
||||
Binary = org.hl7.fhir.instance.model.api.IBaseBinary
|
||||
|
||||
[shared]
|
||||
http://hl7.org/fhir/ValueSet/concept-map-relationship = true
|
||||
http://hl7.org/fhir/ValueSet/type-restful-interaction = false
|
||||
http://hl7.org/fhir/ValueSet/system-restful-interaction = false
|
||||
|
||||
[typenames]
|
||||
ValueSet.compose.include.filter = ConceptSetFilter
|
||||
ValueSet.compose.include.concept.designation = ConceptReferenceDesignation
|
||||
CodeSystem.concept.designation = ConceptDefinitionDesignation
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* #%L
|
||||
* org.hl7.fhir.r5
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2019 Health Level 7
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the \"License\");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an \"AS IS\" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, \
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this \
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, \
|
||||
this list of conditions and the following disclaimer in the documentation \
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
|
@ -0,0 +1,24 @@
|
|||
The Java Core Code Generator
|
||||
|
||||
Note: This code only generates tje R5 java code. Older generated models are now maintained by hand.
|
||||
|
||||
To run this code, run the class JavaCoreGenerator with 3 parameters:
|
||||
* 1: fhir version to generate from (e.g. 4.1.0 or 'current'
|
||||
* 2: project directory to read configuration and templates from - e.g. C:\work\org.hl7.fhir\org.hl7.fhir.core\org.hl7.fhir.core.generator\configuration
|
||||
* 3: project directory to generate code into - e.g. C:\\work\\org.hl7.fhir\\org.hl7.fhir.core\\org.hl7.fhir.r5.new
|
||||
|
||||
The generation process depends on the code it generates - do not regenerate the master R5 code until you have tested that it generates correctly.
|
||||
|
||||
To test the generation:
|
||||
* create a new project, copy the existing R5 code into it, and get it compiling
|
||||
* make sure that project is not in the build path for the generator itself, which depends on the production R5 code
|
||||
* run the generation
|
||||
* refresh etc and make sure that the compiler is happy
|
||||
* copy the JUnit tests ...
|
||||
|
||||
Configuring the Generation
|
||||
|
||||
The most common reason to alter the generation is to add additional utility routines/enhanceements to the generated classes.
|
||||
To do this, edit on the one of the templates in the configuration directory - xx.java, where xx is the class name (may include
|
||||
containing class). You may also need to add to the imports in the configuration.ini file.
|
||||
|
|
@ -24,7 +24,7 @@ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGed.
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
@ -49,10 +49,9 @@ import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
|||
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.tree.analysis.AnalyzerException;
|
||||
|
||||
public class JavaParserJsonGenerator extends JavaBaseGenerator {
|
||||
|
||||
|
||||
private StringBuilder parser = new StringBuilder();
|
||||
private StringBuilder pregt = new StringBuilder();
|
||||
private StringBuilder pregt2 = new StringBuilder();
|
||||
|
|
|
@ -0,0 +1,312 @@
|
|||
package org.hl7.fhir.core.generator.codegen;
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hl7.fhir.core.generator.analysis.Analysis;
|
||||
import org.hl7.fhir.core.generator.analysis.TypeInfo;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaBaseGenerator;
|
||||
import org.hl7.fhir.core.generator.engine.Definitions;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
public class JavaParserRdfGenerator extends JavaBaseGenerator {
|
||||
|
||||
// private StringBuilder parser = new StringBuilder();
|
||||
private StringBuilder composer = new StringBuilder();
|
||||
private StringBuilder reg = new StringBuilder();
|
||||
private StringBuilder regt = new StringBuilder();
|
||||
|
||||
public JavaParserRdfGenerator(OutputStream out, Definitions definitions, Configuration configuration, Date genDate, String version) throws UnsupportedEncodingException {
|
||||
super(out, definitions, configuration, version, genDate);
|
||||
}
|
||||
|
||||
public void seeClass(Analysis analysis) throws Exception {
|
||||
// generateParser(analysis);
|
||||
generateComposer(analysis);
|
||||
if (!analysis.isAbstract()) {
|
||||
if (analysis.getStructure().getKind() == StructureDefinitionKind.COMPLEXTYPE) {
|
||||
regt.append(" } else if (value instanceof "+analysis.getClassName()+") {\r\n compose"+analysis.getClassName()+"(parent, parentType, name, ("+analysis.getClassName()+")value, index);\r\n");
|
||||
}
|
||||
if (analysis.getStructure().getKind() == StructureDefinitionKind.RESOURCE) {
|
||||
reg.append(" } else if (resource instanceof "+analysis.getClassName()+") {\r\n compose"+analysis.getClassName()+"(parent, null, \""+analysis.getName()+"\", ("+analysis.getClassName()+")resource, -1);\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generate() throws Exception {
|
||||
String template = config.getAdornments().get("RdfParser");
|
||||
template = template.replace("{{license}}", config.getLicense());
|
||||
template = template.replace("{{startMark}}", startVMarkValue());
|
||||
|
||||
template = template.replace("{{composer}}", composer.toString());
|
||||
template = template.replace("{{compose-resource}}", reg.toString());
|
||||
template = template.replace("{{compose-type}}", regt.toString());
|
||||
|
||||
write(template);
|
||||
flush();
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
public void generateComposer(Analysis analysis) throws Exception {
|
||||
if (analysis.isAbstract())
|
||||
genInnerAbstractComposer(analysis, analysis.getRootType());
|
||||
else
|
||||
genInnerComposer(analysis, analysis.getRootType());
|
||||
|
||||
for (TypeInfo ti : analysis.getTypeList()) {
|
||||
genInnerComposer(analysis, ti);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void genInnerComposer(Analysis analysis, TypeInfo ti) throws IOException, Exception {
|
||||
String tn = ti.getName();
|
||||
String stn = (ti == analysis.getRootType() ? tn : analysis.getClassName()+"."+tn);
|
||||
String pfx = (ti.getDefn().isInlineType()) && !tn.startsWith(analysis.getClassName()) ? analysis.getClassName() : "";
|
||||
|
||||
composer.append(" protected void compose"+pfx+tn+"(Complex parent, String parentType, String name, "+stn+" element, int index) {\r\n");
|
||||
composer.append(" if (element == null) \r\n");
|
||||
composer.append(" return;\r\n");
|
||||
composer.append(" Complex t;\r\n");
|
||||
composer.append(" if (Utilities.noString(parentType))\r\n");
|
||||
composer.append(" t = parent;\r\n");
|
||||
composer.append(" else {\r\n");
|
||||
composer.append(" t = parent.predicate(\"fhir:\"+parentType+'.'+name);\r\n");
|
||||
composer.append(" }\r\n");
|
||||
composer.append(" compose"+ti.getAncestorName()+"(t, \""+ti.getDefn().getName()+"\", name, element, index);\r\n");
|
||||
if (tn.equals("Coding"))
|
||||
composer.append(" decorateCoding(t, element);\r\n");
|
||||
else if (tn.equals("CodeableConcept"))
|
||||
composer.append(" decorateCodeableConcept(t, element);\r\n");
|
||||
|
||||
for (ElementDefinition ed : ti.getChildren()) {
|
||||
genElement(analysis, ti, ed, matchingInheritedElement(ti.getInheritedChildren(), ed));
|
||||
}
|
||||
composer.append(" }\r\n\r\n");
|
||||
}
|
||||
|
||||
private void genInnerAbstractComposer(Analysis analysis, TypeInfo ti) throws IOException, Exception {
|
||||
String tn = ti.getName();
|
||||
|
||||
composer.append(" protected void compose"+tn+"(Complex t, String parentType, String name, "+tn+" element, int index) {\r\n");
|
||||
composer.append(" compose"+ti.getAncestorName()+"(t, parentType, name, element, index);\r\n");
|
||||
|
||||
for (ElementDefinition ed : ti.getChildren()) {
|
||||
genElement(analysis, ti, ed, null);
|
||||
}
|
||||
composer.append(" }\r\n\r\n");
|
||||
}
|
||||
|
||||
private void genElement(Analysis analysis, TypeInfo ti, ElementDefinition ed, ElementDefinition inh) throws Exception {
|
||||
String name = ed.getName();
|
||||
String gname = "get"+upFirst(checkJavaReservedWord(name))+"()";
|
||||
String tname = ed.getUserString("java.type");
|
||||
// if (tname.startsWith("@")) {
|
||||
// ElementDefn tgt = getElementForPath(root, e.typeCode().substring(1));
|
||||
// tname = typeNames.get(tgt).replace(".", "");
|
||||
// } else if (Utilities.noString(tname) && typeNames.containsKey(e)) {
|
||||
// tname = typeNames.get(e).replace(".", "");
|
||||
// } else if (tname.contains("("))
|
||||
// tname = tname.substring(0, tname.indexOf("("));
|
||||
// if (name.endsWith("[x]") || e.getTypes().size() > 1 || e.typeCode().equals("*")) {
|
||||
// tname = "Type";
|
||||
// if (name.endsWith("[x]"))
|
||||
// name = name.substring(0, name.length()-3);
|
||||
// gname = "get"+upFirst(name)+"()";
|
||||
// } else if (isJavaPrimitive(e) || e.typeCode().startsWith("canonical(")) {
|
||||
// BindingSpecification cd = e.getBinding();
|
||||
// if (e.typeCode().equals("code") && cd != null && cd.getBinding() == BindingSpecification.BindingMethod.CodeList)
|
||||
// tname = "Enum";
|
||||
// if (e.typeCode().equals("code") && cd != null && isEnum(cd))
|
||||
// tname = "Enum";
|
||||
// gname = "get"+upFirst(checkJavaReservedWord(name))+"Element()";
|
||||
// }
|
||||
// else if (definitions.getConstraints().containsKey(tname))
|
||||
// tname = definitions.getConstraints().get(tname).getBaseType();
|
||||
|
||||
if (ed.getPath().equals("Reference.reference")) {
|
||||
gname = "get"+upFirst(checkJavaReservedWord(name))+"Element_()"; // special case
|
||||
tname = tname.substring(0, tname.length()-4);
|
||||
} else if (name.endsWith("[x]")) {
|
||||
tname = "Type"; // not DataType
|
||||
name = name.substring(0, name.length()-3);
|
||||
gname = "get"+upFirst(name)+"()";
|
||||
} else if (ed.hasUserData("java.enum")) {
|
||||
tname = "Enum";
|
||||
if (!ed.unbounded()) {
|
||||
gname = "get"+upFirst(checkJavaReservedWord(name))+"Element()";
|
||||
}
|
||||
} else if (!"xhtml".equals(ed.typeSummary()) && (isPrimitive(ed) || ed.typeSummary().startsWith("canonical()"))) {
|
||||
tname = tname.substring(0, tname.length()-4);
|
||||
if (!ed.unbounded()) {
|
||||
gname = "get"+upFirst(checkJavaReservedWord(name))+"Element()";
|
||||
}
|
||||
}
|
||||
String pfx = ((ed.hasContentReference() || ed.isInlineType()) && !tname.startsWith(analysis.getClassName())) ? analysis.getClassName() : "";
|
||||
|
||||
if (ed.unbounded()) {
|
||||
// if (gname.endsWith("Element()") && !gname.equals("getElement()"))
|
||||
// gname = gname.substring(0, gname.length()-9)+"()";
|
||||
composer.append(" for (int i = 0; i < element."+gname+".size(); i++) {\r\n");
|
||||
composer.append(" compose"+pfx+tname+"(t, \""+ti.getName()+"\", \""+name+"\", element."+gname+".get(i), i);\r\n");
|
||||
composer.append(" }\r\n");
|
||||
} else if (inh != null && inh.unbounded()) {
|
||||
composer.append(" if (element.has"+gname.substring(3).replace("ReferenceElement_", "ReferenceElement")+") {\r\n");
|
||||
composer.append(" compose"+pfx+tname+"(t, \""+ti.getName()+"\", \""+name+"\", element."+gname.replace("()", "FirstRep()")+", -1);\r\n");
|
||||
composer.append(" }\r\n");
|
||||
} else {
|
||||
composer.append(" if (element.has"+gname.substring(3).replace("ReferenceElement_", "ReferenceElement")+") {\r\n");
|
||||
composer.append(" compose"+pfx+tname+"(t, \""+ti.getName()+"\", \""+name+"\", element."+gname+", -1);\r\n");
|
||||
composer.append(" }\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
private String checkJavaReservedWord(String name) {
|
||||
if (Utilities.existsInList(name, "class"))
|
||||
return name+"_";
|
||||
else
|
||||
return name;
|
||||
}
|
||||
|
||||
// private boolean isPrimitive(ElementDefn e) {
|
||||
// return definitions.hasPrimitiveType(e.typeCode());
|
||||
// }
|
||||
|
||||
//
|
||||
// private String prepEnumName(String en) {
|
||||
// String[] parts = en.split("\\.");
|
||||
// if (parts.length == 1)
|
||||
// return upFirst(parts[0]);
|
||||
// else
|
||||
// return upFirst(parts[0])+'.'+upFirst(parts[1]);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private String leaf(String tn) {
|
||||
// return tn.startsWith("java.lang.") ? tn.substring(10) : tn;
|
||||
// }
|
||||
//
|
||||
// private String PrepGenericTypeName(String tn) {
|
||||
// int i = tn.indexOf('(');
|
||||
// return tn.substring(0, i)+"<"+upFirst(tn.substring(i+1).replace(")", ">"));
|
||||
// }
|
||||
//
|
||||
// private String typeName(ElementDefn root, ElementDefn elem, JavaGenClass type, boolean formal) {
|
||||
// String t = elem.typeCode();
|
||||
// if ((type == JavaGenClass.Type || type == JavaGenClass.Constraint) && definitions.getPrimitives().containsKey(t)) {
|
||||
// // if (t.equals("boolean"))
|
||||
// // return "java.lang.Boolean";
|
||||
// // else if (t.equals("integer"))
|
||||
// // return "Integer";
|
||||
// // else if (t.equals("integer64"))
|
||||
// // return "Integer64?";
|
||||
// // else if (t.equals("decimal"))
|
||||
// // return "Decimal";
|
||||
// // else if (t.equals("base64Binary"))
|
||||
// // return "Base64Binary";
|
||||
// // else if (t.equals("instant"))
|
||||
// // return "Instant";
|
||||
// // else if (t.equals("uri"))
|
||||
// // return "Uri";
|
||||
// // else
|
||||
// // return "String";
|
||||
// // else if (t.equals("string"))
|
||||
// // return "StringType";
|
||||
// // else
|
||||
// return upFirst(t);
|
||||
// } else if (elem.usesCompositeType()) {
|
||||
// if (typeNames.containsKey(elem) && typeNames.get(elem) != null)
|
||||
// return typeNames.get(elem);
|
||||
// else
|
||||
// return root.getName();
|
||||
// } else if (elem.getTypes().size() == 0) {
|
||||
// return typeNames.get(elem);
|
||||
// } else if (typeNames.containsKey(elem))
|
||||
// return typeNames.get(elem);
|
||||
// else
|
||||
// return upFirst(t);
|
||||
// }
|
||||
//
|
||||
// private void finishComposer() throws Exception {
|
||||
// composer.append(" @Override\r\n");
|
||||
// composer.append(" protected void composeResource(Complex parent, Resource resource) {\r\n");
|
||||
// composer.append(" "+reg.toString().substring(9));
|
||||
// composer.append(" else\r\n");
|
||||
// composer.append(" throw new Error(\"Unhandled resource type \"+resource.getClass().getName());\r\n");
|
||||
// composer.append(" }\r\n\r\n");
|
||||
//
|
||||
// composer.append(" protected void composeType(Complex parent, String parentType, String name, Type value, int index) {\r\n");
|
||||
// composer.append(" if (value == null)\r\n");
|
||||
// composer.append(" return;\r\n");
|
||||
// composer.append(regtn.toString());
|
||||
// composer.append(" else\r\n");
|
||||
// composer.append(" throw new Error(\"Unhandled type\");\r\n");
|
||||
// composer.append(" }\r\n\r\n");
|
||||
// //
|
||||
// // composer.append(" private boolean nameIsTypeName(XmlPullParser xpp, String prefix) {\r\n");
|
||||
// // composer.append(" "+regn.toString());
|
||||
// // composer.append(" return false;\r\n");
|
||||
// // composer.append(" }\r\n");
|
||||
// //
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void finish() throws IOException {
|
||||
// composer.append("}\r\n");
|
||||
// composer.append("\r\n");
|
||||
// flush();
|
||||
// }
|
||||
// private String getPrimitiveTypeModelName(String code) {
|
||||
// if (code.equals("string"))
|
||||
// return "StringType";
|
||||
// if (definitions.hasPrimitiveType(code))
|
||||
// return upFirst(code)+"Type";
|
||||
// return upFirst(code);
|
||||
// }
|
||||
|
||||
private boolean isPrimitive(ElementDefinition e) {
|
||||
return definitions.hasPrimitiveType(e.typeSummary());
|
||||
}
|
||||
|
||||
private String upFirst(String n) {
|
||||
return n.substring(0,1).toUpperCase() + n.substring(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,508 @@
|
|||
package org.hl7.fhir.core.generator.codegen;
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hl7.fhir.core.generator.analysis.Analysis;
|
||||
import org.hl7.fhir.core.generator.analysis.EnumInfo;
|
||||
import org.hl7.fhir.core.generator.analysis.TypeInfo;
|
||||
import org.hl7.fhir.core.generator.engine.Definitions;
|
||||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
public class JavaParserXmlGenerator extends JavaBaseGenerator {
|
||||
|
||||
private StringBuilder parser = new StringBuilder();
|
||||
private StringBuilder pRes = new StringBuilder();
|
||||
private StringBuilder pTP = new StringBuilder();
|
||||
private StringBuilder pT = new StringBuilder();
|
||||
private StringBuilder pFrag = new StringBuilder();
|
||||
private StringBuilder pCtype = new StringBuilder();
|
||||
private StringBuilder composer = new StringBuilder();
|
||||
private StringBuilder cRes = new StringBuilder();
|
||||
private StringBuilder cRN = new StringBuilder();
|
||||
private StringBuilder cType = new StringBuilder();
|
||||
|
||||
public JavaParserXmlGenerator(OutputStream out, Definitions definitions, Configuration configuration, Date genDate, String version) throws UnsupportedEncodingException {
|
||||
super(out, definitions, configuration, version, genDate);
|
||||
}
|
||||
|
||||
public void seeClass(Analysis analysis) throws Exception {
|
||||
generateParser(analysis);
|
||||
generateComposer(analysis);
|
||||
if (!analysis.isAbstract()) {
|
||||
pFrag.append( " } else if (type.equals(\""+analysis.getName()+"\")) {\r\n return parse"+analysis.getClassName()+"(xpp);\r\n");
|
||||
pCtype.append(" } else if (xpp.getName().equals(prefix+\""+analysis.getName()+"\")) {\r\n return true;\r\n");
|
||||
if (analysis.getStructure().getKind() == StructureDefinitionKind.COMPLEXTYPE) {
|
||||
pTP.append( " } else if (xpp.getName().equals(prefix+\""+analysis.getName()+"\")) {\r\n return parse"+analysis.getClassName()+"(xpp);\r\n");
|
||||
pT.append( " } else if (type.equals(\""+analysis.getName()+"\")) {\r\n return parse"+analysis.getClassName()+"(xpp);\r\n");
|
||||
cType.append( " } else if (type instanceof "+analysis.getClassName()+") {\r\n compose"+analysis.getClassName()+"(prefix+\""+analysis.getName()+"\", ("+analysis.getClassName()+") type);\r\n");
|
||||
}
|
||||
if (analysis.getStructure().getKind() == StructureDefinitionKind.RESOURCE) {
|
||||
pRes.append(" } else if (xpp.getName().equals(\""+analysis.getName()+"\")) {\r\n return parse"+analysis.getClassName()+"(xpp);\r\n");
|
||||
cRes.append(" } else if (resource instanceof "+analysis.getClassName()+") {\r\n compose"+analysis.getClassName()+"(\""+analysis.getName()+"\", ("+analysis.getClassName()+")resource);\r\n");
|
||||
cRN.append( " } else if (resource instanceof "+analysis.getClassName()+") {\r\n compose"+analysis.getClassName()+"(name, ("+analysis.getClassName()+")resource);\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generate() throws Exception {
|
||||
|
||||
String template = config.getAdornments().get("XmlParser");
|
||||
template = template.replace("{{license}}", config.getLicense());
|
||||
template = template.replace("{{startMark}}", startVMarkValue());
|
||||
|
||||
template = template.replace("{{parser}}", parser.toString());
|
||||
template = template.replace("{{parse-resource}}", pRes.toString());
|
||||
template = template.replace("{{parse-type-prefix}}", pTP.toString());
|
||||
template = template.replace("{{parse-type}}", pT.toString());
|
||||
template = template.replace("{{parse-fragment}}", pFrag.toString());
|
||||
template = template.replace("{{check-type}}", pCtype.toString());
|
||||
|
||||
template = template.replace("{{composer}}", composer.toString());
|
||||
template = template.replace("{{compose-resource}}", cRes.toString());
|
||||
template = template.replace("{{compose-resource-name}}", cRN.toString());
|
||||
template = template.replace("{{compose-type}}", cType.toString());
|
||||
|
||||
write(template);
|
||||
flush();
|
||||
close();
|
||||
}
|
||||
|
||||
private void generateParser(Analysis analysis) throws Exception {
|
||||
if (analysis.isAbstract()) {
|
||||
genInnerAbstract(analysis, analysis.getRootType());
|
||||
} else {
|
||||
genInner(analysis, analysis.getRootType());
|
||||
}
|
||||
|
||||
for (TypeInfo ti : analysis.getTypeList()) {
|
||||
genInner(analysis, ti);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void genInner(Analysis analysis, TypeInfo ti) throws IOException, Exception {
|
||||
String tn = ti.getName();
|
||||
String stn = (ti == analysis.getRootType() ? tn : analysis.getClassName()+"."+tn);
|
||||
String pfx = (ti.getDefn().isInlineType()) && !tn.startsWith(analysis.getClassName()) ? analysis.getClassName() : "";
|
||||
|
||||
if (!analysis.isAbstract() || ti != analysis.getRootType()) {
|
||||
parser.append(" protected "+stn+" parse"+pfx+tn+"(XmlPullParser xpp) throws XmlPullParserException, IOException, FHIRFormatError {\r\n");
|
||||
parser.append(" "+stn+" res = new "+stn+"();\r\n");
|
||||
if (ti == analysis.getRootType() && analysis.getStructure().getKind() == StructureDefinitionKind.RESOURCE) {
|
||||
parser.append(" parseResourceAttributes(xpp, res);\r\n");
|
||||
} else {
|
||||
parser.append(" parseElementAttributes(xpp, res);\r\n");
|
||||
}
|
||||
for (ElementDefinition ed : ti.getChildren()) {
|
||||
if (ed.hasRepresentation(PropertyRepresentation.XMLATTR)) {
|
||||
parser.append(" if (xpp.getAttributeValue(null, \""+ed.getName()+"\") != null)\r\n");
|
||||
parser.append(" res.set"+upFirst(getElementName(ed.getName(), true))+"(xpp.getAttributeValue(null, \""+ed.getName()+"\"));\r\n");
|
||||
}
|
||||
}
|
||||
parser.append(" next(xpp);\r\n");
|
||||
parser.append(" int eventType = nextNoWhitespace(xpp);\r\n");
|
||||
parser.append(" while (eventType != XmlPullParser.END_TAG) {\r\n");
|
||||
parser.append(" if (!parse"+pfx+tn+"Content(eventType, xpp, res))\r\n");
|
||||
parser.append(" unknownContent(xpp);\r\n");
|
||||
parser.append(" eventType = nextNoWhitespace(xpp);\r\n");
|
||||
parser.append(" }\r\n");
|
||||
parser.append(" next(xpp);\r\n");
|
||||
parser.append(" parseElementClose(res);\r\n");
|
||||
parser.append(" return res;\r\n");
|
||||
parser.append(" }\r\n\r\n");
|
||||
}
|
||||
parser.append(" protected boolean parse"+pfx+tn+"Content(int eventType, XmlPullParser xpp, "+stn+" res) throws XmlPullParserException, IOException, FHIRFormatError {\r\n");
|
||||
boolean first = true;
|
||||
for (ElementDefinition ed : ti.getChildren()) {
|
||||
if (!ed.hasRepresentation(PropertyRepresentation.XMLATTR)) {
|
||||
genElement(analysis, ti, ed, matchingInheritedElement(ti.getInheritedChildren(), ed), first);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
if (!first)
|
||||
parser.append(" } else ");
|
||||
else
|
||||
parser.append(" ");
|
||||
parser.append("if (!parse"+ti.getAncestorName()+"Content(eventType, xpp, res)){ \r\n");
|
||||
parser.append(" return false;\r\n");
|
||||
parser.append(" }\r\n");
|
||||
parser.append(" return true;\r\n");
|
||||
parser.append(" }\r\n\r\n");
|
||||
}
|
||||
|
||||
private void genInnerAbstract(Analysis analysis, TypeInfo ti) throws IOException, Exception {
|
||||
String tn = ti.getName();
|
||||
parser.append(" protected boolean parse"+upFirst(tn).replace(".", "")+"Content(int eventType, XmlPullParser xpp, "+tn+" res) throws XmlPullParserException, IOException, FHIRFormatError {\r\n");
|
||||
boolean first = true;
|
||||
for (ElementDefinition ed : ti.getChildren()) {
|
||||
if (!ed.hasRepresentation(PropertyRepresentation.XMLATTR)) {
|
||||
genElement(analysis, ti, ed, null, first);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
if (!first)
|
||||
parser.append(" } else ");
|
||||
else
|
||||
parser.append(" ");
|
||||
parser.append("if (!parse"+ti.getAncestorName()+"Content(eventType, xpp, res)){ \r\n");
|
||||
parser.append(" return false;\r\n");
|
||||
parser.append(" }\r\n");
|
||||
parser.append(" return true;\r\n");
|
||||
parser.append(" }\r\n\r\n");
|
||||
}
|
||||
|
||||
private void genElement(Analysis analysis, TypeInfo ti, ElementDefinition ed, ElementDefinition inh, boolean first) 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.equals("[x]") ? name.replace("[x]", "") : "";
|
||||
parser.append(" "+(!first ? "} else " : "")+"if (eventType == XmlPullParser.START_TAG && nameIsTypeName(xpp, \""+pfx+"\")) {\r\n");
|
||||
parser.append(" res.set"+upFirst(getElementName(en, false))+"(parseType(\""+en+"\", xpp));\r\n");
|
||||
} else {
|
||||
String prsr = null;
|
||||
if (ed.hasUserData("java.enum")) {
|
||||
EnumInfo ei = (EnumInfo) ed.getUserData("java.enum"); // getCodeListType(cd.getBinding());
|
||||
ValueSet vs = ei.getValueSet();
|
||||
boolean enShared = vs.hasUserData("shared");
|
||||
String en;
|
||||
if (enShared) {
|
||||
en = "Enumerations."+ei.getName();
|
||||
} else {
|
||||
en = analysis.getClassName()+"."+ei.getName();
|
||||
}
|
||||
prsr = "parseEnumeration(xpp, "+en+".NULL, new "+en.substring(0, en.indexOf("."))+"."+en.substring(en.indexOf(".")+1)+"EnumFactory())"; // en+".fromCode(parseString(xpp))";
|
||||
// parseEnumeration(xpp, Narrative.NarrativeStatus.additional, new Narrative.NarrativeStatusEnumFactory())
|
||||
} else {
|
||||
String tn = ed.getUserString("java.type");
|
||||
if (name.equals("extension")) {
|
||||
name = "extension";
|
||||
tn = "Extension";
|
||||
}
|
||||
if (tn.contains("Reference("))
|
||||
prsr = "parseReference(xpp)";
|
||||
else if (tn.contains("canonical("))
|
||||
prsr = "parseCanonical(xpp)";
|
||||
else if (tn.contains("("))
|
||||
prsr = "parse"+tn+"(xpp)";
|
||||
else if (tn.startsWith(analysis.getName()) && !tn.equals(analysis.getClassName())/* && !definitions.hasType(tn)*/) {
|
||||
prsr = "parse"+upFirst(tn)+"(xpp)";
|
||||
} else if (tn.equals("Resource") || tn.equals("DomainResource"))
|
||||
prsr = "parse"+upFirst(tn)+"Contained(xpp)";
|
||||
else if (isPrimitive(ed)) {
|
||||
prsr = "parse"+upFirst(tn.substring(0, tn.length()-4))+"(xpp)";
|
||||
} else if ((ed.hasContentReference() || ed.isInlineType()) && !tn.startsWith(analysis.getClassName()) ) {
|
||||
prsr = "parse"+analysis.getClassName()+upFirst(tn)+"(xpp)";
|
||||
} else {
|
||||
prsr = "parse"+upFirst(tn)+"(xpp)";
|
||||
}
|
||||
}
|
||||
if (ed.unbounded()) {
|
||||
parser.append(" "+(!first ? "} else " : "")+"if (eventType == XmlPullParser.START_TAG && xpp.getName().equals(\""+name+"\")) {\r\n");
|
||||
parser.append(" res.get"+upFirst(getElementName(name, false))+"().add("+prsr+");\r\n");
|
||||
} else if (inh != null && inh.unbounded()) {
|
||||
parser.append(" "+(!first ? "} else " : "")+"if (eventType == XmlPullParser.START_TAG && xpp.getName().equals(\""+name+"\")) {\r\n");
|
||||
parser.append(" res.add"+upFirst(getElementName(name, false))+(!ed.typeSummary().equals("xhtml") && (isPrimitive(ed) || ed.typeSummary().startsWith("canonical(")) ? "Element" : "")+"("+prsr+");\r\n");
|
||||
} else {
|
||||
parser.append(" "+(!first ? "} else " : "")+"if (eventType == XmlPullParser.START_TAG && xpp.getName().equals(\""+name+"\")) {\r\n");
|
||||
parser.append(" res.set"+upFirst(getElementName(name, false))+(!ed.typeSummary().equals("xhtml") && (isPrimitive(ed) || ed.typeSummary().startsWith("canonical(")) ? "Element" : "")+"("+prsr+");\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPrimitive(ElementDefinition e) {
|
||||
return definitions.hasPrimitiveType(e.typeSummary());
|
||||
}
|
||||
|
||||
private void generateComposer(Analysis analysis) throws Exception {
|
||||
if (analysis.isAbstract()) {
|
||||
genInnerAbstractComposer(analysis, analysis.getRootType());
|
||||
} else {
|
||||
genInnerComposer(analysis, analysis.getRootType());
|
||||
}
|
||||
|
||||
for (TypeInfo ti : analysis.getTypeList()) {
|
||||
genInnerComposer(analysis, ti);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void genInnerComposer(Analysis analysis, TypeInfo ti) throws IOException, Exception {
|
||||
String tn = ti.getName();
|
||||
String stn = (ti == analysis.getRootType() ? tn : analysis.getClassName()+"."+tn);
|
||||
String pfx = (ti.getDefn().isInlineType()) && !tn.startsWith(analysis.getClassName()) ? analysis.getClassName() : "";
|
||||
|
||||
composer.append(" protected void compose"+pfx+tn+"(String name, "+stn+" element) throws IOException {\r\n");
|
||||
composer.append(" if (element != null) {\r\n");
|
||||
if (ti == analysis.getRootType() && analysis.getStructure().getKind() == StructureDefinitionKind.RESOURCE) {
|
||||
composer.append(" composeResourceAttributes(element);\r\n");
|
||||
} else {
|
||||
composer.append(" composeElementAttributes(element);\r\n");
|
||||
}
|
||||
composer.append(" xml.enter(FHIR_NS, name);\r\n");
|
||||
composer.append(" compose"+pfx+tn+"Elements(element);\r\n");
|
||||
composer.append(" composeElementClose(element);\r\n");
|
||||
composer.append(" xml.exit(FHIR_NS, name);\r\n");
|
||||
composer.append(" }\r\n");
|
||||
composer.append(" }\r\n\r\n");
|
||||
|
||||
composer.append(" protected void compose"+pfx+tn+"Elements("+stn+" element) throws IOException {\r\n");
|
||||
composer.append(" compose"+ti.getAncestorName()+"Elements(element);\r\n");
|
||||
|
||||
for (ElementDefinition ed : ti.getChildren()) {
|
||||
if (!ed.hasRepresentation(PropertyRepresentation.XMLATTR)) {
|
||||
genElementCompose(analysis, ti, ed, matchingInheritedElement(ti.getInheritedChildren(), ed));
|
||||
}
|
||||
}
|
||||
composer.append(" }\r\n\r\n");
|
||||
}
|
||||
|
||||
private void genInnerAbstractComposer(Analysis analysis, TypeInfo ti) throws IOException, Exception {
|
||||
String tn = ti.getName();
|
||||
|
||||
composer.append(" protected void compose"+tn+"Elements("+tn+" element) throws IOException {\r\n");
|
||||
composer.append(" compose"+ti.getAncestorName()+"Elements(element);\r\n");
|
||||
|
||||
for (ElementDefinition ed : ti.getChildren()) {
|
||||
if (!ed.hasRepresentation(PropertyRepresentation.XMLATTR)) {
|
||||
genElementCompose(analysis, ti, ed, null);
|
||||
}
|
||||
}
|
||||
composer.append(" }\r\n\r\n");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// private boolean isPrimitive(ElementDefn e) {
|
||||
// return definitions.hasPrimitiveType(e.typeCode());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private String prepEnumName(String en) {
|
||||
// String[] parts = en.split("\\.");
|
||||
// if (parts.length == 1)
|
||||
// return upFirst(parts[0]);
|
||||
// else
|
||||
// return upFirst(parts[0])+'.'+upFirst(parts[1]);
|
||||
//}
|
||||
//
|
||||
//
|
||||
// private String leaf(String tn) {
|
||||
// return tn.startsWith("java.lang.") ? tn.substring(10) : tn;
|
||||
// }
|
||||
//
|
||||
// private String PrepGenericTypeName(String tn) {
|
||||
// int i = tn.indexOf('(');
|
||||
// return tn.substring(0, i)+"<"+upFirst(tn.substring(i+1).replace(")", ">"));
|
||||
// }
|
||||
//
|
||||
// private String typeName(ElementDefn root, ElementDefn elem, JavaGenClass type, boolean formal) {
|
||||
// String t = elem.typeCode();
|
||||
// if ((type == JavaGenClass.Type || type == JavaGenClass.Constraint) && definitions.getPrimitives().containsKey(t)) {
|
||||
//// if (t.equals("boolean"))
|
||||
//// return "java.lang.Boolean";
|
||||
//// else if (t.equals("integer"))
|
||||
//// return "Integer";
|
||||
//// else if (t.equals("decimal"))
|
||||
//// return "Decimal";
|
||||
//// else if (t.equals("base64Binary"))
|
||||
//// return "Base64Binary";
|
||||
//// else if (t.equals("instant"))
|
||||
//// return "Instant";
|
||||
//// else if (t.equals("uri"))
|
||||
//// return "Uri";
|
||||
//// else
|
||||
//// return "String";
|
||||
//// else if (t.equals("string"))
|
||||
//// return "StringType";
|
||||
//// else
|
||||
// return upFirst(t);
|
||||
// } else if (elem.usesCompositeType()) {
|
||||
// if (typeNames.containsKey(elem) && typeNames.get(elem) != null)
|
||||
// return typeNames.get(elem);
|
||||
// else
|
||||
// return root.getName();
|
||||
// } else if (elem.getTypes().size() == 0) {
|
||||
// return typeNames.get(elem);
|
||||
// } else if (typeNames.containsKey(elem))
|
||||
// return typeNames.get(elem);
|
||||
// else
|
||||
// return upFirst(t);
|
||||
// }
|
||||
//
|
||||
// private void finishComposer() throws Exception {
|
||||
// composer.append(" @Override\r\n");
|
||||
// composer.append(" protected void composeResource(Resource resource) throws IOException {\r\n");
|
||||
// composer.append(" "+reg.toString().substring(9));
|
||||
// composer.append(" else if (resource instanceof Binary)\r\n");
|
||||
// composer.append(" composeBinary(\"Binary\", (Binary)resource);\r\n");
|
||||
// composer.append(" else\r\n");
|
||||
// composer.append(" throw new Error(\"Unhandled resource type \"+resource.getClass().getName());\r\n");
|
||||
// composer.append(" }\r\n\r\n");
|
||||
// composer.append(" protected void composeResource(String name, Resource resource) throws IOException {\r\n");
|
||||
// composer.append(" "+regn.toString().substring(9));
|
||||
// composer.append(" else if (resource instanceof Binary)\r\n");
|
||||
// composer.append(" composeBinary(name, (Binary)resource);\r\n");
|
||||
// composer.append(" else\r\n");
|
||||
// composer.append(" throw new Error(\"Unhandled resource type \"+resource.getClass().getName());\r\n");
|
||||
// composer.append(" }\r\n\r\n");
|
||||
// composer.append(" protected void composeType(String prefix, Type type) throws IOException {\r\n");
|
||||
// composer.append(" if (type == null)\r\n");
|
||||
// composer.append(" ;\r\n");
|
||||
// composer.append(regtp.toString());
|
||||
// composer.append(regtn.toString());
|
||||
// composer.append(" else\r\n");
|
||||
// composer.append(" throw new Error(\"Unhandled type: \"+type.fhirType());\r\n");
|
||||
// composer.append(" }\r\n\r\n");
|
||||
////
|
||||
//// composer.append(" private boolean nameIsTypeName(XmlPullParser xpp, String prefix) {\r\n");
|
||||
//// composer.append(" "+regn.toString());
|
||||
//// composer.append(" return false;\r\n");
|
||||
//// composer.append(" }\r\n");
|
||||
////
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void finish() throws IOException {
|
||||
// composer.append("}\r\n");
|
||||
// composer.append("\r\n");
|
||||
// flush();
|
||||
// }
|
||||
|
||||
private String upFirst(String n) {
|
||||
return n.substring(0,1).toUpperCase() + n.substring(1);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,608 @@
|
|||
package org.hl7.fhir.core.generator.codegen.todo;
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hl7.fhir.core.generator.codegen.Configuration;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaBaseGenerator;
|
||||
import org.hl7.fhir.core.generator.engine.Definitions;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
public class JavaConverterGenerator extends JavaBaseGenerator {
|
||||
|
||||
public JavaConverterGenerator(OutputStream arg0, Definitions definitions, Configuration config, String version, Date genDate)
|
||||
throws UnsupportedEncodingException {
|
||||
super(arg0, definitions, config, version, genDate);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
// public enum JavaGenClass { Structure, Type, Resource, AbstractResource, BackboneElement, Constraint }
|
||||
//
|
||||
// private Map<ElementDefn, String> typeNames = new HashMap<ElementDefn, String>();
|
||||
// private List<String> typeNameStrings = new ArrayList<String>();
|
||||
// private List<ElementDefn> enums = new ArrayList<ElementDefn>();
|
||||
// private List<String> elist = new ArrayList<String>();
|
||||
// private List<String> enumNames = new ArrayList<String>();
|
||||
// private List<ElementDefn> strucs = new ArrayList<ElementDefn>();
|
||||
// private boolean doneQ;
|
||||
//
|
||||
// private String genparam;
|
||||
//
|
||||
// public JavaConverterGenerator(OutputStream out) throws UnsupportedEncodingException {
|
||||
// super(out);
|
||||
// }
|
||||
//
|
||||
// public void generate(Definitions definitions, String version, Date genDate) throws Exception {
|
||||
//
|
||||
// this.definitions = definitions;
|
||||
// start(version, genDate);
|
||||
// genVersionCommon();
|
||||
// for (String s : sorted(definitions.getPrimitives().keySet())) {
|
||||
// genVersionConvertor(definitions.getPrimitives().get(s));
|
||||
// }
|
||||
// for (String s : sorted(definitions.getInfrastructure().keySet())) {
|
||||
// generate(definitions.getInfrastructure().get(s), JavaGenClass.Type, null);
|
||||
// }
|
||||
// for (String s : sorted(definitions.getTypes().keySet())) {
|
||||
// generate(definitions.getTypes().get(s), JavaGenClass.Type, null);
|
||||
// }
|
||||
// for (String s : sorted(definitions.getConstraints().keySet())) {
|
||||
// generate(definitions.getConstraints().get(s));
|
||||
// }
|
||||
// genTypeConvertor();
|
||||
//
|
||||
// for (String s : sorted(definitions.getBaseResources().keySet())) {
|
||||
// ResourceDefn n = definitions.getBaseResources().get(s);
|
||||
// generate(n.getRoot(), n.isAbstract() ? JavaGenClass.AbstractResource : JavaGenClass.Resource, null);
|
||||
// }
|
||||
// for (String s : sorted(definitions.getResources().keySet())) {
|
||||
// ResourceDefn n = definitions.getResources().get(s);
|
||||
// generate(n.getRoot(), JavaGenClass.Resource, null);
|
||||
// }
|
||||
// genResourceConvertor();
|
||||
//
|
||||
//
|
||||
// write("\r\n");
|
||||
// write("}\r\n");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void generate(ProfiledType pt) throws Exception {
|
||||
// generate(definitions.getElementDefn(pt.getBaseType()), JavaGenClass.Type, pt.getName());
|
||||
// }
|
||||
//
|
||||
// private void genTypeConvertor() throws IOException {
|
||||
// write(" public static org.hl7.fhir.r5.model.Type convertType(org.hl7.fhir.dstu3.model.Type src) throws FHIRException {\r\n");
|
||||
// write(" if (src == null)\r\n");
|
||||
// write(" return null;\r\n");
|
||||
// for (String s : sorted(definitions.getPrimitives().keySet())) {
|
||||
// write(" if (src instanceof org.hl7.fhir.dstu3.model."+upFirst(s)+"Type)\r\n");
|
||||
// write(" return convert"+upFirst(s)+"((org.hl7.fhir.dstu3.model."+upFirst(s)+"Type) src);\r\n");
|
||||
// }
|
||||
// for (String s : sorted(definitions.getInfrastructure().keySet())) {
|
||||
// if (!exemptTypeName(s)) {
|
||||
// write(" if (src instanceof org.hl7.fhir.dstu3.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.dstu3.model."+s+") src);\r\n");
|
||||
// }
|
||||
// }
|
||||
// for (String s : sorted(definitions.getTypes().keySet())) {
|
||||
// if (!exemptTypeName(s)) {
|
||||
// write(" if (src instanceof org.hl7.fhir.dstu3.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.dstu3.model."+s+") src);\r\n");
|
||||
// }
|
||||
// }
|
||||
// for (String s : sorted(definitions.getConstraints().keySet())) {
|
||||
// write(" if (src instanceof org.hl7.fhir.dstu3.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.dstu3.model."+s+") src);\r\n");
|
||||
// }
|
||||
//
|
||||
// write(" throw new Error(\"Unknown type \"+src.fhirType());\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
// write(" public static org.hl7.fhir.dstu3.model.Type convertType(org.hl7.fhir.r5.model.Type src) throws FHIRException {\r\n");
|
||||
// write(" if (src == null)\r\n");
|
||||
// write(" return null;\r\n");
|
||||
// for (String s : sorted(definitions.getPrimitives().keySet())) {
|
||||
// write(" if (src instanceof org.hl7.fhir.r5.model."+upFirst(s)+"Type)\r\n");
|
||||
// write(" return convert"+upFirst(s)+"((org.hl7.fhir.r5.model."+upFirst(s)+"Type) src);\r\n");
|
||||
// }
|
||||
// for (String s : sorted(definitions.getInfrastructure().keySet())) {
|
||||
// if (!exemptTypeName(s)) {
|
||||
// write(" if (src instanceof org.hl7.fhir.r5.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.r5.model."+s+") src);\r\n");
|
||||
// }
|
||||
// }
|
||||
// for (String s : sorted(definitions.getTypes().keySet())) {
|
||||
// if (!exemptTypeName(s)) {
|
||||
// write(" if (src instanceof org.hl7.fhir.r5.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.r5.model."+s+") src);\r\n");
|
||||
// }
|
||||
// }
|
||||
// for (String s : sorted(definitions.getConstraints().keySet())) {
|
||||
// write(" if (src instanceof org.hl7.fhir.r5.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.r5.model."+s+") src);\r\n");
|
||||
// }
|
||||
// write(" throw new Error(\"Unknown type \"+src.fhirType());\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
// }
|
||||
//
|
||||
// private void genResourceConvertor() throws IOException {
|
||||
// write(" public static org.hl7.fhir.r5.model.Resource convertResource(org.hl7.fhir.dstu3.model.Resource src) throws FHIRException {\r\n");
|
||||
// write(" if (src == null)\r\n");
|
||||
// write(" return null;\r\n");
|
||||
// for (String s : sorted(definitions.getBaseResources().keySet())) {
|
||||
// if (!definitions.getBaseResources().get(s).isAbstract()) {
|
||||
// write(" if (src instanceof org.hl7.fhir.dstu3.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.dstu3.model."+s+") src);\r\n");
|
||||
// }
|
||||
// }
|
||||
// for (String s : sorted(definitions.getResources().keySet())) {
|
||||
// write(" if (src instanceof org.hl7.fhir.dstu3.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.dstu3.model."+s+") src);\r\n");
|
||||
// }
|
||||
// write(" throw new Error(\"Unknown resource \"+src.fhirType());\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
//
|
||||
// write(" public static org.hl7.fhir.dstu3.model.Resource convertResource(org.hl7.fhir.r5.model.Resource src) throws FHIRException {\r\n");
|
||||
// write(" if (src == null)\r\n");
|
||||
// write(" return null;\r\n");
|
||||
// for (String s : sorted(definitions.getBaseResources().keySet())) {
|
||||
// if (!definitions.getBaseResources().get(s).isAbstract()) {
|
||||
// write(" if (src instanceof org.hl7.fhir.r5.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.r5.model."+s+") src);\r\n");
|
||||
// }
|
||||
// }
|
||||
// for (String s : sorted(definitions.getResources().keySet())) {
|
||||
// write(" if (src instanceof org.hl7.fhir.r5.model."+s+")\r\n");
|
||||
// write(" return convert"+s+"((org.hl7.fhir.r5.model."+s+") src);\r\n");
|
||||
// }
|
||||
// write(" throw new Error(\"Unknown resource \"+src.fhirType());\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
// }
|
||||
//
|
||||
// private boolean exemptTypeName(String s) {
|
||||
// return
|
||||
// Utilities.existsInList(s, "Element", "BackboneElement") // structural
|
||||
// ||
|
||||
// Utilities.existsInList(s, "ModuleMetadata"); // no equivalence in DSTU2
|
||||
// }
|
||||
//
|
||||
// private List<String> sorted(Set<String> keys) {
|
||||
// List<String> result = new ArrayList<String>();
|
||||
// result.addAll(keys);
|
||||
// Collections.sort(result);
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void start(String version, Date genDate) throws IOException {
|
||||
// write("package org.hl7.fhir.convertors;\r\n\r\n");
|
||||
// write("import org.hl7.fhir.exceptions.FHIRException;\r\n\r\n");
|
||||
// startMark(version, genDate);
|
||||
// write("\r\n");
|
||||
// write("public class VersionConvertor_30_40 {\r\n");
|
||||
// write("\r\n");
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void genVersionCommon() throws IOException {
|
||||
// write(" private static void copyElement(org.hl7.fhir.dstu3.model.Element src, org.hl7.fhir.r5.model.Element tgt) throws FHIRException {\r\n");
|
||||
// write(" if (src.hasId())\r\n tgt.setId(src.getId());\r\n");
|
||||
// write(" for (org.hl7.fhir.dstu3.model.Extension e : src.getExtension()) {\r\n");
|
||||
// write(" tgt.addExtension(convertExtension(e));\r\n");
|
||||
// write(" }\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
//
|
||||
// write(" private static void copyElement(org.hl7.fhir.r5.model.Element src, org.hl7.fhir.dstu3.model.Element tgt) throws FHIRException {\r\n");
|
||||
// write(" if (src.hasId())\r\n tgt.setId(src.getId());\r\n");
|
||||
// write(" for (org.hl7.fhir.r5.model.Extension e : src.getExtension()) {\r\n");
|
||||
// write(" tgt.addExtension(convertExtension(e));\r\n");
|
||||
// write(" }\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
//
|
||||
// write(" private static void copyBackboneElement(org.hl7.fhir.dstu3.model.BackboneElement src, org.hl7.fhir.r5.model.BackboneElement tgt) throws FHIRException {\r\n");
|
||||
// write(" copyElement(src, tgt);\r\n");
|
||||
// write(" for (org.hl7.fhir.dstu3.model.Extension e : src.getModifierExtension()) {\r\n");
|
||||
// write(" tgt.addModifierExtension(convertExtension(e));\r\n");
|
||||
// write(" }\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
//
|
||||
// write(" private static void copyBackboneElement(org.hl7.fhir.r5.model.BackboneElement src, org.hl7.fhir.dstu3.model.BackboneElement tgt) throws FHIRException {\r\n");
|
||||
// write(" copyElement(src, tgt);\r\n");
|
||||
// write(" for (org.hl7.fhir.r5.model.Extension e : src.getModifierExtension()) {\r\n");
|
||||
// write(" tgt.addModifierExtension(convertExtension(e));\r\n");
|
||||
// write(" }\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void genVersionConvertor(DefinedCode pt) throws IOException {
|
||||
// String tn = getPrimitiveTypeModelName(pt.getCode());
|
||||
// write(" public static org.hl7.fhir.r5.model."+tn+" convert"+tn.substring(0, tn.length()-4)+"(org.hl7.fhir.dstu3.model."+tn+" src) throws FHIRException {\r\n");
|
||||
// write(" org.hl7.fhir.r5.model."+tn+" tgt = new org.hl7.fhir.r5.model."+tn+"(src.getValue());\r\n");
|
||||
// write(" copyElement(src, tgt);\r\n");
|
||||
// write(" return tgt;\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
// write(" public static org.hl7.fhir.dstu3.model."+tn+" convert"+tn.substring(0, tn.length()-4)+"(org.hl7.fhir.r5.model."+tn+" src) throws FHIRException {\r\n");
|
||||
// write(" org.hl7.fhir.dstu3.model."+tn+" tgt = new org.hl7.fhir.dstu3.model."+tn+"(src.getValue());\r\n");
|
||||
// write(" copyElement(src, tgt);\r\n");
|
||||
// write(" return tgt;\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private String getPrimitiveTypeModelName(String code) {
|
||||
// if (code.equals("string"))
|
||||
// return "StringType";
|
||||
// if (definitions.hasPrimitiveType(code))
|
||||
// return upFirst(code)+"Type";
|
||||
// return upFirst(code);
|
||||
// }
|
||||
//
|
||||
// private String upFirst(String n) {
|
||||
// if (Utilities.noString(n))
|
||||
// return "";
|
||||
// return n.substring(0,1).toUpperCase() + n.substring(1);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void generate(ElementDefn n, JavaGenClass clss, String nameOverride) throws Exception {
|
||||
// if (n.getName().equals("Quantity") && !doneQ) {
|
||||
// doneQ = true;
|
||||
// write(" public static void copyQuantity(org.hl7.fhir.dstu3.model.Quantity src, org.hl7.fhir.r5.model.Quantity tgt) throws FHIRException {\r\n");
|
||||
// write(" if (src == null || tgt == null)\r\n");
|
||||
// write(" return;\r\n");
|
||||
// write(" copyElement(src, tgt);\r\n");
|
||||
// write(" if (src.hasValue())\r\n");
|
||||
// write(" tgt.setValue(src.getValue());\r\n");
|
||||
// write(" if (src.hasComparator())\r\n");
|
||||
// write(" tgt.setComparator(convertQuantityComparator(src.getComparator()));\r\n");
|
||||
// write(" if (src.hasUnit())\r\n");
|
||||
// write(" tgt.setUnit(src.getUnit());\r\n");
|
||||
// write(" if (src.hasSystem())\r\n");
|
||||
// write(" tgt.setSystem(src.getSystem());\r\n");
|
||||
// write(" if (src.hasCode())\r\n");
|
||||
// write(" tgt.setCode(src.getCode());\r\n");
|
||||
// write(" }\r\n");
|
||||
// write(" \r\n");
|
||||
// write(" public static void copyQuantity(org.hl7.fhir.r5.model.Quantity src, org.hl7.fhir.dstu3.model.Quantity tgt) throws FHIRException {\r\n");
|
||||
// write(" if (src == null || tgt == null)\r\n");
|
||||
// write(" return;\r\n");
|
||||
// write(" copyElement(src, tgt);\r\n");
|
||||
// write(" if (src.hasValue())\r\n");
|
||||
// write(" tgt.setValue(src.getValue());\r\n");
|
||||
// write(" if (src.hasComparator())\r\n");
|
||||
// write(" tgt.setComparator(convertQuantityComparator(src.getComparator()));\r\n");
|
||||
// write(" if (src.hasUnit())\r\n");
|
||||
// write(" tgt.setUnit(src.getUnit());\r\n");
|
||||
// write(" if (src.hasSystem())\r\n");
|
||||
// write(" tgt.setSystem(src.getSystem());\r\n");
|
||||
// write(" if (src.hasCode())\r\n");
|
||||
// write(" tgt.setCode(src.getCode());\r\n");
|
||||
// write("}\r\n");
|
||||
// write("\r\n");
|
||||
// }
|
||||
// generate(n, n, clss, nameOverride);
|
||||
// }
|
||||
//
|
||||
// private void generate(ElementDefn root, ElementDefn n, JavaGenClass clss, String nameOverride) throws Exception {
|
||||
// if (exemptTypeName(n.getName()))
|
||||
// return;
|
||||
//
|
||||
// typeNames.clear();
|
||||
// typeNameStrings.clear();
|
||||
// enums.clear();
|
||||
// strucs.clear();
|
||||
// enumNames.clear();
|
||||
// String nn = javaClassName(n.getName());
|
||||
// for (ElementDefn e : n.getElements()) {
|
||||
// scanNestedTypes(n, nn, e);
|
||||
// }
|
||||
//
|
||||
// if (clss == JavaGenClass.AbstractResource)
|
||||
// genInnerAbstract(n);
|
||||
// else
|
||||
// genInner(null, root, n, clss, nameOverride);
|
||||
//
|
||||
// for (ElementDefn e : strucs) {
|
||||
// genInner(n.getName(), root, e, clss == JavaGenClass.Resource ? JavaGenClass.BackboneElement : JavaGenClass.Structure, null);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private String javaClassName(String name) {
|
||||
// if (name.equals("List"))
|
||||
// return "ListResource";
|
||||
// else
|
||||
// return name;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void genInner(String typeName, ElementDefn root, ElementDefn ed, JavaGenClass clss, String nameOverride) throws IOException, Exception {
|
||||
// String es = "";
|
||||
// String tn = nameOverride;
|
||||
// String stn = nameOverride;
|
||||
// if (tn == null) {
|
||||
// if (typeName == null)
|
||||
// tn = javaClassName(ed.getName());
|
||||
// else
|
||||
// tn = typeName+"."+(ed.getDeclaredTypeName() != null ? ed.getDeclaredTypeName() : upFirst(ed.getName()));
|
||||
// stn = tn.contains(".") ? tn.substring(tn.lastIndexOf(".") + 1) : tn;
|
||||
// }
|
||||
//
|
||||
// write(" public static org.hl7.fhir.r5.model."+tn+" convert"+stn+"(org.hl7.fhir.dstu3.model."+tn+" src) throws FHIRException {\r\n");
|
||||
// write(" if (src == null)\r\n");
|
||||
// write(" return null;\r\n");
|
||||
// write(" org.hl7.fhir.r5.model."+tn+" tgt = new org.hl7.fhir.r5.model."+tn+"();\r\n");
|
||||
// String parentType = ed.typeCode();
|
||||
// if (Utilities.noString(parentType) || parentType.equals("Type") || parentType.equals("Structure"))
|
||||
// parentType = "Element";
|
||||
// write(" copy"+parentType+"(src, tgt);\r\n");
|
||||
// es = processElements(root, ed, es, "dstu3");
|
||||
// write(" return tgt;\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
//
|
||||
// write(" public static org.hl7.fhir.dstu3.model."+tn+" convert"+stn+"(org.hl7.fhir.r5.model."+tn+" src) throws FHIRException {\r\n");
|
||||
// write(" if (src == null)\r\n");
|
||||
// write(" return null;\r\n");
|
||||
// write(" org.hl7.fhir.dstu3.model."+tn+" tgt = new org.hl7.fhir.dstu3.model."+tn+"();\r\n");
|
||||
// write(" copy"+parentType+"(src, tgt);\r\n");
|
||||
// es = processElements(root, ed, es, "r4");
|
||||
// write(" return tgt;\r\n");
|
||||
// write(" }\r\n\r\n");
|
||||
//
|
||||
// write(es);
|
||||
// }
|
||||
//
|
||||
// private String processElements(ElementDefn root, ElementDefn ed, String es, String ver) throws Exception, IOException {
|
||||
// for (ElementDefn c : ed.getElements()) {
|
||||
// boolean prim = isPrimitive(c) || "xhtml".equals(c.typeCode());
|
||||
// String en = upFirst(c.getName()).replace("[x]", "");
|
||||
// if (en.equals("Class"))
|
||||
// en = "Class_";
|
||||
// String cn = "";
|
||||
// String tn = c.typeCode();
|
||||
// if (tn.contains("("))
|
||||
// tn = tn.substring(0, tn.indexOf("("));
|
||||
// String tt = "";
|
||||
// if (prim) {
|
||||
// BindingSpecification cd = c.getBinding();
|
||||
// String ctn = typeNames.get(c);
|
||||
// tn = ctn;
|
||||
// if (c.typeCode().equals("code") && cd != null && isEnum(cd)) {
|
||||
// cn = "convert"+upFirst(ctn.contains(".") ? ctn.substring(ctn.lastIndexOf(".")+1) : ctn)+"(";
|
||||
// es = es + genEnumConvertor(cn.substring(0, cn.length()-1), ctn, cd);
|
||||
// tn = "Enumeration<org.hl7.fhir."+ver+".model."+tn+">";
|
||||
// } else {
|
||||
// tn = upFirst(tn) + "Type";
|
||||
// }
|
||||
// tt = ".getValue()";
|
||||
// } else {
|
||||
// if (c.typeCode().contains("@")) {
|
||||
// ElementDefn cs = getElementForPath(root, c.typeCode().substring(1));
|
||||
// tn = cs.getDeclaredTypeName() == null ? upFirst(cs.getName()) : cs.getDeclaredTypeName();
|
||||
// cn = "convert"+tn+"(";
|
||||
// tn = root.getName()+"."+tn;
|
||||
// } else if (c.getTypes().size() == 0) {
|
||||
// tn = c.getDeclaredTypeName() == null ? upFirst(c.getName()) : c.getDeclaredTypeName();
|
||||
// cn = "convert"+tn+"(";
|
||||
// if (ed.getPath().contains("."))
|
||||
// tn = root(typeNames.get(ed)) +"."+tn;
|
||||
// else
|
||||
// tn = ed.getName()+"."+tn;
|
||||
// } else if (c.getTypes().size() != 1 || "*".equals(c.typeCode()))
|
||||
// cn = "convertType(";
|
||||
// else
|
||||
// cn = "convert"+upFirst(c.getTypes().get(0).getName())+"(";
|
||||
// }
|
||||
// String ct = Utilities.noString(cn) ? "" : ")";
|
||||
// if (c.unbounded()) {
|
||||
// write(" for (org.hl7.fhir."+ver+".model."+tn+" t : src.get"+en+"())\r\n");
|
||||
// write(" tgt.add"+en+"("+cn+"t"+tt+ct+");\r\n");
|
||||
//
|
||||
// } else {
|
||||
// write(" if (src.has"+en+"())\r\n");
|
||||
// write(" tgt.set"+en+"("+cn+"src.get"+en+"()"+ct+");\r\n");
|
||||
// }
|
||||
// }
|
||||
// return es;
|
||||
// }
|
||||
//
|
||||
// private String root(String s) {
|
||||
// return s.contains(".") ? s.substring(0, s.indexOf(".")) : s;
|
||||
// }
|
||||
//
|
||||
// private String genEnumConvertor(String cn, String ctn, BindingSpecification cd) throws Exception {
|
||||
// if (elist.contains(cn))
|
||||
// return "";
|
||||
// elist.add(cn);
|
||||
//
|
||||
// StringBuilder b = new StringBuilder();
|
||||
// b.append(" private static org.hl7.fhir.r5.model."+ctn+" "+cn+"(org.hl7.fhir.dstu3.model."+ctn+" src) throws FHIRException {\r\n");
|
||||
// b.append(" if (src == null)\r\n");
|
||||
// b.append(" return null;\r\n");
|
||||
// b.append(" switch (src) {\r\n");
|
||||
// for (DefinedCode c : cd.getAllCodes(definitions.getCodeSystems(), definitions.getValuesets(), true)) {
|
||||
// String cc = Utilities.camelCase(c.getCode());
|
||||
// cc = makeConst(cc);
|
||||
// b.append(" case "+cc+": return org.hl7.fhir.r5.model."+ctn+"."+cc+";\r\n");
|
||||
// }
|
||||
// b.append(" default: return org.hl7.fhir.r5.model."+ctn+".NULL;\r\n");
|
||||
// b.append(" }\r\n");
|
||||
// b.append("}\r\n\r\n");
|
||||
// b.append(" private static org.hl7.fhir.dstu3.model."+ctn+" "+cn+"(org.hl7.fhir.r5.model."+ctn+" src) throws FHIRException {\r\n");
|
||||
// b.append(" if (src == null)\r\n");
|
||||
// b.append(" return null;\r\n");
|
||||
// b.append(" switch (src) {\r\n");
|
||||
// for (DefinedCode c : cd.getAllCodes(definitions.getCodeSystems(), definitions.getValuesets(), true)) {
|
||||
// String cc = Utilities.camelCase(c.getCode());
|
||||
// cc = makeConst(cc);
|
||||
// b.append(" case "+cc+": return org.hl7.fhir.dstu3.model."+ctn+"."+cc+";\r\n");
|
||||
// }
|
||||
// b.append(" default: return org.hl7.fhir.dstu3.model."+ctn+".NULL;\r\n");
|
||||
// b.append(" }\r\n");
|
||||
// b.append("}\r\n\r\n");
|
||||
// return b.toString();
|
||||
// }
|
||||
//
|
||||
// private void genInnerAbstract(ElementDefn n) throws IOException, Exception {
|
||||
// String tn = typeNames.containsKey(n) ? typeNames.get(n) : javaClassName(n.getName());
|
||||
// String parent = n.typeCode();
|
||||
// String es = "";
|
||||
// write(" private static void copy"+tn+"(org.hl7.fhir.dstu3.model."+tn+" src, org.hl7.fhir.r5.model."+tn+" tgt) throws FHIRException {\r\n");
|
||||
// if (!Utilities.noString(parent))
|
||||
// write(" copy"+parent+"(src, tgt);\r\n");
|
||||
// es = processElements(n, n, es, "dstu3");
|
||||
// write(" }\r\n");
|
||||
// write(" private static void copy"+tn+"(org.hl7.fhir.r5.model."+tn+" src, org.hl7.fhir.dstu3.model."+tn+" tgt) throws FHIRException {\r\n");
|
||||
// if (!Utilities.noString(parent))
|
||||
// write(" copy"+parent+"(src, tgt);\r\n");
|
||||
// es = processElements(n, n, es, "r4");
|
||||
// write(" }\r\n");
|
||||
// write(es);
|
||||
// }
|
||||
//
|
||||
// private String getCodeListType(String binding) throws IOException {
|
||||
// StringBuilder b = new StringBuilder();
|
||||
// boolean up = true;
|
||||
// for (char ch: binding.toCharArray()) {
|
||||
// if (ch == '-' || ch == ' ')
|
||||
// up = true;
|
||||
// else if (up) {
|
||||
// b.append(Character.toUpperCase(ch));
|
||||
// up = false;
|
||||
// }
|
||||
// else
|
||||
// b.append(ch);
|
||||
// }
|
||||
// return b.toString();
|
||||
// }
|
||||
//
|
||||
// private void scanNestedTypes(ElementDefn root, String path, ElementDefn e) throws Exception {
|
||||
// String tn = null;
|
||||
// if (e.typeCode().equals("code") && e.hasBinding()) {
|
||||
// BindingSpecification cd = e.getBinding();
|
||||
// if (cd != null && isEnum(cd)) {
|
||||
// tn = getCodeListType(cd.getName());
|
||||
// if (!enumNames.contains(tn)) {
|
||||
// enumNames.add(tn);
|
||||
// enums.add(e);
|
||||
// }
|
||||
// if (Utilities.existsInList(tn, "AbstractType", "AdministrativeGender", "AgeUnits", "BindingStrength", "ConceptMapEquivalence", "DataAbsentReason", "DataType", "DocumentReferenceStatus", "FHIRAllTypes", "FHIRDefinedType", "MessageEvent", "NoteType", "PublicationStatus", "RemittanceOutcome", "ResourceType", "SearchParamType", "SpecialValues"))
|
||||
// typeNames.put(e, "Enumerations."+upFirst(tn));
|
||||
// else
|
||||
// typeNames.put(e, rootOf(path)+"."+upFirst(tn));
|
||||
// }
|
||||
// }
|
||||
// if (tn == null) {
|
||||
// if (e.getTypes().size() > 0 && !e.usesCompositeType()) {
|
||||
// tn = e.typeCode();
|
||||
// TypeRef tr = e.getTypes().get(0);
|
||||
// if (tr.isUnboundGenericParam())
|
||||
// tn = genparam;
|
||||
// else if (tr.isXhtml())
|
||||
// tn = "char[]";
|
||||
// else if (tr.isWildcardType())
|
||||
// tn ="Type";
|
||||
// else if (tn.equals("string"))
|
||||
// tn = "String";
|
||||
// typeNames.put(e, tn);
|
||||
// } else {
|
||||
// if (e.usesCompositeType()) {
|
||||
// tn = typeNames.get(getElementForPath(root, e.typeCode().substring(1)));
|
||||
// typeNames.put(e, tn);
|
||||
// } else {
|
||||
// if (e.getDeclaredTypeName() != null)
|
||||
// tn = e.getDeclaredTypeName();
|
||||
// else
|
||||
// tn = upFirst(e.getName());
|
||||
// if (tn.equals("Element"))
|
||||
// tn = "Element_";
|
||||
// if (!e.getName().equals("extension"))
|
||||
// strucs.add(e);
|
||||
// if (typeNameStrings.contains(tn)) {
|
||||
// char i = 'A';
|
||||
// while (typeNameStrings.contains(tn+i))
|
||||
// i++;
|
||||
// tn = tn + i;
|
||||
// }
|
||||
// typeNameStrings.add(tn);
|
||||
// tn = path+"."+tn;
|
||||
// typeNames.put(e, tn);
|
||||
// for (ElementDefn c : e.getElements()) {
|
||||
// scanNestedTypes(root, path, c);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private String rootOf(String path) {
|
||||
// int i = path.indexOf('.');
|
||||
// return i == -1 ? path : path.substring(0, i);
|
||||
// }
|
||||
//
|
||||
// private ElementDefn getElementForPath(ElementDefn root, String pathname) throws Exception {
|
||||
// String[] path = pathname.split("\\.");
|
||||
// if (!path[0].equals(root.getName()))
|
||||
// throw new Exception("Element Path '"+pathname+"' is not legal in this context");
|
||||
// ElementDefn res = root;
|
||||
// for (int i = 1; i < path.length; i++)
|
||||
// {
|
||||
// String en = path[i];
|
||||
// if (en.length() == 0)
|
||||
// throw new Exception("Improper path "+pathname);
|
||||
// ElementDefn t = res.getElementByName(definitions, en, true, false);
|
||||
// if (t == null) {
|
||||
// throw new Exception("unable to resolve "+pathname);
|
||||
// }
|
||||
// res = t;
|
||||
// }
|
||||
// return res;
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// private boolean isPrimitive(ElementDefn e) {
|
||||
// return definitions.hasPrimitiveType(e.typeCode());
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
|
@ -0,0 +1,904 @@
|
|||
package org.hl7.fhir.core.generator.codegen.todo;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.hl7.fhir.core.generator.codegen.Configuration;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaBaseGenerator;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaResourceGenerator;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaResourceGenerator.JavaGenClass;
|
||||
import org.hl7.fhir.core.generator.engine.Definitions;
|
||||
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
/*
|
||||
changes for James
|
||||
- lazy construction of lists
|
||||
- getX will construct if null
|
||||
- add hasX
|
||||
|
||||
*/
|
||||
public class JavaPatternImplGenerator extends JavaBaseGenerator {
|
||||
|
||||
public JavaPatternImplGenerator(OutputStream arg0, Definitions definitions, Configuration config, String version, Date genDate)
|
||||
throws UnsupportedEncodingException {
|
||||
super(arg0, definitions, config, version, genDate);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
//
|
||||
// private static final boolean HAPI_16 = true;
|
||||
// private JavaGenClass clss;
|
||||
// private Map<String, String> adornments;
|
||||
// private Map<String, String> enumInfo;
|
||||
//
|
||||
// public JavaPatternImplGenerator(OutputStream out, Definitions definitions, Map<String, String> adornments, Map<String, String> enumInfo) throws UnsupportedEncodingException {
|
||||
// super(out);
|
||||
// this.definitions = definitions;
|
||||
// this.adornments = adornments;
|
||||
// this.enumInfo = enumInfo;
|
||||
// }
|
||||
//
|
||||
// private Map<ElementDefn, String> typeNames = new HashMap<ElementDefn, String>();
|
||||
// private List<String> typeNameStrings = new ArrayList<String>();
|
||||
// private List<ElementDefn> enums = new ArrayList<ElementDefn>();
|
||||
// private List<String> enumNames = new ArrayList<String>();
|
||||
// private List<ElementDefn> strucs = new ArrayList<ElementDefn>();
|
||||
// private String classname;
|
||||
// private String allfields;
|
||||
// private long hashSum;
|
||||
// private String inheritedHash;
|
||||
//
|
||||
//
|
||||
// public Map<ElementDefn, String> getTypeNames() {
|
||||
// return typeNames;
|
||||
// }
|
||||
//
|
||||
// public void generate(ElementDefn root, String name, JavaGenClass clss, ProfiledType cd, Date genDate, String version, boolean isAbstract, Map<String, SearchParameterDefn> nameToSearchParamDef, ElementDefn template, String patternName, ElementDefn impl) throws Exception {
|
||||
// typeNames.clear();
|
||||
// typeNameStrings.clear();
|
||||
// enums.clear();
|
||||
// strucs.clear();
|
||||
// enumNames.clear();
|
||||
// this.clss = clss;
|
||||
//
|
||||
// boolean isRefType = root.getName().equals("Reference");
|
||||
//
|
||||
//// ElementDefn elem = root.getElementByName("reference");
|
||||
//// elem.getTypes().get(0);
|
||||
//// }
|
||||
//
|
||||
// write("package org.hl7.fhir.r5.patterns;\r\n");
|
||||
// startMark(version, genDate);
|
||||
// if (clss != JavaGenClass.Constraint) {
|
||||
// boolean l = true; // hasList(root);
|
||||
// boolean h = hasXhtml(root);
|
||||
// boolean d = hasDecimal(root);
|
||||
// boolean s = hasString(root);
|
||||
// boolean e = hasSharedEnums(root);
|
||||
// if (l || h || d || e) {
|
||||
// if (l)
|
||||
// write("import java.util.*;\r\n");
|
||||
// if (h) {
|
||||
// write("import org.hl7.fhir.utilities.xhtml.NodeType;\r\n");
|
||||
// write("import org.hl7.fhir.utilities.xhtml.XhtmlNode;\r\n");
|
||||
// }
|
||||
// write("\r\n");
|
||||
// if (d)
|
||||
// write("import java.math.*;\r\n");
|
||||
// if (s)
|
||||
// write("import org.hl7.fhir.utilities.Utilities;\r\n");
|
||||
// if (e)
|
||||
// write("import org.hl7.fhir.r5.model.Enumerations.*;\r\n");
|
||||
// }
|
||||
// }
|
||||
// write("import org.hl7.fhir.r5.model.*;\r\n");
|
||||
// write("import org.hl7.fhir.r5.model.Enumeration;\r\n");
|
||||
// write("import org.hl7.fhir.exceptions.FHIRException;\r\n");
|
||||
//
|
||||
// classname = upFirst(name);
|
||||
// String supertype = root.typeCode();
|
||||
//
|
||||
// if (template != null)
|
||||
// supertype = template.getName();
|
||||
//
|
||||
// write("\r\n");
|
||||
// write("public class "+name+patternName+"Impl extends PatternBaseImpl implements "+patternName+" ");
|
||||
//
|
||||
// write("{\r\n");
|
||||
// write("\r\n");
|
||||
//
|
||||
// write(" private "+name+" wrapped;\r\n");
|
||||
// write("\r\n");
|
||||
// write(" public "+name+patternName+"Impl("+name+" wrapped) {\r\n");
|
||||
// write(" super(wrapped);\r\n");
|
||||
// write(" this.wrapped = wrapped;\r\n");
|
||||
// write(" }\r\n");
|
||||
// write("\r\n");
|
||||
//
|
||||
//
|
||||
// if (clss != JavaGenClass.Constraint) {
|
||||
// for (ElementDefn e : root.getElements()) {
|
||||
// scanNestedTypes(root, root.getName(), e);
|
||||
// }
|
||||
//// for (ElementDefn e : enums) {
|
||||
//// generateEnum(e, upFirst(name));
|
||||
//// }
|
||||
// for (ElementDefn e : strucs) {
|
||||
// generateType(e, clss == JavaGenClass.Resource ? JavaGenClass.BackboneElement : JavaGenClass.Structure, impl, name);
|
||||
// }
|
||||
//
|
||||
// for (ElementDefn e : root.getElements()) {
|
||||
// if (doGenerateAccessors(e))
|
||||
// generateAccessors(root, e, resolveTarget(root, e, impl), " ", patternName, name);
|
||||
// }
|
||||
//
|
||||
// generateFhirType(name);
|
||||
// } else {
|
||||
// write(" private static final long serialVersionUID = "+inheritedHash+"L;\r\n\r\n");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// write("\r\n");
|
||||
// write("}\r\n");
|
||||
// write("\r\n");
|
||||
// flush();
|
||||
// }
|
||||
//
|
||||
// private boolean doGenerateAccessors(ElementDefn e) throws Exception {
|
||||
// String gen = e.getMapping("http://hl7.org/fhir/object-implementation");
|
||||
// if (!e.isFromTemplate()) {
|
||||
// if (gen == null)
|
||||
// return true;
|
||||
// else
|
||||
// return !"no-gen-base".equals(gen);
|
||||
// } else
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// private void generateFhirType(String name) throws IOException {
|
||||
// write(" public String fhirType() {\r\n return \""+name+"\";\r\n}\r\n\r\n");
|
||||
// }
|
||||
//
|
||||
// private String cleanSpName(String code) {
|
||||
// StringBuilder b = new StringBuilder();
|
||||
// for (char c : code.toCharArray())
|
||||
// if (Character.isLetter(c)) {
|
||||
// b.append(c);
|
||||
// } else if (c == '-') {
|
||||
// b.append('_');
|
||||
// }
|
||||
// return b.toString();
|
||||
// }
|
||||
//
|
||||
// private String pipeSeparate(List<String> paths) {
|
||||
// StringBuilder b = new StringBuilder();
|
||||
// boolean first = true;
|
||||
// for (String p : paths) {
|
||||
// if (first)
|
||||
// first = false;
|
||||
// else
|
||||
// b.append("|");
|
||||
// b.append(p);
|
||||
// }
|
||||
// return b.toString();
|
||||
// }
|
||||
//
|
||||
// private String asCommaText(List<TypeRef> types) {
|
||||
// CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
|
||||
// Set<String> tset = new HashSet<String>();
|
||||
// for (TypeRef t : types) {
|
||||
// if (!tset.contains(t.getName())) {
|
||||
// b.append("\""+t.getName()+"\"");
|
||||
// tset.add(t.getName());
|
||||
// }
|
||||
// }
|
||||
// return b.toString();
|
||||
// }
|
||||
//
|
||||
// private String propId(String name) {
|
||||
// return Integer.toString(name.hashCode());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private boolean isAbstract(String typeCode) {
|
||||
// if (typeCode.equals("Resource"))
|
||||
// return true;
|
||||
// else
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private void generateConstructor(String className, List<ElementDefn> 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 (ElementDefn e : params) {
|
||||
// if (!first)
|
||||
// write(", ");
|
||||
// first = false;
|
||||
// String tn = typeNames.get(e);
|
||||
// String en = getElementName(e.getName(), true);
|
||||
// write(tn +" "+en);
|
||||
// }
|
||||
// write(") {\r\n");
|
||||
// write(indent+" super();\r\n");
|
||||
// for (ElementDefn e : params) {
|
||||
// String en = getElementName(e.getName(), true);
|
||||
// write(indent+" this."+en+" = "+en+";\r\n");
|
||||
// }
|
||||
// write(indent+" }\r\n\r\n");
|
||||
// }
|
||||
//
|
||||
// private String upFirst(String name) {
|
||||
// return name.substring(0,1).toUpperCase()+name.substring(1);
|
||||
// }
|
||||
//
|
||||
// private boolean hasList(ElementDefn root) {
|
||||
// for (ElementDefn e : root.getElements()) {
|
||||
// if (!e.getName().equals("text")) {
|
||||
// if (e.unbounded() || hasListInner(e))
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private boolean hasDecimal(ElementDefn root) {
|
||||
// for (ElementDefn e : root.getElements()) {
|
||||
// if (e.typeCode().equals("decimal") || hasDecimalInner(e))
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private boolean hasString(ElementDefn root) {
|
||||
// for (ElementDefn e : root.getElements()) {
|
||||
// if (Utilities.existsInList(e.typeCode(), "string", "id", "code", "uri", "oid", "uuid", "url", "canonical") || hasString(e))
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private boolean hasSharedEnums(ElementDefn root) {
|
||||
// for (ElementDefn e : root.getElements()) {
|
||||
// if ((e.getBinding() != null && e.getBinding().isShared()) || hasSharedEnums(e))
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private boolean hasXhtml(ElementDefn root) {
|
||||
// for (ElementDefn e : root.getElements()) {
|
||||
// if (e.isXhtmlElement() || hasXhtmlInner(e))
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private boolean hasListInner(ElementDefn e) {
|
||||
// for (ElementDefn c : e.getElements()) {
|
||||
// if (c.unbounded() || hasListInner(c))
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private boolean hasXhtmlInner(ElementDefn e) {
|
||||
// for (ElementDefn c : e.getElements()) {
|
||||
// if (c.isXhtmlElement() || hasXhtmlInner(c))
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private boolean hasDecimalInner(ElementDefn e) {
|
||||
// for (ElementDefn c : e.getElements()) {
|
||||
// if (c.typeCode().equals("decimal") || hasDecimalInner(c))
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void generateType(ElementDefn e, JavaGenClass clss, ElementDefn impl, String resName) throws Exception {
|
||||
// String tn = typeNames.get(e);
|
||||
//
|
||||
// write(" public class "+tn+"Impl extends PatternBaseImpl implements EventPerformerComponent {\r\n");
|
||||
// write(" private Element wrapped;\r\n");
|
||||
// write("\r\n");
|
||||
// write(" public "+tn+"Impl(Element wrapped) {\r\n");
|
||||
// write(" super(wrapped);\r\n");
|
||||
// write(" this.wrapped = wrapped;\r\n");
|
||||
// write(" }\r\n");
|
||||
// write("\r\n");
|
||||
// for (ElementDefn c : e.getElements()) {
|
||||
// generateAccessors(e, c, resolveTarget(e, c, impl), " ", tn, resName);
|
||||
// }
|
||||
// write(" }\r\n");
|
||||
// write("\r\n");
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private ElementDefn resolveTarget(ElementDefn e, ElementDefn c, ElementDefn impl) {
|
||||
// String path = e.getName()+"."+c.getName();
|
||||
// for (ElementDefn n : impl.getElements()) {
|
||||
// String wm = getWorkflowMapping(n);
|
||||
// if (wm != null && wm.equals(path))
|
||||
// return n;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private String getWorkflowMapping(ElementDefn n) {
|
||||
// for (String m : n.getMappings().keySet()) {
|
||||
// if ("http://hl7.org/fhir/workflow".equals(m))
|
||||
// return n.getMapping(m);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private void scanNestedTypes(ElementDefn root, String path, ElementDefn e) throws Exception {
|
||||
// String tn = null;
|
||||
// if (e.typeCode().equals("code") && e.hasBinding()) {
|
||||
// BindingSpecification cd = e.getBinding();
|
||||
// if (cd != null && (cd.getBinding() == BindingSpecification.BindingMethod.CodeList)) {
|
||||
// tn = getCodeListType(cd.getValueSet().getName());
|
||||
// if (!enumNames.contains(tn)) {
|
||||
// enumNames.add(tn);
|
||||
// enums.add(e);
|
||||
// }
|
||||
// typeNames.put(e, "Enumeration<"+tn+">");
|
||||
// } else if (isEnum(cd)) {
|
||||
// tn = getCodeListType(cd.getName());
|
||||
// if (!enumNames.contains(tn)) {
|
||||
// enumNames.add(tn);
|
||||
// enums.add(e);
|
||||
// }
|
||||
// typeNames.put(e, "Enumeration<"+tn+">");
|
||||
// }
|
||||
// }
|
||||
// if (tn == null) {
|
||||
// if (e.getTypes().size() > 0 && !e.usesCompositeType()) {
|
||||
// tn = e.typeCode();
|
||||
//// if (clss != JavaGenClass.Resource) {
|
||||
//// if (tn.equals("boolean")) tn = "Boolean";
|
||||
//// else if (tn.equals("integer")) tn = "Integer";
|
||||
//// else if (tn.equals("decimal")) tn = "Decimal";
|
||||
//// else if (tn.equals("base64Binary")) tn = "Base64Binary";
|
||||
//// else if (tn.equals("instant")) tn = "Instant";
|
||||
//// else if (tn.equals("string")) tn = "StringType";
|
||||
//// else if (tn.equals("uri")) tn = "Uri";
|
||||
//// else if (tn.equals("xml:lang")) tn = "Code";
|
||||
//// else if (tn.equals("code")) tn = "Code";
|
||||
//// else if (tn.equals("oid")) tn = "Oid";
|
||||
//// else if (tn.equals("uuid")) tn = "Uuid";
|
||||
//// else if (tn.equals("sid")) tn = "Sid";
|
||||
//// else if (tn.equals("id")) tn = "Id";
|
||||
//// else if (tn.equals("date")) tn = "Date";
|
||||
//// else if (tn.equals("dateTime")) tn = "DateTime";
|
||||
//// else
|
||||
//// tn = getTypeName(e);
|
||||
//// } else
|
||||
// tn = getTypeName(e);
|
||||
// if (e.typeCode().equals("xml:lang"))
|
||||
// tn = "CodeType";
|
||||
// if (e.getTypes().get(0).isUnboundGenericParam())
|
||||
// tn = "T";
|
||||
// else if (e.isXhtmlElement())
|
||||
// tn = "XhtmlNode";
|
||||
// else if (e.getTypes().get(0).isWildcardType())
|
||||
// tn ="org.hl7.fhir.r5.model.Type";
|
||||
// else if (definitions.hasPrimitiveType(tn))
|
||||
// tn = upFirst(tn)+"Type";
|
||||
//
|
||||
// typeNames.put(e, tn);
|
||||
// } else {
|
||||
// if (e.usesCompositeType()) {
|
||||
// tn = typeNames.get(getElementForPath(root, e.typeCode().substring(1)));
|
||||
// typeNames.put(e, tn);
|
||||
//// } else if (e.getDeclaredTypeName() != null) {
|
||||
//// tn = e.getDeclaredTypeName();
|
||||
//// typeNames.put(e, tn);
|
||||
//// System.out.println(tn);
|
||||
// } else {
|
||||
// if (e.getDeclaredTypeName() != null)
|
||||
// tn = e.getDeclaredTypeName();
|
||||
// else
|
||||
// tn = getTitle(e.getName());
|
||||
// if (tn.equals("Element"))
|
||||
// tn = "Element_";
|
||||
// strucs.add(e);
|
||||
// if (typeNameStrings.contains(tn)) {
|
||||
// char i = 'A';
|
||||
// while (typeNameStrings.contains(tn+i))
|
||||
// i++;
|
||||
// tn = tn + i;
|
||||
// }
|
||||
// typeNames.put(e, tn);
|
||||
// typeNameStrings.add(tn);
|
||||
// for (ElementDefn c : e.getElements()) {
|
||||
// scanNestedTypes(root, path+getTitle(e.getName()), c);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private Object getElementForPath(ElementDefn root, String pathname) throws Exception {
|
||||
// String[] path = pathname.split("\\.");
|
||||
// if (!path[0].equals(root.getName()))
|
||||
// throw new Exception("Element Path '"+pathname+"' is not legal in this context");
|
||||
// ElementDefn res = root;
|
||||
// for (int i = 1; i < path.length; i++)
|
||||
// {
|
||||
// String en = path[i];
|
||||
// if (en.length() == 0)
|
||||
// throw new Exception("Improper path "+pathname);
|
||||
// ElementDefn t = res.getElementByName(definitions, en, true, false);
|
||||
// if (t == null) {
|
||||
// throw new Exception("unable to resolve "+pathname);
|
||||
// }
|
||||
// res = t;
|
||||
// }
|
||||
// return res;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private String getCodeListType(String binding) {
|
||||
// StringBuilder b = new StringBuilder();
|
||||
// boolean up = true;
|
||||
// for (char ch: binding.toCharArray()) {
|
||||
// if (ch == '-')
|
||||
// up = true;
|
||||
// else if (up) {
|
||||
// b.append(Character.toUpperCase(ch));
|
||||
// up = false;
|
||||
// }
|
||||
// else
|
||||
// b.append(ch);
|
||||
// }
|
||||
// return b.toString();
|
||||
// }
|
||||
//
|
||||
// private String getTypeClassList(ElementDefn e, String tn) throws Exception {
|
||||
// CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
|
||||
// for (TypeRef tr : e.getTypes()) {
|
||||
// if (tr.isResourceReference()) {
|
||||
// for (String p : tr.getParams())
|
||||
// if (p.equalsIgnoreCase("Any")) {
|
||||
// b.append("Reference.class");
|
||||
// } else {
|
||||
// if (p.equals("List"))
|
||||
// b.append(p+"Resource.class");
|
||||
// else
|
||||
// b.append(p+".class");
|
||||
// }
|
||||
// } else if (definitions.hasPrimitiveType(tr.getName())) {
|
||||
// b.append(upFirst(tr.getName())+"Type.class");
|
||||
// } else if (tr.getName().startsWith("@")){
|
||||
// b.append(tn+".class");
|
||||
// } else if (!tr.getName().equalsIgnoreCase("*") && !tr.getName().equalsIgnoreCase("xhtml")) {
|
||||
// b.append(getTypename(tr)+".class");
|
||||
// }
|
||||
// }
|
||||
// return b.toString();
|
||||
// }
|
||||
//
|
||||
// private String getSimpleType(String n) {
|
||||
// if (n.equals("StringType"))
|
||||
// return "String";
|
||||
// if (n.equals("CodeType"))
|
||||
// return "String";
|
||||
// if (n.equals("MarkdownType"))
|
||||
// return "String";
|
||||
// if (n.equals("Base64BinaryType"))
|
||||
// return "byte[]";
|
||||
// if (n.equals("UriType"))
|
||||
// return "String";
|
||||
// if (n.equals("UrlType"))
|
||||
// return "String";
|
||||
// if (n.equals("CanonicalType"))
|
||||
// return "String";
|
||||
// if (n.equals("OidType"))
|
||||
// return "String";
|
||||
// if (n.equals("IntegerType"))
|
||||
// return "int";
|
||||
// if (n.equals("UnsignedIntType"))
|
||||
// return "int";
|
||||
// if (n.equals("PositiveIntType"))
|
||||
// return "int";
|
||||
// if (n.equals("BooleanType"))
|
||||
// return "boolean";
|
||||
// if (n.equals("DecimalType"))
|
||||
// return "BigDecimal";
|
||||
// if (n.equals("DateTimeType"))
|
||||
// return "Date";
|
||||
// if (n.equals("DateType"))
|
||||
// return "Date";
|
||||
// if (n.equals("IdType"))
|
||||
// return "String";
|
||||
// if (n.equals("InstantType"))
|
||||
// return "Date";
|
||||
// if (n.equals("TimeType"))
|
||||
// return "String";
|
||||
//
|
||||
// String tns = null;
|
||||
// if (n.indexOf("<") > 0) {
|
||||
// tns = n.substring(n.indexOf("<")+1);
|
||||
// tns = tns.substring(0, tns.length()-1);
|
||||
// }
|
||||
//
|
||||
// if (tns != null && enumNames.contains(tns))
|
||||
// return tns;
|
||||
//
|
||||
// return "??";
|
||||
// }
|
||||
// private void generateAccessors(ElementDefn root, ElementDefn e, ElementDefn impl, String indent, String className, String resName) throws Exception {
|
||||
// String tn = typeNames.get(e);
|
||||
//
|
||||
// boolean isReferenceRefField = (root.getName().equals("Reference") && e.getName().equals("reference"));
|
||||
// String cvtB = getConversion1(e, impl);
|
||||
// String cvtR = getConversion2(e, impl);
|
||||
// String cvtE = Utilities.noString(cvtB) ? "" : ")";
|
||||
//
|
||||
// String simpleType = getSimpleType(tn);
|
||||
// write(indent+"public int get"+getTitle(getElementName(e.getName(), false))+"Min() {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" return 0;\r\n");
|
||||
// else
|
||||
// write(indent+" return "+impl.getMinCardinality()+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write(indent+"public int get"+getTitle(getElementName(e.getName(), false))+"Max() {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" return 0;\r\n");
|
||||
// else
|
||||
// write(indent+" return "+impl.getMaxCardinality()+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// if (e.unbounded()) {
|
||||
// /*
|
||||
// * getXXX()for repeatable type
|
||||
// */
|
||||
// String listGenericType;
|
||||
// if (tn == null && e.usesCompositeType()) {
|
||||
// listGenericType = root.getName();
|
||||
// } else {
|
||||
// listGenericType = tn;
|
||||
// }
|
||||
// write(indent+"public List<"+listGenericType+"> get"+getTitle(getElementName(e.getName(), false))+"() throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else if (impl.unbounded())
|
||||
// write(indent+" return wrapped.get"+getTitle(getElementName(impl.getName(), false))+"();\r\n");
|
||||
// else {
|
||||
// write(indent+" ArrayList<"+listGenericType+"> list = new ArrayList<"+listGenericType+">();\r\n");
|
||||
// write(indent+" list.add("+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"()"+cvtE+");\r\n");
|
||||
// write(indent+" return list;\r\n");
|
||||
// }
|
||||
// write(indent+"}\r\n\r\n");
|
||||
//
|
||||
// /*
|
||||
// * setXXX(List<foo>) for repeating type
|
||||
// */
|
||||
// write(indent+"public " + className + " set"+getTitle(getElementName(e.getName(), false))+"(" + "List<"+listGenericType+"> the" + getTitle(getElementName(e.getName(), false)) + ") throws FHIRException {\r\n\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else {
|
||||
// if (impl.unbounded())
|
||||
// write(indent+" wrapped.set"+getTitle(getElementName(impl.getName(), false))+"("+cvtR+"the" + getTitle(getElementName(e.getName(), false)) + ""+cvtE+");\r\n");
|
||||
// else
|
||||
// write(indent+" wrapped.set"+getTitle(getElementName(impl.getName(), false))+"("+cvtR+"the" + getTitle(getElementName(e.getName(), false)) + ".get(0)"+cvtE+");\r\n");
|
||||
// write(indent+" return this;\r\n\r\n");
|
||||
// }
|
||||
// write(indent+"}\r\n\r\n");
|
||||
//
|
||||
// /*
|
||||
// * hasXXX() for repeatable type
|
||||
// */
|
||||
// write(indent+"public boolean has"+getTitle(getElementName(e.getName(), false))+"() {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" return false;\r\n");
|
||||
// else
|
||||
// write(indent+" return wrapped.has"+getTitle(getElementName(impl.getName(), false))+"();\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
//
|
||||
// write("\r\n");
|
||||
// if (e.getTypes().size() == 1 && (definitions.getPrimitives().containsKey(e.typeCode()) || e.typeCode().equals("xml:lang") || e.typeCode().startsWith("canonical("))) {
|
||||
// /*
|
||||
// * addXXXElement() for repeatable primitive
|
||||
// */
|
||||
// write(indent+"public "+tn+" add"+getTitle(getElementName(e.getName(), false))+"Element() throws FHIRException {\r\n");
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
//
|
||||
// /*
|
||||
// * addXXX(foo) for repeatable primitive
|
||||
// */
|
||||
// write(indent+"public "+className+" add"+getTitle(getElementName(e.getName(), false))+"("+simpleType+" value) throws FHIRException {\r\n");
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
//
|
||||
// /*
|
||||
// * hasXXX(foo) for repeatable primitive
|
||||
// */
|
||||
// write(indent+"public boolean has"+getTitle(getElementName(e.getName(), false))+"("+simpleType+" value) {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" return false;\r\n");
|
||||
// else
|
||||
// write(indent+" return wrapped.has"+getTitle(getElementName(impl.getName(), false))+"(value);\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
// } else {
|
||||
// if (!definitions.getBaseResources().containsKey(tn)) {
|
||||
// /*
|
||||
// * addXXX() for repeatable composite
|
||||
// */
|
||||
// write(indent+"public "+tn+" add"+getTitle(getElementName(e.getName(), false))+"() throws FHIRException {\r\n");
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
//
|
||||
// /*
|
||||
// * addXXX(foo) for repeatable composite
|
||||
// */
|
||||
// write(indent+"public "+className+" add"+getTitle(getElementName(e.getName(), false))+"("+tn+" t) throws FHIRException {\r\n");
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
// } else {
|
||||
// /*
|
||||
// * addXXX(foo) for repeatable composite
|
||||
// */
|
||||
// write(indent+"public "+className+" add"+getTitle(getElementName(e.getName(), false))+"("+tn+" t) throws FHIRException {\r\n");
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * getXXXFirstRep() for repeatable element
|
||||
// */
|
||||
// if (!"DomainResource".equals(className)) {
|
||||
// write(indent+"public "+tn+" get"+getTitle(getElementName(e.getName(), false))+"FirstRep() throws FHIRException {\r\n\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else if (impl.unbounded())
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"FirstRep()"+cvtE+";\r\n");
|
||||
// else
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"()"+cvtE+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (isJavaPrimitive(e) || (e.getTypes().size() == 1 && e.typeCode().startsWith("canonical("))) {
|
||||
// if (isReferenceRefField) {
|
||||
// /*
|
||||
// * Reference#getReferenceElement is defined differently in BaseReference.java?
|
||||
// */
|
||||
// write(indent+"public "+tn+" get"+getTitle(getElementName(e.getName(), false))+"Element_() throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else if (impl.unbounded())
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"ElementFirstRep()"+cvtE+";\r\n");
|
||||
// else
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"Element_()"+cvtE+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// } else {
|
||||
// write(indent+"public "+tn+" get"+getTitle(getElementName(e.getName(), false))+"Element() throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else if (impl.unbounded())
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"ElementFirstRep()"+cvtE+";\r\n");
|
||||
// else
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"Element()"+cvtE+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// }
|
||||
// write("\r\n");
|
||||
//
|
||||
// write(indent+"public boolean has"+getTitle(getElementName(e.getName(), false))+"Element() {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" return false;\r\n");
|
||||
// else
|
||||
// write(indent+" return wrapped.has"+getTitle(getElementName(impl.getName(), false))+"Element();\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
// write(indent+"public boolean has"+getTitle(getElementName(e.getName(), false))+"() {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" return false;\r\n");
|
||||
// else
|
||||
// write(indent+" return wrapped.has"+getTitle(getElementName(impl.getName(), false))+"();\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
// write(indent+"public "+className+" set"+getTitle(getElementName(e.getName(), false))+"Element("+tn+" value) throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else {
|
||||
// if (impl.unbounded()) {
|
||||
// write(indent+" wrapped.set"+getTitle(getElementName(impl.getName(), false))+"Element(value);\r\n");
|
||||
// } else {
|
||||
// write(indent+" wrapped.set"+getTitle(getElementName(impl.getName(), false))+"Element(value);\r\n");
|
||||
// }
|
||||
// write(indent+" return this;\r\n\r\n");
|
||||
// }
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write("\r\n");
|
||||
// write(indent+"public "+simpleType+" get"+getTitle(getElementName(e.getName(), false))+"() throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else if (impl.unbounded())
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"FirstRep()"+cvtE+";\r\n");
|
||||
// else
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+"()"+cvtE+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// generateSetter(e, indent, className, tn, simpleType, impl, resName, cvtR, cvtE);
|
||||
//
|
||||
// // BigDecimal sugar methods
|
||||
// if (simpleType.equals("BigDecimal")) {
|
||||
// generateSetter(e, indent, className, tn, "long", impl, resName, cvtR, cvtE);
|
||||
// generateSetter(e, indent, className, tn, "double", impl, resName, cvtR, cvtE);
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// write(indent+"public "+tn+" get"+getTitle(getElementName(e.getName(), false))+"() throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else if (impl.unbounded())
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+(isPrimitive(impl.typeCode()) ? "Element" : "")+"FirstRep()"+cvtE+";\r\n");
|
||||
// else
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+(isPrimitive(impl.typeCode()) ? "Element" : "")+"()"+cvtE+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// if (e.getTypes().size() > 1 && (tn.equals("Type") || !tn.endsWith(".Type"))) {
|
||||
// for (TypeRef t : e.getTypes()) {
|
||||
// String ttn = getTypename(t);
|
||||
// TypeRef ti = impl == null ? null : getTypeFromImplementation(impl, t);
|
||||
// write(indent+"public "+ttn+" get"+getTitle(getElementName(e.getName(), false))+ttn+"() throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else if (ti == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' does not support the type '"+ttn+"' for the resource '"+resName+"'\");\r\n");
|
||||
// else
|
||||
// write(indent+" return "+cvtB+"wrapped.get"+getTitle(getElementName(impl.getName(), false))+ttn+"()"+cvtE+";\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write(indent+"public boolean has"+getTitle(getElementName(e.getName(), false))+ttn+"() { \r\n");
|
||||
// if (impl == null || ti == null)
|
||||
// write(indent+" return false;\r\n");
|
||||
// else
|
||||
// write(indent+" return wrapped.has"+getTitle(getElementName(impl.getName(), false))+ttn+"(); // tt2\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// }
|
||||
// }
|
||||
// write(indent+"public boolean has"+getTitle(getElementName(e.getName(), false))+"() {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" return false;\r\n");
|
||||
// else
|
||||
// write(indent+" return wrapped.has"+getTitle(getElementName(impl.getName(), false))+"();\r\n");
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// write(indent+"public "+className+" set"+getTitle(getElementName(e.getName(), false))+"("+tn+" value) throws FHIRException {\r\n"); if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else {
|
||||
// if (impl.unbounded()) {
|
||||
// write(indent+" wrapped.get"+getTitle(getElementName(impl.getName(), false))+"().clear();\r\n");
|
||||
// write(indent+" if (value != null)\r\n");
|
||||
// write(indent+" wrapped.get"+getTitle(getElementName(impl.getName(), false))+"().add(value);\r\n");
|
||||
// } else
|
||||
// write(indent+" wrapped.set"+getTitle(getElementName(impl.getName(), false))+"(value);\r\n");
|
||||
// write(indent+" return this;\r\n\r\n");
|
||||
// }
|
||||
// write(indent+"}\r\n\r\n");
|
||||
// if (e.getTypes().size() == 1 && e.typeCode().startsWith("Reference(")) {
|
||||
// List<String> params = e.getTypes().get(0).getParams();
|
||||
// String rn = params.size() == 1 ? params.get(0) : "Resource";
|
||||
// if (rn.equals("Any"))
|
||||
// rn = "Resource";
|
||||
// else if (rn.equals("List"))
|
||||
// rn = "ListResource";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private TypeRef getTypeFromImplementation(ElementDefn impl, TypeRef t) {
|
||||
// for (TypeRef ti : impl.getTypes()) {
|
||||
// if (ti.getName().equals(t.getName()))
|
||||
// return ti;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private String getConversion1(ElementDefn e, ElementDefn impl) {
|
||||
// if ( e == null || e.getTypes().size() != 1 || impl == null || impl.getTypes().size() != 1)
|
||||
// return "";
|
||||
// String tp = e.getTypes().get(0).getName();
|
||||
// String ti = impl.getTypes().get(0).getName();
|
||||
// if (tp.equals(ti))
|
||||
// return "";
|
||||
// return "convert"+Utilities.capitalize(ti)+"To"+Utilities.capitalize(tp)+"(";
|
||||
// }
|
||||
//
|
||||
// private String getConversion2(ElementDefn e, ElementDefn impl) {
|
||||
// if ( e == null || e.getTypes().size() != 1 || impl == null || impl.getTypes().size() != 1)
|
||||
// return "";
|
||||
// String tp = e.getTypes().get(0).getName();
|
||||
// String ti = impl.getTypes().get(0).getName();
|
||||
// if (tp.equals(ti))
|
||||
// return "";
|
||||
// return "convert"+Utilities.capitalize(tp)+"To"+Utilities.capitalize(ti)+"(";
|
||||
// }
|
||||
//
|
||||
// private void generateSetter(ElementDefn e, String indent, String className, String tn, String simpleType, ElementDefn impl, String resName, String cvtR, String cvtE) throws IOException {
|
||||
// write(indent+"public "+className+" set"+getTitle(getElementName(e.getName(), false))+"("+simpleType+" value) throws FHIRException {\r\n");
|
||||
// if (impl == null)
|
||||
// write(indent+" throw new FHIRException(\"The pattern property '"+e.getName()+"' is not supported in '"+resName+"'\");\r\n");
|
||||
// else {
|
||||
// if (impl.unbounded()) {
|
||||
// write(indent+" wrapped.get"+getTitle(getElementName(impl.getName(), false))+"().clear();\r\n");
|
||||
// write(indent+" if (value != null)\r\n");
|
||||
// write(indent+" wrapped.set"+getTitle(getElementName(impl.getName(), false))+"("+cvtR+"value"+cvtE+");\r\n");
|
||||
// } else {
|
||||
// write(indent+" wrapped.set"+getTitle(getElementName(impl.getName(), false))+"("+cvtR+"value"+cvtE+");\r\n");
|
||||
// }
|
||||
// write(indent+" return this;\r\n\r\n");
|
||||
// }
|
||||
// write("}\r\n\r\n");
|
||||
// }
|
||||
//
|
||||
// private boolean isString(String tn) {
|
||||
// return tn.equals("StringType") || tn.equals("CodeType") || tn.equals("IdType") || tn.equals("UriType") || tn.equals("OidType") || tn.equals("CanonicalType") || tn.equals("UrlType") || tn.equals("UuidType");
|
||||
// }
|
||||
//
|
||||
// public long getHashSum() {
|
||||
// return hashSum;
|
||||
// }
|
||||
//
|
||||
// public void setInheritedHash(String value) {
|
||||
// inheritedHash = value;
|
||||
//
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -15,6 +15,8 @@ import org.hl7.fhir.core.generator.codegen.Configuration;
|
|||
import org.hl7.fhir.core.generator.codegen.JavaEnumerationsGenerator;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaFactoryGenerator;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaParserJsonGenerator;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaParserRdfGenerator;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaParserXmlGenerator;
|
||||
import org.hl7.fhir.core.generator.codegen.JavaResourceGenerator;
|
||||
import org.hl7.fhir.core.generator.loader.DefinitionsLoader;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
|
@ -53,6 +55,7 @@ public class JavaCoreGenerator {
|
|||
|
||||
|
||||
private void generate(String version, String src, String dest) throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
Date date = new Date();
|
||||
|
||||
String ap = Utilities.path(src, "src", "main", "resources");
|
||||
|
@ -82,6 +85,8 @@ public class JavaCoreGenerator {
|
|||
|
||||
JavaFactoryGenerator fgen = new JavaFactoryGenerator(new FileOutputStream(Utilities.path(dest, "src", "org", "hl7", "fhir", "r5", "model", "ResourceFactory.java")), master, config, date, npm.version());
|
||||
JavaParserJsonGenerator jgen = new JavaParserJsonGenerator(new FileOutputStream(Utilities.path(dest, "src", "org", "hl7", "fhir", "r5", "formats", "JsonParser.java")), master, config, date, npm.version());
|
||||
JavaParserXmlGenerator xgen = new JavaParserXmlGenerator(new FileOutputStream(Utilities.path(dest, "src", "org", "hl7", "fhir", "r5", "formats", "XmlParser.java")), master, config, date, npm.version());
|
||||
JavaParserRdfGenerator rgen = new JavaParserRdfGenerator(new FileOutputStream(Utilities.path(dest, "src", "org", "hl7", "fhir", "r5", "formats", "RdfParser.java")), master, config, date, npm.version());
|
||||
|
||||
for (StructureDefinition sd : master.getStructures().getList()) {
|
||||
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && sd.getKind() == StructureDefinitionKind.COMPLEXTYPE) {
|
||||
|
@ -97,6 +102,8 @@ public class JavaCoreGenerator {
|
|||
gen.generate(analysis);
|
||||
gen.close();
|
||||
jgen.seeClass(analysis);
|
||||
xgen.seeClass(analysis);
|
||||
rgen.seeClass(analysis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,6 +120,8 @@ public class JavaCoreGenerator {
|
|||
gen.generate(analysis);
|
||||
gen.close();
|
||||
jgen.seeClass(analysis);
|
||||
xgen.seeClass(analysis);
|
||||
rgen.seeClass(analysis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +139,8 @@ public class JavaCoreGenerator {
|
|||
gen.generate(analysis);
|
||||
gen.close();
|
||||
jgen.seeClass(analysis);
|
||||
xgen.seeClass(analysis);
|
||||
rgen.seeClass(analysis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +157,8 @@ public class JavaCoreGenerator {
|
|||
gen.generate(analysis);
|
||||
gen.close();
|
||||
jgen.seeClass(analysis);
|
||||
xgen.seeClass(analysis);
|
||||
rgen.seeClass(analysis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +168,13 @@ public class JavaCoreGenerator {
|
|||
System.out.println(" .. JsonParser");
|
||||
jgen.generate();
|
||||
jgen.close();
|
||||
System.out.println("Done");
|
||||
System.out.println(" .. XmlParser");
|
||||
xgen.generate();
|
||||
xgen.close();
|
||||
System.out.println(" .. RdfParser");
|
||||
rgen.generate();
|
||||
rgen.close();
|
||||
System.out.println("Done ("+Long.toString(System.currentTimeMillis()-start)+"ms)");
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue