use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method filterGrandChildren.
private void filterGrandChildren(List<ElementDefinition> grandChildren, String string, PropertyWrapper prop) {
List<ElementDefinition> toRemove = new ArrayList<ElementDefinition>();
toRemove.addAll(grandChildren);
for (BaseWrapper b : prop.getValues()) {
List<ElementDefinition> list = new ArrayList<ElementDefinition>();
for (ElementDefinition ed : toRemove) {
PropertyWrapper p = b.getChildByName(tail(ed.getPath()));
if (p != null && p.hasValues())
list.add(ed);
}
toRemove.removeAll(list);
}
grandChildren.removeAll(toRemove);
}
use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generateByProfile.
private void generateByProfile(ResourceWrapper res, StructureDefinition profile, BaseWrapper e, List<ElementDefinition> allElements, ElementDefinition defn, List<ElementDefinition> children, XhtmlNode x, String path, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
if (children.isEmpty()) {
renderLeaf(res, e, defn, x, false, showCodeDetails, readDisplayHints(defn));
} else {
for (PropertyWrapper p : splitExtensions(profile, e.children())) {
if (p.hasValues()) {
ElementDefinition child = getElementDefinition(children, path + "." + p.getName(), p);
if (child != null) {
Map<String, String> displayHints = readDisplayHints(child);
if (!exemptFromRendering(child)) {
List<ElementDefinition> grandChildren = getChildrenForPath(allElements, path + "." + p.getName());
filterGrandChildren(grandChildren, path + "." + p.getName(), p);
if (p.getValues().size() > 0 && child != null) {
if (isPrimitive(child)) {
XhtmlNode para = x.addTag("p");
String name = p.getName();
if (name.endsWith("[x]"))
name = name.substring(0, name.length() - 3);
if (showCodeDetails || !isDefaultValue(displayHints, p.getValues())) {
para.addTag("b").addText(name);
para.addText(": ");
if (renderAsList(child) && p.getValues().size() > 1) {
XhtmlNode list = x.addTag("ul");
for (BaseWrapper v : p.getValues()) renderLeaf(res, v, child, list.addTag("li"), false, showCodeDetails, displayHints);
} else {
boolean first = true;
for (BaseWrapper v : p.getValues()) {
if (first)
first = false;
else
para.addText(", ");
renderLeaf(res, v, child, para, false, showCodeDetails, displayHints);
}
}
}
} else if (canDoTable(path, p, grandChildren)) {
x.addTag("h3").addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
XhtmlNode tbl = x.addTag("table").setAttribute("class", "grid");
XhtmlNode tr = tbl.addTag("tr");
// work around problem with empty table rows
tr.addTag("td").addText("-");
addColumnHeadings(tr, grandChildren);
for (BaseWrapper v : p.getValues()) {
if (v != null) {
tr = tbl.addTag("tr");
// work around problem with empty table rows
tr.addTag("td").addText("*");
addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints);
}
}
} else {
for (BaseWrapper v : p.getValues()) {
if (v != null) {
XhtmlNode bq = x.addTag("blockquote");
bq.addTag("p").addTag("b").addText(p.getName());
generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails);
}
}
}
}
}
}
}
}
}
}
use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.
the class LoincToDEConvertor method processLoincCodes.
private void processLoincCodes() {
Element row = XMLUtil.getFirstChild(xml.getDocumentElement());
int i = 0;
while (row != null) {
i++;
if (i % 1000 == 0)
System.out.print(".");
String code = col(row, "LOINC_NUM");
String comp = col(row, "COMPONENT");
DataElement de = new DataElement();
de.setId("loinc-" + code);
de.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
bundle.getEntry().add(new BundleEntryComponent().setResource(de));
Identifier id = new Identifier();
id.setSystem("http://hl7.org/fhir/commondataelement/loinc");
id.setValue(code);
de.addIdentifier(id);
de.setPublisher("Regenstrief + FHIR Project Team");
if (!col(row, "STATUS").equals("ACTIVE"))
// till we get good at this
de.setStatus(ConformanceResourceStatus.DRAFT);
else
de.setStatus(ConformanceResourceStatus.RETIRED);
de.setDateElement(DateTimeType.now());
de.setName(comp);
ElementDefinition dee = de.addElement();
// PROPERTY ignore
// TIME_ASPCT
// SYSTEM
// SCALE_TYP
// METHOD_TYP
// dee.getCategory().add(new CodeableConcept().setText(col(row, "CLASS")));
// SOURCE
// DATE_LAST_CHANGED - should be in ?
// CHNG_TYPE
dee.setComments(col(row, "COMMENTS"));
if (hasCol(row, "CONSUMER_NAME"))
dee.addAlias(col(row, "CONSUMER_NAME"));
// SURVEY_QUEST_SRC
if (hasCol(row, "RELATEDNAMES2")) {
String n = col(row, "RELATEDNAMES2");
for (String s : n.split("\\;")) {
if (!Utilities.noString(s))
dee.addAlias(s);
}
}
dee.addAlias(col(row, "SHORTNAME"));
// ORDER_OBS
// CDISC Code
// HL7_FIELD_SUBFIELD_ID
// ------------------ EXTERNAL_COPYRIGHT_NOTICE todo
dee.setDefinition(col(row, "LONG_COMMON_NAME"));
// HL7_V2_DATATYPE
String cc = makeType(col(row, "HL7_V3_DATATYPE"), code);
if (cc != null)
dee.addType().setCode(cc);
// todo... CURATED_RANGE_AND_UNITS
// todo: DOCUMENT_SECTION
// STATUS_REASON
// STATUS_TEXT
// CHANGE_REASON_PUBLIC
// COMMON_TEST_RANK
// COMMON_ORDER_RANK
// COMMON_SI_TEST_RANK
// HL7_ATTACHMENT_STRUCTURE
// units:
// UNITSREQUIRED
// SUBMITTED_UNITS
ToolingExtensions.setAllowableUnits(dee, makeUnits(col(row, "EXAMPLE_UNITS"), col(row, "EXAMPLE_UCUM_UNITS")));
// EXAMPLE_SI_UCUM_UNITS
row = XMLUtil.getNextSibling(row);
}
System.out.println("done");
}
use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method getChildTypesByName.
private void getChildTypesByName(String type, String name, TypeDetails result) throws PathEngineException, DefinitionException {
if (Utilities.noString(type))
throw new PathEngineException("No type provided in BuildToolPathEvaluator.getChildTypesByName");
if (type.equals("xhtml"))
return;
String url = null;
if (type.contains(".")) {
url = "http://hl7.org/fhir/StructureDefinition/" + type.substring(0, type.indexOf("."));
} else {
url = "http://hl7.org/fhir/StructureDefinition/" + type;
}
String tail = "";
StructureDefinition sd = worker.fetchResource(StructureDefinition.class, url);
if (sd == null)
// this really is an error, because we can only get to here if the internal infrastrucgture is wrong
throw new DefinitionException("Unknown type " + type);
List<StructureDefinition> sdl = new ArrayList<StructureDefinition>();
ElementDefinitionMatch m = null;
if (type.contains("."))
m = getElementDefinition(sd, type, false);
if (m != null && hasDataType(m.definition)) {
if (m.fixedType != null) {
StructureDefinition dt = worker.fetchTypeDefinition(m.fixedType);
if (dt == null)
throw new DefinitionException("unknown data type " + m.fixedType);
sdl.add(dt);
} else
for (TypeRefComponent t : m.definition.getType()) {
StructureDefinition dt = worker.fetchTypeDefinition(t.getCode());
if (dt == null)
throw new DefinitionException("unknown data type " + t.getCode());
sdl.add(dt);
}
} else {
sdl.add(sd);
if (type.contains("."))
tail = type.substring(type.indexOf("."));
}
for (StructureDefinition sdi : sdl) {
String path = sdi.getSnapshot().getElement().get(0).getPath() + tail + ".";
if (name.equals("**")) {
assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
if (ed.getPath().startsWith(path))
for (TypeRefComponent t : ed.getType()) {
if (t.hasCode() && t.getCodeElement().hasValue()) {
String tn = null;
if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
tn = ed.getPath();
else
tn = t.getCode();
if (t.getCode().equals("Resource")) {
for (String rn : worker.getResourceNames()) {
if (!result.hasType(worker, rn)) {
result.addType(rn);
getChildTypesByName(rn, "**", result);
}
}
} else if (!result.hasType(worker, tn)) {
result.addType(tn);
getChildTypesByName(tn, "**", result);
}
}
}
}
} else if (name.equals("*")) {
assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
if (ed.getPath().startsWith(path) && !ed.getPath().substring(path.length()).contains("."))
for (TypeRefComponent t : ed.getType()) {
if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
result.addType(ed.getPath());
else if (t.getCode().equals("Resource"))
result.addTypes(worker.getResourceNames());
else
result.addType(t.getCode());
}
}
} else {
path = sdi.getSnapshot().getElement().get(0).getPath() + tail + "." + name;
ElementDefinitionMatch ed = getElementDefinition(sdi, path, false);
if (ed != null) {
if (!Utilities.noString(ed.getFixedType()))
result.addType(ed.getFixedType());
else
for (TypeRefComponent t : ed.getDefinition().getType()) {
if (Utilities.noString(t.getCode()))
// throw new PathEngineException("Illegal reference to primitive value attribute @ "+path);
break;
if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
result.addType(path);
else if (t.getCode().equals("Resource"))
result.addTypes(worker.getResourceNames());
else
result.addType(t.getCode());
}
}
}
}
}
use of org.hl7.fhir.r4b.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeElementDefinitionTypeRefComponent.
protected void composeElementDefinitionTypeRefComponent(Complex parent, String parentType, String name, ElementDefinition.TypeRefComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeElement(t, "type", name, element, index);
if (element.hasCodeElement())
composeCode(t, "ElementDefinition", "code", element.getCodeElement(), -1);
for (int i = 0; i < element.getProfile().size(); i++) composeUri(t, "ElementDefinition", "profile", element.getProfile().get(i), i);
for (int i = 0; i < element.getAggregation().size(); i++) composeEnum(t, "ElementDefinition", "aggregation", element.getAggregation().get(i), i);
if (element.hasVersioningElement())
composeEnum(t, "ElementDefinition", "versioning", element.getVersioningElement(), -1);
}
Aggregations