use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.
the class JavaParserXmlGenerator method genElementCompose.
private void genElementCompose(Analysis analysis, TypeInfo ti, ElementDefinition ed, ElementDefinition inh) throws Exception {
String name = ed.getName();
if (name.endsWith("[x]") || name.equals("[type]")) {
String en = name.endsWith("[x]") && !name.equals("[x]") ? name.replace("[x]", "") : "value";
String pfx = name.endsWith("[x]") ? name.replace("[x]", "") : "";
composer.append(" if (element.has" + upFirst(getElementName(en, false)) + "()) {\r\n");
composer.append(" composeType(\"" + pfx + "\", element.get" + upFirst(getElementName(en, false)) + "());\r\n");
composer.append(" }");
} else {
String comp = null;
String en = null;
String tn = ed.getUserString("java.type");
if (ed.hasUserData("java.enum")) {
EnumInfo ei = (EnumInfo) ed.getUserData("java.enum");
ValueSet vs = ei.getValueSet();
boolean enShared = vs.hasUserData("shared");
if (enShared) {
en = "Enumerations." + ei.getName();
} else {
en = analysis.getClassName() + "." + ei.getName();
}
} else {
if (name.equals("extension")) {
name = "extension";
tn = "Extension";
}
if (tn.equals("XhtmlNode")) {
tn = "xhtml";
comp = "composeXhtml";
} else if (isPrimitive(ed)) {
comp = "compose" + tn.substring(0, tn.length() - 4);
} else if (tn.contains("Reference(")) {
comp = "composeReference";
tn = "Reference";
} else if (tn.contains("canonical(")) {
comp = "composeCanonical";
tn = "CanonicalType";
} else if (tn.contains("(")) {
comp = "compose" + tn;
} else if ((ed.hasContentReference() || ed.isInlineType()) && !tn.startsWith(analysis.getClassName())) {
comp = "compose" + analysis.getClassName() + tn;
} else {
comp = "compose" + tn;
}
}
if (ed.unbounded()) {
if (en != null) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" for (Enumeration<" + en + "> e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
composer.append(" composeEnumeration(\"" + name + "\", e, new " + en + "EnumFactory());\r\n");
} else {
String stn = ed.isInlineType() || ed.hasContentReference() ? analysis.getClassName() + "." + tn : tn;
// String pfx = ed.isInlineType() || ed.hasContentReference() ? analysis.getClassName() : "";
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) { \r\n");
composer.append(" for (" + stn + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
if (ed.typeSummary().equals("Resource")) {
composer.append(" {\r\n");
composer.append(" xml.enter(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" " + comp + "(e);\r\n");
composer.append(" xml.exit(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" }\r\n");
} else {
composer.append(" " + comp + "(\"" + name + "\", e);\r\n");
}
composer.append(" }\r\n");
}
} else if (en != null) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "Element())\r\n");
composer.append(" composeEnumeration(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + en + "EnumFactory());\r\n");
} else if (!"xhtml".equals(ed.typeSummary()) && (isJavaPrimitive(ed) || ed.typeSummary().startsWith("canonical("))) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "Element()) {\r\n");
composer.append(" " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element());\r\n");
composer.append(" }\r\n");
} else if (ed.typeSummary().equals("Resource")) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" xml.enter(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" " + comp + "(element.get" + upFirst(getElementName(name, false)) + "());\r\n");
composer.append(" xml.exit(FHIR_NS, \"" + name + "\");\r\n");
composer.append(" }\r\n");
} else if (inh != null && inh.unbounded()) {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "FirstRep());\r\n");
composer.append(" }\r\n");
} else {
composer.append(" if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
composer.append(" " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "());\r\n");
composer.append(" }\r\n");
}
}
}
use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.
the class VersionConvertorPrimitiveTypeTests method testCanonicalType10_40Conversion.
@Test
public void testCanonicalType10_40Conversion() {
ConversionContext10_40.INSTANCE.init(mock(VersionConvertor_10_40.class), CONTEXT_PATH);
for (String urlString : URL_STRINGS) {
{
org.hl7.fhir.r4.model.CanonicalType src = new CanonicalType();
src.setValueAsString(urlString);
Assertions.assertEquals(urlString, src.getValueAsString());
org.hl7.fhir.dstu2.model.Reference actualTgt = Canonical10_40.convertCanonicalToReference(src);
Assertions.assertEquals(src.getValueAsString(), actualTgt.getReference());
}
{
org.hl7.fhir.dstu2.model.Reference src = new org.hl7.fhir.dstu2.model.Reference(urlString);
Assertions.assertEquals(urlString, src.getReference());
org.hl7.fhir.r4.model.CanonicalType tgt = Canonical10_40.convertReferenceToCanonical(src);
Assertions.assertEquals(src.getReference(), tgt.getValueAsString());
}
}
ConversionContext10_40.INSTANCE.close(CONTEXT_PATH);
}
use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.
the class ValueSetComparer method compareDefinitions.
private void compareDefinitions(ConceptSetComponent left, ConceptSetComponent right, StructuralMatch<Element> combined, ConceptSetComponent union, ConceptSetComponent intersection) {
// system must match, but the rest might not. we're going to do the full comparison whatever, so the outcome looks consistent to the user
List<CanonicalType> matchVSR = new ArrayList<>();
for (CanonicalType l : left.getValueSet()) {
CanonicalType r = findInList(right.getValueSet(), l, left.getValueSet());
if (r == null) {
union.getValueSet().add(l);
combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed ValueSet", "ValueSet.compose.include.valueSet")));
} else {
matchVSR.add(r);
if (l.getValue().equals(r.getValue())) {
union.getValueSet().add(l);
intersection.getValueSet().add(l);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, null);
combined.getChildren().add(sm);
} else {
union.getValueSet().add(l);
union.getValueSet().add(r);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Values are different", "ValueSet.compose.include.valueSet"));
combined.getChildren().add(sm);
}
}
}
for (CanonicalType r : right.getValueSet()) {
if (!matchVSR.contains(r)) {
union.getValueSet().add(r);
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Add ValueSet", "ValueSet.compose.include.valueSet"), r));
}
}
List<ConceptReferenceComponent> matchCR = new ArrayList<>();
for (ConceptReferenceComponent l : left.getConcept()) {
ConceptReferenceComponent r = findInList(right.getConcept(), l, left.getConcept());
if (r == null) {
union.getConcept().add(l);
combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this Concept", "ValueSet.compose.include.concept")));
} else {
matchCR.add(r);
if (l.getCode().equals(r.getCode())) {
ConceptReferenceComponent cu = new ConceptReferenceComponent();
ConceptReferenceComponent ci = new ConceptReferenceComponent();
union.getConcept().add(cu);
intersection.getConcept().add(ci);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
combined.getChildren().add(sm);
compareConcepts(l, r, sm, cu, ci);
} else {
union.getConcept().add(l);
union.getConcept().add(r);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Concepts are different", "ValueSet.compose.include.concept"));
combined.getChildren().add(sm);
compareConcepts(l, r, sm, null, null);
}
}
}
for (ConceptReferenceComponent r : right.getConcept()) {
if (!matchCR.contains(r)) {
union.getConcept().add(r);
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this Concept", "ValueSet.compose.include.concept"), r));
}
}
List<ConceptSetFilterComponent> matchFR = new ArrayList<>();
for (ConceptSetFilterComponent l : left.getFilter()) {
ConceptSetFilterComponent r = findInList(right.getFilter(), l, left.getFilter());
if (r == null) {
union.getFilter().add(l);
combined.getChildren().add(new StructuralMatch<Element>(l, vmI(IssueSeverity.INFORMATION, "Removed this item", "ValueSet.compose.include.filter")));
} else {
matchFR.add(r);
if (l.getProperty().equals(r.getProperty()) && l.getOp().equals(r.getOp())) {
ConceptSetFilterComponent cu = new ConceptSetFilterComponent();
ConceptSetFilterComponent ci = new ConceptSetFilterComponent();
union.getFilter().add(cu);
intersection.getFilter().add(ci);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r);
combined.getChildren().add(sm);
compareFilters(l, r, sm, cu, ci);
} else {
union.getFilter().add(l);
union.getFilter().add(r);
StructuralMatch<Element> sm = new StructuralMatch<Element>(l, r, vmI(IssueSeverity.INFORMATION, "Codes are different", "ValueSet.compose.include.filter"));
combined.getChildren().add(sm);
compareFilters(l, r, sm, null, null);
}
}
}
for (ConceptSetFilterComponent r : right.getFilter()) {
if (!matchFR.contains(r)) {
union.getFilter().add(r);
combined.getChildren().add(new StructuralMatch<Element>(vmI(IssueSeverity.INFORMATION, "Added this item", "ValueSet.compose.include.filter"), r));
}
}
}
use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method makeChoiceRows.
private void makeChoiceRows(List<Row> subRows, ElementDefinition element, HierarchicalTableGenerator gen, String corePath, String profileBaseFileName, boolean mustSupportMode) {
// create a child for each choice
for (TypeRefComponent tr : element.getType()) {
if (!mustSupportMode || allTypesMustSupport(element) || isMustSupport(tr)) {
Row choicerow = gen.new Row();
String t = tr.getWorkingCode();
if (isReference(t)) {
choicerow.getCells().add(gen.new Cell(null, null, tail(element.getPath()).replace("[x]", Utilities.capitalize(t)), null, null));
choicerow.getCells().add(gen.new Cell());
choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
choicerow.setIcon("icon_reference.png", HierarchicalTableGenerator.TEXT_ICON_REFERENCE);
Cell c = gen.new Cell();
choicerow.getCells().add(c);
if (ADD_REFERENCE_TO_TABLE) {
if (tr.getWorkingCode().equals("canonical"))
c.getPieces().add(gen.new Piece(corePath + "datatypes.html#canonical", "canonical", null));
else
c.getPieces().add(gen.new Piece(corePath + "references.html#Reference", "Reference", null));
if (!mustSupportMode && isMustSupportDirect(tr) && element.getMustSupport()) {
c.addPiece(gen.new Piece(null, " ", null));
c.addStyledText(translate("sd.table", "This type must be supported"), "S", "white", "red", null, false);
}
c.getPieces().add(gen.new Piece(null, "(", null));
}
boolean first = true;
for (CanonicalType rt : tr.getTargetProfile()) {
if (!mustSupportMode || allProfilesMustSupport(tr.getTargetProfile()) || isMustSupport(rt)) {
if (!first)
c.getPieces().add(gen.new Piece(null, " | ", null));
genTargetLink(gen, profileBaseFileName, corePath, c, tr, rt.getValue());
if (!mustSupportMode && isMustSupport(rt) && element.getMustSupport()) {
c.addPiece(gen.new Piece(null, " ", null));
c.addStyledText(translate("sd.table", "This target must be supported"), "S", "white", "red", null, false);
}
first = false;
}
}
if (first) {
c.getPieces().add(gen.new Piece(null, "Any", null));
}
if (ADD_REFERENCE_TO_TABLE) {
c.getPieces().add(gen.new Piece(null, ")", null));
}
} else {
StructureDefinition sd = context.fetchTypeDefinition(t);
if (sd == null) {
System.out.println("Unable to find " + t);
sd = context.fetchTypeDefinition(t);
} else if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
choicerow.getCells().add(gen.new Cell(null, null, tail(element.getPath()).replace("[x]", Utilities.capitalize(t)), sd.getDescription(), null));
choicerow.getCells().add(gen.new Cell());
choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
choicerow.setIcon("icon_primitive.png", HierarchicalTableGenerator.TEXT_ICON_PRIMITIVE);
Cell c = gen.new Cell(null, corePath + "datatypes.html#" + t, sd.getType(), null, null);
choicerow.getCells().add(c);
if (!mustSupportMode && isMustSupport(tr) && element.getMustSupport()) {
c.addPiece(gen.new Piece(null, " ", null));
c.addStyledText(translate("sd.table", "This type must be supported"), "S", "white", "red", null, false);
}
} else {
choicerow.getCells().add(gen.new Cell(null, null, tail(element.getPath()).replace("[x]", Utilities.capitalize(t)), sd.getDescription(), null));
choicerow.getCells().add(gen.new Cell());
choicerow.getCells().add(gen.new Cell(null, null, "", null, null));
choicerow.setIcon("icon_datatype.gif", HierarchicalTableGenerator.TEXT_ICON_DATATYPE);
Cell c = gen.new Cell(null, pkp.getLinkFor(corePath, t), sd.getType(), null, null);
choicerow.getCells().add(c);
if (!mustSupportMode && isMustSupport(tr) && element.getMustSupport()) {
c.addPiece(gen.new Piece(null, " ", null));
c.addStyledText(translate("sd.table", "This type must be supported"), "S", "white", "red", null, false);
}
}
if (tr.hasProfile()) {
Cell typeCell = choicerow.getCells().get(3);
typeCell.addPiece(gen.new Piece(null, "(", null));
boolean first = true;
for (CanonicalType pt : tr.getProfile()) {
if (!mustSupportMode || allProfilesMustSupport(tr.getProfile()) || isMustSupport(pt)) {
if (first)
first = false;
else
typeCell.addPiece(gen.new Piece(null, " | ", null));
StructureDefinition psd = context.fetchResource(StructureDefinition.class, pt.getValue());
if (psd == null)
typeCell.addPiece(gen.new Piece(null, "?gen-e2?", null));
else
typeCell.addPiece(gen.new Piece(psd.getUserString("path"), psd.getName(), psd.present()));
if (!mustSupportMode && isMustSupport(pt) && element.getMustSupport()) {
typeCell.addPiece(gen.new Piece(null, " ", null));
typeCell.addStyledText(translate("sd.table", "This profile must be supported"), "S", "white", "red", null, false);
}
}
}
typeCell.addPiece(gen.new Piece(null, ")", null));
}
}
choicerow.getCells().add(gen.new Cell());
subRows.add(choicerow);
}
}
}
use of org.hl7.fhir.r4.model.CanonicalType in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method addDependentResources.
private boolean addDependentResources(Parameters pin, ConceptSetComponent inc) {
boolean cache = false;
for (CanonicalType c : inc.getValueSet()) {
ValueSet vs = fetchResource(ValueSet.class, c.getValue());
if (vs != null) {
pin.addParameter().setName("tx-resource").setResource(vs);
if (isTxCaching && cacheId == null || !cached.contains(vs.getVUrl())) {
cached.add(vs.getVUrl());
cache = true;
}
addDependentResources(pin, vs);
}
}
CodeSystem cs = fetchResource(CodeSystem.class, inc.getSystem());
if (cs != null) {
pin.addParameter().setName("tx-resource").setResource(cs);
if (isTxCaching && cacheId == null || !cached.contains(cs.getVUrl())) {
cached.add(cs.getVUrl());
cache = true;
}
// todo: supplements
}
return cache;
}
Aggregations