use of org.hl7.fhir.r5.model.DataType in project org.hl7.fhir.core by hapifhir.
the class OperationDefinition30_50 method convertOperationDefinitionParameterBindingComponent.
public static org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent convertOperationDefinitionParameterBindingComponent(org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterBindingComponent src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent tgt = new org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent();
ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
if (src.hasStrength())
tgt.setStrengthElement(Enumerations30_50.convertBindingStrength(src.getStrengthElement()));
if (src.hasValueSet()) {
DataType t = ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getValueSet());
if (t instanceof org.hl7.fhir.r5.model.Reference)
tgt.setValueSet(((org.hl7.fhir.r5.model.Reference) t).getReference());
else
tgt.setValueSet(t.primitiveValue());
tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet()));
}
return tgt;
}
use of org.hl7.fhir.r5.model.DataType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method createExampleElement.
private org.hl7.fhir.r4b.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
DataType v = accessor.getExampleValue(ed);
if (v != null) {
return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
} else {
org.hl7.fhir.r4b.elementmodel.Element res = new org.hl7.fhir.r4b.elementmodel.Element(tail(ed.getPath()), new Property(context, ed, profile));
boolean hasValue = false;
List<ElementDefinition> children = getChildMap(profile, ed);
for (ElementDefinition child : children) {
if (!child.hasContentReference()) {
org.hl7.fhir.r4b.elementmodel.Element e = createExampleElement(profile, child, accessor);
if (e != null) {
hasValue = true;
res.getChildren().add(e);
}
}
}
if (hasValue)
return res;
else
return null;
}
}
use of org.hl7.fhir.r5.model.DataType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method genFixedValue.
private void genFixedValue(HierarchicalTableGenerator gen, Row erow, DataType value, boolean snapshot, boolean pattern, String corePath, boolean skipnoValue) {
String ref = pkp.getLinkFor(corePath, value.fhirType());
if (ref != null && ref.contains(".html")) {
ref = ref.substring(0, ref.indexOf(".html")) + "-definitions.html#";
} else {
ref = "?gen-fv?";
}
StructureDefinition sd = context.fetchTypeDefinition(value.fhirType());
for (org.hl7.fhir.r4b.model.Property t : value.children()) {
if (t.getValues().size() > 0 || snapshot) {
ElementDefinition ed = findElementDefinition(sd, t.getName());
if (t.getValues().size() == 0 || (t.getValues().size() == 1 && t.getValues().get(0).isEmpty())) {
if (!skipnoValue) {
Row row = gen.new Row();
erow.getSubRows().add(row);
Cell c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref + ed.getPath() : corePath + (VersionUtilities.isR5Ver(context.getVersion()) ? "types-definitions.html#" + ed.getBase().getPath() : "element-definitions.html#" + ed.getBase().getPath())), t.getName(), null));
c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece(null, null, null));
c = gen.new Cell();
row.getCells().add(c);
if (!pattern) {
c.addPiece(gen.new Piece(null, "0..0", null));
row.setIcon("icon_fixed.gif", "Fixed Value");
} else if (isPrimitive(t.getTypeCode())) {
row.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
c.addPiece(gen.new Piece(null, "0.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
} else if (isReference(t.getTypeCode())) {
row.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
c.addPiece(gen.new Piece(null, "0.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
} else {
row.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
c.addPiece(gen.new Piece(null, "0.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
}
c = gen.new Cell();
row.getCells().add(c);
if (t.getTypeCode().contains("(")) {
String tc = t.getTypeCode();
String tn = tc.substring(0, tc.indexOf("("));
c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, tn), tn, null));
c.addPiece(gen.new Piece(null, "(", null));
String[] p = tc.substring(tc.indexOf("(") + 1, tc.indexOf(")")).split("\\|");
for (String s : p) {
c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, s), s, null));
}
c.addPiece(gen.new Piece(null, ")", null));
} else {
c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, t.getTypeCode()), t.getTypeCode(), null));
}
c = gen.new Cell();
c.addPiece(gen.new Piece(null, ed.getShort(), null));
row.getCells().add(c);
}
} else {
for (Base b : t.getValues()) {
Row row = gen.new Row();
erow.getSubRows().add(row);
row.setIcon("icon_fixed.gif", "Fixed Value");
Cell c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref + ed.getPath() : (VersionUtilities.isThisOrLater("4.1", context.getVersion()) ? corePath + "types-definitions.html#" + ed.getBase().getPath() : corePath + "element-definitions.html#" + ed.getBase().getPath())), t.getName(), null));
c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece(null, null, null));
c = gen.new Cell();
row.getCells().add(c);
if (pattern)
c.addPiece(gen.new Piece(null, "1.." + (t.getMaxCardinality() == 2147483647 ? "*" : Integer.toString(t.getMaxCardinality())), null));
else
c.addPiece(gen.new Piece(null, "1..1", null));
c = gen.new Cell();
row.getCells().add(c);
if (b.fhirType().contains("(")) {
String tc = b.fhirType();
String tn = tc.substring(0, tc.indexOf("("));
c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, tn), tn, null));
c.addPiece(gen.new Piece(null, "(", null));
String[] p = tc.substring(tc.indexOf("(") + 1, tc.indexOf(")")).split("\\|");
for (String s : p) {
c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, s), s, null));
}
c.addPiece(gen.new Piece(null, ")", null));
} else {
c.addPiece(gen.new Piece(pkp.getLinkFor(corePath, b.fhirType()), b.fhirType(), null));
}
if (b.isPrimitive()) {
c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece(null, ed.getShort(), null));
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight: bold"));
String s = b.primitiveValue();
// ok. let's see if we can find a relevant link for this
String link = null;
if (Utilities.isAbsoluteUrl(s)) {
link = pkp.getLinkForUrl(corePath, s);
}
c.getPieces().add(gen.new Piece(link, s, null).addStyle("color: darkgreen"));
} else {
c = gen.new Cell();
row.getCells().add(c);
c.addPiece(gen.new Piece(null, ed.getShort(), null));
c.addPiece(gen.new Piece("br"));
c.getPieces().add(gen.new Piece(null, "Fixed Value: ", null).addStyle("font-weight: bold"));
c.getPieces().add(gen.new Piece(null, "(complex)", null).addStyle("color: darkgreen"));
genFixedValue(gen, row, (DataType) b, snapshot, pattern, corePath, skipnoValue);
}
}
}
}
}
}
use of org.hl7.fhir.r5.model.DataType in project org.hl7.fhir.core by hapifhir.
the class ShExGenerator method genTypeRef.
/**
* Generate a type reference
* @param sd Containing structure definition
* @param ed Containing element definition
* @param id Element id
* @param typ Element type
* @return Type reference string
*/
private String genTypeRef(StructureDefinition sd, ElementDefinition ed, String id, ElementDefinition.TypeRefComponent typ) {
if (typ.hasProfile()) {
if (typ.getWorkingCode().equals("Reference"))
return genReference("", typ);
else if (profileUtilities.getChildList(sd, ed).size() > 0) {
// inline anonymous type - give it a name and factor it out
innerTypes.add(new ImmutablePair<StructureDefinition, ElementDefinition>(sd, ed));
return simpleElement(sd, ed, id);
} else {
String ref = getTypeName(typ);
datatypes.add(ref);
return simpleElement(sd, ed, ref);
}
} else if (typ.getWorkingCode().startsWith(Constants.NS_SYSTEM_TYPE)) {
String xt = typ.getWorkingCode();
// TODO: Remove the next line when the type of token gets switched to string
// TODO: Add a rdf-type entry for valueInteger to xsd:integer (instead of int)
ST td_entry = tmplt(PRIMITIVE_ELEMENT_DEFN_TEMPLATE).add("typ", xt.replace("xsd:token", "xsd:string").replace("xsd:int", "xsd:integer"));
StringBuilder facets = new StringBuilder();
if (ed.hasMinValue()) {
DataType mv = ed.getMinValue();
facets.append(tmplt(MINVALUE_TEMPLATE).add("val", mv.primitiveValue()).render());
}
if (ed.hasMaxValue()) {
DataType mv = ed.getMaxValue();
facets.append(tmplt(MAXVALUE_TEMPLATE).add("val", mv.primitiveValue()).render());
}
if (ed.hasMaxLength()) {
int ml = ed.getMaxLength();
facets.append(tmplt(MAXLENGTH_TEMPLATE).add("val", ml).render());
}
if (ed.hasPattern()) {
DataType pat = ed.getPattern();
facets.append(tmplt(PATTERN_TEMPLATE).add("val", pat.primitiveValue()).render());
}
td_entry.add("facets", facets.toString());
return td_entry.render();
} else if (typ.getWorkingCode() == null) {
ST primitive_entry = tmplt(PRIMITIVE_ELEMENT_DEFN_TEMPLATE);
primitive_entry.add("typ", "xsd:string");
return primitive_entry.render();
} else if (typ.getWorkingCode().equals("xhtml")) {
return tmplt(XHTML_TYPE_TEMPLATE).render();
} else {
datatypes.add(typ.getWorkingCode());
return simpleElement(sd, ed, typ.getWorkingCode());
}
}
use of org.hl7.fhir.r5.model.DataType in project org.hl7.fhir.core by hapifhir.
the class ImplementationGuide14_50 method convertImplementationGuidePackageResourceComponent.
public static org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent convertImplementationGuidePackageResourceComponent(org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageResourceComponent src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent();
ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
if (src.hasExampleFor()) {
DataType t = ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getExampleFor());
tgt.setExample(t instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.model.Reference) t).getReference()) : t);
} else if (src.hasExample())
tgt.setExample(new org.hl7.fhir.r5.model.BooleanType(src.getExample()));
if (src.hasName())
tgt.setNameElement(String14_50.convertString(src.getNameElement()));
if (src.hasDescription())
tgt.setDescriptionElement(String14_50.convertString(src.getDescriptionElement()));
if (src.hasSourceReference())
tgt.setReference(Reference14_50.convertReference(src.getSourceReference()));
else if (src.hasSourceUriType())
tgt.setReference(new org.hl7.fhir.r5.model.Reference(src.getSourceUriType().getValue()));
return tgt;
}
Aggregations