public void AddMedication(MedicationAddRequest request)
        {
            using (var context = new HackathonEntities())
            {
                var med = new Medication()
                {
                    MedicalName = request.medName,
                    GenericName = request.name
                };
                context.Medications.Add(med);
                context.SaveChanges();

                var patientId = context.Patients.FirstOrDefault(x => x.UserId == request.userId).PatientId;

                var script = new Script()
                {
                    PatientId      = patientId,
                    MedicationId   = med.MedicationId,
                    Dosage         = request.dosage,
                    MedicationTime = request.time,
                    MPId           = 6,
                    DateIssued     = DateTime.Now,
                    DateFilled     = DateTime.Now,
                    DatePickedUp   = DateTime.Now
                };

                context.Scripts.Add(script);
                context.SaveChanges();
                context.Dispose();
            }
        }
        public void createUser(UserCreationRequest request)
        {
            var response = new HttpResponseMessage();

            try
            {
                using (var context = new HackathonEntities())
                {
                    var exists = context.users.Where(x => x.email.Equals(request.email) && x.delete_ts != null).FirstOrDefault();

                    if (exists != null && exists.email.Length > 0)
                    {
                        response = Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                               "An account with this email already exists.");
                        throw new HttpResponseException(response);
                    }
                    var user = new user()
                    {
                        first_name = request.firstName,
                        last_name  = request.lastName,
                        email      = request.email,
                        password   = hashPassword(request.password),
                        create_ts  = DateTime.Now
                    };
                    context.users.Add(user);
                    context.SaveChanges();
                    context.Dispose();
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(response);
            }
        }
        public List <ScriptModel> getPatientScripts(int?patientId)
        {
            using (var context = new HackathonEntities())
            {
                var scriptIds = context.Scripts.Where(x => x.PatientId == patientId).Select(x => x.ScriptId);
                var scripts   = new List <ScriptModel>();
                foreach (var id in scriptIds)
                {
                    var script = context.Scripts.FirstOrDefault(x => x.ScriptId == id);
                    var medicalProfessional     = context.MedicalProfessionals.FirstOrDefault(x => x.MPId == script.MPId);
                    var medicalProfessionalUser = context.users.FirstOrDefault(x => x.id == medicalProfessional.UserId);
                    var medication = context.Medications.FirstOrDefault(x => x.MedicationId == script.MedicationId);
                    scripts.Add(new ScriptModel(script)
                    {
                        PrescribedBy = "Dr. " + medicalProfessionalUser.first_name + " " +
                                       medicalProfessionalUser.last_name,
                        Phone = medicalProfessional.Phone,
                        Email = medicalProfessional.Email,
                        MedicationGenericName = medication.GenericName,
                        MedicationMedicalName = medication.MedicalName
                    });
                }

                context.Dispose();
                return(scripts);
            }
        }
 public List <Script> GetPrescriptions()
 {
     using (var context = new HackathonEntities())
     {
         return(context.Scripts.ToList());
     }
 }
        public void MarkPrescriptionsAsPickedUp(List <int> prescriptionIds)
        {
            using (var context = new HackathonEntities())
            {
                context.PharmacyEvents.Where(s => prescriptionIds.Contains(s.ScriptId))
                .ForEach(s =>
                {
                    if (s.DateFilled == null)
                    {
                        s.DateFilled = DateTime.Now;
                    }

                    s.DatePickedUp = DateTime.Now;
                });
//                context.Scripts.Where(s => prescriptionIds.Contains(s.ScriptId))
//                    .ForEach(s =>
//                    {
//                        if (s.DateFilled == null)
//                        {
//                            s.DateFilled = DateTime.Now;
//                        }
//
//                        s.DatePickedUp = DateTime.Now;
//                    });
                context.SaveChanges();
            }
        }
 public user checkIfUserExists(string email)
 {
     using (var context = new HackathonEntities())
     {
         return(context.users.FirstOrDefault(x => x.email.Equals(email) && x.delete_ts != null));
     }
 }
        public List <PatientScript> GetIncomingPrescriptions()
        {
            ReconcilePharmacyEventsToScripts();
            using (var context = new HackathonEntities())
            {
                return((from s in context.Scripts
                        join pe in context.PharmacyEvents on s.ScriptId equals pe.ScriptId
                        where s.MPId != null && s.DateFilled == null && pe.DateFilled == null
                        select new
                {
                    Script = s,
                    FirstName = s.Patient.user.first_name,
                    LastName = s.Patient.user.last_name,
                    PrescribedBy = "Dr. " + s.MedicalProfessional.user.first_name + " " +
                                   s.MedicalProfessional.user.last_name,
                    Medication = s.Medication
                }
                        ).ToList().Select(s => new PatientScript(
                                              s.Script,
                                              s.FirstName,
                                              s.LastName,
                                              s.PrescribedBy,
                                              s.Medication
                                              )).ToList());
//                return context.Scripts.Where(s => s.DateFilled == null && s.DatePickedUp == null).ToList();
            }
        }
Exemple #8
0
        public void assignMedication(ScriptRequest request)
        {
            using (var context = new HackathonEntities())
            {
                var medication = new Medication()
                {
                    GenericName = request.MedicationGenericName,
                    MedicalName = request.MedicationMedicalName
                };
                context.Medications.Add(medication);
                context.SaveChanges();

                medication = context.Medications.FirstOrDefault(x => x.GenericName == request.MedicationGenericName &&
                                                                x.MedicalName == request.MedicationMedicalName);
                var script = new Script()
                {
                    MPId            = request.medicalProfessionalId,
                    PatientId       = request.patientId,
                    MedicationId    = medication.MedicationId,
                    PharmId         = request.pharmacyId,
                    Dosage          = request.Dosage,
                    MedicationTime  = request.MedicationTime,
                    MedicationRoute = request.MedicationRoute,
                    DateIssued      = DateTime.Now
                };
                context.Scripts.Add(script);
                context.SaveChanges();
                context.Dispose();
            }
        }
Exemple #9
0
 public List <PatientDataResponse> getPatientsForMP(int medicalProfessionalId)
 {
     using (var context = new HackathonEntities())
     {
         var patientIdList = context.MpToPatients.Where(x => x.MPId == medicalProfessionalId).Select(x => x.PatientId).ToList();
         var results       = new List <PatientDataResponse>();
         foreach (var patientId in patientIdList)
         {
             var patient = patientRepository.getPatientDataFromId(patientId);
             var user    = userRepository.getUserInfoFromId(patient.UserId);
             var scripts = patientRepository.getPatientScripts(patientId);
             var result  = new PatientDataResponse()
             {
                 id        = user.id,
                 PatientId = patient.PatientId,
                 firstName = user.first_name,
                 lastName  = user.last_name,
                 email     = user.email,
                 AtRisk    = patient.AtRisk.Value ? "Yes" : "No",
                 DOB       = patient.DOB.Value.ToString("MM-dd-yyyy"),
                 Gender    = patient.Gender,
                 Scripts   = scripts
             };
             results.Add(result);
         }
         ;
         return(results);
     }
 }
        public void createPatientAndTieToMP(PatientCreationRequest patientRequest)
        {
            var response = new HttpResponseMessage();

            try
            {
                using (var context = new HackathonEntities())
                {
                    var exists = userRespository.checkIfUserExists(patientRequest.email);

                    if (exists != null && exists.email.Length > 0)
                    {
                        response = Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                               "An account with this email already exists.");
                        throw new HttpResponseException(response);
                    }
                    else
                    {
                        medicalProfessionalRepository.CreateNewPatientAndMPRecord(patientRequest);
                    }
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(response);
            }
        }
 public Patient checkIfPatientExists(int userId)
 {
     using (var context = new HackathonEntities())
     {
         return(context.Patients.FirstOrDefault(x => x.UserId.Equals(userId)));
     }
 }
        public IEnumerable <CountAndWeightByLongLat_Result> Get()
        {
            var e = new HackathonEntities();

            return(e.CountAndWeightByLongLat(DateTime.Now - new TimeSpan(14, 0, 0, 0),
                                             DateTime.Now,
                                             1, 0, 0, 0, 0));
        }
 public user getUserInfoFromId(int?id)
 {
     using (var context = new HackathonEntities())
     {
         var user = context.users.FirstOrDefault(x => x.id == id);
         context.Dispose();
         return(user);
     }
 }
 public user getUserInfo(string email)
 {
     using (var context = new HackathonEntities())
     {
         var user = context.users.FirstOrDefault(x => x.email == email);
         context.Dispose();
         return(user);
     }
 }
 public Patient getPatientInfo(int userId)
 {
     using (var context = new HackathonEntities())
     {
         var patient = context.Patients.FirstOrDefault(x => x.UserId == userId);
         context.Dispose();
         return(patient);
     }
 }
 public List <Script> GetScriptsByPatientAndMedication(MedicationPrescriptionRequest request)
 {
     using (var context = new HackathonEntities())
     {
         var patientId = context.Patients.FirstOrDefault(x => x.UserId == request.userId).PatientId;
         return(context.Scripts.Where(s => s.PatientId == patientId && s.MedicationId == request.medicationId)
                .ToList());
     }
 }
 public Patient getPatientDataFromId(int?patientId)
 {
     using (var context = new HackathonEntities())
     {
         var patient = context.Patients.FirstOrDefault(x => x.PatientId == patientId);
         context.Dispose();
         return(patient);
     }
 }
Exemple #18
0
 public MedicalProfessional getMedicalProfessionalData(int userId)
 {
     using (var context = new HackathonEntities())
     {
         var medicalProfessional = context.MedicalProfessionals.FirstOrDefault(x => x.UserId == userId);
         context.Dispose();
         return(medicalProfessional);
     }
 }
 internal void patientPickedUpMedication(int scriptId)
 {
     using (var context = new HackathonEntities())
     {
         var script = context.Scripts.FirstOrDefault(x => x.ScriptId == scriptId);
         script.DatePickedUp = DateTime.Now;
         script.DateFilled   = script.DateFilled == null ? DateTime.Now : script.DateFilled;
         context.SaveChanges();
         context.Dispose();
     }
 }
 public List <Medication> GetMedicationByPatient(int patientId)
 {
     using (var context = new HackathonEntities())
     {
         var meds         = context.Medications.ToList();
         var returnedMeds = meds.Where(m =>
                                       context.Scripts.Where(s => s.PatientId == patientId).Select(s => s.MedicationId)
                                       .Contains(m.MedicationId)).ToList();
         return(returnedMeds);
     }
 }
        public void MarkPrescriptionsAsFilled(List <int> prescriptionIds)
        {
            using (var context = new HackathonEntities())
            {
                context.PharmacyEvents.Where(s => prescriptionIds.Contains(s.ScriptId))
                .ForEach(s => s.DateFilled = DateTime.Now);
//                context.Scripts.Where(s => prescriptionIds.Contains(s.ScriptId))
//                    .ForEach(s => s.DateFilled = DateTime.Now);
                context.SaveChanges();
            }
        }
Exemple #22
0
 internal void fillMedication(int scriptId)
 {
     using (var context = new HackathonEntities())
     {
         var script = context.Scripts.FirstOrDefault(x => x.ScriptId == scriptId);
         if (script != null)
         {
             script.DateFilled = DateTime.Now;
             context.SaveChanges();
         }
     }
 }
Exemple #23
0
 public void CreateMedicalProfessional(int userId)
 {
     using (var context = new HackathonEntities())
     {
         var medicalProf = new MedicalProfessional()
         {
             UserId = userId
         };
         context.MedicalProfessionals.Add(medicalProf);
         context.SaveChanges();
         context.Dispose();
     }
 }
        public IEnumerable <CountAndWeightByLongLat_Result> Get(DateTime start, DateTime end, int precision = 1,
                                                                decimal lat1 = 0, decimal lng1 = 0, decimal lat2 = 0, decimal lng2 = 0)
        {
            var e = new HackathonEntities();

            return(e.CountAndWeightByLongLat(start,
                                             end,
                                             precision,
                                             lat1,
                                             lng1,
                                             lat2,
                                             lng2));
        }
 public void patientUsedMedication(int scriptId)
 {
     using (var context = new HackathonEntities())
     {
         var script       = context.Scripts.FirstOrDefault(x => x.ScriptId == scriptId);
         var patientUsage = new PatientUsage(script)
         {
             DateTaken = DateTime.Now
         };
         context.PatientUsages.Add(patientUsage);
         context.SaveChanges();
         context.Dispose();
     }
 }
Exemple #26
0
 public void assignPatientToMp(int medicalProfessionalId, int patientId)
 {
     using (var context = new HackathonEntities())
     {
         var mpToPatient = new MpToPatient()
         {
             MPId      = medicalProfessionalId,
             PatientId = patientId
         };
         context.MpToPatients.Add(mpToPatient);
         context.SaveChanges();
         context.Dispose();
     }
 }
 public void createNewPharmacy(PharmacyCreationRequest request, int userId)
 {
     using (var context = new HackathonEntities())
     {
         var pharmacy = new Pharmacy()
         {
             UserId   = userId,
             Location = request.Location,
             Name     = request.Name
         };
         context.Pharmacies.Add(pharmacy);
         context.SaveChanges();
         context.Dispose();
     }
 }
Exemple #28
0
        public IEnumerable <DeltaOverTimeByLongLat_Result> Get(DateTime start1, DateTime end1, DateTime start2, DateTime end2, int precision = 1,
                                                               decimal lat1 = 0, decimal lng1 = 0, decimal lat2 = 0, decimal lng2 = 0)
        {
            var e = new HackathonEntities();

            return(e.DeltaOverTimeByLongLat(start1,
                                            end1,
                                            start2,
                                            end2,
                                            precision,
                                            lat1,
                                            lng1,
                                            lat2,
                                            lng2));
        }
 public void patientDeniedMedication(PatientDeniedMedicationRequest request)
 {
     using (var context = new HackathonEntities())
     {
         var script        = context.Scripts.FirstOrDefault(x => x.ScriptId == request.ScriptId);
         var patientDenied = new PatientDenied(script)
         {
             DateDenied = DateTime.Now,
             Reason     = request.Reason
         };
         context.PatientDenieds.Add(patientDenied);
         context.SaveChanges();
         context.Dispose();
     }
 }
Exemple #30
0
 public void createNewMedicalProfessional(MedicalProfessionalRequest request, int userId)
 {
     using (var context = new HackathonEntities())
     {
         var medicalProfessional = new MedicalProfessional()
         {
             UserId  = userId,
             Address = request.Address,
             Email   = request.email,
             Phone   = request.Phone
         };
         context.MedicalProfessionals.Add(medicalProfessional);
         context.SaveChanges();
         context.Dispose();
     }
 }