在 mirth connect 中将本地时间的 hl7 日期时间转换为 UTC 的 iso 日期
In mirth connect convert hl7 datetime in local time to iso date in UTC
我有以下代码解析 HL7 2.1 消息中的字段,它将其转换为 JSON 对象以便在 Logstash/ElasticSearch/Kibana 中进一步处理 我的问题是如何正确解析日期时间从 HL7 本地时间到变压器中的 UTC ISO8691 日期时间的戳记。我已经包含了变压器的全部代码。
ConvertToISODate 函数是一种简单地创建 ISO 日期时间字符串的 hack,但它不会将其转换为我需要的 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);
我知道这不是您要找的答案,但这可能会有所帮助:
在 Mirth 中编写 JavaScript 代码时,您可以使用任何 JAVA class:
//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);
这就是我最后做的事情:
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 时间字符串。
我有以下代码解析 HL7 2.1 消息中的字段,它将其转换为 JSON 对象以便在 Logstash/ElasticSearch/Kibana 中进一步处理 我的问题是如何正确解析日期时间从 HL7 本地时间到变压器中的 UTC ISO8691 日期时间的戳记。我已经包含了变压器的全部代码。
ConvertToISODate 函数是一种简单地创建 ISO 日期时间字符串的 hack,但它不会将其转换为我需要的 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);
我知道这不是您要找的答案,但这可能会有所帮助: 在 Mirth 中编写 JavaScript 代码时,您可以使用任何 JAVA class:
//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);
这就是我最后做的事情:
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 时间字符串。