use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class Analyser method getAbstractChildren.
private List<ElementDefinition> getAbstractChildren(StructureDefinition structure) {
if (!structure.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-interface")) {
return new ArrayList<>();
}
List<ElementDefinition> res = new ArrayList<>();
StructureDefinition sdb = definitions.getStructures().get(structure.getBaseDefinition());
res.addAll(getAbstractChildren(sdb));
res.addAll(filterChildren(new ProfileUtilities(null, null, null).getChildList(structure, structure.getSnapshot().getElementFirstRep())));
return res;
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class Analyser method analyse.
public Analysis analyse(StructureDefinition sd) throws Exception {
Analysis res = new Analysis(definitions, sd);
if (VersionUtilities.isR4BVer(version)) {
res.setAncestor(definitions.getStructures().get(getR4bAncestor(sd)));
} else {
res.setAncestor(definitions.getStructures().get(sd.getBaseDefinition()));
}
res.setAbstract(sd.getAbstract());
res.setInterface(sd.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-interface"));
res.setClassName(sd.getName().equals("List") ? "ListResource" : sd.getName());
TypeInfo type = new TypeInfo();
type.setName(res.getClassName());
if (res.getAncestor() != null) {
type.setAncestorName(res.getAncestor().getName());
}
res.getTypes().put(type.getName(), type);
res.setRootType(type);
sd.setUserData("java.type.info", type);
type.setDefn(sd.getSnapshot().getElementFirstRep());
type.setChildren(filterChildren(new ProfileUtilities(null, null, null).getChildList(sd, type.getDefn())));
if (res.getAncestor() != null) {
type.setInheritedChildren(getAbstractChildren(res.getAncestor()));
}
for (ElementDefinition e : type.getChildren()) {
scanNestedTypes(res, type, type.getName(), e);
}
if (sd.getKind() == StructureDefinitionKind.RESOURCE) {
res.setSearchParams(getSearchParams(sd.getName()));
}
for (ElementDefinition e : type.getChildren()) {
String nn = e.getUserString("java.type");
if (nn.startsWith("@")) {
ElementDefinition er = getElementForPath(sd, nn.substring(1));
if (!er.hasUserData("java.type")) {
throw new Exception("not found: " + er);
}
String nnn = er.getUserString("java.type");
e.setUserData("java.type", nnn);
e.setUserData("java.type.info", er.getUserData("java.type.info"));
}
}
return res;
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class Analyser method scanNestedTypes.
private void scanNestedTypes(Analysis analysis, TypeInfo type, String path, ElementDefinition e) throws Exception {
String tn = null;
if (e.typeSummary().equals("code") && e.hasBinding()) {
ElementDefinitionBindingComponent cd = e.getBinding();
if (isEnum(cd)) {
ValueSet vs = definitions.getValuesets().get(cd.getValueSet());
if (vs != null) {
tn = getCodeListType(vs.getName());
EnumInfo ei = analysis.getEnums().get(tn);
if (ei == null) {
ei = new EnumInfo(tn);
analysis.getEnums().put(tn, ei);
ei.setValueSet(vs);
}
if (tn.equals("SubscriptionStatus")) {
// work around cause there's a Resource with the same name
tn = "org.hl7.fhir.r4b.model.Enumerations." + tn;
}
e.setUserData("java.type", "Enumeration<" + tn + ">");
e.setUserData("java.enum", ei);
}
}
}
if (tn == null) {
if (e.getType().size() > 0 && !e.hasContentReference() && (!Utilities.existsInList(e.getType().get(0).getCode(), "Element", "BackboneElement"))) {
tn = getTypeName(e);
if (e.typeSummary().equals("xml:lang"))
tn = "CodeType";
if (e.typeSummary().equals("xhtml"))
tn = "XhtmlNode";
else if (e.getType().size() > 1)
tn = "DataType";
else if (definitions.hasPrimitiveType(tn))
tn = upFirst(tn) + "Type";
e.setUserData("java.type", tn);
} else {
if (e.hasContentReference()) {
ElementDefinition er = getElementForPath(analysis.getStructure(), e.getContentReference().substring(1));
tn = er.getUserString("java.type");
if (Utilities.noString(tn)) {
// have to resolve this later
e.setUserData("java.type", "@" + er.getPath());
} else {
e.setUserData("java.type", tn);
}
} else {
String cpath;
if (e.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
tn = upFirst(e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) + "Component";
cpath = e.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name");
} else if (config.getIni().hasProperty("typenames", e.getPath())) {
tn = upFirst(config.getIni().getStringProperty("typenames", e.getPath())) + "Component";
cpath = config.getIni().getStringProperty("typenames", e.getPath());
} else {
tn = path + upFirst(getTitle(e.getName())) + "Component";
cpath = path + getTitle(e.getName());
}
if (tn.equals("Element"))
tn = "Element_";
if (analysis.getTypes().containsKey(tn)) {
char i = 'A';
while (analysis.getTypes().containsKey(tn + i)) {
i++;
}
tn = tn + i;
}
e.setUserData("java.type", tn);
tn = upFirst(tn);
TypeInfo ctype = new TypeInfo();
ctype.setName(tn);
analysis.getTypes().put(ctype.getName(), ctype);
analysis.getTypeList().add(ctype);
ctype.setDefn(e);
ctype.setAncestorName(e.typeSummary());
ctype.setChildren(filterChildren(new ProfileUtilities(null, null, null).getChildList(analysis.getStructure(), ctype.getDefn())));
for (ElementDefinition c : ctype.getChildren()) {
scanNestedTypes(analysis, ctype, cpath, c);
}
}
}
}
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method seeProfile.
private void seeProfile(String url, StructureDefinition p) throws FHIRException {
if (Utilities.noString(url))
url = p.getUrl();
if (!p.hasSnapshot()) {
if (!p.hasBase())
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") has no base and no snapshot");
StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBase());
if (sd == null)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + ") base " + p.getBase() + " could not be resolved");
List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
pu.generateSnapshot(sd, p, p.getUrl(), p.getName());
for (ValidationMessage msg : msgs) {
if (msg.getLevel() == IssueSeverity.ERROR || msg.getLevel() == IssueSeverity.FATAL)
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot: " + msg.getMessage());
}
if (!p.hasSnapshot())
throw new DefinitionException("Profile " + p.getName() + " (" + p.getUrl() + "). Error generating snapshot");
pu = null;
}
if (structures.containsKey(p.getUrl()))
throw new DefinitionException("Duplicate structures " + p.getUrl());
structures.put(p.getId(), p);
structures.put(p.getUrl(), p);
if (!p.getUrl().equals(url))
structures.put(url, p);
}
use of org.hl7.fhir.r5.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method makeTypeList.
private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
ValueSet vs = new ValueSet();
vs.setName("Type options for " + path);
vs.setDescription(vs.getName());
vs.setStatus(ConformanceResourceStatus.ACTIVE);
vs.setExpansion(new ValueSetExpansionComponent());
vs.getExpansion().setIdentifier(Factory.createUUID());
vs.getExpansion().setTimestampElement(DateTimeType.now());
for (TypeRefComponent t : types) {
ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
if (t.getCode().equals("Reference") && (t.hasProfile() && t.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))) {
cc.setCode(t.getProfile().get(0).getValue().substring(40));
cc.setSystem("http://hl7.org/fhir/resource-types");
cc.setDisplay(cc.getCode());
} else {
ProfileUtilities pu = new ProfileUtilities(context, null, null);
StructureDefinition ps = null;
if (t.hasProfile())
ps = pu.getProfile(profile, t.getProfile().get(0).getValue());
if (ps != null) {
cc.setCode(t.getProfile().get(0).getValue());
cc.setDisplay(ps.getSnapshot().getElement().get(0).getType().get(0).getCode());
cc.setSystem("http://hl7.org/fhir/resource-types");
} else {
cc.setCode(t.getCode());
cc.setDisplay(t.getCode());
cc.setSystem("http://hl7.org/fhir/data-types");
}
}
t.setUserData("text", cc.getCode());
}
return vs;
}
Aggregations