private string SaveRefillEncounterData(string nodeJson, int ptn_pk, int visitPK, int locationId, int userId)
        {
            string       result      = string.Empty;
            ResponseType ObjResponse = new ResponseType();

            try
            {
                HIVCE.Common.Entities.RefillEncounterDB obj = SerializerUtil.ConverToObject <HIVCE.Common.Entities.RefillEncounterDB>(nodeJson);
                IClinicalEncounter clinicalencounter        = (IClinicalEncounter)ObjectFactory.CreateInstance("HIVCE.BusinessLayer.BLClinicalEncounter, HIVCE.BusinessLayer");
                obj.Ptn_pk     = ptn_pk;
                obj.Visit_Id   = visitPK;
                obj.LocationId = locationId;

                bool flag = clinicalencounter.SaveRefillEncounterData(obj, userId, locationId);
                if (flag)
                {
                    ObjResponse.Success = EnumUtil.GetEnumDescription(Success.True);
                }
                else
                {
                    ObjResponse.Success = EnumUtil.GetEnumDescription(Success.False);
                }

                try
                {
                    IinitialFollowupVisit tbscreenManager = (IinitialFollowupVisit)ObjectFactory.CreateInstance("BusinessProcess.Clinical.BInitialFollowupVisit, BusinessProcess.Clinical");
                    tbscreenManager.SaveTBScreeningDetails(ptn_pk, visitPK, null, Convert.ToInt32(ddlTBFindings.SelectedItem.Value), locationId, userId);
                }
                catch { }
            }
            catch (Exception ex)
            {
                if (ex.Message.ToLower().Contains("visit already exists"))
                {
                    ObjResponse.ErrorMessage = ex.Message;
                }
                ObjResponse.Success = EnumUtil.GetEnumDescription(Success.False);
            }
            finally
            {
            }

            result = SerializerUtil.ConverToJson <ResponseType>(ObjResponse);
            return(result);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int PatientId  = 0;
            int visitPK    = 0;
            int locationId = 0;
            int userId     = 0;

            if (!IsPostBack)
            {
                if (Session["AppLocation"] == null || Session.Count == 0 || Session["AppUserID"].ToString() == "")
                {
                    Response.Redirect("~/frmlogin.aspx", true);
                }

                if (!object.Equals(Session["PatientId"], null))
                {
                    PatientId = Convert.ToInt32(Session["PatientId"]);
                    if (PatientId == 0)
                    {
                        Response.Redirect("~/ClinicalForms/frmPatient_Home.aspx", true);
                    }
                    this.hidPID.Value = PatientId.ToString();
                }

                if (!object.Equals(Session["PatientVisitId"], null))
                {
                    if (!object.Equals(Request.QueryString["add"], null))
                    {
                        if (Request.QueryString["add"].ToString() == "0")
                        {
                            visitPK = 0;
                            Session["PatientVisitId"] = "0";
                        }
                    }
                    else
                    {
                        visitPK = Convert.ToInt32(Session["PatientVisitId"]);
                    }
                }
                else
                {
                    if (!object.Equals(Request.QueryString["add"], null))
                    {
                        if (Request.QueryString["add"].ToString() == "0")
                        {
                            visitPK = 0;
                        }
                    }
                }
                this.hidVId.Value = visitPK.ToString();

                if (!object.Equals(Session["AppLocationId"], null))
                {
                    locationId = Convert.ToInt32(Session["AppLocationId"]);
                }
                if (!object.Equals(Session["AppUserId"], null))
                {
                    userId = Convert.ToInt32(Session["AppUserId"]);
                }
                if (!object.Equals(Session["PatientSex"], null))
                {
                    this.hidGender.Value = Session["PatientSex"].ToString();
                }
                if (!object.Equals(Session["PatientAge"], null))
                {
                    this.hidDOB.Value = Session["PatientAge"].ToString();
                }
                if (!object.Equals(Session["patientageinyearmonth"], null))
                {
                    this.hidPAYM.Value = Session["patientageinyearmonth"].ToString();
                }
                if (!object.Equals(Session["TechnicalAreaName"], null))
                {
                    this.hidsrvNm.Value = Session["TechnicalAreaName"].ToString();
                }
                if (!object.Equals(Session["TechnicalAreaId"], null))
                {
                    this.hidMOD.Value = Session["TechnicalAreaId"].ToString();
                }

                //TB Assesment
                //------------------------------------------------------------------------------------
                DataSet theDS = new DataSet();
                theDS.ReadXml(MapPath("..\\XMLFiles\\ALLMasters.con"));
                DataView      theDVDecode = new DataView();
                DataTable     theDTCode   = new DataTable();
                BindFunctions BindManager = new BindFunctions();
                IQCareUtils   theUtils    = new IQCareUtils();

                //TB Assesment Outcome
                theDVDecode           = new DataView(theDS.Tables["mst_pmtctdecode"]);
                theDVDecode.RowFilter = "CodeName='TBAssessmentoutcome' and (DeleteFlag = 0 or DeleteFlag IS NULL) and SystemId in(0,1)";
                theDVDecode.Sort      = "SRNo desc";
                if (theDVDecode.Table != null)
                {
                    theDTCode = (DataTable)theUtils.CreateTableFromDataView(theDVDecode);
                    BindManager.BindCheckedList(cblTBAssesment, theDTCode, "Name", "ID");
                }

                //TB Findings
                theDVDecode           = new DataView(theDS.Tables["mst_Decode"]);
                theDVDecode.RowFilter = "DeleteFlag=0 and CodeName='TBFindings' and Name not in('Other')";
                if (theDVDecode.Table != null)
                {
                    theDTCode = (DataTable)theUtils.CreateTableFromDataView(theDVDecode);
                    BindManager.BindCombo(ddlTBFindings, theDTCode, "Name", "Id");
                }
                //------------------------------------------------------------------------------------


                if (!object.Equals(Request.QueryString["data"], null))
                {
                    string response = string.Empty;


                    if (Session["AppLocation"] == null || Session.Count == 0 || Session["AppUserID"].ToString() == "")
                    {
                        CLogger.WriteLog(ELogLevel.ERROR, "Session expired!!");

                        ResponseType responsetype =
                            new ResponseType()
                        {
                            Success      = EnumUtil.GetEnumDescription(Success.False),
                            ErrorMessage = "Session expired"
                        };
                        response = SerializerUtil.ConverToJson <ResponseType>(responsetype);
                        SendResponse(response);
                    }
                    if (Request.QueryString["data"].ToString() == "getdata")
                    {
                        response = GetRefillEncounter(Convert.ToInt32(PatientId), visitPK, locationId);
                        SendResponse(response);

                        IinitialFollowupVisit tbscreenManager = (IinitialFollowupVisit)ObjectFactory.CreateInstance("BusinessProcess.Clinical.BInitialFollowupVisit, BusinessProcess.Clinical");
                        DataSet tbscreenDS = tbscreenManager.GetTBScreeningData(visitPK);
                        ddlTBFindings.SelectedValue = tbscreenDS.Tables[0].Rows[0]["TBFindings"].ToString();
                    }
                    if (Request.QueryString["data"].ToString() == "getzscore")
                    {
                        response = GetZScoreDetails(Convert.ToInt32(PatientId), visitPK, locationId);
                        SendResponse(response);
                    }
                    if (Request.QueryString["data"].ToString() == "saverefillencounter")
                    {
                        System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream);
                        string jsonString         = "";
                        jsonString = sr.ReadToEnd();

                        response = SaveRefillEncounterData(jsonString, PatientId, visitPK, locationId, userId);
                        SendResponse(response);
                    }
                }
            }
        }