use of org.hl7.fhir.r4b.model.Element in project org.hl7.fhir.core by hapifhir.
the class CountryCodesConverter method execute.
private void execute() throws ParserConfigurationException, SAXException, IOException {
Document src = load();
CodeSystem cs1 = new CodeSystem();
CodeSystem cs2 = new CodeSystem();
CodeSystem cs3 = new CodeSystem();
setMetadata(src, cs1, "iso3166", "urn:iso:std:iso:3166", "", "");
setMetadata(src, cs2, "iso3166-2", "urn:iso:std:iso:3166:-2", "Part2", " Part 2");
cs1.addProperty().setCode("canonical").setDescription("The 2 letter code that identifies the same country (so 2/3/numeric codes can be aligned)").setType(PropertyType.CODE);
cs2.addProperty().setCode("country").setDescription("The 2 letter code that identifies the country for the subdivision").setType(PropertyType.CODE);
for (Element e : XMLUtil.getNamedChildren(src.getDocumentElement(), "country")) {
System.out.println(e.getAttribute("id"));
String c2 = XMLUtil.getNamedChildText(e, "alpha-2-code");
String c3 = XMLUtil.getNamedChildText(e, "alpha-3-code");
String cN = XMLUtil.getNamedChildText(e, "numeric-code");
Element n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
if (n == null)
continue;
String name = n.getTextContent();
n = XMLUtil.getNamedChildByAttribute(e, "full-name", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "full-name-upper-case", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
if (n == null)
n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
String desc = n.getTextContent();
ConceptDefinitionComponent cc = cs1.addConcept();
cc.setCode(c2);
cc.setDisplay(name);
cc.setDefinition(desc);
poplang(e, cc);
if (c3 != null) {
cc = cs1.addConcept();
cc.setCode(c3);
cc.setDisplay(name);
cc.setDefinition(desc);
cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
poplang(e, cc);
}
if (cN != null) {
cc = cs1.addConcept();
cc.setCode(cN);
cc.setDisplay(name);
cc.setDefinition(desc);
cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
poplang(e, cc);
}
for (Element sd : XMLUtil.getNamedChildren(e, "subdivision")) {
cc = cs2.addConcept();
cc.setCode(XMLUtil.getNamedChildText(sd, "subdivision-code"));
Element l = XMLUtil.getNamedChild(sd, "subdivision-locale");
cc.setDisplay(XMLUtil.getNamedChildText(l, "subdivision-locale-name"));
cc.addProperty().setCode("country").setValue(new CodeType(c2));
}
}
cs1.setCount(cs1.getConcept().size());
cs2.setCount(cs2.getConcept().size());
throw new Error("Needs revisiting");
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166.json")), cs1);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166.json")), cs1); // format hasn't changed
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166-2.json")), cs2);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166-2.json")), cs2); // format hasn't changed
}
use of org.hl7.fhir.r4b.model.Element in project org.hl7.fhir.core by hapifhir.
the class ArgonautConverter method processMedicationsSection.
private void processMedicationsSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
scanSection("Medications", section);
ListResource list = new ListResource();
list.setId(context.getBaseId() + "-list-medications");
list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafmedicationlist");
list.setSubject(context.getSubjectRef());
list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
list.setTitle(cda.getChild(section, "title").getTextContent());
list.setStatus(ListStatus.CURRENT);
list.setMode(ListMode.SNAPSHOT);
list.setDateElement(context.getNow());
list.setSource(context.getAuthorRef());
buildNarrative(list, cda.getChild(section, "text"));
int i = 0;
for (Element c : cda.getChildren(section, "entry")) {
// allergy problem act
Element sa = cda.getChild(c, "substanceAdministration");
MedicationStatement ms = new MedicationStatement();
ms.setId(context.getBaseId() + "-medication-" + i);
ms.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/medicationstatement-daf-dafmedicationstatement");
i++;
ms.setSubject(context.getSubjectRef());
boolean found = false;
for (Element e : cda.getChildren(sa, "id")) {
Identifier id = convert.makeIdentifierFromII(e);
ms.getIdentifier().add(id);
}
if (!found) {
ms.setStatus(MedicationStatementStatus.COMPLETED);
list.addEntry().setItem(new Reference().setReference("MedicationStatement/" + ms.getId()));
// allergy observation
Element mm = cda.getChild(cda.getChild(cda.getChild(sa, "consumable"), "manufacturedProduct"), "manufacturedMaterial");
ms.setMedication(new Reference().setReference("#med"));
Medication med = new Medication();
med.setId("med");
med.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(mm, "code")), null));
ms.getContained().add(med);
Dosage dosage = ms.addDosage();
// allergy observation
Element qty = cda.getChild(sa, "doseQuantity");
try {
if (cda.getChild(qty, "low") != null) {
// todo: this is not correct?
dosage.getExtension().add(new Extension().setUrl("http://healthintersections.com.au/fhir/extensions/medication-statement-range").setValue(convert.makeRangeFromIVLPQ(qty)));
} else {
dosage.setDose(convert.makeQuantityFromPQ(qty));
}
} catch (Exception e) {
System.out.println(" invalid dose quantity '" + qty.getAttribute("value") + " " + qty.getAttribute("unit") + "' (" + e.getClass().getName() + ") in " + context.getBaseId());
}
dosage.setRoute(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(sa, "routeCode")), null));
Type t = convert.makeSomethingFromGTS(cda.getChildren(sa, "effectiveTime"));
if (t instanceof Timing) {
dosage.setTiming((Timing) t);
if (dosage.getTiming().hasRepeat() && dosage.getTiming().getRepeat().hasBounds())
ms.setEffective(dosage.getTiming().getRepeat().getBounds());
} else if (t instanceof Period)
ms.setEffective(t);
else
throw new Exception("Undecided how to handle " + t.getClass().getName());
for (Element e : cda.getChildren(sa, "author")) {
if (ms.hasInformationSource())
throw new Error("additional author discovered");
Practitioner p = processPerformer(cda, convert, context, e, "assignedAuthor", "assignedPerson");
Reference ref = new Reference().setReference("Practitioner/" + p.getId()).setDisplay(p.getUserString("display"));
ms.setInformationSource(ref);
ms.setDateAssertedElement(convert.makeDateTimeFromTS(cda.getChild(e, "time")));
}
saveResource(ms);
}
}
saveResource(list);
}
use of org.hl7.fhir.r4b.model.Element in project org.hl7.fhir.core by hapifhir.
the class ADLImporter method execute.
private void execute() throws Exception {
// load config
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
adlConfig = builder.parse(new FileInputStream(config)).getDocumentElement();
// load ADL
builder = factory.newDocumentBuilder();
adl = builder.parse(new FileInputStream(source)).getDocumentElement();
check("root", adl.getNamespaceURI(), "http://schemas.openehr.org/v1", "Wrong namespace for ADL XML");
check("root", adl.getNodeName(), "archetype", "Wrong XML for ADL XML");
check("root", XMLUtil.getNamedChild(adl, "adl_version").getTextContent(), "1.4", "unsupported ADL version");
String id = XMLUtil.getFirstChild(XMLUtil.getNamedChild(adl, "archetype_id")).getTextContent().split("\\.")[1];
// create structure definition
StructureDefinition sd = new StructureDefinition();
sd.setId(id);
// populate metadata
Element description = XMLUtil.getNamedChild(adl, "description");
Element details = XMLUtil.getNamedChild(description, "details");
sd.setDescription(XMLUtil.getNamedChild(details, "purpose").getTextContent());
sd.setCopyright(XMLUtil.getNamedChild(details, "copyright").getTextContent());
sd.setPurpose("Use:\r\n" + XMLUtil.getNamedChild(details, "use").getTextContent() + "\r\n\r\nMisuse:\r\n" + XMLUtil.getNamedChild(details, "misuse").getTextContent());
List<Element> set = new ArrayList<Element>();
XMLUtil.getNamedChildren(details, "keywords", set);
for (Element e : set) sd.addKeyword().setDisplay(e.getTextContent());
String status = XMLUtil.getNamedChild(description, "lifecycle_state").getTextContent();
if ("CommitteeDraft".equals(status) || "AuthorDraft".equals(status))
sd.setStatus(PublicationStatus.DRAFT);
else
throw new Exception("Unknown life cycle state " + XMLUtil.getNamedChild(description, "lifecycle_state").getTextContent());
// load texts from ontology
Element ontology = XMLUtil.getNamedChild(adl, "ontology");
Element term_definitions = XMLUtil.getNamedChild(ontology, "term_definitions");
set.clear();
XMLUtil.getNamedChildren(term_definitions, "items", set);
for (Element item : set) {
processTextItem(item);
}
// load data and protocol
Element definition = XMLUtil.getNamedChild(adl, "definition");
NodeTreeEntry root = new NodeTreeEntry();
root.setTypeName(XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent());
root.setAtCode(XMLUtil.getNamedChild(definition, "node_id").getTextContent());
root.setName(generateToken(root.getAtCode(), true));
sd.setName(root.getName());
root.setCardinality(readCardinality("root", XMLUtil.getNamedChild(definition, "occurrences")));
set.clear();
XMLUtil.getNamedChildren(definition, "attributes", set);
for (Element item : set) {
// we're actually skipping this level - we don't care about data protocol etc.
// XMLUtil.getNamedChild(XMLUtil.getNamedChild(item, "children"), "attributes");
Element attributes = item;
loadChildren(root.getAtCode(), root, attributes);
}
dumpChildren("", root);
genElements(sd, root.getName(), root);
// save
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
System.out.println("done. saved as " + dest);
}
use of org.hl7.fhir.r4b.model.Element 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.Element 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());
}
}
}
}
}
Aggregations