我有以下代码解析HL7 2.1消息中的字段,它将其转换为JSON对象以便在Logstash / ElasticSearch / Kibana中进一步处理我的问题是如何正确地解析从HL7本地时间到日期时间戳的日期时间戳变压器中的UTCISO8691日期时间。我已经包含了变压器的整个代码。
ConvertToISODate函数是简单地创建ISO日期时间字符串的黑客,但它不会将其转换为我需要的UTC。
function ConvertToISODate(hl7Date) {
// this function will return an ISO formatted date string from the insanity that is hl7 dates
// this function is also insane but the sane ways didn't seem to work
var outdate = '';
//4 year
outdate += hl7Date.substring(0,4) + '-';
//2 month
outdate += hl7Date.substring(4,6) + '-';
//2 day
outdate += hl7Date.substring(6,8) + 'T';
//2 hour
outdate += hl7Date.substring(8,10) + ':';
//2 minute
outdate += hl7Date.substring(10,12) + ':';
//2 second assume start of minute as not precise
outdate += '00.000Z';
return outdate;
}
function Group(obrseg) {
this.seqno = obrseg['OBR.1']['OBR.1.1'].toString();
if (this.seqno == '') {
this.seqno = '1';
} else {
this.seqno = this.seqno;
}
this.reptno = obrseg['OBR.3']['OBR.3.1'].toString();
this.reqno = obrseg['OBR.3']['OBR.3.1'].toString().substr(0, 10);
this.test = obrseg['OBR.4']['OBR.4.1'].toString(); // TODO what about s/a's ?
this.groupname = obrseg['OBR.4']['OBR.4.2'].toString();
this.priority = obrseg['OBR.5']['OBR.5.1'].toString();
this.reg_dt = ConvertToISODate(obrseg['OBR.6']['OBR.6.1'].toString());
this.requester_id = obrseg['OBR.16']['OBR.16.1'].toString();
this.requester_surname = obrseg['OBR.16']['OBR.16.2'].toString();
this.requester_firstname = obrseg['OBR.16']['OBR.16.3'].toString();
this.rept_dt = ConvertToISODate(obrseg['OBR.22']['OBR.22.1'].toString());
this.status = obrseg['OBR.25']['OBR.25.1'].toString();
}
function Constit(obxseg) {
this.seqno = obxseg['OBX.1']['OBX.1.1'].toString();
if (this.seqno == '') {
this.seqno = '1';
} else {
this.seqno = this.seqno;
}
this.valtype =obxseg['OBX.2']['OBX.2.1'].toString();
this.test = obxseg['OBX.3']['OBX.3.1'].toString(); // TODO what about s/a's ?
this.testname = obxseg['OBX.3']['OBX.3.2'].toString();
this.result = obxseg['OBX.5']['OBX.5.1'].toString();
this.abn_flags = obxseg['OBX.8']['OBX.8.1'].toString();
this.status = obxseg['OBX.11']['OBX.11.1'].toString();
}
// FIXME what about NTE ???
var curGroup = null;
var lastReqno = null;
// this is the main output string
var eventOut = {};
// eventOut.obr = {};
var obrIndex = 0;
// get the orginating lab from the msh header
eventOut["originatinglab"] = msg['MSH']['MSH.4']['MSH.4.1'].toString();
eventOut.groups = [];
for each (seg in msg.children()) {
switch(seg.name().toString()) {
case "OBR":
curGroup = new Group(seg);
if (lastReqno == null || lastReqno != curGroup.reqno) {
lastReqno = curGroup.reqno;
}
// add current group to eventOut Object
eventOut["reptno"] = curGroup.reptno;
//eventOut.obr[curGroup.seqno] = curGroup;
//eventOut.obr[curGroup.seqno]["obx"] = {};
eventOut.groups[obrIndex] = curGroup;
eventOut.groups[obrIndex++]["tests"] = [];
var obxIndex = 0;
break;
case "OBX":
var constit = new Constit(seg);
//eventOut.obr[curGroup.seqno]["obx"][constit.seqno] = constit;
eventOut.groups[obrIndex - 1]["tests"][obxIndex++] = constit;
break;
default:
break; // ignore
}
}
// now to serilize the object and save to the channel map
// var eventOutString = JSON.stringify(eventOut);
json = JSON.stringify(eventOut, null); // Convert XML HL7 to json don't pretty print
// json = JSON.parse(json); // turn it back into a javascript object
// json.orignal_message = original.toString();
// json = JSON.stringify(json);
channelMap.put('xml', msg);
channelMap.put('json', json);
答案 0 :(得分:0)
我知道这不是您正在寻找的答案,但这可能会有所帮助: 在Mirth中编写JavaScript代码时,您可以使用任何JAVA类:
//get DoB
var rawDate = msg['PID']['PID.7']['PID.7.1'].toString()
var formatter = java.text.SimpleDateFormat("yyyyMMdd");
var date = formatter.parse(rawDate);
//format to MM/dd/yyyy
formatter = java.text.SimpleDateFormat("MM/dd/yyyy");
var pretty_time = formatter.format(date);
答案 1 :(得分:0)
这就是我最终做的事情:
function ConvertToISODate(hl7Date) {
// this function will return an ISO formatted date string in UTC from the insanity that is hl7 dates
// the function is now more sane
var utcDate = new Date();
utcDate.setFullYear(hl7Date.substring(0,4), hl7Date.substring(4,6)-1, hl7Date.substring(6,8));
utcDate.setHours(hl7Date.substring(8,10),hl7Date.substring(10,12),'00');
return utcDate.toISOString();
}
这似乎现在处理hl7消息中的时间戳是本地时间这一事实,但我想要一个ISO格式的UTC时间字符串。