44import com .google .common .base .Strings ;
55import com .nedap .archie .ArchieLanguageConfiguration ;
66import com .nedap .archie .aom .*;
7+ import com .nedap .archie .aom .primitives .CInteger ;
8+ import com .nedap .archie .aom .primitives .CString ;
79import com .nedap .archie .aom .primitives .CTerminologyCode ;
810import com .nedap .archie .aom .terminology .ArchetypeTerm ;
911import com .nedap .archie .aom .terminology .ArchetypeTerminology ;
1820import com .nedap .archie .rm .datatypes .CodePhrase ;
1921import com .nedap .archie .rm .datavalues .DvCodedText ;
2022import com .nedap .archie .rm .datavalues .quantity .DvOrdinal ;
23+ import com .nedap .archie .rm .datavalues .quantity .DvQuantity ;
2124import com .nedap .archie .rm .support .identification .TerminologyId ;
25+
2226import org .slf4j .Logger ;
2327import org .slf4j .LoggerFactory ;
2428
25- import javax .xml .xpath .XPathExpressionException ;
2629import java .util .HashMap ;
2730import java .util .List ;
2831import java .util .Map ;
2932
33+ import javax .xml .xpath .XPathExpressionException ;
34+
3035public class UpdatedValueHandler {
3136
3237 private static final Logger logger = LoggerFactory .getLogger (UpdatedValueHandler .class );
@@ -35,6 +40,44 @@ public static Map<String, Object> pathHasBeenUpdated(Object rmObject, Archetype
3540 if (parent instanceof CodePhrase ) {
3641 return fixCodePhrase (rmObject , archetype , pathOfParent );
3742 }
43+ if (parent instanceof DvQuantity ) {
44+ return fixDvQuantity (rmObject , archetype , pathOfParent );
45+ }
46+
47+ return new HashMap <>();
48+ }
49+
50+ private static Map <String , Object > fixDvQuantity (Object rmObject , Archetype archetype , String pathOfParent ) {
51+ try {
52+ Map <String , Object > result = new HashMap <>();
53+
54+ RMPathQuery rmPathQuery = new RMPathQuery (pathOfParent );
55+ DvQuantity quantity = rmPathQuery .find (ArchieRMInfoLookup .getInstance (), rmObject );
56+
57+ OperationalTemplate template = (OperationalTemplate ) archetype ;
58+
59+ CAttribute units = template .getDefinition ().itemAtPath (pathOfParent + "/units" );
60+ CAttribute precision = template .getDefinition ().itemAtPath (pathOfParent + "/precision" );
61+
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
64+
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 );
70+
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 );
76+
77+ return result ;
78+ } catch (Exception e ) {
79+ logger .warn ("cannot fix DvQuantity" , e );
80+ }
3881
3982 return new HashMap <>();
4083 }
0 commit comments