package com.dbs.mplus.fatima.httpTask;

import android.content.Context;
import android.util.Log;

import com.dbs.mplus.fatima.model.CategoryVO;
import com.dbs.mplus.fatima.model.ConsentImageListVO;
import com.dbs.mplus.fatima.model.ConsentListVO;
import com.dbs.mplus.fatima.model.ConsentSetListVO;
import com.dbs.mplus.fatima.model.ConsentWriteListVO;
import com.dbs.mplus.fatima.model.DeptListVO;
import com.dbs.mplus.fatima.model.DoctorListVO;
import com.dbs.mplus.fatima.model.PatientInfoVO;
import com.dbs.mplus.fatima.model.PatientListVO;
import com.dbs.mplus.fatima.util.ConsentConfig;
import com.dbs.mplus.fatima.util.Util;

import org.json.JSONObject;
import org.ksoap2.serialization.SoapObject;

import java.util.ArrayList;
import java.util.HashMap;

public class DataParser {
  private static final String TAG = "DataParser";
//  public static DataParser instance;
//
//  public static DataParser getInstance() {
//    if(instance == null) {
//      instance = new DataParser();
//    }
//    return instance;
//  }

  public static ArrayList<DeptListVO> getWardNDeptList(Context mContext, String result) {
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);

    ArrayList<HashMap<String, String>> rts = Util.parseJSON(mContext, res);
    ArrayList<HashMap<String, String>> arrayList = Util.parseJSON(mContext, rts.get(0).get("DeptListVO"));
    ArrayList<DeptListVO> deptListVOS = new ArrayList<DeptListVO>();

    for (int i = 0; i < arrayList.size(); i++) {
      HashMap<String, String> mm = arrayList.get(i);
      String deptCd = mm.get("deptcd").trim();
      String deptNm = mm.get("deptnm").trim();
      deptListVOS.add(new DeptListVO(deptCd, deptNm));
    }

    return deptListVOS;
  }

  public static ArrayList<DoctorListVO> getDoctorList(Context mContext, String result) {
    ArrayList<DoctorListVO> doctorListVOS = new ArrayList<DoctorListVO>();
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);
    ArrayList<HashMap<String, String>> rts1 = Util.parseJSON(mContext, res);
    ArrayList<HashMap<String, String>> rts2 = Util.parseJSON(mContext, rts1.get(0).get("DocListVO"));

    for (int i = 0; i < rts2.size(); i++) {
      HashMap<String, String> mm = rts2.get(i);
      String doctorId = mm.get("doctorid").trim();
      String doctorNm = mm.get("doctornm").trim();
      doctorListVOS.add(new DoctorListVO(doctorId, doctorNm));
    }


    return doctorListVOS;
  }

  public static ArrayList<PatientListVO> getPatientList(Context mContext, String result) {
    ArrayList<PatientListVO> arrayList = new ArrayList<PatientListVO>();
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);

    ArrayList<HashMap<String, String>> mapArrayList = Util.parseJSON(mContext, res);
    ArrayList<HashMap<String, String>> list = null;

    if (mapArrayList.size() == 0) {
      return arrayList;
    } else {
      if (mapArrayList.size() == 1) {
        HashMap<String, String> temp = mapArrayList.get(0);
        for (String key : temp.keySet()) {
          String data = temp.get(key);
          if (data.equals("")) {
            return arrayList;
          }
        }

      }
    }

    if (mapArrayList.get(0).get("PatListVO") == null) {
      list = mapArrayList;
    } else {
      list = Util.parseJSON(mContext, mapArrayList.get(0).get("PatListVO"));
    }

    if (list != null && list.size() > 0) {
      for (int i = 0; i < list.size(); i++) {
        HashMap<String, String> mm = list.get(i);
        String pid = "";
        String inDd = "";
        String cretNo = "";
        String seqNo = "";
        String instCd = "";
        String hngNm = "";
        String fSexAmFlag = "";
        String ordDeptCd = "";
        String doctorId = "";
        String hd = "";
        String sa = "";
        String deptNm = "";
        String deptEngAbbr = "";
        String doctorNm = "";
        String diagNm = "";
        String dschNoti = "";
        String roomCd = "";
        String cnst = "";
        String ordType = "";
        String boStyle = "";
        String elbulbodStat = "";
        String ordTm = "";
        String ordDrId = "";
        String ordDrNm = "";
        String ordDd = "";
        String opRoomNm = "";
        String astReqFlag = "";
        String anstDrNm = "";
        String erOrdDeptNm = "";
        String erMediSpclNm = "";
        String badCd = "";
        try {
          pid = mm.get("pid").trim();
          pid = Util.plusZero2("7", Integer.parseInt(pid));
        } catch (Exception e) {
        }
        try {
          inDd = mm.get("indd").trim();
        } catch (Exception e) {
        }
        try {
          cretNo = mm.get("cretno").trim();
        } catch (Exception e) {
        }
        try {
          seqNo = mm.get("seqno").trim();
        } catch (Exception e) {
        }
        try {
          instCd = mm.get("instcd").trim();
        } catch (Exception e) {
        }
        try {
          hngNm = mm.get("hngnm").trim();
        } catch (Exception e) {
        }
        try {
          fSexAmFlag = mm.get("fsexamflag").trim();
        } catch (Exception e) {
        }
        try {
          ordDeptCd = mm.get("orddeptcd").trim();
        } catch (Exception e) {
        }
        try {
          doctorId = mm.get("doctorid").trim();
        } catch (Exception e) {
        }
        try {
          hd = mm.get("hd").trim();
        } catch (Exception e) {
        }
        try {
          sa = mm.get("sa").trim();
        } catch (Exception e) {
        }
        try {
          deptNm = mm.get("deptnm").trim();
        } catch (Exception e) {
        }
        try {
          deptEngAbbr = mm.get("deptengabbr").trim();
        } catch (Exception e) {
        }
        try {
          doctorNm = mm.get("doctornm").trim();
        } catch (Exception e) {
        }
        try {
          diagNm = mm.get("diagnm").trim();
        } catch (Exception e) {
        }
        try {
          dschNoti = mm.get("dschnoti").trim();
        } catch (Exception e) {
        }
        try {
          roomCd = mm.get("roomcd").trim();
        } catch (Exception e) {
        }
        try {
          cnst = mm.get("cnst").trim();
        } catch (Exception e) {
        }
        try {
          ordType = mm.get("ordtype").trim();
        } catch (Exception e) {
        }
        try {
          boStyle = mm.get("bostyle").trim();
        } catch (Exception e) {
        }
        try {
          elbulbodStat = mm.get("elbulbodstat").trim();
        } catch (Exception e) {
        }
        try {
          ordTm = mm.get("ordtm").trim();
        } catch (Exception e) {
        }
        try {
          ordDrId = mm.get("orddrid").trim();
        } catch (Exception e) {
        }
        try {
          ordDrNm = mm.get("orddrnm").trim();
        } catch (Exception e) {
        }
        try {
          ordDd = mm.get("orddd").trim();
        } catch (Exception e) {
        }
        try {
          opRoomNm = mm.get("oproomnm").trim();
        } catch (Exception e) {
        }
        try {
          astReqFlag = mm.get("anstreqflag").trim();
        } catch (Exception e) {
        }
        try {
          anstDrNm = mm.get("anstdrnm").trim();
        } catch (Exception e) {
        }
        try {
          erOrdDeptNm = mm.get("erorddeptnm").trim();
        } catch (Exception e) {
        }
        try {
          erMediSpclNm = mm.get("ermedispclnm").trim();
        } catch (Exception e) {
        }
        String opCnfmDd = "";
        try {
          opCnfmDd = mm.get("opcnfmdd").trim();
        } catch (Exception e) {
        }
        try {
          badCd = mm.get("badcd").trim();
        } catch (Exception e) {
        }

        arrayList.add(new PatientListVO(pid, inDd, cretNo, seqNo, instCd, hngNm, fSexAmFlag, ordDeptCd, doctorId, hd, sa, deptNm, deptEngAbbr, doctorNm, diagNm, dschNoti, roomCd, cnst, ordType, boStyle, elbulbodStat, ordTm, ordDrId, ordDrNm, ordDd, opRoomNm, astReqFlag, anstDrNm, erOrdDeptNm, erMediSpclNm, opCnfmDd, badCd));
      }
    }

    return arrayList;
  }

  public static PatientInfoVO getPatientInfo(Context mContext, String result) {
    PatientInfoVO patientInfoVO = null;
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);

    ArrayList<HashMap<String, String>> arrayList = Util.parseJSON(mContext, res);

    String rts = arrayList.get(0).get("GetPatientInfoResult");
    if (rts != null && rts.equals("")) {
    } else {
      for (int i = 0; i < arrayList.size(); i++) {
        HashMap<String, String> mm = arrayList.get(i);
        String pid = "";
        String sa = "";
        String patientNm = "";
        String juminNo = "";
        String hosType = "";
        String ward = "";
        String roomNo = "";
        String adDate = "";
        String dschDd = "";
        String visitType = "";
        String deptCd = "";
        String deptHngNm = "";
        String deptEngNm = "";
        String opDeptCd = "";
        String opDeptNm = "";
        String opDrId = "";
        String opDrNm = "";
        String dxCd = "";
        String dxNm = "";
        String bp = "";
        String dm = "";
        String heart = "";
        String kidney = "";
        String respiration = "";
        String hx = "";
        String allergy = "";
        String drug = "";
        String smoking = "";
        String idio = "";
        String nacrotics = "";
        String airway = "";
        String hemorrhage = "";
        String statusEtc = "";
        String orderNo = "";
        String printTime = "";
        String mainDrId = "";
        String mainDrNm = "";
        String ocrCd = "";
        String inputId = "";
        String inputNm = "";
        String signImg = "";
        String cretNo = "";
        String zipCdAddr = "";
        String telNo = "";
        String insuKind = "";
        String erDrNm = "";

        try {
          pid = mm.get("IO_Pt_ID").trim();
          pid = Util.plusZero2("7", Integer.parseInt(pid));
        } catch (Exception e) {
        }
        try {
          sa = mm.get("IO_sex_age_y_m").trim();
        } catch (Exception e) {
        }
        try {
          patientNm = mm.get("IO_Pt_Name").trim();
        } catch (Exception e) {
        }
        try {
          juminNo = mm.get("IO_JuminNo").trim();
        } catch (Exception e) {
        }
        try {
          hosType = mm.get("IO_HosType").trim();
        } catch (Exception e) {
        }
        try {
          ward = mm.get("IO_Ward").trim();
        } catch (Exception e) {
        }
        try {
          roomNo = mm.get("IO_RoomNo").trim();
        } catch (Exception e) {
        }
        try {
          adDate = mm.get("IO_ADdate").trim();
        } catch (Exception e) {
        }
        try {
          dschDd = mm.get("IO_Dschdd").trim();
        } catch (Exception e) {
        }
        try {
          visitType = mm.get("IO_VisitType").trim();
        } catch (Exception e) {
        }
        try {
          deptCd = mm.get("IO_DeptCd").trim();
        } catch (Exception e) {
        }
        try {
          deptHngNm = mm.get("IO_DeptNm").trim();
        } catch (Exception e) {
        }
        try {
          deptEngNm = mm.get("IO_Dept2").trim();
        } catch (Exception e) {
        }
        try {
          opDeptCd = mm.get("IO_OPdeptCd").trim();
        } catch (Exception e) {
        }
        try {
          opDeptNm = mm.get("IO_OPdeptNm").trim();
        } catch (Exception e) {
        }
        try {
          opDrId = mm.get("IO_OPdrId").trim();
        } catch (Exception e) {
        }
        try {
          opDrNm = mm.get("IO_OPdrNm").trim();
        } catch (Exception e) {
        }
        try {
          dxCd = mm.get("IO_DxCd").trim();
        } catch (Exception e) {
        }
        try {
          dxNm = mm.get("IO_DxNm").trim();
        } catch (Exception e) {
        }
        try {
          bp = mm.get("IO_bp").trim();
        } catch (Exception e) {
        }
        try {
          dm = mm.get("IO_dm").trim();
        } catch (Exception e) {
        }
        try {
          heart = mm.get("IO_heart").trim();
        } catch (Exception e) {
        }
        try {
          kidney = mm.get("IO_kidney").trim();
        } catch (Exception e) {
        }
        try {
          respiration = mm.get("IO_respiration").trim();
        } catch (Exception e) {
        }
        try {
          hx = mm.get("IO_hx").trim();
        } catch (Exception e) {
        }
        try {
          allergy = mm.get("IO_allergy").trim();
        } catch (Exception e) {
        }
        try {
          drug = mm.get("IO_drug").trim();
        } catch (Exception e) {
        }
        try {
          smoking = mm.get("IO_smoking").trim();
        } catch (Exception e) {
        }
        try {
          idio = mm.get("IO_idio").trim();
        } catch (Exception e) {
        }
        try {
          nacrotics = mm.get("IO_nacrotics").trim();
        } catch (Exception e) {
        }
        try {
          airway = mm.get("IO_airway").trim();
        } catch (Exception e) {
        }
        try {
          hemorrhage = mm.get("IO_hemorrhage").trim();
        } catch (Exception e) {
        }
        try {
          statusEtc = mm.get("IO_status_etc").trim();
        } catch (Exception e) {
        }
        try {
          orderNo = mm.get("IO_OrderNo").trim();
        } catch (Exception e) {
        }
        try {
          printTime = mm.get("IO_PrintTime").trim();
        } catch (Exception e) {
        }
        try {
          mainDrId = mm.get("IO_MaindrId").trim();
        } catch (Exception e) {
        }
        try {
          mainDrNm = mm.get("IO_MaindrNm").trim();
        } catch (Exception e) {
        }
        try {
          ocrCd = mm.get("IO_OcrCd").trim();
        } catch (Exception e) {
        }
        try {
          inputId = mm.get("IO_InputId").trim();
        } catch (Exception e) {
        }
        try {
          inputNm = mm.get("IO_InputNm").trim();
        } catch (Exception e) {
        }
        try {
          signImg = mm.get("IO_SignImg").trim();
        } catch (Exception e) {
        }
        try {
          cretNo = mm.get("IO_CretNo").trim();
        } catch (Exception e) {
        }
        try {
          zipCdAddr = mm.get("IO_Zipcdaddr").trim();
        } catch (Exception e) {
        }
        try {
          telNo = mm.get("IO_Tel").trim();
        } catch (Exception e) {
        }
        try {
          insuKind = mm.get("IO_Insukind").trim();
        } catch (Exception e) {
        }
        try {
          erDrNm = mm.get("IO_ErdrNm").trim();
        } catch (Exception e) {
        }

        patientInfoVO = new PatientInfoVO();
        patientInfoVO.setPid(pid);
        patientInfoVO.setSa(sa);
        patientInfoVO.setPatientNm(patientNm);
        patientInfoVO.setJuminNo(juminNo);
        patientInfoVO.setHosType(hosType);
        patientInfoVO.setWard(ward);
        patientInfoVO.setRoomNo(roomNo);
        patientInfoVO.setAdDate(adDate);
        patientInfoVO.setDschDd(dschDd);
        patientInfoVO.setVisitType(visitType);
        patientInfoVO.setDeptCd(deptCd);
        patientInfoVO.setDeptHngNm(deptHngNm);
        patientInfoVO.setDeptEngNm(deptEngNm);
        patientInfoVO.setOpDeptCd(opDeptCd);
        patientInfoVO.setOpDeptNm(opDeptNm);
        patientInfoVO.setOpDrId(opDrId);
        patientInfoVO.setOpDrNm(opDrNm);
        patientInfoVO.setDxCd(dxCd);
        patientInfoVO.setDxNm(dxNm);
        patientInfoVO.setBp(bp);
        patientInfoVO.setDm(dm);
        patientInfoVO.setHeart(heart);
        patientInfoVO.setKidney(kidney);
        patientInfoVO.setRespiration(respiration);
        patientInfoVO.setHx(hx);
        patientInfoVO.setAllergy(allergy);
        patientInfoVO.setDrug(drug);
        patientInfoVO.setSmoking(smoking);
        patientInfoVO.setIdio(idio);
        patientInfoVO.setNacrotics(nacrotics);
        patientInfoVO.setAirway(airway);
        patientInfoVO.setHemorrhage(hemorrhage);
        patientInfoVO.setStatusEtc(statusEtc);
        patientInfoVO.setOrderNo(orderNo);
        patientInfoVO.setPrintTime(printTime);
        patientInfoVO.setMainDrId(mainDrId);
        patientInfoVO.setMainDrNm(mainDrNm);
        patientInfoVO.setOcrCd(ocrCd);
        patientInfoVO.setInputId(inputId);
        patientInfoVO.setInputNm(inputNm);
        patientInfoVO.setSignImg(signImg);
        patientInfoVO.setCretNo(cretNo);
        patientInfoVO.setZipCdAddr(zipCdAddr);
        patientInfoVO.setTelNo(telNo);
        patientInfoVO.setInsuKind(insuKind);
        patientInfoVO.setErDrNm(erDrNm);

        return patientInfoVO;
      }
    }

    return null;
  }

  public static ArrayList<ConsentListVO> getConsentList(Context mContext, String result) {
    ArrayList<ConsentListVO> arrayList = new ArrayList<ConsentListVO>();
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);

    ArrayList<HashMap<String, String>> mapArrayList = Util.parseJSON(mContext, res);

    String rts = "";
    ArrayList<HashMap<String, String>> list = null;
    if (mapArrayList.get(0).get("ConsentVO") == null) {
      rts = mapArrayList.get(0).get("GetConsentListResult");
      list = mapArrayList;
    } else {
      rts = mapArrayList.get(0).get("ConsentVO");
      list = Util.parseJSON(mContext, rts);
    }

//    rts = mapArrayList.get(0).get("GetConsentListResult");
    if (rts != null && rts.equals("")) {
    } else {
      for (int i = 0; i < list.size(); i++) {
        HashMap<String, String> mm = list.get(i);
        String consentMstRid = "";
        String consentStateDisp = "";
        String consentName = "";
        String hosType = "";
        String patientCode = "";
        String visitType = "";
        String orderNo = "";
        String orderCd = "";
        String orderNm = "";
        String clnDeptCd = "";
        String clnDeptNm = "";
        String ward = "";
        String roomCd = "";
        String formRid = "";
        String formCd = "";
        String formGuid = "";
        String prntCnt = "";
        String ocrNumber = "";
        String consentState = "";
        String cosignDcId = "";
        String cosignDcName = "";
        String createUserId = "";
        String createUserName = "";
        String createDateTime = "";
        String clnDate = "";
        String cretno = "";
        String ocrTagYN = "";

        try {
          consentMstRid = mm.get("ConsentMstRid").trim();
        } catch (Exception e) {
        }
        try {
          consentStateDisp = mm.get("ConsentStateDisp").trim();
        } catch (Exception e) {
        }
        try {
          consentName = mm.get("ConsentName").trim();
        } catch (Exception e) {
        }
        try {
          hosType = mm.get("HosType").trim();
        } catch (Exception e) {
        }
        try {
          patientCode = mm.get("PatientCode").trim();
        } catch (Exception e) {
        }
        try {
          visitType = mm.get("VisitType").trim();
        } catch (Exception e) {
        }
        try {
          orderNo = mm.get("orderNo").trim();
        } catch (Exception e) {
        }
        try {
          orderCd = mm.get("OrderCd").trim();
        } catch (Exception e) {
        }
        try {
          orderNm = mm.get("OrderNm").trim();
        } catch (Exception e) {
        }
        try {
          clnDeptCd = mm.get("ClnDeptCd").trim();
        } catch (Exception e) {
        }
        try {
          clnDeptNm = mm.get("ClnDeptNm").trim();
        } catch (Exception e) {
        }
        try {
          ward = mm.get("Ward").trim();
        } catch (Exception e) {
        }
        try {
          roomCd = mm.get("RoomCd").trim();
        } catch (Exception e) {
        }
        try {
          formRid = mm.get("FormRid").trim();
        } catch (Exception e) {
        }
        try {
          formCd = mm.get("FormCd").trim();
        } catch (Exception e) {
        }
        try {
          formGuid = mm.get("FormGuid").trim();
        } catch (Exception e) {
        }
        try {
          prntCnt = mm.get("PrntCnt").trim();
        } catch (Exception e) {
        }
        try {
          ocrNumber = mm.get("OcrNumber").trim();
        } catch (Exception e) {
        }
        try {
          consentState = mm.get("ConsentState").trim();
        } catch (Exception e) {
        }
        try {
          cosignDcId = mm.get("CosignDcId").trim();
        } catch (Exception e) {
        }
        try {
          cosignDcName = mm.get("CosignDcName").trim();
        } catch (Exception e) {
        }
        try {
          createUserId = mm.get("CreateUserId").trim();
        } catch (Exception e) {
        }
        try {
          createUserName = mm.get("CreateUserName").trim();
        } catch (Exception e) {
        }
        try {
          createDateTime = mm.get("CreateDateTime").trim();
        } catch (Exception e) {
        }
        try {
          clnDate = mm.get("ClnDate").trim();
        } catch (Exception e) {
        }
        try {
          cretno = mm.get("Cretno").trim();
        } catch (Exception e) {
        }
        try {
          ocrTagYN = mm.get("OcrTagYN").trim();
        } catch (Exception e) {
        }

        arrayList.add(new ConsentListVO(consentMstRid, consentStateDisp, consentName, hosType, patientCode, visitType, orderNo, orderCd, orderNm, clnDeptCd, clnDeptNm, ward, roomCd, formRid, formCd, formGuid, prntCnt, ocrNumber, consentState, cosignDcId, cosignDcName, createUserId, createUserName, createDateTime, clnDate, cretno, ocrTagYN));
      }
    }

    return arrayList;
  }

  public static ArrayList<ConsentSetListVO> getConsentSetList(Context mContext, String result, String apiType) {
    ArrayList<ConsentSetListVO> arrayList = new ArrayList<ConsentSetListVO>();
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);

    ArrayList<HashMap<String, String>> mapArrayList = Util.parseJSON(mContext, res);
    ArrayList<HashMap<String, String>> mapArrayList1 = null;

    if (mapArrayList.get(0).get("ConsentBySearchVO") != null) {
      mapArrayList1 = Util.parseJSON(mContext, mapArrayList.get(0).get("ConsentBySearchVO"));
    } else if (mapArrayList.get(0).get("ConsentSetVO") != null) {
      mapArrayList1 = Util.parseJSON(mContext, mapArrayList.get(0).get("ConsentSetVO"));
    } else if (mapArrayList.get(0).get("GetConsentSetListResult") != null) {

    } else if (mapArrayList.get(0).get("GetConsentBySearchResult") != null) {

    } else {
      mapArrayList1 = mapArrayList;
    }

//    for (String key : mapArrayList.get(0).keySet()) {
//      mapArrayList1 = Util.parseJSON(mContext, mapArrayList.get(0).get(key));
//    }

    if (mapArrayList1 == null) {
    } else {
      for (int i = 0; i < mapArrayList1.size(); i++) {
        HashMap<String, String> mm = mapArrayList1.get(i);
        String formRid = "";
        String formGuid = "";
        String formCd = "";
        String formName = "";
        String setAuth = "";
        String fullCategoryName = "";
        String prntCnt = "";
        String printOnly = "";
        String ocrTagYN = "";

        try {
          formRid = mm.get("FormRid").trim();
        } catch (Exception e) {
        }
        try {
          formGuid = mm.get("FormGuid").trim();
        } catch (Exception e) {
        }
        try {
          formCd = mm.get("FormCd").trim();
        } catch (Exception e) {
        }
        try {
          formName = mm.get("FormName").trim();
        } catch (Exception e) {
        }
        try {
          setAuth = mm.get("SetAuth").trim();
        } catch (Exception e) {
        }
        try {
          fullCategoryName = mm.get("FullCategoryName").trim();
        } catch (Exception e) {
        }
        try {
          prntCnt = mm.get("PrntCnt").trim();
        } catch (Exception e) {
        }
        try {
          printOnly = mm.get("PrintOnly").trim();
        } catch (Exception e) {
        }
        try {
          ocrTagYN = mm.get("OcrTagYN").trim();
        } catch (Exception e) {
        }

        arrayList.add(new ConsentSetListVO(formRid, formGuid, formCd, formName, setAuth, apiType.equals(ConsentConfig.GET_CONSENT_SET_LIST) ? "" : fullCategoryName, prntCnt, printOnly, ocrTagYN));
      }
    }

    return arrayList;
  }

  public static ArrayList<CategoryVO> getCategoryList(Context mContext, String result) {
    ArrayList<CategoryVO> arrayList = new ArrayList<CategoryVO>();
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);
    ArrayList<HashMap<String, String>> mapArrayList = Util.parseJSON(mContext, res);
    ArrayList<HashMap<String, String>> mapArrayList1 = null;
    for (String key : mapArrayList.get(0).keySet()) {
      mapArrayList1 = Util.parseJSON(mContext, mapArrayList.get(0).get(key));
    }

    if (mapArrayList1 == null && mapArrayList1.size() == 0) {
    } else {
      for (int i = 0; i < mapArrayList1.size(); i++) {
        HashMap<String, String> mm = mapArrayList1.get(i);

        String categoryType = "";
        String categoryId = "";
        String categoryName = "";

        try {
          categoryType = mm.get("CategoryType").trim();
        } catch (Exception e) {
        }
        try {
          categoryId = mm.get("CategoryId").trim();
        } catch (Exception e) {
        }
        try {
          categoryName = mm.get("CategoryName").trim();
        } catch (Exception e) {
        }
        
        arrayList.add(new CategoryVO(categoryType, categoryId, categoryName));
      }
    }
    return arrayList;
  }

  public static ArrayList<ConsentWriteListVO> getUnfinishedListPerDoctor(Context mContext, String result) {
    ArrayList<ConsentWriteListVO> arrayList = new ArrayList<ConsentWriteListVO>();
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);

    ArrayList<HashMap<String, String>> mapArrayList = Util.parseJSON(mContext, res);
    ArrayList<HashMap<String, String>> mapArrayList1 = null;
    for (String key : mapArrayList.get(0).keySet()) {
      mapArrayList1 = Util.parseJSON(mContext, mapArrayList.get(0).get(key));
    }

    if (mapArrayList1 == null && mapArrayList1.size() == 0) {
    } else {
      for (int i = 0; i < mapArrayList1.size(); i++) {
        HashMap<String, String> mm = mapArrayList1.get(i);

        String pid = "";
        String formCd = "";
        String formNm = "";
        String hngNm = "";
        String orderDate = "";
        String printOnly = "";
        String certTarget = "";
        String consentState = "";
        String consentMstRid = "";
        String ordDd = "";
        String ordType = "";
        String ordDeptCd = "";
        String orderNo = "";
        String orderCd = "";
        String ocrNumber = "";
        String cretNo = "";
        String createUserName = "";
        String formRid = "";
        String formGuid = "";

        try {
          pid = mm.get("pid").trim();
        } catch(Exception e){

        }
        try {
          formCd = mm.get("formcd").trim();
        } catch(Exception e){

        }
        try {
          formNm = mm.get("formnm").trim();
        } catch (Exception e) {

        }
        try {
          hngNm = mm.get("hngnm").trim();
        } catch(Exception e){

        }
        try {
          orderDate = mm.get("orderdate").trim();
        } catch(Exception e){

        }
        try {
          printOnly = mm.get("printonly").trim();
        } catch(Exception e){

        }
        try {
          certTarget = mm.get("certtarget").trim();
        } catch(Exception e){

        }
        try {
          consentState = mm.get("consentstate").trim();
        } catch(Exception e){

        }
        try {
          consentMstRid = mm.get("consentmstrid").trim();
        } catch(Exception e){

        }
        try {
          ordDd = mm.get("orddd").trim();
        } catch(Exception e){

        }
        try {
          ordType = mm.get("ordtype").trim();
        } catch(Exception e){

        }
        try {
          ordDeptCd = mm.get("orddeptcd").trim();
        } catch(Exception e){

        }
        try {
          orderNo = mm.get("orderno").trim();
        } catch(Exception e){

        }
        try {
          orderCd = mm.get("ordercd").trim();
        } catch (Exception e) {

        }
        try {
          ocrNumber = mm.get("ocrnumber").trim();
        } catch(Exception e){

        }
        try {
          cretNo = mm.get("cretno").trim();
        } catch(Exception e){

        }
        try {
          createUserName = mm.get("createusername").trim();
        } catch(Exception e){

        }
        try {
          formRid = mm.get("formrid").trim();
        } catch(Exception e){

        }
        try {
          formGuid = mm.get("formguid").trim();
        } catch(Exception e){

        }

        arrayList.add(new ConsentWriteListVO(pid, formCd, formNm, hngNm, orderDate, printOnly, certTarget, consentState, consentMstRid, ordDd, ordType, ordDeptCd, orderNo, orderCd, ocrNumber, cretNo, createUserName, formRid, formGuid));
      }
    }
    return arrayList;
  }

  public static ArrayList<ConsentImageListVO> getConsetImageList(Context mContext, String result) {
    ArrayList<ConsentImageListVO> arrayList = new ArrayList<>();
    JSONObject object = Util.xmltoJsonObject(result);
    String res = Util.xmlToJsonString(object);

    ArrayList<HashMap<String, String>> mapArrayList = Util.parseJSON(mContext, res);
    ArrayList<HashMap<String, String>> mapArrayList1 = null;

    for (String key : mapArrayList.get(0).keySet()) {
      mapArrayList1 = Util.parseJSON(mContext, mapArrayList.get(0).get(key));
    }

    if (mapArrayList1 == null && mapArrayList1.size() == 0) {
    } else {
      for (int i = 0; i < mapArrayList1.size(); i++) {
        HashMap<String, String> mm = mapArrayList1.get(i);
        
        String _consentMstRid = "";
        String _consentImageRid = "";
        String _formRid = "";
        String _imagePath = "";
        String _imageFileName = "";
        String _completeYn = "";
        String _createUserId = "";
        String _createDateTime = "";

        try {
          _consentMstRid = mm.get("ConsentMstRid").trim();
        } catch (Exception e) {
        }
        try {
          _consentImageRid = mm.get("ConsentImageRid").trim();
        } catch (Exception e) {
        }
        try {
          _formRid = mm.get("FormRid").trim();
        } catch (Exception e) {
        }
        try {
          _imagePath = mm.get("ImagePath").trim();
        } catch (Exception e) {
        }
        try {
          _imageFileName = mm.get("ImageFilename").trim();
        } catch (Exception e) {
        }
        try {
          _completeYn = mm.get("CompleteYn").trim();
        } catch (Exception e) {
        }
        try {
          _createUserId = mm.get("CreateUserId").trim();
        } catch (Exception e) {
        }
        try {
          _createDateTime = mm.get("CreateDatetime").trim();
        } catch (Exception e) {
        }

        arrayList.add(new ConsentImageListVO(_consentMstRid, _consentImageRid, _formRid, _imagePath, _imageFileName, _completeYn, _createUserId, _createDateTime));
      }
    }

    return arrayList;
  }
}
