use of org.hl7.fhir.r4.model.Observation in project kindling by HL7.
the class PageProcessor method generateToc.
private String generateToc() throws Exception {
// return breadCrumbManager.makeToc();
List<String> entries = new ArrayList<String>();
entries.addAll(toc.keySet());
Collections.sort(entries, new SectionSorter());
Set<String> pages = new HashSet<String>();
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(folders.dstDir, false, true);
TableModel model = gen.new TableModel("toc", true);
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Table of Contents", "Table of Contents", null, 0));
Deque<TocItem> stack = new ArrayDeque<TocItem>();
for (String s : entries) {
TocEntry t = toc.get(s);
if (!t.isIg() && !s.startsWith("?")) {
String nd = s;
while (nd.endsWith(".0")) nd = nd.substring(0, nd.length() - 2);
int d = Utilities.charCount(nd, '.');
if (d < 4 && !pages.contains(t.getLink())) {
String np = getNormativePackageForPage(t.getLink());
pages.add(t.getLink());
while (!stack.isEmpty() && stack.getFirst().depth >= d) stack.pop();
Row row = gen.new Row();
row.setIcon("icon_page.gif", null);
String td = t.getText();
if (!stack.isEmpty()) {
if (td.startsWith(stack.getFirst().entry.getText() + " - "))
td = td.substring(stack.getFirst().entry.getText().length() + 3);
else if (td.startsWith(stack.getFirst().entry.getText()))
td = td.substring(stack.getFirst().entry.getText().length());
}
Cell cell = gen.new Cell(null, t.getLink(), nd + " " + td, t.getText() + " ", null);
row.getCells().add(cell);
if (np != null) {
cell.addPiece(gen.new Piece(null, " ", null));
cell.addPiece(gen.new Piece("versions.html#std-process", "basic".equals(np) ? "(Normative)" : "(Normative / " + Utilities.capitalize(np) + ")", null).addStyle("color: #008000"));
if (np.equals("infrastructure"))
row.setIcon("icon_page_n_i.gif", null);
else if (np.equals("conformance"))
row.setIcon("icon_page_n_c.gif", null);
else if (np.equals("patient"))
row.setIcon("icon_page_n_p.gif", null);
else if (np.equals("observation"))
row.setIcon("icon_page_n_o.gif", null);
else
row.setIcon("icon_page_n.gif", null);
} else {
cell.addPiece(gen.new Piece(null, " ", null));
cell.addPiece(gen.new Piece("versions.html#std-process", "(Trial Use)", null).addStyle("color: #b3b3b3"));
}
if (stack.isEmpty())
model.getRows().add(row);
else
stack.getFirst().row.getSubRows().add(row);
stack.push(new TocItem(t, row, d));
}
}
}
return new XhtmlComposer(XhtmlComposer.HTML).compose(gen.generate(model, "", 0, null));
}
use of org.hl7.fhir.r4.model.Observation in project kindling by HL7.
the class PageProcessor method profileDictionaryLink.
private String profileDictionaryLink(ConstraintStructure profile) {
String uri = ToolingExtensions.readStringExtension(profile.getResource(), "http://hl7.org/fhir/StructureDefinition/datadictionary");
if (Utilities.noString(uri))
return "<!-- no uri -->";
Dictionary dict = definitions.getDictionaries().get(uri);
if (dict == null)
return "<p>This profile specifies that the value of the " + profile.getResource().getSnapshot().getElement().get(0).getPath() + " resource must be a valid Observation as defined in the data dictionary (Unknown? - " + uri + ").</p>";
else
return "<p>This profile specifies that the value of the " + profile.getResource().getSnapshot().getElement().get(0).getPath() + " resource must be a valid Observation as defined in the data dictionary <a href=\"" + uri + ".html\">" + dict.getName() + "</a>.</p>";
}
use of org.hl7.fhir.r4.model.Observation in project kindling by HL7.
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];
String baseType = XMLUtil.getNamedChild(XMLUtil.getNamedChild(adl, "definition"), "rm_type_name").getTextContent();
if (!baseType.equals("OBSERVATION"))
return;
// load texts from ontology
List<Element> set = new ArrayList<Element>();
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);
}
// create structure definition
StructureDefinition sd = new StructureDefinition();
sd.setId("netha-" + id);
sd.setUrl("http://hl7.org/fhir/StructureDefinition/" + sd.getId());
sd.setKind(StructureDefinitionKind.LOGICAL);
populateMetadata(set, sd);
// load data and protocol
Element definition = XMLUtil.getNamedChild(adl, "definition");
NodeTreeEntry root = new NodeTreeEntry();
root.typeName = XMLUtil.getNamedChild(definition, "rm_type_name").getTextContent();
root.atCode = XMLUtil.getNamedChild(definition, "node_id").getTextContent();
root.name = generateToken(root.atCode, true);
sd.setName(root.name);
root.cardinality = 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.atCode, root, attributes);
}
dumpChildren("", root);
genElements(sd, root.name, root);
// save
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(dest), sd);
System.out.println("done. saved as " + dest);
}
use of org.hl7.fhir.r4.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7EncounterFHIRConversionTest method testEncounterReferencesObservationAndDiagnosis.
/**
* Testing Encounter correctly references Observation AND Diagnosis when both are present.
*/
@Test
void testEncounterReferencesObservationAndDiagnosis() throws IOException {
String hl7message = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.6|\n" + "PID|||1234^^^^MR||DOE^JANE^|||F|||||||||||||||||||||\n" + "PV1|1|O|Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||\n" + "OBX|1|SN|24467-3^CD3+CD4+ (T4 helper) cells [#/volume] in Blood^LN||=^440|{Cells}/uL^cells per microliter^UCUM|649-1346 cells/mcL|L|||F\r" + "DG1|1|ICD10|^Ovarian Cancer|||||||||||||||||||||\r";
String json = ftv.convert(hl7message, OPTIONS);
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
assertThat(obsResource).hasSize(1);
List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
assertThat(encounterResource).hasSize(1);
Encounter enc = (Encounter) encounterResource.get(0);
List<Reference> reasonRefs = enc.getReasonReference();
assertEquals(2, reasonRefs.size());
// Guess at the order of the references
Reference refObservation = reasonRefs.get(0);
Reference refCondition = reasonRefs.get(1);
// If guessed wrong, reverse them
if (!refObservation.getReference().contains("Observation")) {
refObservation = reasonRefs.get(1);
refCondition = reasonRefs.get(0);
}
assertTrue(refObservation.getReference().contains("Observation"));
assertTrue(refCondition.getReference().contains("Condition"));
}
use of org.hl7.fhir.r4.model.Observation in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_content_test.
@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_content_test(String segment) {
String documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||TEXT||||201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + // Next three lines create an attachment
"OBX|1|TX|||ECHOCARDIOGRAPHIC REPORT||||||F|||202101010000|||\n" + "OBX|2|TX|||NORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH||||||F|||202101010000|||\n" + "OBX|3|TX|||HYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%||||||F|||202101010000|||\n";
DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
DocumentReference.DocumentReferenceContentComponent content = report.getContentFirstRep();
// Future TXA.3, currently always defaults to text/plain
assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
// TXA.7 date
assertThat(content.getAttachment().getCreationElement().toString()).containsPattern("2018-01-18T03:46:00");
assertThat(content.getAttachment().hasData()).isTrue();
String decodedData = new String(Base64.getDecoder().decode(content.getAttachment().getDataElement().getValueAsString()));
assertThat(decodedData).isEqualTo("ECHOCARDIOGRAPHIC REPORT\nNORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH\nHYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%");
// TODO: Determine if we need to look at anything other than OBX.2 when it is TX
// Leave this test in place as a reminder
documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1||||||201801180346||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + // TODO: find better code for this test which is to see that OBX.2 is the fallback.
"OBX|1|SN|||||||||F";
report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
content = report.getContentFirstRep();
// Because the OBX is not TX, the content is put in an Observation
// FHIR requires a Content element, so only a minimal one is created.
// Future OBX.2 is the backup for content type, but currently always defaults to text/plain
assertThat(content.getAttachment().hasContentType()).isTrue();
// Currently always defaults to text/plain
assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
// TXA.7 date
assertThat(content.getAttachment().getCreationElement().toString()).containsPattern("2018-01-18T03:46:00");
assertThat(content.getAttachment().hasData()).isFalse();
// Test that content is created even if TXA.7 is empty
documentReferenceMessage = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + // Ensure that empty TXA.7 still works
"TXA|1||||||||<PHYSID1>||||||||||AV|||<PHYSID2>||\n" + "OBX|1|SN|||||||||F";
report = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
content = report.getContentFirstRep();
// Because the OBX is not TX, the content is put in an Observation
// FHIR requires a Content element, so only a minimal one is created.
// Currently always defaults to text/plain
assertThat(content.getAttachment().hasContentType()).isTrue();
// Currently always defaults to text/plain, even if not data for content
assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
// No TXA.7 date
assertThat(content.getAttachment().hasCreationElement()).isFalse();
assertThat(content.getAttachment().hasData()).isFalse();
}
Aggregations