use of org.hl7.fhir.dstu2016may.model.ElementDefinition 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.dstu2016may.model.ElementDefinition in project kindling by HL7.
the class PageProcessor method parseConceptMapMapping.
private ConceptMap parseConceptMapMapping(ElementDefn logical, ElementDefinition resource, String src) throws FHIRException {
if (!src.startsWith("{map:"))
return null;
ConceptMap map = new ConceptMap();
map.setId(logical.getPath() + "2" + resource.getPath());
map.setUrl("http://hl7.org/fhir/ConceptMap/" + map.getId());
map.setVersion(version.toCode());
ConceptMapGroupComponent grp = map.addGroup();
String[] statements = src.substring(0, src.length() - 1).substring(5).split("\\;");
if (statements.length == 0)
throw new FHIRException("Unable to parse map details '" + src + "'");
for (String s : statements) {
String[] p = s.split("\\=");
if (p.length < 2)
throw new FHIRException("Unable to parse map details '" + src + "'");
if (":default".equals(p[0].trim())) {
grp.getUnmapped().setMode(ConceptMapGroupUnmappedMode.FIXED);
grp.getUnmapped().setCode(p[1].trim());
} else {
grp.addElement().setCode(p[0].trim()).addTarget().setRelationship(ConceptMapRelationship.EQUIVALENT).setCode(p[1].trim());
}
}
return map;
}
use of org.hl7.fhir.dstu2016may.model.ElementDefinition in project kindling by HL7.
the class Publisher method processProfile.
private void processProfile(Profile ap, ConstraintStructure profile, String filename, ResourceDefn baseResource) throws Exception {
// create StructureDefinition structures if needed (create differential definitions from spreadsheets)
if (profile.getResource() == null) {
StructureDefinition p = new ProfileGenerator(page.getDefinitions(), page.getWorkerContext(), page, page.getGenDate(), page.getVersion(), dataElements, fpUsages, page.getFolders().rootDir, page.getUml(), page.getRc()).generate(ap, profile, profile.getDefn(), profile.getId(), profile.getUsage(), page.getValidationErrors(), baseResource);
p.setUserData("pack", ap);
profile.setResource(p);
if (profile.getResourceInfo() != null) {
profile.getResourceInfo().setUserData(ToolResourceUtilities.RES_ACTUAL_RESOURCE, p);
}
if (page.getProfiles().has(p.getUrl()))
throw new Exception("Duplicate Profile URL " + p.getUrl());
page.getProfiles().see(p, page.packageInfo());
} else {
profile.getResource().setUserData("pack", ap);
sortProfile(profile.getResource());
for (ElementDefinition ed : profile.getResource().getDifferential().getElement()) if (!ed.hasId())
throw new Exception("Missing ID");
// special case: if the profile itself doesn't claim a date, it's date is the date of this publication
if (!profile.getResource().hasDate())
profile.getResource().setDate(page.getGenDate().getTime());
if (profile.getResource().hasBaseDefinition() && !profile.getResource().hasSnapshot()) {
// cause it probably doesn't, coming from the profile directly
StructureDefinition base = getSnapShotForProfile(profile.getResource().getBaseDefinition());
new ProfileUtilities(page.getWorkerContext(), page.getValidationErrors(), page).generateSnapshot(base, profile.getResource(), profile.getResource().getBaseDefinition().split("#")[0], "http://hl7.org/fhir", profile.getResource().getName());
}
if (page.getProfiles().has(profile.getResource().getUrl()))
throw new Exception("Duplicate Profile URL " + profile.getResource().getUrl());
System.out.println("register " + profile.getResource().getUrl());
page.getProfiles().see(profile.getResource(), page.packageInfo());
}
if (!Utilities.noString(filename))
profile.getResource().setUserData("filename", filename + ".html");
if (Utilities.noString(profile.getResource().getUserString("path"))) {
String path = "";
ImplementationGuideDefn ig = page.getDefinitions().getUsageIG(ap.getCategory(), "processProfile");
if (ig != null && !ig.isCore())
path = ig.getCode() + File.separator;
profile.getResource().setUserData("path", path + filename + ".html");
}
}
use of org.hl7.fhir.dstu2016may.model.ElementDefinition in project kindling by HL7.
the class Publisher method minifyProfile.
private void minifyProfile(StructureDefinition p) {
p.getContact().clear();
p.setDescriptionElement(null);
p.getKeyword().clear();
p.setPurposeElement(null);
p.getMapping().clear();
p.setDifferential(null);
for (ElementDefinition ed : p.getSnapshot().getElement()) {
ed.setShortElement(null);
ed.setDefinitionElement(null);
ed.setCommentElement(null);
ed.setRequirementsElement(null);
ed.getAlias().clear();
ed.setMeaningWhenMissingElement(null);
ed.getMapping().clear();
}
}
use of org.hl7.fhir.dstu2016may.model.ElementDefinition in project kindling by HL7.
the class PageProcessor method displayExtensionCardinality.
private String displayExtensionCardinality(StructureDefinition ed) {
ElementDefinition e = ed.getSnapshot().getElementFirstRep();
String m = "";
if (ed.getSnapshot().getElementFirstRep().getIsModifier())
m = " <b title=\"This is a modifier extension\">M</b>";
return Integer.toString(e.getMin()) + ".." + e.getMax() + m;
}
Aggregations