Announcement

Collapse
No announcement yet.

Create JSON from HL7

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create JSON from HL7

    ]Hello Everyone,

    looking for a good way to take OBX3.1 and OBX3.2 and add them to a JSON. So basically I need to make the JSON elements based on the OBX segments. There could by any number of OBX segments..

    Example, with the following OBX segments, I would need to create the below JSON object..


    Example OBX segments:

    OBX|1|CWE|123^Text1^LN||
    OBX|2|CWE|456^Text2^LN||
    OBX|3|NM|789^Text3^LN|||

    JSON Needed:

    JSON_Elements
    [
    {
    “value1”: “Canned Comment”,
    “value2”: “123”,
    “value3”: “Text1”
    },
    {
    “value1”: “Canned Comment”,
    “value2": “456”,
    “value3”: “Text2”
    },
    {
    “value1”: “Canned Comment”,
    “value2": “789”,
    “value3”: “Text3”
    },
    ]
    Last edited by gojoshi; 12-19-2018, 04:37 AM.

  • #2
    I think the below code should give you what are looking for.

    var encountersObject = [];

    //Loop through all PV1 Seigments
    for (i=0; i < msg['PV1'].length(); i++) {
    //Build Allergies Sub Object
    encountersSubObject = {code:{}};

    //Encounters.Code Begin
    encountersSubObject.code.code = msg['PV1'][i]['PV1.2']['PV1.2.1'].toString();
    encountersSubObject.code.originalText = msg['PV1'][i]['PV1.2']['PV1.2.1'].toString();
    encountersSubObject.code.displayName = msg['PV1'][i]['PV1.2']['PV1.2.2'].toString();
    }

    Comment


    • #3
      Hey bhesler thank you for the response..

      Since there are usually multiple OBX segments, I came up with something a little different. It seems to work for me:

      var empJSON = {}


      for each (seg in msg.children()) {
      if (seg.name().toString() == "OBX") {
      if (seg['OBX.3']['OBX.3.1'].toString() == "ABC")
      {
      empJSON.username = "empJSON.username";
      empJSON.icon_url = "empJSON.icon_url";
      empJSON.text = "empJSON.text";
      }
      }
      }

      Comment


      • #4
        Not sure if your requirements changed, but this is how to solve the original question.

        Code:
        var obxJson = [];
        for each (var obx in msg.OBX) {
            obxJson.push({
                value1: 'Canned Comment',
                value2: obx['OBX.3']['OBX.3.1'].toString(),
                value3: obx['OBX.3']['OBX.3.2'].toString()
            });
        }

        Comment

        Working...
        X