Skip to content

Commit

Permalink
add action/protocol and avoid nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
nr23730 committed Feb 27, 2024
1 parent b711a7b commit 0c4d43e
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/main/java/de/uksh/medic/etl/openehrmapper/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ public static void processAttributeChildren(String path, String name, Object jso
}
NodeList children = CACHE_NODE_LIST.get(newPath + "/rm_type_name");
for (int i = 0; i < children.getLength(); i++) {
if (children.item(i) == null) {
if (children.item(i) == null || children.item(i).getFirstChild() == null || map == null) {
System.out.print("null");
}
if (children.item(i).getFirstChild() == null) {
continue;
return;
}
String type = "gen_" + children.item(i).getFirstChild().getTextContent();
type = type.replaceAll("[^A-Za-z_]+", "_");
Expand Down Expand Up @@ -195,7 +193,7 @@ public static void gen_INSTRUCTION(String path, String name, Object jsonmap, Map
String oapActivities = path + "/attributes[rm_attribute_name=\"activities\"]";
String oapProtocol = path + "/attributes[rm_attribute_name=\"protocol\"]";
Boolean oaActivities = (Boolean) XP.evaluate(oapActivities, opt, XPathConstants.BOOLEAN);
Boolean oaProtocol = (Boolean) XP.evaluate(oapActivities, opt, XPathConstants.BOOLEAN);
Boolean oaProtocol = (Boolean) XP.evaluate(oapProtocol, opt, XPathConstants.BOOLEAN);

Instruction instruction = new Instruction();
instruction.setArchetypeDetails(new Archetyped(new ArchetypeID(paramName), "1.1.0"));
Expand Down Expand Up @@ -245,8 +243,10 @@ public static void gen_ACTIVITY(String path, String name, Object jsonmap, Map<St
public static void gen_ACTION(String path, String name, Object jsonmap, Map<String, Object> map)
throws Exception {
String paramName = getArcheTypeId(path);
String oap = path + "/attributes[rm_attribute_name=\"description\"]";
Boolean oa = (Boolean) XP.evaluate(oap, opt, XPathConstants.BOOLEAN);
String oapDescription = path + "/attributes[rm_attribute_name=\"description\"]";
String oapProtocol = path + "/attributes[rm_attribute_name=\"protocol\"]";
Boolean oaDescription = (Boolean) XP.evaluate(oapDescription, opt, XPathConstants.BOOLEAN);
Boolean oaProtocol = (Boolean) XP.evaluate(oapProtocol, opt, XPathConstants.BOOLEAN);

Action action = new Action();
action.setArchetypeDetails(new Archetyped(new ArchetypeID(paramName), "1.1.0"));
Expand All @@ -255,17 +255,21 @@ public static void gen_ACTION(String path, String name, Object jsonmap, Map<Stri
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());
IsmTransition ism = new IsmTransition();
ism.setCurrentState(
new DvCodedText("completed", new CodePhrase(new TerminologyId("openehr"), "532", "completed")));
action.setIsmTransition(ism);

if (map.containsKey(paramName)) {
action.setTime(new DvDateTime(((Map<String, List<String>>) map.get(paramName)).get("time").get(0)));
ItemTree itemTree = new ItemTree();
processAttributeChildren(oap, paramName, itemTree, (Map<String, Object>) 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) {
ItemTree description = new ItemTree();
ItemTree protocol = new ItemTree();
processAttributeChildren(oapDescription, paramName, description, (Map<String, Object>) map.get(paramName));
processAttributeChildren(oapProtocol, paramName, protocol, (Map<String, Object>) map.get(paramName));
action.setDescription(description);
action.setProtocol(protocol);

if (oaDescription || oaProtocol) {
((ArrayList<ContentItem>) jsonmap).add(action);
}
}
Expand Down Expand Up @@ -343,12 +347,15 @@ public static void gen_ELEMENT(String path, String name, Object jsonmap, Map<Str
}
String label = getLabel(nodeId, name);

((List) map.get(nodeId)).forEach(e -> {
((List<Object>) map.get(nodeId)).forEach(e -> {
Element el = new Element();
el.setArchetypeNodeId(nodeId);
el.setNameAsString(label);
Map<String, Object> mo = new HashMap<>();
mo.put(nodeId, e);
if (e instanceof Map || e instanceof List) {
return;
}
processAttributeChildren(newPath, nodeId, el, mo);
((ArrayList<Element>) jsonmap).add(el);

Expand Down Expand Up @@ -629,7 +636,7 @@ private static void deepMerge(Map<String, Object> map1, Map<String, Object> map2
}
}

@SuppressWarnings("rawtypes")
@SuppressWarnings({ "rawtypes", "unchecked" })
private static List merge(List list1, List list2) {
list2.removeAll(list1);
list1.addAll(list2);
Expand Down

0 comments on commit 0c4d43e

Please sign in to comment.