简体   繁体   中英

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

<?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

i need to map the element in Xml to a different key in 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.

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.

Your JSON tool might have a way of parsing and traversing the whole JSON object recursively.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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