Question
· May 1

Parsing a JSON message with

I have the JSON message below. I am struggling with parsing the data in the OtherProcedures section. That section can be null, or have from one to many other procedures. Any help is greatly appreciated. I have tried using/setting an iterator to go thru the data but not having any success with that. 

{
    "Action": "1",
    "CaseNumber": "",
    "MessageId": "",
    "ControlId": "",
    "Patient": "idz",
    "DateOfOperation": "20240401",
    "PrimarySurgeon": "you",
    "AttendingSurgeon": "me",
    "SurgicalSpecialty": "12",
    "PrincipalOperativeProcedure": "Ingenuial Hernia Repair",
    "PrincipalPreOperativeDiagnosis": "Hernia Surgery",
    "LateralityOfProcedure": "2",
    "PlannedAdmissionStatus": "I",
    "PlannedPrincipalProcedureCode": "29848",
    "ICD10Code": "K40.00",
    "HospitalAdmissionStatus": "I",
    "MajorOrMinor": "J",
    "CaseScheduleType": "EL",
    "Palliation": "Y",
    "PlannedPostOpCare": "PACU for 4 hrs",
    "RequestAnesthesiaTechnique": "S",
    "intraoperativeXRays": "Y",
    "ReferringPhysician": "mine",
    "ConsultId": "692",
    "Scheduler": "scheduler",
    "OtherProcedures": [
        {
            "otherProcedure": "Liposuction",
            "plannedOtherProcCPTCode": "15772",
            "otherProcedureCodeComments": "Adding a second procedure."
        },
        {
            "otherProcedure": "colonoscopy",
            "plannedOtherProcCPTCode": "44389",
            "otherProcedureCodeComments": "Adding a third procedure."
        }
    ]
}

Product version: IRIS 2022.1
$ZV: IRIS for Windows (x86-64) 2021.1.2 (Build 338U) Tue Apr 12 2022 12:04:03 EDT
Discussion (5)2
Log in or sign up to continue

Sorry, got pulled away before I finished the post to add my code. This code is a REST API. The pInput is the JSON message in the original post. this code does write out the key and type but I need to get the values for each procedure. Not sure how to get that data. 

ClassMethod fileSurgery1(pInput As REST.SwitchLane.Periopt.SurgeryData, Output pOutput As %String) As %Status

    #Dim obj As %DynamicAbstractObject

    s obj =pInput.OtherProcedures

    s iterator = obj.%GetIterator()

    while iterator.%GetNext(.key, .value)

    {

        set type = obj.%GetTypeOf(key)

        write !,"key= ",key,!,"Type= ",type

    }

    q 200

OtherProcedures is a dynamic abstract object. I parse it out of the main JSON message. In the class definition for the JSON message:

Property OtherProcedures As list Of OtherProcedures;

Class REST.SwitchLane.Periopt.OtherProcedures Extends (%JSON.Adaptor, %Persistent)

{

Property OtherProcedure As %String;

Property PlannedOtherProcCPTCode As %String;

Property ProcedureCodeComments As %String;

}

got it to work, but there might be a better solution, if so, please comment

ClassMethod EditSurgery() As %Status
{
    S EditData={}.%FromJSON(%request.Content)
    w !,EditData.SurgeryCase,!
    #Dim otherProc As %DynamicObject
    s otherProc=EditData.OtherProcedures
    s iterator=otherProc.%GetIterator()
    while iterator.%GetNext(.key, .OtherProcedure) {
        set type = otherProc.%GetTypeOf(key)
        s name=otherProc.%Get(key).OtherProcedure
        s cpt=otherProc.%Get(key).PlannedOtherProcCPTCode
        s comment=otherProc.%Get(key).ProcedureCodeComments
        w !," name= ",name," cpt= ",cpt," comments= ",comment
    }

    q 200
}