Esempio n. 1
0
        public string GetPatientARTInitiation(int patientId)
        {
            var patientTreatmentManager = new PatientTreatmentTrackerManager();

            try
            {
                String dateARTInitiation    = null;
                var    ptnTreatmentBaseline = patientTreatmentManager.GetPatientbaselineRegimenLookup(patientId);
                if (ptnTreatmentBaseline != null && ptnTreatmentBaseline.DispensedByDate.HasValue)
                {
                    dateARTInitiation = ptnTreatmentBaseline.DispensedByDate.ToString();
                }

                return(dateARTInitiation);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var patientTransfer   = new PatientTransferInmanager();
            var patientDiagnosis  = new PatientHivDiagnosisManager();
            var patientEntryPoint = new PatientEntryPointManager();
            PatientLookupManager patientLookup = new PatientLookupManager();

            Session["TechnicalAreaId"] = 203;
            var objTransfer          = patientTransfer.GetPatientTransferIns(PatientId);
            var objDiagnosis         = patientDiagnosis.GetPatientHivDiagnosisList(PatientId);
            var objEntryPoint        = patientEntryPoint.GetPatientEntryPoints(Convert.ToInt32(Session["PatientPK"]));
            var patientDetailSummary = patientLookup.GetPatientDetailSummary(Convert.ToInt32(Session["PatientPK"]));

            if (patientDetailSummary != null)
            {
                this.ptnPk = patientDetailSummary.ptn_pk.HasValue ? patientDetailSummary.ptn_pk.Value : 0;
            }


            if (objTransfer.Count > 0)
            {
                foreach (var item in objTransfer)
                {
                    lblTransferinDate.Text     = "<h6>" + item.TransferInDate.ToString("dd-MMM-yyyy") + "</h6>";
                    lblTreatmentStartDate.Text = "<h6>" + item.TreatmentStartDate.ToString("dd-MMM-yyyy") + "</h6>";;
                    //lblTIRegimen.Text = "<h6>" + LookupLogic.GetLookupNameById(Convert.ToInt32(item.CurrentTreatment)).ToString() + "</h6>"; ;
                    lblFacilityFrom.Text = "<h6>" + item.FacilityFrom.ToString() + "</h6>";;
                }
            }
            else
            {
                lblTransferinDate.Text     = "N/A";
                lblTreatmentStartDate.Text = "N/A";
                lblTIRegimen.Text          = "N/A";
                lblFacilityFrom.Text       = "N/A";
            }

            if (objDiagnosis.Count > 0)
            {
                foreach (var item in objDiagnosis)
                {
                    if (item.HivDiagnosisDate.HasValue)
                    {
                        DateTime HivDiagnosisDate = item.HivDiagnosisDate.Value;
                        lblDateOfHivDiagnosis.Text = HivDiagnosisDate.ToString("dd-MMM-yyyy");
                    }
                    else
                    {
                        lblDateOfHivDiagnosis.Text = "Not Taken";
                    }

                    if (item.EnrollmentDate.HasValue)
                    {
                        lblDateOfEnrollment.Text = item.EnrollmentDate.Value.ToString("dd-MMM-yyyy");
                    }
                    else
                    {
                        lblDateOfEnrollment.Text = "Not Taken";
                    }

                    // lblWhoStage.Text = LookupLogic.GetLookupNameById(item.EnrollmentWhoStage).ToString();
                    //lblDateOfHivDiagnosis.Text = item.HivDiagnosisDate.ToString("dd-MMM-yyyy");
                    lblARTInitiationDate.Text = Convert.ToString(item.ArtInitiationDate);
                }
            }
            else
            {
                lblDateOfHivDiagnosis.Text = "Not Taken";
                lblDateOfEnrollment.Text   = "Not Taken";
                lblWhoStage.Text           = "Not Taken";
                lblARTInitiationDate.Text  = "Not Taken";
            }

            if (objEntryPoint.Count > 0)
            {
                foreach (var item in objEntryPoint)
                {
                    lblEntryPoint.Text = LookupLogic.GetLookupNameById(item.EntryPointId);
                }
            }
            else
            {
                lblEntryPoint.Text = "missing";
            }

            if (!IsPostBack)
            {
                ILookupManager mgr =
                    (ILookupManager)
                    ObjectFactory.CreateInstance("BusinessProcess.CCC.BLookupManager, BusinessProcess.CCC");

                List <LookupItemView> keyPopulationList = mgr.GetLookItemByGroup("PopulationType");
                if (keyPopulationList != null && keyPopulationList.Count > 0)
                {
                    bioPatientPopulation.Items.Add(new ListItem("select", "0"));
                    foreach (var item in keyPopulationList)
                    {
                        bioPatientPopulation.Items.Add(new ListItem(item.ItemDisplayName, item.ItemId.ToString()));
                    }
                }

                List <LookupCounty> ct = mgr.GetLookupCounties();

                if (ct != null && ct.Count > 0)
                {
                    smrCounty.Items.Add(new ListItem("select", "0"));
                    foreach (var item in ct)
                    {
                        smrCounty.Items.Add(new ListItem(item.CountyName, item.CountyId.ToString()));
                    }
                }

                List <LookupItemView> vw = mgr.GetGenderOptions();
                if (vw != null && vw.Count > 0)
                {
                    trtGender.Items.Add(new ListItem("select", "0"));

                    foreach (var item in vw)
                    {
                        trtGender.Items.Add(new ListItem(item.ItemName, item.ItemId.ToString()));
                    }
                }

                if (vw != null && vw.Count > 0)
                {
                    Gender.Items.Add(new ListItem("select", "0"));

                    foreach (var item in vw)
                    {
                        Gender.Items.Add(new ListItem(item.ItemName, item.ItemId.ToString()));
                    }
                }

                List <LookupItemView> keyPopList = mgr.GetLookItemByGroup("KeyPopulation");
                if (keyPopList != null && keyPopList.Count > 0)
                {
                    var    patientLookUp = new PatientLookupManager();
                    int    sex           = patientLookUp.GetPatientSexId(Convert.ToInt32(Session["PatientPK"]));
                    string gender        = LookupLogic.GetLookupNameById(sex);
                    //bioPatientKeyPopulation.Items.Add(new ListItem("select", "0"));
                    foreach (var item in keyPopList)
                    {
                        if (gender == "Female" && item.DisplayName == "Men having Sex with Men")
                        {
                        }
                        else if (gender == "Male" && item.DisplayName == "Female Sex Worker")
                        {
                        }
                        else
                        {
                            bioPatientKeyPopulation.Items.Add(new ListItem(item.ItemDisplayName, item.ItemId.ToString()));
                        }
                    }
                }

                // Get Patient Regimen Map:
                IPatientTreatmentTrackerManager patientTreatmentTrackerManager = (IPatientTreatmentTrackerManager)ObjectFactory.CreateInstance("BusinessProcess.CCC.Lookup.BPatientTreatmentTrackerManager, BusinessProcess.CCC");
                var curentRegimen = patientTreatmentTrackerManager.GetCurrentPatientRegimen(PatientId);

                if (curentRegimen != null)
                {
                    if (curentRegimen.RegimenId > 0)
                    {
                        //lblCurrentRegimen.Text = "<span class='label label-success'>" + curentRegimen.Regimen.ToString() + " started on : " + Convert.ToDateTime(curentRegimen.DispensedByDate).ToString("dd-MMM-yyyy") + "</span>";
                        lblCurrentRegimen.Text = "<span class='label label-success'>" + curentRegimen.Regimen.ToString() + " | " + Convert.ToDateTime(curentRegimen.DispensedByDate).ToString("dd-MMM-yyyy") + "</span>";
                    }
                    else
                    {
                        lblCurrentRegimen.Text = "<span class='label label-danger'>Patient NOT on ARVs</span>";
                    }
                }
                else
                {
                    lblCurrentRegimen.Text = "<span class='label label-danger'>Patient NOT on ARVs</span>";
                }

                //Get Adherance Status
                ILookupManager patientAdheLookupManager = (ILookupManager)ObjectFactory.CreateInstance("BusinessProcess.CCC.BLookupManager, BusinessProcess.CCC");
                var            adherenceList            = LookupLogic.GetLookItemByGroup("ARVAdherence");
                int            adherenceType            = 34;
                if (adherenceList.Count > 0)
                {
                    adherenceType = adherenceList[0].MasterId;
                }

                var adheranceStatus = patientAdheLookupManager.GetPatientAdherence(PatientId, adherenceType);

                if (adheranceStatus != null)
                {
                    string adheranceString = LookupLogic.GetLookupNameById(adheranceStatus.Score);
                    switch (adheranceString)
                    {
                    case "Poor":
                        lblAdheranceStatus.Text = "<span class='label label-danger'> Poor [Offer Adherence Interventions]</span>";
                        break;

                    case "Good":
                        lblAdheranceStatus.Text = "<span class='label label-success'> Good </span>";
                        break;

                    case "Fair":
                        lblAdheranceStatus.Text = "<span class='label label-warning'> Fair [Consider Adherence Intervetion]</span>";
                        break;
                    }
                }
                else
                {
                    lblAdheranceStatus.Text = "<span class='label label-danger'>Adherance Assessment Not Done</span>";
                }

                /*update Treatment Initiation for New Patients */
                if (PatientType == "New")
                {
                    var patientTreatmentManager = new PatientTreatmentTrackerManager();
                    var ptnTreatmentInitiation  = patientTreatmentManager.GetCurrentPatientRegimen(PatientId);
                    var ptnTreatmentBaseline    = patientTreatmentManager.GetPatientbaselineRegimenLookup(PatientId);
                    if (ptnTreatmentInitiation != null)
                    {
                        if (ptnTreatmentBaseline != null)
                        {
                            if (ptnTreatmentBaseline.DispensedByDate.HasValue)
                            {
                                DateTime DispensedByDate = (DateTime)ptnTreatmentBaseline.DispensedByDate;

                                lblFirstline.Text = DispensedByDate.ToString("dd-MMM-yyyy");
                                lblcohort.Text    = DispensedByDate.ToString("MMM") + "-" + DispensedByDate.Year;
                            }

                            lblRegimenName.Text = ptnTreatmentInitiation.Regimen.ToString();
                            //lblCurrentRegimen.Text = "<span class='label label-success'>" + ptnTreatmentBaseline.Regimen.ToString() + "</span>";
                            lblARTInitiationDate.Text = ptnTreatmentBaseline.CreateDate.ToString("dd-MMM-yyyy");

                            // lblRegimenName.Text = ptnTreatmentInitiation.Regimen.ToString();
                            //lblCurrentRegimen.Text = "<span class='label label-success'>" + ptnTreatmentBaseline.Regimen.ToString() + "</span>";
                            //lblARTInitiationDate.Text = ptnTreatmentBaseline.CreateDate.ToString("dd-MMM-yyyy");
                        }
                    }
                    else
                    {
                        lblDateOfARTInitiation.Text = "<span class='label'> Not dispensed</span>";
                        lblcohort.Text = "<span class='label label-danger'>N/A</span>";
                        // lblCurrentRegimen.Text = "<span class='label label-danger'>PATIENT NOT ON ARVs</span>";
                    }
                }

                // viral Load Alerts

                //PatientLabTracker vltestId = _lookupData.GetPatientLabTestId(PatientId);  //check patient has vl lab
                PatientLabTracker lastVL = _lookupData.GetPatientLastVL(PatientId);

                //if (lastVL != null)
                //{
                //    labTestId = lastVL.LabTestId;
                //}
                if (lastVL != null)
                {
                    //var labOrder = _lookupData.GetPatientCurrentviralLoadInfo(PatientId);  //get vl lab details for patient

                    //if (lastVL != null)
                    //{
                    //foreach (var item in _lookupData.GetPatientVlById(labOrder.Id))
                    //{
                    //    vlValue = item.ResultValues;
                    //}

                    // vlValue = Convert.ToDecimal(_lookupData.GetPatientVL(LabOrder.Id));
                    if (PatientType == "New")
                    {
                        //lblbaselineVL.Text = Convert.ToString(vlValue);
                        DateTime x = Convert.ToDateTime(lastVL.SampleDate);
                        lblBlDate.Text = x.ToString("dd-MMM-yyyy");
                    }
                    else
                    {
                        lblbaselineVL.Text = "<span class='label label-danger'>Not Taken</span>";
                        lblBlDate.Text     = "<span class='label label-danger'>N/A</span>";
                    }
                    if (lastVL.Results != null)
                    {
                        switch (lastVL.Results.ToLower().Trim())
                        {
                        case "pending":
                            var      pendingDueDate = Convert.ToDateTime(lastVL.SampleDate);
                            DateTime sampleDate     = Convert.ToDateTime(lastVL.SampleDate.ToString());

                            if ((DateTime.Today.Subtract(sampleDate).Days > 30))
                            {
                                lblVL.Text        = "<span class='label label-danger' > Overdue | Ordered On: " + ((DateTime)lastVL.SampleDate).ToString("dd-MMM-yyyy") + "</span>";
                                lblvlDueDate.Text = "<span class='label label-success'> " + pendingDueDate.AddMonths(6).ToString("dd-MMM-yyy") + " </span>";
                            }
                            else if ((lastVL.Results == "Pending") && (DateTime.Today.Subtract(sampleDate).Days < 30))
                            {
                                lblVL.Text        = "<span class='label label-warning'> Pending | Ordered On: " + ((DateTime)lastVL.SampleDate).ToString("dd-MMM-yyyy") + "</span>";
                                lblvlDueDate.Text = "<span class='label label-success'> " + pendingDueDate.AddMonths(6).ToString("dd-MMM-yyy") + " </span>";
                            }
                            else
                            {
                                lblVL.Text         = "<span class='label label-warning'>" + lastVL.Results + "| Date: " + ((DateTime)lastVL.SampleDate).ToString("dd-MMM-yyyy") + "</span>";
                                lblbaselineVL.Text = "<span class='label label-warning'>" + lastVL.Results + "| Date: " + ((DateTime)lastVL.SampleDate).ToString("dd-MMM-yyyy") + "</span>";
                            }
                            break;

                        case "complete":
                        case "completed":
                            if (lastVL.ResultValues >= 1000)
                            {
                                lblVL.Text        = "<span class='label label-danger'>" + lastVL.ResultValues + " copies/ml (" + Convert.ToDateTime(lastVL.SampleDate).ToString("dd-MMM-yyyy") + ")</span>";
                                lblvlDueDate.Text = "<span class='label label-success' > " + ((DateTime)lastVL.SampleDate).AddMonths(3).ToString("dd-MMM-yyyy") + "</span>";
                            }
                            else if (lastVL.ResultValues <= 50)
                            {
                                lblVL.Text        = "<span class='label label-success'> Undetectable VL (" + Convert.ToDateTime(lastVL.SampleDate).ToString("dd-MMM-yyyy") + ")</span>";
                                lblvlDueDate.Text = "<span class='label label-success' > " + ((DateTime)lastVL.SampleDate).AddMonths(12).ToString("dd-MMM-yyyy") + "</span>";
                            }
                            else
                            {
                                lblVL.Text        = "<span class='label label-success' > Complete | Results : " + lastVL.ResultValues + " copies/ml</span>";
                                lblvlDueDate.Text = "<span class='label label-success' > " + ((DateTime)lastVL.SampleDate).AddMonths(12).ToString("dd-MMM-yyyy") + "</span>";
                            }
                            break;

                        default:
                            var patientEnrollment = new PatientEnrollmentManager();
                            var enrolDate         = patientEnrollment.GetPatientEnrollmentDate(PatientId);

                            var treatmentTrackerManager = new PatientTreatmentTrackerManager();

                            var patientBaseline = treatmentTrackerManager.GetPatientbaselineRegimenLookup(PatientId);

                            DateTime today = DateTime.Today;
                            // TimeSpan difference = today.Date - enrolDate.Date;
                            TimeSpan difference = today.Date - patientBaseline.CreateDate;
                            int      days       = (int)difference.TotalDays;

                            if (patientBaseline != null)
                            {
                                if (patientBaseline.RegimenId > 0)
                                {
                                    if (days < 180)
                                    {
                                        lblvlDueDate.Text = "<span class='label label-success'>" + patientBaseline.CreateDate.AddMonths(6).ToString("dd-MMM-yyyy") + "</span>";
                                        lblVL.Text        = "<span class='label label-success fa fa-exclamation'><strong>  VL Not Requested  </strong></span>";
                                    }
                                    else
                                    {
                                        lblVL.Text        = "<span class='label label-danger'> Not Done </span>";
                                        lblvlDueDate.Text = "<span class='label label-danger'><strong> Overdue Since | " + patientBaseline.CreateDate.AddMonths(6).ToString("dd-MMM-yyyy") + " </strong></span>";
                                    }
                                }
                                else
                                {
                                    lblVL.Text        = "<span class='label label-danger'> Not Available </span>";
                                    lblvlDueDate.Text = "<span class='label label-danger'><strong> unknown </strong></span>";
                                }
                            }
                            else
                            {
                                lblVL.Text        = "<span class='label label-danger'> Not Done </span>";
                                lblvlDueDate.Text = "<span class='label label-danger'><strong>  Overdue Since | " + patientBaseline.CreateDate.AddMonths(6).ToString("dd-MMM-yyyy") + " </strong></span>";
                            }


                            break;
                        }
                    }
                    else
                    {
                        //var patientEnrollment = new PatientEnrollmentManager();
                        //var enrolDate = patientEnrollment.GetPatientEnrollmentDate(PatientId);

                        var treatmentTrackerManager = new PatientTreatmentTrackerManager();
                        var patientBaseline         = treatmentTrackerManager.GetPatientbaselineRegimenLookup(PatientId);

                        if (patientBaseline != null)
                        {
                            if (patientBaseline.RegimenId > 0)
                            {
                                DateTime today = DateTime.Today;
                                //TimeSpan difference = today.Date - enrolDate.Date;
                                TimeSpan difference = today.Date - patientBaseline.CreateDate;
                                int      days       = (int)difference.TotalDays;

                                if (days < 180)
                                {
                                    lblvlDueDate.Text = "<span class='label label-success'>" + patientBaseline.CreateDate.AddMonths(6).ToString("dd-MMM-yyyy") + "</span>";
                                    lblVL.Text        = "<span class='label label-success fa fa-exclamation'><strong>  VL Not Requested  </strong></span>";
                                }
                                else
                                {
                                    lblVL.Text        = "<span class='label label-danger'> Not Done </span>";
                                    lblvlDueDate.Text = "<span class='label label-danger'><strong>  Overdue Since | " + patientBaseline.CreateDate.AddMonths(6).ToString("dd-MMM-yyyy") + " </strong></span>";
                                }
                            }
                            else
                            {
                                lblVL.Text        = "<span class='label label-danger'> Not Done</span>";
                                lblvlDueDate.Text = "<span class='label label-danger'><strong> unknown </strong></span>";
                            }
                        }
                        else
                        {
                            lblVL.Text        = "<span class='label label-danger'> Not Done </span>";
                            lblvlDueDate.Text = "<span class='label label-danger'><strong> unknown </strong></span>";
                        }
                    }
                    //}
                }
                else
                {
                    //var patientEnrollment = new PatientEnrollmentManager();
                    //var enrolDate = patientEnrollment.GetPatientEnrollmentDate(PatientId);

                    var treatmentTrackerManager = new PatientTreatmentTrackerManager();
                    var patientBaseline         = treatmentTrackerManager.GetPatientbaselineRegimenLookup(PatientId);

                    DateTime today = DateTime.Today;
                    //TimeSpan difference = today.Date - enrolDate.Date;
                    TimeSpan difference = today.Date - patientBaseline.CreateDate;

                    if (patientBaseline != null)
                    {
                        if (patientBaseline.RegimenId > 0)
                        {
                            int days = (int)difference.TotalDays;

                            if (days < 180)
                            {
                                lblvlDueDate.Text = "<span class='label label-success'>" + patientBaseline.CreateDate.AddMonths(6).ToString("dd-MMM-yyyy") + "</span>";
                                lblVL.Text        = "<span class='label label-success fa fa-exclamation'><strong>  VL Not Requested  </strong></span>";
                            }
                            else
                            {
                                lblVL.Text        = "<span class='label label-danger'> Not Available </span>";
                                lblvlDueDate.Text = "<span class='label label-danger'><strong> Overdue </strong></span>";
                            }
                        }
                        else
                        {
                            lblVL.Text        = "<span class='label label-danger'> Not Done </span>";
                            lblvlDueDate.Text = "<span class='label label-danger'><strong> unknown </strong></span>";
                        }
                    }
                    else
                    {
                        lblVL.Text        = "<span class='label label-danger'> Not Done </span>";
                        lblvlDueDate.Text = "<span class='label label-danger'><strong> unknown </strong></span>";
                    }
                }

                PharmacyHistoryDrugSubstitutionsManager pharmacyHistoryDrug = new PharmacyHistoryDrugSubstitutionsManager();
                var pharmacyDrugsSubstitutionsSwitchesData = pharmacyHistoryDrug.GetPharmacyDrugsSubstitutionsSwitchesData(this.ptnPk);

                if (pharmacyDrugsSubstitutionsSwitchesData.Count > 0)
                {
                    for (int p = 0; p < pharmacyDrugsSubstitutionsSwitchesData.Count; p++)
                    {
                        HtmlTableRow  tableRow = new HtmlTableRow();
                        HtmlTableCell idcell   = new HtmlTableCell();
                        idcell.InnerHtml = (p + 1).ToString();
                        tableRow.Controls.Add(idcell);

                        HtmlTableCell cell = new HtmlTableCell();
                        cell.InnerHtml = pharmacyDrugsSubstitutionsSwitchesData[p].regimentype;
                        tableRow.Controls.Add(cell);

                        HtmlTableCell cell2 = new HtmlTableCell();
                        cell2.InnerHtml = pharmacyDrugsSubstitutionsSwitchesData[p].DispensedByDate.HasValue
                            ? pharmacyDrugsSubstitutionsSwitchesData[p].DispensedByDate.Value.ToString("dd-MMM-yyyy")
                            : "not dispensed";
                        tableRow.Controls.Add(cell2);

                        tblPharmacyHistory.Rows.Add(tableRow);
                    }
                }
            }
        }