use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project kindling by HL7.
the class Publisher method checkElement.
private void checkElement(StructureDefinition sd, ElementDefinition ed, boolean inDiff) {
check(ed.hasPath(), sd, "Element has no path");
Set<String> codes = new HashSet<String>();
for (TypeRefComponent tr : ed.getType()) {
String tc = tr.getWorkingCode();
if (codes.contains(tc))
check(false, sd, ed.getPath() + ": type '" + tc + "' is duplicated");
if ((!inDiff || tr.hasCode()) && tc != null)
if (ed.getPath().contains("."))
check(page.getDefinitions().hasBaseType(tc) || tc.equals("Resource"), sd, ed.getPath() + ": type '" + tc + "' is not valid (a)");
else if (sd.hasBaseDefinition()) {
if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT)
check(page.getDefinitions().hasConcreteResource(tc) || page.getDefinitions().hasBaseType(tc), sd, ed.getPath() + ": type '" + tc + "' is not valid (b)");
else
check(page.getDefinitions().hasAbstractResource(tc) || tc.equals("Element"), sd, ed.getPath() + ": type '" + tc + "' is not valid (c)");
}
if (tr.hasProfile()) {
check(tr.getProfile().size() == 1, sd, ed.getPath() + ": multiple profiles found: " + tr.getProfile());
String pt = tr.getProfile().get(0).getValue();
if (pt.contains("#")) {
String[] parts = pt.split("\\#");
StructureDefinition exd = page.getWorkerContext().fetchResource(StructureDefinition.class, parts[0]);
if (exd == null)
check(false, sd, ed.getPath() + ": profile '" + pt + "' is not valid (definition not found)");
else {
ElementDefinition ex = null;
for (ElementDefinition et : exd.getSnapshot().getElement()) if (et.hasFixed() && et.getFixed() instanceof UriType && ((UriType) et.getFixed()).asStringValue().equals(parts[1]))
ex = et;
check(ex != null, sd, ed.getPath() + ": profile '" + pt + "' is not valid (inner path not found)");
}
} else
check((page.getWorkerContext().hasResource(StructureDefinition.class, pt)) || isStringPattern(tail(pt)), sd, ed.getPath() + ": profile '" + pt + "' is not valid (d)");
}
if (tr.hasTargetProfile()) {
String pt = tr.getTargetProfile().get(0).getValue();
if (pt.contains("#")) {
String[] parts = pt.split("\\#");
StructureDefinition exd = page.getWorkerContext().fetchResource(StructureDefinition.class, parts[0]);
if (exd == null)
check(false, sd, ed.getPath() + ": target profile '" + pt + "' is not valid (definition not found)");
else {
ElementDefinition ex = null;
for (ElementDefinition et : exd.getSnapshot().getElement()) if (et.hasFixed() && et.getFixed() instanceof UriType && ((UriType) et.getFixed()).asStringValue().equals(parts[1]))
ex = et;
check(ex != null, sd, ed.getPath() + ": target profile '" + pt + "' is not valid (inner path not found)");
}
} else
check((page.getWorkerContext().hasResource(StructureDefinition.class, pt)) || isStringPattern(tail(pt)), sd, ed.getPath() + ": target profile '" + pt + "' is not valid (d)");
}
}
}
use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project kindling by HL7.
the class CDAGenerator method checkType.
private void checkType(TypeRefComponent t) {
String id = t.getWorkingCode();
if (Utilities.existsInList(id, "string", "Element", "code", "boolean", "Resource"))
return;
for (StructureDefinition sd : structures) {
if (sd.getId().equals(fix(id)))
return;
}
if (id.equals("http://hl7.org/fhir/cda/StructureDefinition/PN") || id.equals("http://hl7.org/fhir/cda/StructureDefinition/ON"))
t.setCode("http://hl7.org/fhir/cda/StructureDefinition/EN");
else if (id.equals("NARRATIVE"))
t.setCode("xhtml");
else
System.out.println("Unknown data type " + id);
}
use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project kindling by HL7.
the class TypeParser method convert.
public List<TypeRefComponent> convert(IWorkerContext context, String path, List<TypeRef> types, boolean resource, ElementDefinition ed) throws Exception {
List<TypeRefComponent> list = new ArrayList<TypeRefComponent>();
for (TypeRef t : types) {
// Expand any Resource(A|B|C) references
if (t.hasParams() && !("Reference".equals(t.getName()) || "canonical".equals(t.getName()))) {
throw new Exception("Only resource references can specify parameters. Path " + path);
}
if (t.getParams().size() > 0) {
if (t.getProfile() != null && t.getParams().size() != 1) {
throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types. Path " + path);
}
if (t.getProfile() != null) {
TypeRefComponent childType = getTypeComponent(list, t.getName());
if (t.getVersioning() != null)
childType.setVersioning(t.getVersioning());
if (t.getName().equals("Reference") || t.getName().equals("canonical"))
childType.addTargetProfile(t.getProfile());
else
childType.addProfile(t.getProfile());
} else
for (String param : t.getParams()) {
TypeRefComponent childType = getTypeComponent(list, t.getName());
if (t.getVersioning() != null)
childType.setVersioning(t.getVersioning());
String p = "Any".equals(param) ? "Resource" : param;
if (t.getName().equals("Reference") || t.getName().equals("canonical"))
childType.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
else
childType.addProfile("http://hl7.org/fhir/StructureDefinition/" + p);
}
} else if (t.isWildcardType()) {
// this list is filled out manually because it may be running before the types referred to have been loaded
for (String n : TypesUtilities.wildcardTypes(version)) {
TypeRefComponent tc = new TypeRefComponent().setCode(n);
if (t.getVersioning() != null)
tc.setVersioning(t.getVersioning());
list.add(tc);
}
} else if (Utilities.noString(t.getName()) && t.getProfile() != null) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, t.getProfile());
TypeRefComponent tc = getTypeComponent(list, sd != null ? sd.getType() : t.getName());
if (t.getVersioning() != null)
tc.setVersioning(t.getVersioning());
if (t.getName().equals("Reference"))
tc.addTargetProfile(t.getProfile());
else
tc.addProfile(t.getProfile());
} else if (t.getName().startsWith("=")) {
if (resource)
list.add(new TypeRefComponent().setCode("BackboneElement"));
else
list.add(new TypeRefComponent().setCode("Element"));
ToolingExtensions.addStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", t.getName().substring(1));
} else {
StructureDefinition sd = context.fetchTypeDefinition(t.getName());
if (sd == null)
throw new Exception("Unknown type '" + t.getName() + "'");
TypeRefComponent tc = getTypeComponent(list, sd.getType());
if (t.getVersioning() != null)
tc.setVersioning(t.getVersioning());
if (t.getName().equals("Reference")) {
if (t.hasProfile())
tc.addTargetProfile(t.getProfile());
} else if (t.hasProfile())
tc.addProfile(t.getProfile());
}
}
// no duplicates
for (TypeRefComponent tr1 : list) {
for (TypeRefComponent tr2 : list) {
if (tr1 != tr2) {
if (tr1.getWorkingCode().equals(tr2.getWorkingCode()))
throw new Exception("duplicate code " + tr1.getWorkingCode());
}
}
}
return list;
}
use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project kindling by HL7.
the class SpreadSheetReloader method parseType.
private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
ed.getType().clear();
ed.setContentReferenceElement(null);
if (ed.getPath().equals("Resource.id")) {
ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
} else {
if (Utilities.noString(value)) {
if (ed.getPath().contains(".")) {
ed.addType().setCode("BackboneElement");
}
} else if (value.startsWith("#")) {
ed.setContentReference(value);
} else {
List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
for (TypeRef tr : tl) {
TypeRefComponent t = ed.addType().setCode(tr.getName());
if ("SimpleQuantity".equals(t.getCode())) {
t.setCode("Quantity");
t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
}
for (String p : tr.getParams()) {
if (p.equals("Definition")) {
t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
} else {
t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
}
}
if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
}
}
}
}
}
use of org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent in project kindling by HL7.
the class SpreadSheetCreator method type.
private String type(ElementDefinition ed) {
if (ed.hasContentReference()) {
return ed.getContentReference();
}
List<String> tl = new ArrayList<>();
for (TypeRefComponent tr : ed.getType()) {
String s;
if (tr.getCode().equals("canonical") && tr.hasExtension(BuildExtensions.EXT_PATTERN)) {
s = "canonical(" + tr.getExtensionString(BuildExtensions.EXT_PATTERN).substring(40) + ")";
} else {
s = summary(tr);
if (s == null) {
return null;
}
}
tl.add(s);
}
return String.join(" | ", tl);
}
Aggregations