using System;
using System.Collections.Generic;
using CLIP.eForm.Consent.WebService;
using CLIP.eForm.Consent.Entity;
using System.Web.Services;

namespace CLIP.eForm.Consent.Web
{
    public partial class DoctorList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
//            srchdd = (string.IsNullOrEmpty(this.Request.Params["IO_ADdate"])) ? DateTime.Now.ToShortDateString() : this.Request.Params["IO_ADdate"];
        }
        
        [WebMethod]
        public static string SetDeptDropdown(string gubun, string dutinstcd)
        {
            CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("SetDeptDropdown : {0}", gubun));
            List<DeptListVO> resultList = null;
            string sResultJson = string.Empty;
            using (HospitalSvc svc = new HospitalSvc())
            {
                //수술,시술 선택에 따른 진료과 정보 바인딩
                resultList = svc.GetDeptList(gubun, dutinstcd);
                resultList.Remove(resultList.Find(kvp => kvp.deptCd.Trim() == ""));
                if (resultList != null)
                {
                    if (resultList != null && resultList.Count > 0)
                    {
                        sResultJson = "[";
                        int i = 0;
                        foreach (DeptListVO cVO in resultList)
                        {
                            if (i > 0) sResultJson += ",";
                            else sResultJson += "{ \"DeptListVo\":{ \"deptnm\":\"선택\",\"deptcd\":\"\"} },";
                            sResultJson += "{\"DeptListVo\":{";
                            sResultJson += "\"deptnm\":\"" + cVO.deptNm + "\",";
                            sResultJson += "\"deptcd\":\"" + cVO.deptCd + "\",";
                            sResultJson += "\"No\":\"" + (i + 1) + "\"";
                            sResultJson += "} }";
                            i++;
                        }
                        sResultJson += "]";
                    }
                }
            }
            return sResultJson;
        }


        [WebMethod]
        public static string SetDoctorList(string deptCd, string deptNm, string srchdd, string dutinstcd)
        {
            CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("SetDoctorList : deptCd[{0}]", deptCd));
            CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("SetDoctorList : deptNm[{0}]", deptNm));
            CLIP.eForm.Server.Diagnostics.LogHelper.LoggingHandler.Debug(string.Format("SetDoctorList : srchdd[{0}]", srchdd));
            List<DocListVO> resultList = null;
            string sResultJson = string.Empty;
            using (HospitalSvc svc = new HospitalSvc())
            {
                resultList = svc.GetDoctorList(srchdd.Replace("-", "").Replace("/", ""), deptCd, dutinstcd);
                if (resultList != null)
                {
                    if (resultList != null && resultList.Count > 0)
                    {
                        sResultJson = "[";
                        int i = 0;
                        foreach (DocListVO cVO in resultList)
                        {
                            if (i > 0) sResultJson += ",";
                            sResultJson += "{";
                            sResultJson += "\"doctorid\":\"" + cVO.doctorId + "\",";
                            sResultJson += "\"doctornm\":\"" + cVO.doctorNm + "\",";
                            sResultJson += "\"deptCd\":\"" + deptCd + "\",";
                            sResultJson += "\"deptNm\":\"" + deptNm + "\",";
                            sResultJson += "\"doctorkind\":\"" + cVO.doctorKind + "\",";
                            sResultJson += "\"No\":\"" + (i + 1) + "\"";
                            sResultJson += "}";
                            i++;
                        }
                        sResultJson += "]";
                    }
                }
            }
            return sResultJson;
        }
    }
}