Skip to content

Commit 9c8fc92

Browse files
committed
address some review comments
1 parent 6d05b2d commit 9c8fc92

1 file changed

Lines changed: 46 additions & 23 deletions

File tree

openehr-rm/src/main/java/com/nedap/archie/rminfo/UpdatedValueHandler.java

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,60 @@ public static Map<String, Object> pathHasBeenUpdated(Object rmObject, Archetype
4949

5050
private static Map<String, Object> fixDvQuantity(Object rmObject, Archetype archetype, String pathOfParent) {
5151
try {
52-
Map<String, Object> result = new HashMap<>();
53-
54-
RMPathQuery rmPathQuery = new RMPathQuery(pathOfParent);
55-
DvQuantity quantity = rmPathQuery.find(ArchieRMInfoLookup.getInstance(), rmObject);
52+
// TODO Check for magnitude?
53+
// TODO Check if this fix actually needs to occur
54+
return fixForMagnitude(rmObject, (OperationalTemplate) archetype, pathOfParent);
55+
} catch (Exception e) {
56+
logger.warn("cannot fix DvQuantity", e);
57+
}
5658

57-
OperationalTemplate template = (OperationalTemplate) archetype;
59+
return new HashMap<>();
60+
}
5861

59-
CAttribute units = template.getDefinition().itemAtPath(pathOfParent + "/units");
60-
CAttribute precision = template.getDefinition().itemAtPath(pathOfParent + "/precision");
62+
private static Map<String, Object> fixForMagnitude(Object rmObject, OperationalTemplate template, String pathOfParent) {
63+
Map<String, Object> result = new HashMap<>();
6164

62-
if (units.getChildren().size() != 1 || precision.getChildren().size() != 1)
63-
return result; // Only fix if there is 1 unit and 1 precision, don't assume anything otherwise
65+
RMPathQuery rmPathQuery = new RMPathQuery(pathOfParent);
66+
DvQuantity quantity = rmPathQuery.find(ArchieRMInfoLookup.getInstance(), rmObject);
6467

65-
// Fix units
66-
CString cString = (CString) units.getChildren().get(0);
67-
String assumedUnitValue = cString.getAssumedValue();
68-
quantity.setUnits(assumedUnitValue);
69-
result.put(pathOfParent + "/units", assumedUnitValue);
68+
CAttribute units = template.getDefinition().itemAtPath(pathOfParent + "/units");
69+
CAttribute precision = template.getDefinition().itemAtPath(pathOfParent + "/precision");
7070

71-
// Fix precision
72-
CInteger cInteger = (CInteger) units.getChildren().get(0);
73-
long assumedPrecisionValue = cInteger.getAssumedValue();
74-
quantity.setPrecision(assumedPrecisionValue);
75-
result.put(pathOfParent + "/precision", assumedPrecisionValue);
71+
if (units.getChildren().size() != 1) return result; // Only fix if there is 1 unit
7672

77-
return result;
78-
} catch (Exception e) {
79-
logger.warn("cannot fix DvQuantity", e);
73+
// Fix units
74+
CString cString = (CString) units.getChildren().get(0);
75+
List<String> cStringConstraint = cString.getConstraint();
76+
if(cStringConstraint != null && cStringConstraint.size() == 1) {
77+
String constraint = cStringConstraint.get(0);
78+
if(!CString.isRegexConstraint(constraint)) {
79+
quantity.setUnits(constraint);
80+
result.put(pathOfParent + "/units", constraint);
81+
}
8082
}
8183

82-
return new HashMap<>();
84+
if (precision.getChildren().size() != 1)
85+
return result; // Only fix if there is 1 precision
86+
87+
// Fix precision
88+
CInteger cInteger = (CInteger) precision.getChildren().get(0);
89+
90+
List<Interval<Long>> cIntegerConstraint = cInteger.getConstraint();
91+
92+
if (cIntegerConstraint != null && cIntegerConstraint.size() == 1) {
93+
Interval<Long> interval = cIntegerConstraint.get(0);
94+
long value;
95+
if (interval.isUpperUnbounded()) {
96+
value = -1;
97+
} else if (interval.isUpperIncluded() && interval.getUpper() != null) {
98+
value = interval.getUpper();
99+
} else if (interval.getUpper() != null) {
100+
value = interval.getUpper() -1 ;
101+
} else throw new IllegalStateException("upper bound was not available");
102+
quantity.setPrecision(value);
103+
result.put(pathOfParent + "/precision", value);
104+
}
105+
return result;
83106
}
84107

85108
private static Map<String, Object> fixCodePhrase(Object rmObject, Archetype archetype, String pathOfParent) {

0 commit comments

Comments
 (0)