Exemplo n.º 1
0
        public AddFamilyMemberResultClass ArchivePrescription(WritePrescriptionInputClass aptmnt)
        {
            AddFamilyMemberResultClass res = new AddFamilyMemberResultClass();

            try
            {
                AccessTokenValidationModel tokencheck = TokAuth.IsAccessTokenValid(aptmnt.DoctorId, aptmnt.AccessToken,
                                                                                   aptmnt.Lati, aptmnt.Longi, aptmnt.DeviceType, aptmnt.NotificationToken);

                res.Access = tokencheck;
                if (res.Access.IsTokenValid == true)
                {
                    if (aptmnt.DoctorId == 0)
                    {
                        res.IsSuccess  = false;
                        res.ErrMessage = "Doctor id not supplied.";
                    }
                    if (aptmnt.HospitalId == 0)
                    {
                        res.IsSuccess  = false;
                        res.ErrMessage = "Hospital id not supplied.";
                    }
                    if (aptmnt.PrescriptionId == 0)
                    {
                        res.IsSuccess  = false;
                        res.ErrMessage = "Prescription id not supplied.";
                    }



                    using (wfhealthdbEntities obj = new wfhealthdbEntities())
                    {
                        // getting prescription from db
                        var pr = (from p in obj.Prescriptions where p.Id == aptmnt.PrescriptionId && (p.IsArchivedByDoc == false || p.IsArchivedByDoc == null) && (p.IsDeleted == false || p.IsDeleted == null) select p).SingleOrDefault();

                        if (pr == null)
                        {
                            res.IsSuccess  = false;
                            res.ErrMessage = "Given presecription not found.";
                            return(res);
                        }

                        pr.IsArchivedByDoc = true;
                        obj.SaveChanges();
                    }
                    res.IsSuccess  = true;
                    res.ErrMessage = "Prescription saved successfully.";
                }
                return(res);
            }
            catch (Exception ex)
            {
                res.IsSuccess  = false;
                res.ErrMessage = "Server Error";
                return(res);
            }
        }
        public AccessTokenValidationModel IsAccessTokenValid(int UserId, string AccessToken, string Lati, string Longi, string DeviceType, string NotificationToken)
        {
            AccessTokenValidationModel re = new AccessTokenValidationModel();


            using (wfhealthdbEntities obj = new wfhealthdbEntities())
            {
                var r = (from s in obj.UsersMasters
                         where s.Id == UserId && s.AccessToken == AccessToken && s.IsActive == true
                         select
                         s).SingleOrDefault();

                if (r != null)
                {
                    re.IsTokenValid = true;


                    DateTime currentTime = DateTime.UtcNow;

                    r.Lati              = Lati;
                    r.Longi             = Longi;
                    r.DeviceType        = DeviceType;
                    r.NotificationToken = NotificationToken;

                    DateTime lastseen = currentTime;
                    TimeSpan t;
                    if (r.LastSeenOn != null)
                    {
                        t = currentTime - Convert.ToDateTime(r.LastSeenOn);
                    }
                    else
                    {
                        t = currentTime - lastseen;
                    }


                    if (t.TotalMinutes > 20)
                    {
                        re.AccessToken = GetNewAccessToken();

                        r.AccessToken     = re.AccessToken;
                        r.LastSeenOn      = lastseen;
                        re.IsTokenUpdated = true;
                        re.IsTokenValid   = true;
                        re.ErrMessage     = "OK";
                        obj.SaveChanges();
                    }


                    else
                    {
                        re.IsTokenUpdated = false;
                        re.AccessToken    = AccessToken;
                        re.IsTokenValid   = true;
                        re.ErrMessage     = "OK";
                    }
                }
                else
                {
                    re.IsTokenValid   = false;
                    re.IsTokenUpdated = false;
                    re.ErrMessage     = "Invalid access token or user id";
                }

                return(re);
            }
        }
Exemplo n.º 3
0
        public GetPrescriptionResultClass GetAppointmentPrescriptions(CancelAppointmentInputClass aptmnt)
        {
            GetPrescriptionResultClass res = new GetPrescriptionResultClass();

            try
            {
                if (aptmnt.user.HospitalId == 0)
                {
                    res.IsSuccess  = false;
                    res.ErrMessage = "Hospital id not supplied.";
                    return(res);
                }
                if (aptmnt.AppointmentId == 0)
                {
                    res.IsSuccess  = false;
                    res.ErrMessage = "Appointment id not supplied.";
                    return(res);
                }

                using (wfhealthdbEntities obj = new wfhealthdbEntities())
                {
                    AccessTokenValidationModel tokencheck = TokAuth.IsAccessTokenValid(aptmnt.user.UserId, aptmnt.user.AccessToken,
                                                                                       aptmnt.user.Lati, aptmnt.user.Longi, aptmnt.user.DeviceType, aptmnt.user.NotificationToken);

                    res.Access = tokencheck;
                    if (res.Access.IsTokenValid == true)
                    {
                        var userdetail = (from c in obj.UsersInHospitals where c.IsActive == true && c.Hospital_Id == aptmnt.user.HospitalId && c.User_Id == aptmnt.user.UserId select c).SingleOrDefault();
                        if (userdetail != null)
                        {
                            // checking for given appointment
                            var appointmentdetails = (from c in obj.Appointments
                                                      where c.Id == aptmnt.AppointmentId
                                                      select c).SingleOrDefault();

                            if (appointmentdetails != null)
                            {
                                // getting prescriptions for given appoiment
                                List <PrescriptionOutputInternal> prescriptionsToReturn = new List <PrescriptionOutputInternal>();
                                var allprescriptions = (from c in obj.Prescriptions
                                                        where
                                                        c.Appointment_Id == aptmnt.AppointmentId &&
                                                        c.Hospital_Id == aptmnt.user.HospitalId && c.Doctor_Id == aptmnt.user.UserId &&
                                                        c.IsDeleted == false &&
                                                        (c.IsArchivedByDoc == false || c.IsArchivedByDoc == null)
                                                        select c).ToList();
                                foreach (Prescription p in allprescriptions)
                                {
                                    PrescriptionOutputInternal p1 = new PrescriptionOutputInternal();
                                    p1.IsForFamMember = p.IsForFamilyMember ?? false;
                                    p1.PrescriptionId = p.Id;

                                    p1.WrittenOn = p.CreatedOn;
                                    if (p.FamilyMemberId != null && p.FamilyMemberId > 0)
                                    {
                                        p1.FamMemberId = Convert.ToInt16(p.FamilyMemberId);
                                    }


                                    p1.PrescriptionNotes = encDec.Decrypt(p.PrescriptionText);
                                    // getting attachments with given prescription
                                    List <PrescriptopmImageClass> PrescriptionAttachments = new List <PrescriptopmImageClass>();
                                    var allpattachments = (from c in obj.PrescriptionAttachments
                                                           where c.Prescription_Id == p.Id && (c.IsActive == true || c.IsActive == null) &&
                                                           c.Hospital_Id == aptmnt.user.HospitalId &&
                                                           c.Doctor_Id == aptmnt.user.UserId
                                                           select c).ToList();
                                    foreach (PrescriptionAttachment v in allpattachments)
                                    {
                                        PrescriptopmImageClass pic = new PrescriptopmImageClass();
                                        pic.AttachmentId     = v.Id;
                                        pic.attachementNotes = encDec.Decrypt(v.Docsummary);
                                        pic.PrescriptionImg  = v.DocPath;
                                        PrescriptionAttachments.Add(pic);
                                    }
                                    p1.PrescriptionAttachments = PrescriptionAttachments;
                                    prescriptionsToReturn.Add(p1);
                                }

                                // adding final result into response
                                res.IsSuccess     = true;
                                res.ErrMessage    = "OK";
                                res.prescriptions = prescriptionsToReturn;
                            }
                            else
                            {
                                res.IsSuccess  = false;
                                res.ErrMessage = "No record found for given appoinment id.";
                            }
                        }
                        else
                        {
                            res.IsSuccess  = false;
                            res.ErrMessage = "User not found in given hospital.";
                        }
                    }
                    else
                    {
                        res.IsSuccess  = false;
                        res.ErrMessage = "Invalid access token or user id.";
                    }
                }
            }
            catch (Exception)
            {
                res.IsSuccess  = false;
                res.ErrMessage = "Server Error.";
            }
            return(res);
        }
Exemplo n.º 4
0
        public AddFamilyMemberResultClass EditPrescription(WritePrescriptionInputClass aptmnt)
        {
            AddFamilyMemberResultClass res = new AddFamilyMemberResultClass();

            try
            {
                AccessTokenValidationModel tokencheck = TokAuth.IsAccessTokenValid(aptmnt.DoctorId, aptmnt.AccessToken,
                                                                                   aptmnt.Lati, aptmnt.Longi, aptmnt.DeviceType, aptmnt.NotificationToken);

                res.Access = tokencheck;
                if (res.Access.IsTokenValid == true)
                {
                    if (aptmnt.DoctorId == 0)
                    {
                        res.IsSuccess  = false;
                        res.ErrMessage = "Doctor id not supplied.";
                    }
                    if (aptmnt.HospitalId == 0)
                    {
                        res.IsSuccess  = false;
                        res.ErrMessage = "Hospital id not supplied.";
                    }
                    if (aptmnt.PrescriptionId == 0)
                    {
                        res.IsSuccess  = false;
                        res.ErrMessage = "Prescription id not supplied.";
                    }
                    if (aptmnt.IsForFamMember == true)
                    {
                        if (aptmnt.FamMemberId == 0)
                        {
                            res.IsSuccess  = false;
                            res.ErrMessage = "Family Member id not supplied.";
                        }
                    }
                    else
                    {
                        if (aptmnt.UserId == 0)
                        {
                            res.IsSuccess  = false;
                            res.ErrMessage = "Patient id not supplied.";
                        }
                    }


                    using (wfhealthdbEntities obj = new wfhealthdbEntities())
                    {
                        // getting prescription from db
                        var pr = (from p in obj.Prescriptions where p.Id == aptmnt.PrescriptionId && (p.IsDeleted == null || p.IsDeleted == false) select p).SingleOrDefault();

                        if (pr == null)
                        {
                            res.IsSuccess  = false;
                            res.ErrMessage = "Given presecription not found.";
                            return(res);
                        }

                        // checking if prescription written is not null

                        pr.PrescriptionText = aptmnt.PrescriptionNotes.Trim().Length > 0 ? encDec.Encrypt(aptmnt.PrescriptionNotes.Trim()) : null;
                        pr.Appointment_Id   = aptmnt.AppointmentId;
                        pr.Hospital_Id      = aptmnt.HospitalId;
                        pr.Doctor_Id        = aptmnt.DoctorId;
                        pr.Patient_Id       = aptmnt.UserId;
                        pr.CreatedOn        = DateTime.UtcNow;
                        pr.IsArchivedByDoc  = false;
                        pr.IsArchivedByPat  = false;
                        if (aptmnt.IsForFamMember == true)
                        {
                            pr.IsForFamilyMember = true;
                            pr.FamilyMemberId    = aptmnt.FamMemberId;
                        }
                        else
                        {
                            pr.FamilyMemberId    = null;
                            pr.IsForFamilyMember = false;
                        }


                        obj.SaveChanges();


                        // checking attachments and saving in db
                        if (aptmnt.PrescriptionAttachments.Count > 0)
                        {
                            foreach (PrescriptopmImageClass pic in aptmnt.PrescriptionAttachments)
                            {
                                if (pic.PrescriptionImg.Length > 0 && pic.AttachmentId > 0)
                                {
                                    var pa =
                                        (from t in obj.PrescriptionAttachments
                                         where t.IsActive == true && t.Id == pic.AttachmentId
                                         select t).SingleOrDefault();
                                    if (pa != null)
                                    {
                                        pa.DocPath        = pic.PrescriptionImg.Trim();
                                        pa.CreatedOn      = DateTime.UtcNow;
                                        pa.Appointment_Id = aptmnt.AppointmentId;
                                        pa.Doctor_Id      = aptmnt.DoctorId;
                                        pa.Patient_Id     = aptmnt.UserId;

                                        pa.Hospital_Id = aptmnt.HospitalId;
                                        pa.IsActive    = true;
                                        if (pic.attachementNotes.Trim().Length > 0)
                                        {
                                            pa.Docsummary = encDec.Encrypt(pic.attachementNotes.Trim());
                                        }
                                        else
                                        {
                                            pa.Docsummary = null;
                                        }
                                        pa.Prescription_Id = pr.Id;


                                        obj.SaveChanges();
                                    }
                                }
                                if (pic.PrescriptionImg.Length > 0 && pic.AttachmentId == 0)
                                {
                                    PrescriptionAttachment pa = new PrescriptionAttachment();



                                    pa.DocPath        = pic.PrescriptionImg.Trim();
                                    pa.CreatedOn      = DateTime.UtcNow;
                                    pa.Appointment_Id = aptmnt.AppointmentId;
                                    pa.Doctor_Id      = aptmnt.DoctorId;
                                    pa.Patient_Id     = aptmnt.UserId;

                                    pa.Hospital_Id = aptmnt.HospitalId;
                                    pa.IsActive    = true;
                                    if (pic.attachementNotes.Trim().Length > 0)
                                    {
                                        pa.Docsummary = encDec.Encrypt(pic.attachementNotes.Trim());
                                    }
                                    else
                                    {
                                        pa.Docsummary = null;
                                    }
                                    pa.Prescription_Id = pr.Id;

                                    obj.PrescriptionAttachments.Add(pa);
                                    obj.SaveChanges();
                                }
                            }
                        }
                    }
                    res.IsSuccess  = true;
                    res.ErrMessage = "Prescription saved successfully.";
                }
                return(res);
            }
            catch (Exception ex)
            {
                res.IsSuccess  = false;
                res.ErrMessage = "Server Error";
                return(res);
            }
        }
Exemplo n.º 5
0
        public GetPatientsListResultClass GetPatientsList(GetAppointmentInputModel aptmnt)
        {
            GetPatientsListResultClass res = new GetPatientsListResultClass();

            try
            {
                AccessTokenValidationModel tokencheck = TokAuth.IsAccessTokenValid(aptmnt.UserId, aptmnt.AccessToken,
                                                                                   aptmnt.Lati, aptmnt.Longi, aptmnt.DeviceType, aptmnt.NotificationToken);

                res.Access = tokencheck;
                if (res.Access.IsTokenValid == true)
                {
                    // getting appointments of docotr in given
                    // checking if user is doctor and valid in given hospital
                    using (wfhealthdbEntities obj = new wfhealthdbEntities())
                    {
                        int roleid     = Utility.GetRoleId("Doctor");
                        var userResult =
                            (from c in obj.UsersMasters where c.Id == aptmnt.UserId && c.Role_Id == roleid && c.IsActive == true select c)
                            .SingleOrDefault();
                        if (userResult != null)
                        {
                            // checking if given doctor is active in given hospital
                            var userInHospcheck = (from d in obj.UsersInHospitals
                                                   where
                                                   d.User_Id == aptmnt.UserId && d.Hospital_Id == aptmnt.HospitalId &&
                                                   d.IsActive == true
                                                   select d).SingleOrDefault();
                            if (userInHospcheck != null)
                            {
                                roleid = Utility.GetRoleId("Patient");
                                // getting all doctors in given hospital
                                var allDoctors = (from c in obj.UsersMasters
                                                  join d in obj.UsersInHospitals on c.Id equals d.User_Id



                                                  where c.Role_Id == roleid && d.Hospital_Id == aptmnt.HospitalId && d.IsActive == true
                                                  select new PatientProfileOutputClass
                                {
                                    PatientEmail = c.eMail,
                                    PatientId = c.Id,
                                    PatientName = c.Name
                                }).ToList();

                                foreach (PatientProfileOutputClass doc in allDoctors)
                                {
                                    var docdetails = (from c in obj.UsersDetails where c.User_Id == doc.PatientId select c).SingleOrDefault();

                                    if (docdetails != null)
                                    {
                                        doc.PatientSkype   = docdetails.skypeId;
                                        doc.PatientWebsite = docdetails.Website;
                                    }
                                }

                                res.IsSuccess  = true;
                                res.ErrMessage = "OK";
                                res.Patients   = allDoctors;
                            }
                            else
                            {
                                res.ErrMessage = "Given user is not associated with Given hospital.";
                                res.IsSuccess  = false;
                            }
                        }
                        else
                        {
                            res.ErrMessage = "Given user is not a Doctor.";
                            res.IsSuccess  = false;
                        }
                    }
                }

                return(res);
            }
            catch
            {
                res.ErrMessage = "Error occurred at server.";
                res.IsSuccess  = false;
                return(res);
            }
        }
Exemplo n.º 6
0
        public DoctorAppointmentsResultClass GetAppointments(GetAppointmentInputModel aptmnt)
        {
            DoctorAppointmentsResultClass res = new DoctorAppointmentsResultClass();

            try
            {
                AccessTokenValidationModel tokencheck = TokAuth.IsAccessTokenValid(aptmnt.UserId, aptmnt.AccessToken,
                                                                                   aptmnt.Lati, aptmnt.Longi, aptmnt.DeviceType, aptmnt.NotificationToken);

                res.Access = tokencheck;
                if (res.Access.IsTokenValid == true)
                {
                    // getting appointments of docotr in given
                    // checking if user is doctor and valid in given hospital
                    using (wfhealthdbEntities obj = new wfhealthdbEntities())
                    {
                        var userResult =
                            (from c in obj.UsersMasters where c.Id == aptmnt.UserId && c.Role_Id == 2 && c.IsActive == true select c)
                            .SingleOrDefault();
                        if (userResult != null)
                        {
                            // checking if given doctor is active in given hospital
                            var userInHospcheck = (from d in obj.UsersInHospitals
                                                   where
                                                   d.User_Id == aptmnt.UserId && d.Hospital_Id == aptmnt.HospitalId &&
                                                   d.IsActive == true
                                                   select d).SingleOrDefault();
                            if (userInHospcheck != null)
                            {
                                List <DoctorAppointmentsResultClassInternal> Appointments = new List <DoctorAppointmentsResultClassInternal>();
                                // getting all appointments of doctor
                                var allaptDates = (from r in obj.Appointments
                                                   where
                                                   r.Doctor_Id == aptmnt.UserId && r.Hospital_Id == aptmnt.HospitalId &&
                                                   (r.IsCancelledByPat == null || r.IsCancelledByPat == false) &&
                                                   (r.IsMeetingHeld == null || r.IsMeetingHeld == false)
                                                   select EntityFunctions.TruncateTime(r.AppointmentDate)).Distinct().ToList();

                                foreach (DateTime?aptDate in allaptDates)
                                {
                                    DoctorAppointmentsResultClassInternal aptInternal = new DoctorAppointmentsResultClassInternal();
                                    var allaptmntsOnDate = (from r in obj.Appointments
                                                            where
                                                            EntityFunctions.TruncateTime(r.AppointmentDate) == aptDate && r.Doctor_Id == aptmnt.UserId &&
                                                            r.Hospital_Id == aptmnt.HospitalId &&
                                                            (r.IsCancelledByPat == null || r.IsCancelledByPat == false) &&
                                                            (r.IsMeetingHeld == null || r.IsMeetingHeld == false)
                                                            select r).ToList();
                                    List <DoctorAppointmentsResultClassInternalTimingsInDate> appointmentsOfdate = new List <DoctorAppointmentsResultClassInternalTimingsInDate>();
                                    foreach (Appointment apt in allaptmntsOnDate)
                                    {
                                        DoctorAppointmentsResultClassInternalTimingsInDate currentApt = new DoctorAppointmentsResultClassInternalTimingsInDate();
                                        currentApt.AptId     = apt.Id.ToString();
                                        currentApt.AptReason = encDec.Decrypt(apt.AptReason);

                                        currentApt.AptType     = apt.AptType;
                                        currentApt.PatientId   = apt.Patient_Id.ToString();
                                        currentApt.PatientName = apt.UsersMaster1.Name;

                                        currentApt.FromTime = apt.TimeFrom;
                                        currentApt.ToTime   = apt.TimeTo;
                                        appointmentsOfdate.Add(currentApt);
                                    }

                                    aptInternal.aptDate      = Convert.ToDateTime(aptDate).ToShortDateString();
                                    aptInternal.appointments = appointmentsOfdate;

                                    Appointments.Add(aptInternal);

                                    res.Appointments = Appointments;
                                    res.IsSuccess    = true;
                                    res.ErrMessage   = "OK";
                                }
                            }
                            else
                            {
                                res.ErrMessage = "Given user is not associated with Given hospital.";
                                res.IsSuccess  = false;
                            }
                        }
                        else
                        {
                            res.ErrMessage = "Given user is not a Doctor.";
                            res.IsSuccess  = false;
                        }
                    }
                }

                return(res);
            }
            catch
            {
                res.ErrMessage = "Error occurred at server.";
                res.IsSuccess  = false;
                return(res);
            }
        }