简体   繁体   English

将H7消息转换为Json

[英]Converting Hl7 message to Json

i need to convert the HL7 message to JSON so i used Hapi to convert the message to xml and then used a JSON library to convert the xml to JSON,The output for xml is 我需要将HL7消息转换为JSON,所以我使用了Hapi将消息转换为xml,然后使用JSON库将xml转换为JSON,xml的输出为

<?xml version="1.0" encoding="UTF-8"?>
<ADT_A01 xmlns="urn:hl7-org:v2xml">
    <MSH>
        <MSH.1>|</MSH.1>
        <MSH.2>^~\&amp;</MSH.2>
        <MSH.3>
            <HD.1>7EDIT</HD.1>
        </MSH.3>
        <MSH.4>
            <HD.1>7EDIT.COM</HD.1>
        </MSH.4>
        <MSH.5>
            <HD.1>IS</HD.1>
        </MSH.5>
        <MSH.6>
            <HD.1>FACILITY</HD.1>
        </MSH.6>
        <MSH.7>20150721160705</MSH.7>
        <MSH.8>S</MSH.8>
        <MSH.9>
            <MSG.1>ADT</MSG.1>
            <MSG.2>A01</MSG.2>
        </MSH.9>
        <MSH.10>MSG00001</MSH.10>
        <MSH.11>
            <PT.1>P</PT.1>
        </MSH.11>
        <MSH.12>
            <VID.1>2.6</VID.1>
        </MSH.12>
        <MSH.13>1</MSH.13>
        <MSH.14>ST</MSH.14>
        <MSH.15>AL</MSH.15>
        <MSH.16>AL</MSH.16>
        <MSH.17>972</MSH.17>
        <MSH.18>WINDOWS-1252</MSH.18>
    </MSH>
    <EVN>
        <EVN.1>A01</EVN.1>
        <EVN.2>20150721160852</EVN.2>
        <EVN.3>20150721160854</EVN.3>
        <EVN.4>01</EVN.4>
        <EVN.5>
            <XCN.1>st</XCN.1>
        </EVN.5>
        <EVN.6>20150721160917</EVN.6>
        <EVN.7>
            <HD.1>IS</HD.1>
        </EVN.7>
    </EVN>
    <PID>
        <PID.1>1</PID.1>
        <PID.2>
            <CX.1>ST</CX.1>
            <CX.4>
                <HD.1>IS</HD.1>
            </CX.4>
        </PID.2>
        <PID.3>
            <CX.1>12345</CX.1>
        </PID.3>
        <PID.5>
            <XPN.1>
                <FN.1>JOSEPH</FN.1>
            </XPN.1>
        </PID.5>
    </PID>
    <PV1>
        <PV1.2>B</PV1.2>
        <PV1.3>
            <PL.1>IS</PL.1>
        </PV1.3>
        <PV1.4>A</PV1.4>
        <PV1.5>
            <CX.1>S</CX.1>
        </PV1.5>
        <PV1.6>
            <PL.1>S2</PL.1>
        </PV1.6>
        <PV1.7>
            <XCN.1>REALM</XCN.1>
        </PV1.7>
        <PV1.8>
            <XCN.1>HANNAH</XCN.1>
        </PV1.8>
        <PV1.9>
            <XCN.1>DOCTOR</XCN.1>
        </PV1.9>
        <PV1.10>SUR</PV1.10>
        <PV1.11>
            <PL.1>PC</PL.1>
        </PV1.11>
        <PV1.12>S</PV1.12>
        <PV1.13>R</PV1.13>
        <PV1.14>7</PV1.14>
        <PV1.15>A0</PV1.15>
        <PV1.16>IN</PV1.16>
        <PV1.17>
            <XCN.1>NUMBER</XCN.1>
        </PV1.17>
        <PV1.18>AM</PV1.18>
        <PV1.19>
            <CX.1>NUM</CX.1>
        </PV1.19>
        <PV1.20>
            <FC.1>FC</FC.1>
        </PV1.20>
        <PV1.21>PR</PV1.21>
        <PV1.22>S</PV1.22>
        <PV1.23>SS</PV1.23>
        <PV1.24>S</PV1.24>
    </PV1>
</ADT_A01>

Here the output is like segmenName.FieldName (MSH.1),so the Json is also the same ,instead of segmenName.FieldName ,i need to give a meanigful name to each field, i am unable to figure out how to do this 这里的输出类似于segmenName.FieldName(MSH.1),因此Json也相同,而不是segmenName.FieldName,我需要给每个字段起一个卑鄙的名字,我无法弄清楚该怎么做

i need to map the element in Xml to a different key in JSON 我需要将Xml中的元素映射到JSON中的其他键

One way of doing this is to have a mapping of fields/names, and traverse all your JSON looking for fields on the mapping, when a field is found, change it's name to the correspondent name in the mapping. 一种方法是对字段/名称进行映射,并遍历所有JSON以查找映射上的字段,当找到字段时,将其名称更改为映射中的对应名称。

You might not be able to change the JSON you are traversing, in that case, the traverse should be cloning the structure, creating JSON nodes with the correspondent names. 您可能无法更改要遍历的JSON,在这种情况下,遍历应该是克隆结构,并使用对应的名称创建JSON节点。

Your JSON tool might have a way of parsing and traversing the whole JSON object recursively. 您的JSON工具可能具有递归解析和遍历整个JSON对象的方式。

Another way is that you implement the XML-JSON conversion (it is really simple to do), and include the "name mapping" step into that conversion. 另一种方法是实现XML-JSON转换(这确实很简单),并将“名称映射”步骤包括在该转换中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM