/// <summary>
        /// Created a observations viewmodel of the specified registry/patient
        ///
        /// </summary>
        /// <param name="registry"></param>
        /// <returns>the observation viewmodel data-subject,body,date and author</returns>
        private List <ObservationsVM> GetObservationVM(ClinicRegistryManager registry)
        {
            ObservationsVM        vm = null;
            List <ObservationsVM> listObservationsVM = new List <ObservationsVM>();
            VisitManager          vManager           = null;

            db.Entry(registry).Reference(x => x.Staff_doctor).Load();
            //List<Observations> obs = db.Observations.Where(x => x.clinicalRegistry.ClinicRegistryManagerId == registry.ClinicRegistryManagerId).ToList();
            List <Observations> obs = SetListObservation(registry);

            foreach (Observations item in obs)
            {
                vManager = db.VisitManagers.Where(x => x.PatientVisitRegistry.ClinicRegistryManagerId == registry.ClinicRegistryManagerId).FirstOrDefault();

                if (vManager != null)
                {
                    vm               = new ObservationsVM();
                    vm.Subject       = item.subject;
                    vm.observationID = item.observations_ID;
                    vm.Date          = vManager.visit.Visit_Date;

                    vm.Author = db.ClinicRegistryManagers.Where(x => x.ClinicRegistryManagerId == registry.ClinicRegistryManagerId).FirstOrDefault().Staff_doctor.Name;
                }
                listObservationsVM.Add(vm);
            }

            return(listObservationsVM);
        }
Пример #2
0
        /// <summary>
        /// is an auxilliary function and receives a single ICD object as a param
        /// aaociated the code to the disease object and consequently
        /// to the clincRegistry instance
        /// </summary>
        /// <param name="disCode">ICD code object</param>
        private void saveDiagnosisAUX(CID_DiseaseCode disCode)
        {
            CIDCode diseaseCode = db.CIDCodes.Where(x => x.CID_DiseaseCode.DiseaseCode == disCode.DiseaseCode &&
                                                    x.CID_DiseaseCode.CIDCategory.CID_CategorID == disCode.CIDCategory.CID_CategorID).FirstOrDefault();

            Disease disease = new Disease {
                Disease_start_date = DateTime.Now, Disease_is_active = true
            };
            ClinicRegistryManager registry = SingletonClinicRegistry.GetInstance(db);

            try {
                Diagnosis diagnosis = new Diagnosis {
                    Diagnosis_CID_code = diseaseCode, Diagnosis_disease = disease, ClinicRegistry_Manager = registry
                };
                db.Diagnoses.Add(diagnosis);
                db.SaveChanges();
                //db.Entry(diagnosis).State = EntityState.Detached;
            } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the name of the physician.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        private string setPhysicianName(int id)
        {
            ClinicRegistryManager registry = db.ClinicRegistryManagers.Where(x => x.ClinicRegistryManagerId == id).FirstOrDefault();

            db.Entry(registry).Reference(x => x.Staff_doctor).Load();
            return(registry.Staff_doctor.Name);
        }
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static ClinicRegistryManager GetInstance(HPCareDBContext context)
        {
            Patient patient = context.Users.Find(HttpContext.Current.Session["patientId"]) as Patient;
            //get information about the current clinic logged in
            CurrentUserId currentStaff   = new CurrentUserId();
            int           currentIdStaff = currentStaff.AccessDatabase(HttpContext.Current.User.Identity.Name);
            //Users staff = currentStaff.ReturnCurrentUser(currentIdStaff);
            Staff staff = context.Users.Find(currentIdStaff) as Staff;

            if (singletonInstance == null)
            {
                // singletonInstance = new ClinicRegistryManager { ClinicRegistryManagerId = AccessDatabase(patient, staff, context).ClinicRegistryManagerId };
                singletonInstance = new ClinicRegistryManager {
                    Clinic_patient = patient, Staff_doctor = staff
                };
                Visit visit = new Visit {
                    Visit_Date = DateTime.Today.Date, Visit_Hour = DateTime.Now.TimeOfDay
                };
                context.VisitManagers.Add(new VisitManager {
                    visit = visit, PatientVisitRegistry = singletonInstance
                });
                context.SaveChanges();
            }

            return(context.ClinicRegistryManagers.Find(singletonInstance.ClinicRegistryManagerId));
        }
        private List <Observations> SetListObservation(ClinicRegistryManager registry)
        {
            Patient patient = db.Users.Find(HttpContext.Current.Session["patientId"]) as Patient;

            if (patient == null)
            {
                return
                    (db.Observations.Where(x => x.clinicalRegistry.ClinicRegistryManagerId == registry.ClinicRegistryManagerId && x.IsClassified == false).ToList());
            }
            return(db.Observations.Where(x => x.clinicalRegistry.ClinicRegistryManagerId == registry.ClinicRegistryManagerId).ToList());
        }