Beispiel #1
0
        public string Post()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            try
            {
                VisitDbContext dbContext = new VisitDbContext(base.connString);
                string         str       = this.ReadPostData();
                string         reqType   = this.ReadQueryStringData("reqType");

                if (reqType == "concludeVisit")
                {
                    var visitid = DanpheJSONConvert.DeserializeObject <int>(str);
                    var visit   = dbContext.Visits.Where(v => v.PatientVisitId == visitid).Select(p => p).FirstOrDefault();
                    visit.ConcludeDate = System.DateTime.Now;
                    dbContext.Visits.Attach(visit);
                    dbContext.Entry(visit).Property(a => a.ConcludeDate).IsModified = true;
                    dbContext.SaveChanges();

                    responseData.Status = "OK";
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = "Error " + ex.Message;
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
        //20Aug2018 : Ashim: This logic is not used anywhere. It has been replaced by
        //generate visit code for post visit
        public static string UpdateVisitCode(int patientVisitId, VisitDbContext visitDbContext)
        {
            try
            {
                string visitCode = null;
                if (patientVisitId != 0)
                {
                    VisitModel visit = visitDbContext.Visits
                                       .Where(a => a.PatientVisitId == patientVisitId)
                                       .FirstOrDefault <VisitModel>();
                    if (visit.VisitType == "outpatient")
                    {
                        visit.VisitCode = "V" + (visit.PatientVisitId + 100000);
                    }
                    else
                    {
                        visit.VisitCode = "H" + (visit.PatientVisitId + 100000);
                    }

                    visitDbContext.Entry(visit).State = EntityState.Modified;
                    visitDbContext.SaveChanges();
                    visitCode = visit.VisitCode;
                }
                return(visitCode);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #3
0
        //private string QuickAppointmentCreate()
        //{
        //    DanpheHTTPResponse<QuickAppointmentVM> responseData = new DanpheHTTPResponse<QuickAppointmentVM>();

        //    try
        //    {
        //        string str = Request.Form.Keys.First<string>();
        //        QuickAppointmentVM ipQckApptModel = DanpheJSONConvert.DeserializeObject<QuickAppointmentVM>(str);

        //        PatientModel currPat = ipQckApptModel.Patient;
        //        AppointmentModel currAppt = ipQckApptModel.Appointment;
        //        BillingTransactionModel currBillTxn = ipQckApptModel.BillingTransaction;

        //        PatientDbContext patDbContext = new PatientDbContext(connectionStr);
        //        //create patient and save if not registered. else get patient details from id.
        //        if (currPat.PatientId == 0)
        //        {
        //            currPat.EMPI = CreateEmpi(currPat);

        //            patDbContext.Patients.Add(currPat);
        //            patDbContext.SaveChanges();

        //            //assign patient properties to appointment object
        //            currAppt.PatientId = currPat.PatientId;
        //            currPat.PatientCode = UpdatePatientCode(currPat.PatientId);
        //        }
        //        else {
        //            //if patient's already registered, get his/her details and assign..
        //            int patId = currPat.PatientId;
        //            currPat = patDbContext.Patients.Where(p => p.PatientId == patId).FirstOrDefault();
        //            ipQckApptModel.Patient = currPat;
        //        }

        //        //create new appointment.
        //        currAppt.AppointmentStatus = "initiated";
        //        currAppt.PatientType = "outpatient";

        //        AppointmentDbContext apptDbcontext = new AppointmentDbContext(connectionStr);
        //        apptDbcontext.Appointments.Add(currAppt);
        //        apptDbcontext.SaveChanges();

        //        //create new visit.
        //        VisitModel newVisit = new VisitModel();
        //        newVisit.PatientId = currPat.PatientId;
        //        newVisit.VisitDate = currAppt.AppointmentDate;
        //        newVisit.VisitTime = currAppt.AppointmentDate.Add(currAppt.AppointmentTime);
        //        newVisit.ProviderId = currAppt.ProviderId;
        //        newVisit.ProviderName = currAppt.ProviderName;
        //        newVisit.VisitType = "outpatient";//fixed for outpatient. need to check for admission.
        //        newVisit.VisitStatus = "initiated";//fixed for quickAppointment
        //        newVisit.AppointmentType = "New";

        //        newVisit.AppointmentId = currAppt.AppointmentId;
        //        newVisit.BillingStatus = "paid";///Update this status once posting to billing is successfull..

        //        VisitDbContext visitDbcontext = new VisitDbContext(connectionStr);
        //        visitDbcontext.Visits.Add(newVisit);
        //        visitDbcontext.SaveChanges();
        //        UpdateVisitCode(newVisit.PatientVisitId);
        //        //this should save to both billing transaction and transactionitem.
        //        BillingDbContext billDbcontext = new BillingDbContext(connectionStr);
        //        currBillTxn.CreatedOn = System.DateTime.Now;
        //        currBillTxn.PatientId = currPat.PatientId;


        //        currBillTxn.PatientVisitId = newVisit.PatientVisitId;
        //        if (currBillTxn.BillingTransactionItems != null && currBillTxn.BillingTransactionItems.Count > 0)
        //        {
        //            currBillTxn.BillingTransactionItems[0].PatientId = currPat.PatientId;

        //        }


        //        billDbcontext.BillingTransactions.Add(currBillTxn);
        //        billDbcontext.SaveChanges();
        //        //assign current patient to billing transaction..
        //        currBillTxn.Patient = currPat;//check it again if we can send this or not.. sudarshan:14july
        //        responseData.Results = ipQckApptModel;
        //        responseData.Status = "OK";

        //    }
        //    catch (Exception ex)
        //    {
        //        responseData.Status = "Failed";
        //        responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
        //    }

        //    return DanpheJSONConvert.SerializeObject(responseData, true);

        //}


        //Move it to a common function to be used between visit and appointment controller.
        //IMPORTANT.. we need to change this logic, so that we get unique id everytime.
        private void UpdateVisitCode(int patientVisitId)
        {
            VisitDbContext visitDbContext = new VisitDbContext(connString);

            try
            {
                if (patientVisitId != 0)
                {
                    VisitModel visit = visitDbContext.Visits
                                       .Where(a => a.PatientVisitId == patientVisitId)
                                       .FirstOrDefault <VisitModel>();
                    if (visit.VisitType == "outpatient")
                    {
                        visit.VisitCode = "V" + (visit.PatientVisitId + 100000);
                    }
                    else
                    {
                        visit.VisitCode = "H" + (visit.PatientVisitId + 100000);
                    }

                    visitDbContext.Entry(visit).State = EntityState.Modified;
                    visitDbContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public static Boolean ReAssignProviderTxn(VisitDbContext visitDb, VisitModel visit, BillingDbContext billingDb)
        {
            using (var dbContextTxn = visitDb.Database.BeginTransaction())
            {
                try
                {
                    //updating visit-table
                    visitDb.Visits.Attach(visit);
                    visitDb.Entry(visit).Property(x => x.ProviderId).IsModified   = true;
                    visitDb.Entry(visit).Property(x => x.ProviderName).IsModified = true;
                    visitDb.Entry(visit).Property(x => x.ModifiedBy).IsModified   = true;
                    visitDb.Entry(visit).Property(x => x.ModifiedOn).IsModified   = true;
                    visitDb.Entry(visit).Property(x => x.Remarks).IsModified      = true;
                    visitDb.SaveChanges();

                    //updating billingTxnItem table

                    //getting ServiceDepartmentId of OPD
                    int servDeptId = (from d in billingDb.ServiceDepartment
                                      where d.ServiceDepartmentName == "OPD"
                                      select d.ServiceDepartmentId).FirstOrDefault();
                    //for updating get data from table using PatientVisitId as RequisitionId
                    BillingTransactionItemModel billitm = (from b in billingDb.BillingTransactionItems
                                                           where b.RequisitionId == visit.PatientVisitId && b.ServiceDepartmentId == servDeptId
                                                           select b).FirstOrDefault();
                    //assiging updated values
                    billitm.ProviderId   = visit.ProviderId;
                    billitm.ProviderName = visit.ProviderName;

                    billingDb.BillingTransactionItems.Attach(billitm);
                    billingDb.Entry(billitm).Property(x => x.ProviderId).IsModified   = true;
                    billingDb.Entry(billitm).Property(x => x.ProviderName).IsModified = true;
                    billingDb.SaveChanges();


                    //Commit Transaction
                    dbContextTxn.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    //Rollback all transaction if exception occured
                    dbContextTxn.Rollback();
                    throw ex;
                }
            }
        }
        //updated visit logic.
        //created by: nagesh
        public static string CreateNewPatientVisitCode(string visitType, string connString)
        {
            try
            {
                VisitDbContext visitDbContext = new VisitDbContext(connString);
                var            visitCode      = "";
                if (visitType != null)
                {
                    //VisitDbContext visitDbContext = new VisitDbContext(connString);
                    var year       = DateTime.Now.Year;
                    var patVisitId = visitDbContext.Visits.Where(s => s.VisitType == visitType && s.VisitDate.Year == year).DefaultIfEmpty()
                                     .Max(t => t.PatientVisitId == null ? 0 : t.PatientVisitId);
                    string codeChar;
                    switch (visitType)
                    {
                    case "inpatient":
                        codeChar = "H";
                        break;

                    case "emergency":
                        codeChar = "ER";
                        break;

                    default:
                        codeChar = "V";
                        break;
                    }
                    if (patVisitId > 0)
                    {
                        var vCodMax = (from v in visitDbContext.Visits
                                       where v.PatientVisitId == patVisitId
                                       select v.VisitCode).FirstOrDefault();
                        int newCodeDigit = Convert.ToInt32(vCodMax.Substring(codeChar.Length + 2)) + 1;
                        visitCode = (string)codeChar + DateTime.Now.ToString("yy") + String.Format("{0:D5}", newCodeDigit);
                    }
                    else
                    {
                        visitCode = (string)codeChar + DateTime.Now.ToString("yy") + String.Format("{0:D5}", 1);
                    }
                }
                return(visitCode);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void UpdateRequisitionItemsBillStatus(VisitDbContext visitDbContext,
                                                            string serviceDepartmentName,
                                                            string billStatus, //provisional,paid,unpaid,returned
                                                            int?userId,
                                                            long?requisitionId,
                                                            DateTime?modifiedDate)
        {
            string integrationName = visitDbContext.ServiceDepartments
                                     .Where(a => a.ServiceDepartmentName == serviceDepartmentName)
                                     .Select(a => a.IntegrationName).FirstOrDefault();

            if (integrationName != null)
            {
                //update status in lab
                if (integrationName.ToLower() == "lab")
                {
                    var labItem = visitDbContext.LabRequisitions.Where(req => req.RequisitionId == requisitionId).FirstOrDefault();
                    if (labItem != null)
                    {
                        labItem.BillingStatus = billStatus;
                        labItem.ModifiedOn    = modifiedDate;
                        labItem.ModifiedBy    = userId;
                        visitDbContext.Entry(labItem).Property(a => a.BillingStatus).IsModified = true;
                        visitDbContext.Entry(labItem).Property(a => a.ModifiedOn).IsModified    = true;
                        visitDbContext.Entry(labItem).Property(a => a.ModifiedBy).IsModified    = true;
                    }
                }
                //update status for Radiology
                else if (integrationName.ToLower() == "radiology")
                {
                    var radioItem = visitDbContext.RadiologyImagingRequisitions.Where(req => req.ImagingRequisitionId == requisitionId).FirstOrDefault();
                    if (radioItem != null)
                    {
                        radioItem.BillingStatus = billStatus;
                        radioItem.ModifiedOn    = modifiedDate;
                        radioItem.ModifiedBy    = userId;
                        visitDbContext.Entry(radioItem).Property(a => a.BillingStatus).IsModified = true;
                        visitDbContext.Entry(radioItem).Property(a => a.ModifiedOn).IsModified    = true;
                        visitDbContext.Entry(radioItem).Property(a => a.ModifiedBy).IsModified    = true;
                    }
                }
            }
        }
        /// <summary>
        /// To get the latest patient visit of current patient.
        /// </summary>
        /// <param name="visitDbContext"></param>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public static VisitModel GetPatientLatestVisit(VisitDbContext visitDbContext, int patientId)
        {
            VisitModel retVisit = new VisitModel();

            if (visitDbContext != null)
            {
                //if we do orderbydescending, the latest visit would come at the top.
                var patAllVisits = (from v in visitDbContext.Visits
                                    where v.PatientId == patientId
                                    select v
                                    ).OrderByDescending(v => v.PatientVisitId).ToList();
                //take first element of the Ordered-List.
                if (patAllVisits != null && patAllVisits.Count > 0)
                {
                    retVisit = patAllVisits.ElementAt(0);
                }
            }

            return(retVisit);
        }
        public static bool HasDuplicateVisitWithSameProvider(VisitDbContext visitDb, int patientId, int?providerId, DateTime visitDate)
        {
            //sud:19Jun'19--For DepartmentLevel appointment, ProviderId will be Zero or Null. so return false in that case.//Needs revision.
            if (providerId == null || providerId == 0)
            {
                return(false);
            }

            List <VisitModel> patientvisitList = (from visit in visitDb.Visits
                                                  where visit.PatientId == patientId &&
                                                  DbFunctions.TruncateTime(visit.VisitDate) == DbFunctions.TruncateTime(visitDate) &&
                                                  visit.ProviderId == providerId && visit.IsActive == true && visit.BillingStatus != "returned"
                                                  select visit).ToList();

            if (patientvisitList.Count != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #9
0
        public string Put()
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            try
            {
                VisitDbContext dbContext = new VisitDbContext(base.connString);
                string         str       = this.ReadPostData();
                string         reqType   = this.ReadQueryStringData("reqType");
                //string billingStatus = this.ReadQueryStringData("billingStatus");
                //int patientVisitId = ToInt(this.ReadQueryStringData("billingStatus"));
                bool continuedVisitStatus = ToBool(this.ReadQueryStringData("continuedVisitStatus"));

                if (reqType == "reassignProvider")
                {
                    VisitModel visitData = DanpheJSONConvert.DeserializeObject <VisitModel>(str);
                    visitData.ModifiedOn   = System.DateTime.Now;
                    visitData.ProviderName = GetProviderName(visitData.ProviderId);

                    BillingDbContext billingDbContext = new BillingDbContext(base.connString);

                    Boolean Flag = false;
                    Flag = VisitBL.ReAssignProviderTxn(dbContext, visitData, billingDbContext);
                    if (Flag)
                    {
                        responseData.Status = "OK";
                    }
                    else
                    {
                        responseData.Status = "Failed";
                    }
                }
                else if (reqType == "changeProvider")
                {
                    VisitModel data  = DanpheJSONConvert.DeserializeObject <VisitModel>(str);
                    var        visit = dbContext.Visits.Where(v => v.PatientVisitId == data.PatientVisitId).Select(p => p).FirstOrDefault();
                    visit.ModifiedBy   = data.ModifiedBy;
                    visit.ModifiedOn   = System.DateTime.Now;
                    visit.ProviderName = GetProviderName(data.ProviderId);
                    visit.ProviderId   = data.ProviderId;
                    visit.Remarks      = string.IsNullOrEmpty(visit.Remarks) ? data.Remarks : (visit.Remarks + data.Remarks);

                    dbContext.Visits.Attach(visit);
                    dbContext.Entry(visit).Property(a => a.ModifiedBy).IsModified   = true;
                    dbContext.Entry(visit).Property(a => a.ModifiedOn).IsModified   = true;
                    dbContext.Entry(visit).Property(a => a.ProviderName).IsModified = true;
                    dbContext.Entry(visit).Property(a => a.ProviderId).IsModified   = true;
                    dbContext.Entry(visit).Property(a => a.Remarks).IsModified      = true;

                    dbContext.SaveChanges();


                    responseData.Status  = "OK";
                    responseData.Results = visit.ProviderName;
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
Beispiel #10
0
        public string Get(string department,
                          string reqType,
                          int providerId,
                          int patientId,
                          DateTime requestDate,
                          string status,
                          int membershipTypeId)
        {
            AppointmentDbContext        dbContextAppointment = new AppointmentDbContext(connString);
            DanpheHTTPResponse <object> responseData         = new DanpheHTTPResponse <object>();

            //RbacUser currentUser = HttpContext.Session.Get<RbacUser>("currentuser");
            //if (currentUser == null || !RBAC.UserHasPermission(currentUser.UserId, "APT", "appointment-read"))
            //{
            //    HttpResponseMessage message = new HttpResponseMessage(System.Net.HttpStatusCode.NotFound);
            //    responseData.Status = "Failed";
            //    responseData.ErrorMessage = "Unauthorized access.";
            //    return DanpheJSONConvert.SerializeObject(responseData);
            //}

            #region get request example
            //for reference
            //if (!string.IsNullOrEmpty(fName) || !string.IsNullOrEmpty(doctor) || appointmentId != 0)
            //{
            //    //If nothing is passed during search->Condition in LHS is TRUE and neglects the condition in the RHS
            //    //If some value is passed during search -> LHS will be false and checks if RHS is TRUE
            //    //If both the LHS and RHS in any one of the 3 conditions is false then query returns nothing.
            //    result = (from app in dbContextSearch.Appointments
            //              where (appointmentId == 0 || appointmentId == app.AppointmentId)
            //             && (string.IsNullOrEmpty(fName) || app.FirstName.ToLower().Contains(fName.ToLower()))
            //             && (string.IsNullOrEmpty(doctor) || app.ProviderName.ToLower().Contains(doctor.ToLower()))
            //              select app).ToList();
            //    return JsonConvert.SerializeObject(result);
            //}
            #endregion
            try
            {
                //gets the doctorschedule from appointment table
                if (reqType == "doctorschedule")
                {
                    //.ToList()is done two times,since we can't use requestDate.Date inside IQueryable
                    List <AppointmentModel> apptList = (from d in dbContextAppointment.Appointments
                                                        where d.ProviderId == providerId
                                                        select d).ToList().Where(a => a.AppointmentDate.Date == requestDate.Date).ToList();
                    AppointmentDay apptDay = AppointmentDay.FormatData(apptList);
                    responseData.Status  = "OK";
                    responseData.Results = apptDay;
                }
                //loads appointments with requested status
                else if (reqType == "getAppointments")
                {
                    var date = DateTime.Today;
                    List <AppointmentModel> appointmentList = (from app in dbContextAppointment.Appointments
                                                               select app
                                                               ).OrderByDescending(x => x.AppointmentId).ToList();
                    responseData.Status  = "OK";
                    responseData.Results = appointmentList;
                }
                //get the patient's today's or future's appointments
                else if (reqType == "checkForClashingAppointment")
                {
                    List <AppointmentModel> patAppointmentList = (from app in dbContextAppointment.Appointments
                                                                  where app.PatientId == patientId &&
                                                                  app.AppointmentDate >= DbFunctions.TruncateTime(requestDate.Date) &&
                                                                  app.ProviderId == providerId
                                                                  select app).ToList();

                    VisitDbContext dbContext = new VisitDbContext(base.connString);

                    List <VisitModel> patientvisitList = (from visit in dbContext.Visits
                                                          where visit.PatientId == patientId &&
                                                          DbFunctions.TruncateTime(visit.VisitDate) == DbFunctions.TruncateTime(requestDate.Date) &&
                                                          visit.ProviderId == providerId
                                                          select visit).ToList();

                    if ((patAppointmentList != null && patAppointmentList.Count != 0) || (patientvisitList != null && patientvisitList.Count != 0))
                    {
                        responseData.Status  = "OK";
                        responseData.Results = true;
                    }
                    else
                    {
                        responseData.Status  = "OK";
                        responseData.Results = false;
                    }
                }
                //get the discoutnpercantage using membershipTypeid
                else if (reqType == "GetMembershipDeatils")
                {
                    PatientDbContext patientDbContext = new PatientDbContext(connString);
                    var membershipDeatils             = (from mem in patientDbContext.MembershipTypes
                                                         where mem.MembershipTypeId == membershipTypeId
                                                         select new
                    {
                        MembershipTypeId = mem.MembershipTypeId,
                        DiscountPercent = mem.DiscountPercent,
                        MembershipTypeName = mem.MembershipTypeName
                    }).FirstOrDefault();

                    responseData.Status  = "OK";
                    responseData.Results = membershipDeatils;
                }
                //get the TotalAmount using providerId
                else if (reqType == "GetTotalAmountByProviderId")
                {
                    BillingDbContext billingDbContext = new BillingDbContext(connString);

                    ServiceDepartmentModel srvDept = billingDbContext.ServiceDepartment.Where(s => s.ServiceDepartmentName == "OPD").FirstOrDefault();

                    if (srvDept != null)
                    {
                        ///remove tolist from below query-- one doc will have only one opd-tkt price.. <sudrshan:14jul2017>
                        var billingItemPrice = (from bill in billingDbContext.BillItemPrice
                                                where bill.ServiceDepartmentId == srvDept.ServiceDepartmentId && bill.ItemId == providerId
                                                select bill.Price).ToList();

                        responseData.Status  = "OK";
                        responseData.Results = billingItemPrice;
                    }
                    else
                    {
                        responseData.Status       = "Failed";
                        responseData.ErrorMessage = "Failed to get OPD-Ticket Price";
                    }
                }   //getting appointment list of selected ProvideId
                else if (reqType == "get-appointment-list")
                {
                    ////.ToList()is done two times,since we can't use requestDate.Date inside IQueryable
                    //List<AppointmentModel> apptList = (from d in dbContextAppointment.Appointments
                    //                                   where d.ProviderId == providerId
                    //                                   select d).ToList();
                    //AppointmentDay apptDay = AppointmentDay.FormatData(apptList);

                    ////responseData.Status = "OK";
                    //responseData.Results = apptDay;

                    var apptList = (from apt in dbContextAppointment.Appointments
                                    where apt.ProviderId == providerId && apt.AppointmentDate == requestDate
                                    select new
                    {
                        PatientName = apt.FirstName + " " + (string.IsNullOrEmpty(apt.MiddleName) ? "" : apt.MiddleName + " ") + apt.LastName,
                        Time = apt.AppointmentTime,
                        Date = apt.AppointmentDate,
                    }).ToList();
                    if (apptList != null)
                    {
                        responseData.Status  = "OK";
                        responseData.Results = apptList;
                    }
                    else
                    {
                        responseData.Status = "Failed";
                    }
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }