diff --git a/src/main/java/de/uksh/medic/etl/openehrmapper/Generator.java b/src/main/java/de/uksh/medic/etl/openehrmapper/Generator.java index 6cc8cef..190a99b 100644 --- a/src/main/java/de/uksh/medic/etl/openehrmapper/Generator.java +++ b/src/main/java/de/uksh/medic/etl/openehrmapper/Generator.java @@ -7,6 +7,7 @@ import com.nedap.archie.rm.composition.ContentItem; import com.nedap.archie.rm.composition.Evaluation; import com.nedap.archie.rm.composition.Instruction; +import com.nedap.archie.rm.composition.IsmTransition; import com.nedap.archie.rm.composition.Observation; import com.nedap.archie.rm.composition.Section; import com.nedap.archie.rm.datastructures.Cluster; @@ -63,7 +64,7 @@ private void generateCache() { public static void processAttributeChildren(String path, String name, Object jsonmap, Map map) { String newPath = path + "/children"; - if (!CACHE_NODE_LIST.containsKey(path + "/rm_type_name")) { + if (!CACHE_NODE_LIST.containsKey(newPath + "/rm_type_name")) { XPathExpression expr; try { expr = XP.compile(newPath + "/rm_type_name"); @@ -98,22 +99,21 @@ public static void processAttributeChildren(String path, String name, Object jso // Navigation Class descriptions // https://specifications.openehr.org/releases/RM/latest/ehr.html#_class_descriptions_4 + @SuppressWarnings("unchecked") public static void gen_SECTION(String path, String name, Object jsonmap, Map map) throws Exception { - String nodeId = getNodeId(path); - String label = getTypeLabel(path, nodeId); - // String newPath = path + "/attributes"; + String paramName = getArcheTypeId(path); + String label = getTypeLabel(path, getNodeId(path)); + String newPath = path + "/attributes"; Section section = new Section(); - section.setArchetypeNodeId(nodeId); + section.setArchetypeNodeId(paramName); section.setNameAsString(label); + List items = new ArrayList<>(); + processAttributeChildren(newPath, paramName, items, (Map) map.get(paramName)); + section.setItems(items); - // events.setTime(new DvDateTime((String) map.get("events_time"))); - // ItemTree itemTree = new ItemTree(); - // processAttributeChildren(path, nodeId, itemTree, map); - // section.setItems(itemTree); - - // ((History) jsonmap).addEvent(events); + ((List) jsonmap).add(section); } // Entry Class descriptions @@ -224,11 +224,11 @@ public static void gen_ACTIVITY(String path, String name, Object jsonmap, Map) map.get(nodeId)); + processAttributeChildren(oap, name, itemTree, (Map) map.get(nodeId)); activity.setDescription(itemTree); if (oa) { ((ArrayList) jsonmap).add(activity); @@ -236,22 +236,34 @@ public static void gen_ACTIVITY(String path, String name, Object jsonmap, Map map) throws Exception { - String nodeId = getNodeId(path); - String label = getTypeLabel(path, nodeId); - // String newPath = path + "/attributes"; - Action action = new Action(); - action.setArchetypeNodeId(nodeId); - - action.setNameAsString(label); + String paramName = getArcheTypeId(path); + String oap = path + "/attributes[rm_attribute_name=\"description\"]"; + Boolean oa = (Boolean) XP.evaluate(oap, opt, XPathConstants.BOOLEAN); - // events.setTime(new DvDateTime((String) map.get("events_time"))); - // ItemTree itemTree = new ItemTree(); - // processAttributeChildren(path, nodeId, itemTree, map); - // section.setItems(itemTree); + Action action = new Action(); + action.setArchetypeDetails(new Archetyped(new ArchetypeID(paramName), "1.1.0")); + action.setArchetypeNodeId(paramName); + action.setNameAsString(getLabel(getNodeId(path), paramName)); + action.setLanguage(new CodePhrase(new TerminologyId("ISO_639-1"), "de")); + action.setEncoding(new CodePhrase(new TerminologyId("IANA_character-sets"), "UTF-8")); + action.setSubject(new PartySelf()); - // ((History) jsonmap).addEvent(events); + if (map.containsKey(paramName)) { + action.setTime(new DvDateTime(((Map>) map.get(paramName)).get("time").get(0))); + ItemTree itemTree = new ItemTree(); + processAttributeChildren(oap, paramName, itemTree, (Map) map.get(paramName)); + action.setDescription(itemTree); + IsmTransition ism = new IsmTransition(); + ism.setCurrentState( + new DvCodedText("completed", new CodePhrase(new TerminologyId("openehr"), "532", "completed"))); + action.setIsmTransition(ism); + if (oa) { + ((ArrayList) jsonmap).add(action); + } + } } // INSTRUCTION_DETAILS @@ -274,7 +286,6 @@ public static void gen_ITEM_TREE(String path, String name, Object jsonmap, Map items = new ArrayList(); itemTree.setItems(items); - processAttributeChildren(newPath, archeTypeId, items, map); + processAttributeChildren(newPath, name, items, map); } // Representation Class descriptions @@ -316,7 +327,7 @@ public static void gen_CLUSTER(String path, String name, Object jsonmap, cluster.setArchetypeNodeId(aNodeId); cluster.setNameAsString(label); ArrayList items = new ArrayList(); - Generator.processAttributeChildren(newPath, paramName, items, (Map) map.get(code)); + processAttributeChildren(newPath, paramName, items, (Map) map.get(code)); cluster.setItems(items); ((ArrayList) jsonmap).add(cluster); } @@ -513,8 +524,8 @@ public static void gen_DV_URI(String path, String name, Object jsonmap, // XPath Query functions private static String getLabel(String code, String archetype) throws Exception { - String path = "/template/definition/attributes[rm_attribute_name=\"content\"]//children[archetype_id/value=\"" - + archetype + "\"]/term_definitions[@code=\"" + code + "\"]/items[@id=\"text\"]"; + String path = "//archetype_id[value=\"" + archetype + "\"]/../term_definitions[@code=\"" + code + + "\"]/items[@id=\"text\"]/text()"; if (!CACHE.containsKey(path)) { XPathExpression expr = XP.compile(path); CACHE.put(path, (String) expr.evaluate(opt, XPathConstants.STRING));