package com.dbs.dbsec.httpTask;

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

import com.dbs.dbsec.R;
import com.dbs.dbsec.model.CategoryVO;
import com.dbs.dbsec.model.ConsentFormListVO;
import com.dbs.dbsec.model.DeptListVO;
import com.dbs.dbsec.model.DoctorListVO;
import com.dbs.dbsec.model.PatientInfoVO;
import com.dbs.dbsec.model.PatientListVO;
import com.dbs.dbsec.model.UserLoginDeptList;
import com.dbs.dbsec.util.Common;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;

public class ParseJsonData {
  private static final String TAG = "ParseJsonData";
  private Context mContext;
  public static ParseJsonData instance;

  public ParseJsonData(Context mContext) {
    this.mContext = mContext;
  }

  public static ParseJsonData getInstance(Context mContext) {
    if (instance == null) {
      instance = new ParseJsonData(mContext);
    }

    return instance;
  }

  public ArrayList<UserLoginDeptList> userLoginDeptList(ArrayList<HashMap<String, String>> result) {
    String data = result.get(0).get("data");
    ArrayList<HashMap<String, String>> dataAr = Common.parseJSON(mContext, data);
    ArrayList<UserLoginDeptList> rts = new ArrayList<UserLoginDeptList>();
    for (int i = 0; i < dataAr.size(); i++) {
      HashMap<String, String> mm = dataAr.get(i);
      String dutplceInstCd = mm.get("dutplceInstCd");
      String dutplceInstNm = mm.get("dutplceInstNm");
      String userId        = mm.get("userId");
      String userName      = mm.get("userName");
      String jobKindCd     = mm.get("jobKindCd");
      String jobKindNm     = mm.get("jobKindNm");
      String drKind        = mm.get("drKind");
      String deptCd        = mm.get("deptCd");
      String deptHngNm     = mm.get("deptHngNm");
      String dutplceCd     = mm.get("dutplceCd");
      String indexPage     = mm.get("indexPage");
      String sortNo        = mm.get("sortNo");
      String fromDd        = mm.get("fromDd");

      rts.add(new UserLoginDeptList(dutplceInstCd, dutplceInstNm, userId, userName, jobKindCd, jobKindNm, drKind, deptCd, deptHngNm, dutplceCd, indexPage, sortNo, fromDd));
    }

    return rts;
  }

  public ArrayList<DeptListVO> getWardNDeptList(ArrayList<HashMap<String, String>> result) {
    String data = result.get(0).get("data");
    ArrayList<HashMap<String, String>> rts = Common.parseJSON(mContext, data);
    ArrayList<DeptListVO> arrayList = new ArrayList<DeptListVO>();
    for (int i = 0; i < rts.size(); i++) {
      HashMap<String, String> mm = rts.get(i);
      String deptCd = mm.get("deptCd");
      String deptNm = mm.get("deptNm");

      arrayList.add(new DeptListVO(deptCd, deptNm));
    }

    return arrayList;
  }

  public ArrayList<DoctorListVO> getDoctorList(ArrayList<HashMap<String, String>> result) {
    String data = result.get(0).get("data");
    ArrayList<HashMap<String, String>> rts = Common.parseJSON(mContext, data);
    ArrayList<DoctorListVO> arrayList = new ArrayList<DoctorListVO>();
    for (int i = 0; i < rts.size(); i++) {
      HashMap<String, String> mm = rts.get(i);
      String doctorId   = mm.get("doctorId");
      String doctorNm   = mm.get("doctorNm");
      String doctorKind = mm.get("doctorKind");
      String drKind     = mm.get("drKind");

      arrayList.add(new DoctorListVO(doctorId, doctorNm, doctorKind, drKind));
    }


    return arrayList;
  }

  public ArrayList<PatientListVO> getPatientList(ArrayList<HashMap<String, String>> result) {

    String data = result.get(0).get("data");
    ArrayList<HashMap<String, String>> rts = Common.parseJSON(mContext, data);
    ArrayList<PatientListVO> arrayList = new ArrayList<PatientListVO>();

    for (int i = 0; i < rts.size(); i++) {
      HashMap<String, String> mm = rts.get(i);
      String pid = mm.get("pid");
      String inDd = mm.get("inDd");
      String cretNo = mm.get("cretNo");
      String ordType = mm.get("ordType");
      String hngNm = mm.get("hngNm");
      String ordDeptCd = mm.get("ordDeptCd");
      String doctorId = mm.get("doctorId");
      String sexNAge = mm.get("sexNAge");
      String deptNm = mm.get("deptNm");
      String doctorNm = mm.get("doctorNm");
      String roomCd = mm.get("roomCd");
      String opRoomNm = mm.get("opRoomNm");
      String oprsrvNo = mm.get("oprsrvNo");

      arrayList.add(new PatientListVO(pid, inDd, cretNo, ordType, hngNm, ordDeptCd, doctorId, sexNAge, deptNm, doctorNm, roomCd, opRoomNm, oprsrvNo));
    }
    return arrayList;
  }

  public PatientInfoVO getPatientInfo(ArrayList<HashMap<String, String>> result) {

    String data = result.get(0).get("data");
    PatientInfoVO patientInfoVO = null;
    ArrayList<HashMap<String, String>> rts = Common.parseJSON(mContext, data);

    patientInfoVO = new PatientInfoVO();
    for (int i = 0; i < rts.size(); i++) {
      HashMap<String, String> mm = rts.get(i);

      String ordDeptCd = mm.get("ordDeptCd");
      String deptEngAbbr = mm.get("deptEngAbbr");
      String ordDeptNm = mm.get("ordDeptNm");
      String pid = mm.get("pid");
      String cretNo = mm.get("cretNo");
      String roomCd = mm.get("roomCd");
      String inDd = mm.get("inDd");
      String dschDd = mm.get("dschDd");
      String ordType = mm.get("ordType");
      String instCd = mm.get("instCd");
      String mainDrId = mm.get("mainDrId");
      String mainDrName = mm.get("mainDrName");
      String erDrNm = mm.get("erDrNm");
      String firstRgstDt = mm.get("firstRgstDt");
      String sa = mm.get("sa");
      String patientName = mm.get("patientName");
      String juminNo = mm.get("juminNo");
      String zipCdAddr = mm.get("zipCdAddr");
      String telNum = mm.get("telNum");
      String insuKind = mm.get("insuKind");
      String ward = mm.get("ward");
      String dxCd = mm.get("dxCd");
      String dxNm = mm.get("dxNm");
      String gb = mm.get("gb");
      String gbn = mm.get("gbn");
      String opDeptCd = mm.get("opDeptCd");
      String opDeptNm = mm.get("opDeptNm");
      String opDrNm = mm.get("opDrNm");
      String opDrId = mm.get("opDrId");
      String opCnfmDd = mm.get("opCnfmDd");
      String perfDrNm = mm.get("perfDrNm");
      String perfDrFlag = mm.get("perfDrFlag");
      String perfDrDept = mm.get("perfDrDept");
      String opDiagNm = mm.get("opDiagNm");
      String opNm = mm.get("opNm");
      String anstDrNm1 = mm.get("anstDrNm1");
      String anstDrFlag1 = mm.get("anstDrFlag1");
      String anstDeptNm1 = mm.get("anstDeptNm1");
      String anstDrNm2 = mm.get("anstDrNm2");
      String anstDrFlag2 = mm.get("anstDrFlag2");
      String anstDeptNm2 = mm.get("anstDeptNm2");
      String anstDrNm3 = mm.get("anstDrNm3");
      String anstDrFlag3 = mm.get("anstDrFlag3");
      String anstDeptNm3 = mm.get("anstDeptNm3");
      String opRsrvNo = mm.get("opRsrvNo");
      String orderNo = mm.get("orderNo");
      String printTime = mm.get("printTime");
      String ocrCd = mm.get("ocrCd");
      String inputId = mm.get("inputId");
      String inputNm = mm.get("inputNm");
      String signImg = mm.get("signImg");
      String bp = mm.get("bp");
      String dm = mm.get("dm");
      String heart = mm.get("heart");
      String kidney = mm.get("kidney");
      String respiration = mm.get("respiration");
      String hx = mm.get("hx");
      String allergy = mm.get("allergy");
      String drug = mm.get("drug");
      String smoking = mm.get("smoking");
      String idio = mm.get("idio");
      String nacrotics = mm.get("nacrotics");
      String airway = mm.get("airway");
      String hemorrhage = mm.get("hemorrhage");
      String statusEt = mm.get("statusEt");

      patientInfoVO.setOrdDeptCd(ordDeptCd);
      patientInfoVO.setDeptEngAbbr(deptEngAbbr);
      patientInfoVO.setOrdDeptNm(ordDeptNm);
      patientInfoVO.setPid(pid);
      patientInfoVO.setCretNo(cretNo);
      patientInfoVO.setRoomCd(roomCd);
      patientInfoVO.setInDd(inDd);
      patientInfoVO.setDschDd(dschDd);
      patientInfoVO.setOrdType(ordType);
      patientInfoVO.setInstCd(instCd);
      patientInfoVO.setMainDrId(mainDrId);
      patientInfoVO.setMainDrName(mainDrName);
      patientInfoVO.setErDrNm(erDrNm);
      patientInfoVO.setFirstRgstDt(firstRgstDt);
      patientInfoVO.setSa(sa);
      patientInfoVO.setPatientName(patientName);
      patientInfoVO.setJuminNo(juminNo);
      patientInfoVO.setZipCdAddr(zipCdAddr);
      patientInfoVO.setTelNum(telNum);
      patientInfoVO.setInsuKind(insuKind);
      patientInfoVO.setWard(ward);
      patientInfoVO.setDxCd(dxCd);
      patientInfoVO.setDxNm(dxNm);
      patientInfoVO.setGb(gb);
      patientInfoVO.setGbn(gbn);
      patientInfoVO.setOpDeptCd(opDeptCd);
      patientInfoVO.setOpDeptNm(opDeptNm);
      patientInfoVO.setOpDrNm(opDrNm);
      patientInfoVO.setOpDrId(opDrId);
      patientInfoVO.setOpCnfmDd(opCnfmDd);
      patientInfoVO.setPerfDrNm(perfDrNm);
      patientInfoVO.setPerfDrFlag(perfDrFlag);
      patientInfoVO.setPerfDrDept(perfDrDept);
      patientInfoVO.setOpDiagNm(opDiagNm);
      patientInfoVO.setOpNm(opNm);
      patientInfoVO.setAnstDrNm1(anstDrNm1);
      patientInfoVO.setAnstDrFlag1(anstDrFlag1);
      patientInfoVO.setAnstDeptNm1(anstDeptNm1);
      patientInfoVO.setAnstDrNm2(anstDrNm2);
      patientInfoVO.setAnstDrFlag2(anstDrFlag2);
      patientInfoVO.setAnstDeptNm2(anstDeptNm2);
      patientInfoVO.setAnstDrNm3(anstDrNm3);
      patientInfoVO.setAnstDrFlag3(anstDrFlag3);
      patientInfoVO.setAnstDeptNm3(anstDeptNm3);
      patientInfoVO.setOpRsrvNo(opRsrvNo);
      patientInfoVO.setOrderNo(orderNo);
      patientInfoVO.setPrintTime(printTime);
      patientInfoVO.setOcrCd(ocrCd);
      patientInfoVO.setInputId(inputId);
      patientInfoVO.setInputNm(inputNm);
      patientInfoVO.setSignImg(signImg);
      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.setStatusEt(statusEt);
    }
    return patientInfoVO;
  }

  public ArrayList<CategoryVO> getCategoryList(ArrayList<HashMap<String, String>> result) {
    String data = result.get(0).get("data");
    ArrayList<HashMap<String, String>> rts = Common.parseJSON(mContext, data);
    ArrayList<CategoryVO> arrayList = new ArrayList<CategoryVO>();

    for (int i = 0; i < rts.size(); i++) {
      HashMap<String, String> mm = rts.get(i);
      String categoryId = mm.get("categoryId");
      String categoryCode = mm.get("categoryCode");
      String parentCategoryId = mm.get("parentCategoryId");
      String categoryName = mm.get("categoryName");

      arrayList.add(new CategoryVO(categoryId, categoryCode, parentCategoryId, categoryName));
    }
    return arrayList;
  }

  public ArrayList<ConsentFormListVO> getConsentFormList(ArrayList<HashMap<String, String>> result) {
    String data = result.get(0).get("data");
    ArrayList<HashMap<String, String>> rts = Common.parseJSON(mContext, data);
    ArrayList<ConsentFormListVO> arrayList = new ArrayList<ConsentFormListVO>();

    for (int i = 0; i < rts.size(); i++) {
      HashMap<String, String> mm = rts.get(i);

      String idx = mm.get("idx");
      String formId = mm.get("formId");
      String formCode = mm.get("formCode");
      String formName = mm.get("formName");
      String formPrntNm = mm.get("formPrntNm");
      String printCnt = mm.get("printCnt");
      String certPass = mm.get("certPass");
      String pid = mm.get("pid");
      String deptEngAggr = mm.get("deptEngAggr");
      String consentState = mm.get("consentState");
      String consentMstRid = mm.get("consentMstRid");
      String ocrTag = mm.get("ocrTag");
      String modifyUserId = mm.get("modifyUserId");
      String modifyUserNm = mm.get("modifyUserNm");
      String modifyDateTime = mm.get("modifyDateTime");
      String create_dateTime = mm.get("create_dateTime");
      String clnDate = mm.get("clnDate");
      String cretNo = mm.get("cretNo");
      String ordType = mm.get("ordType");
      String deptCd = mm.get("deptCd");
      String mainDrId = mm.get("mainDrId");
      String patientName = mm.get("patientName");

      arrayList.add(new ConsentFormListVO(idx, formId, formCode, formName, formPrntNm, printCnt, certPass, pid, deptEngAggr, consentState, consentMstRid, ocrTag, modifyUserId, modifyUserNm, modifyDateTime, create_dateTime, clnDate, cretNo, ordType, deptCd, mainDrId, patientName));
    }
    return arrayList;
  }

}
