Sidebar

How can I convert all low and high dates in a cda to UTC format?

0 votes
273 views
asked Mar 20, 2019 by brandon-w-8204 (30,600 points)

1 Answer

0 votes

Here is a script to convert all low and high dates in a cda to a UTC format


function setDateTimeToUtc(dateToConvert) {
   var deducedDate = qie.deduceDate(dateToConvert);
   qie.debug('deducedDate: ' + deducedDate);
   var date = new java.util.Date(deducedDate.getTime());
   var utc_format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm");
   utc_format.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
   return utc_format.format(date);
}
var parameterMap = qie.newParameterMap();
var lowDates = message.getAllNodes('//low/@value');
for (var lowDate = 0; lowDate < lowDates.length; lowDate++) {
   var orginalDate= lowDates[lowDate];
   
   if (parameterMap.get('orginalDate') === null) {
      //value is not in parameterMap
      parameterMap.put(orginalDate, 'processed');
      qie.debug('orginalDate[' + lowDate + ']: ' + orginalDate);
      var utcDate = qie.formatDate("yyyyMMdd'T'HHmmssSSS'Z'", setDateTimeToUtc(orginalDate));
      if (StringUtils.isNotBlank(utcDate)) {
         message.setNode('//low[@value=\'' + orginalDate + '\']/@value', utcDate);
      }
   }
}

parameterMap = qie.newParameterMap();
var highDates = message.getAllNodes('//high/@value');
for (var highDate = 0; highDate < highDates.length; highDate++) {
   var orginalHighDate= highDates[highDate];
   
   if (parameterMap.get('orginalDate') === null) {
      //value is not in parameterMap
      parameterMap.put(orginalHighDate, 'processed');
      qie.debug('orginalDate[' + highDate + ']: ' + orginalHighDate);
      var utcHighDate = qie.formatDate("yyyyMMdd'T'HHmmssSSS'Z'", setDateTimeToUtc(orginalHighDate));
      if (StringUtils.isNotBlank(utcHighDate)) {
         message.setNode('//high[@value=\'' + orginalHighDate + '\']/@value', utcHighDate);
      }
   }
}

answered Mar 20, 2019 by brandon-w-8204 (30,600 points)
...