コード例 #1
0
        public async Task <PrescriptionListWithCount> getPatientPrescriptionsList(PrescriptionListFilterModel prescriptionListFilterModel)
        {
            var preseciptionList = new List <PharmacyManagementDTO>();

            preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                     .OrderByDescending(p => p.Prescriptiondate)
                                     .Where(p => (p.Patientid.Contains(prescriptionListFilterModel.PatientId)) && (p.Isactive == true) &&
                                            (p.Locationid == prescriptionListFilterModel.LocationId) &&
                                            (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                     .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                     .Take(prescriptionListFilterModel.PageSize)
                                     .Select(presc => new PharmacyManagementDTO
            {
                Facility    = presc.Location.Locationname,
                Prescno     = presc.Prescriptionid,
                Prescdate   = presc.Prescriptiondate,
                Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                Agegender   = CalculateAge((DateTime)presc.Patient.Dob) + "/Yrs" + presc.Patient.Gender.Gendername,
                Regno       = UInt32.Parse(presc.Patientid),
                //Plantype = _context.PlanType.Where(pl=>pl.planid==Int32.Parse(presc.Patient.Plantype)).Select(pl=>pl.planname).FirstOrDefault(),
                //Plantype = _context.PlanType.FromSqlInterpolated($"SELECT planname from PlanType where planid = {presc.Patient.Plantype}").FirstOrDefault().ToString(),
                Company      = presc.Patient.Spons.Sponsortype,
                Alert        = 0,
                Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                Store        = presc.Indentstore.Departmentname,
                Encounterid  = presc.Encounterid ?? 1
            })).ToListAsync();
            //int count = preseciptionList.Count();
            int count = _context.ConsultationPrescription.Where(p => (p.Patientid.Contains(prescriptionListFilterModel.PatientId)) && (p.Isactive == true) &&
                                                                (p.Locationid == prescriptionListFilterModel.LocationId) &&
                                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true))).Count();
            //int count = preseciptionList.Count();
            var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);

            return(prescriptionListWithCount);
        }
コード例 #2
0
        public async Task <PrescriptionListWithCount> getConsultationPrescriptionsList(PrescriptionListFilterModel prescriptionListFilterModel)
        {
            var preseciptionList = new List <PharmacyManagementDTO>();

            if (prescriptionListFilterModel.Date.HasValue && prescriptionListFilterModel.LocationId.HasValue && prescriptionListFilterModel.ProviderId.HasValue)
            {
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                         .Where(p => (p.Patientid != null) && p.Isactive == true &&
                                                (((p.Prescriptiondate == prescriptionListFilterModel.Date) ||
                                                  (p.Locationid == prescriptionListFilterModel.LocationId) ||
                                                  (p.ProviderId == prescriptionListFilterModel.ProviderId))) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                         .OrderByDescending(p => p.Prescriptiondate)
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = CalculateAge((DateTime)presc.Patient.Dob) + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //Plantype = _context.PlanType.Where(pl=>pl.planid==Int32.Parse(presc.Patient.Plantype)).Select(pl=>pl.planname).FirstOrDefault(),
                    //Plantype = _context.PlanType.FromSqlInterpolated($"SELECT planname from PlanType where planid = {presc.Patient.Plantype}").FirstOrDefault().ToString(),
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                }))
                                   .ToListAsync();
                int count = _context.ConsultationPrescription.FromSqlInterpolated($"SELECT prescriptionid AS pid FROM Consultation_Prescription WHERE  patientid is not null  AND (locationid = {prescriptionListFilterModel.LocationId}  OR ProviderID = {prescriptionListFilterModel.ProviderId} OR prescriptiondate == {prescriptionListFilterModel.Date})").Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
            else if (prescriptionListFilterModel.Date.HasValue && prescriptionListFilterModel.LocationId.HasValue && !prescriptionListFilterModel.ProviderId.HasValue)
            {
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                         .OrderByDescending(p => p.Prescriptiondate)
                                         .Where(p => (p.Patientid != null) && (p.Isactive == true) && (
                                                    ((p.Prescriptiondate == prescriptionListFilterModel.Date) ||
                                                     (p.Locationid == prescriptionListFilterModel.LocationId))) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = CalculateAge((DateTime)presc.Patient.Dob) + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //Plantype = _context.PlanType.Where(pl=>pl.planid==Int32.Parse(presc.Patient.Plantype)).Select(pl=>pl.planname).FirstOrDefault(),
                    //Plantype = _context.PlanType.FromSqlInterpolated($"SELECT planname from PlanType where planid = {presc.Patient.Plantype}").FirstOrDefault().ToString(),
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                })).ToListAsync();



                int count = _context.ConsultationPrescription.FromSqlInterpolated($"SELECT prescriptionid AS pid FROM Consultation_Prescription WHERE  patientid is not null  AND (locationid = {prescriptionListFilterModel.LocationId} OR prescriptiondate = {prescriptionListFilterModel.Date})").Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
            else if (prescriptionListFilterModel.Date.HasValue && prescriptionListFilterModel.ProviderId.HasValue && !prescriptionListFilterModel.LocationId.HasValue)
            {
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                         .OrderByDescending(p => p.Prescriptiondate)
                                         .Where(p => (p.Patientid != null) && (p.Isactive == true) && (
                                                    ((p.Prescriptiondate == prescriptionListFilterModel.Date) ||
                                                     (p.ProviderId == prescriptionListFilterModel.ProviderId))) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = CalculateAge((DateTime)presc.Patient.Dob) + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //Plantype = _context.PlanType.Where(pl=>pl.planid==Int32.Parse(presc.Patient.Plantype)).Select(pl=>pl.planname).FirstOrDefault(),
                    //Plantype = _context.PlanType.FromSqlInterpolated($"SELECT planname from PlanType where planid = {presc.Patient.Plantype}").FirstOrDefault().ToString(),
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                })).ToListAsync();

                int count = _context.ConsultationPrescription.FromSqlInterpolated($"SELECT prescriptionid AS pid FROM Consultation_Prescription WHERE  patientid is not null  AND (ProviderID = {prescriptionListFilterModel.ProviderId} OR prescriptiondate = {prescriptionListFilterModel.Date})").Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
            else if (!prescriptionListFilterModel.Date.HasValue && prescriptionListFilterModel.ProviderId.HasValue && prescriptionListFilterModel.LocationId.HasValue)
            {
                //date filtering wasn't selected but both providerid and location selected
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()

                                         .Where(p => (p.Patientid != null) && (p.Isactive == true) && (
                                                    (p.Locationid == prescriptionListFilterModel.LocationId) ||
                                                    (p.ProviderId == prescriptionListFilterModel.ProviderId)) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                         .OrderByDescending(p => p.Prescriptiondate)
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = (CalculateAge((DateTime)presc.Patient.Dob)).ToString() + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //PlanType = presc.Patient.PlanType.planname,
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                })).ToListAsync();
                int count = _context.ConsultationPrescription.FromSqlInterpolated($"SELECT prescriptionid AS pid FROM Consultation_Prescription WHERE  patientid is not null  AND (locationid = {prescriptionListFilterModel.LocationId}  OR ProviderID = {prescriptionListFilterModel.ProviderId})").Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
            else if (!prescriptionListFilterModel.Date.HasValue && !prescriptionListFilterModel.ProviderId.HasValue && prescriptionListFilterModel.LocationId.HasValue)
            {
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                         .Where(p => (p.Patientid != null) && (p.Isactive == true) &&
                                                ((p.Locationid == prescriptionListFilterModel.LocationId)) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                         .OrderByDescending(p => p.Prescriptiondate)
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = (CalculateAge((DateTime)presc.Patient.Dob)).ToString() + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //PlanType = presc.Patient.PlanType.planname,
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                })).ToListAsync();
                int count = _context.ConsultationPrescription.FromSqlInterpolated($"SELECT prescriptionid AS pid FROM Consultation_Prescription WHERE  patientid is not null  AND locationid = {prescriptionListFilterModel.LocationId}").Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
            else if (!prescriptionListFilterModel.Date.HasValue && prescriptionListFilterModel.ProviderId.HasValue && !prescriptionListFilterModel.LocationId.HasValue)
            {
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                         .Where(p => (p.Patientid != null) && (p.Isactive == true) &&
                                                (p.Locationid == prescriptionListFilterModel.LocationId) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                         .OrderByDescending(p => p.Prescriptiondate)
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = CalculateAge((DateTime)presc.Patient.Dob) + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //Plantype = _context.PlanType.Where(pl=>pl.planid==Int32.Parse(presc.Patient.Plantype)).Select(pl=>pl.planname).FirstOrDefault(),
                    //Plantype = _context.PlanType.FromSqlInterpolated($"SELECT planname from PlanType where planid = {presc.Patient.Plantype}").FirstOrDefault().ToString(),
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                })).ToListAsync();

                int count = _context.ConsultationPrescription.FromSqlInterpolated($"SELECT prescriptionid AS pid FROM Consultation_Prescription WHERE patientid is not null  AND ProviderID = {prescriptionListFilterModel.ProviderId}").Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
            else if (prescriptionListFilterModel.Date.HasValue && !prescriptionListFilterModel.LocationId.HasValue && !prescriptionListFilterModel.ProviderId.HasValue)
            {
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                         .Where(p => (p.Patientid != null) && (p.Isactive == true) &&
                                                (p.Prescriptiondate == prescriptionListFilterModel.Date) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true)))
                                         .OrderByDescending(p => p.Prescriptiondate)
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = CalculateAge((DateTime)presc.Patient.Dob) + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //Plantype = _context.PlanType.Where(pl=>pl.planid==Int32.Parse(presc.Patient.Plantype)).Select(pl=>pl.planname).FirstOrDefault(),
                    //Plantype = _context.PlanType.FromSqlInterpolated($"SELECT planname from PlanType where planid = {presc.Patient.Plantype}").FirstOrDefault().ToString(),
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                })).ToListAsync();
                int count = _context.ConsultationPrescription.FromSqlInterpolated($"SELECT prescriptionid AS pid FROM Consultation_Prescription WHERE  patientid is not null  AND prescriptiondate = {prescriptionListFilterModel.Date}").Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
            else
            {
                preseciptionList = await(_context.ConsultationPrescription.AsNoTracking()
                                         .Where(p => p.Patientid != null && (p.Isactive == true) &&
                                                (_context.ConsultationPrescriptionDetails.Any(pd => pd.Prescriptionid == p.Prescriptionid && pd.Isactive == true))
                                                ).OrderByDescending(p => p.Prescriptiondate)
                                         .Skip((prescriptionListFilterModel.PageNumber - 1) * prescriptionListFilterModel.PageSize)
                                         .Take(prescriptionListFilterModel.PageSize)
                                         .Select(presc => new PharmacyManagementDTO
                {
                    Facility    = presc.Location.Locationname,
                    Prescno     = presc.Prescriptionid,
                    Prescdate   = presc.Prescriptiondate,
                    Patientname = presc.Patient.Firstname + " " + presc.Patient.Lastname,
                    Agegender   = CalculateAge((DateTime)presc.Patient.Dob) + "/Yrs" + presc.Patient.Gender.Gendername,
                    Regno       = UInt32.Parse(presc.Patientid),
                    //Plantype = _context.PlanType.Where(pl=>pl.planid==Int32.Parse(presc.Patient.Plantype)).Select(pl=>pl.planname).FirstOrDefault(),
                    //Plantype = _context.PlanType.FromSqlInterpolated($"SELECT planname from PlanType where planid = {presc.Patient.Plantype}").FirstOrDefault().ToString(),
                    Company      = presc.Patient.Spons.Sponsortype,
                    Alert        = 0,
                    Doctorname   = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Seenbydoctor = _context.ApplicationUser.Where(o => o.Appuserid == presc.Doctorid).Select(o => o.Lastname + " " + o.Firstname).FirstOrDefault(),
                    Store        = presc.Indentstore.Departmentname,
                    Encounterid  = presc.Encounterid ?? 1
                })).ToListAsync();

                int count = _context.ConsultationPrescription.Count();
                var prescriptionListWithCount = new PrescriptionListWithCount(preseciptionList, count);
                return(prescriptionListWithCount);
            }
        }