Exemplo n.º 1
0
        private Hospital_Entity_Framework.Visit CheckVisitCount(int patientId)
        {
            try
            {
                var checkVisit = _db.Visits.Where(v => v.PatientId == patientId).OrderByDescending(v => v.VisitCount).Select(v => v.VisitCount).First();

                var insert = new Hospital_Entity_Framework.Visit {
                    VisitCount = checkVisit + 1, PatientId = patientId, Date = DateTime.Now
                };
                _db.Visits.Add(insert);
                _db.SaveChanges();

                var getVisit = _db.Visits.Single(v => v.PatientId == patientId && v.VisitCount == checkVisit + 1);
                return(getVisit);
            }
            catch
            {
                var insert = new Hospital_Entity_Framework.Visit {
                    VisitCount = 1, PatientId = patientId, Date = DateTime.Now
                };
                _db.Visits.Add(insert);
                _db.SaveChanges();

                var getVisit = _db.Visits.Single(v => v.PatientId == patientId && v.VisitCount == 1);
                return(getVisit);
            }
        }
        private void CreateVisit(int patientId, string description)
        {
            try
            {
                var checkVisit = _db.Visits.Where(v => v.PatientId == patientId).OrderByDescending(v => v.VisitCount).Select(v => v.VisitCount).First();

                var insert = new Hospital_Entity_Framework.Visit {
                    VisitCount = checkVisit + 1, PatientId = patientId, Date = DateTime.Now
                };
                _db.Visits.Add(insert);
                _db.SaveChanges();

                var getVisit = _db.Visits.Single(v => v.PatientId == patientId && v.VisitCount == checkVisit + 1);

                var get = _db.LaboratoryEstimates.Where(v => v.PatientId == patientId)
                          .First(v => v.Description == description);

                _db.Visits.First(v => v.Id == getVisit.Id && v.VisitCount == getVisit.VisitCount).LaboratoryEstimates.Add(get);
                _db.SaveChanges();
            }
            catch
            {
                var insert = new Hospital_Entity_Framework.Visit {
                    VisitCount = 1, PatientId = patientId, Date = DateTime.Now
                };
                _db.Visits.Add(insert);
                _db.SaveChanges();

                var getVisit = _db.Visits.Single(v => v.PatientId == patientId && v.VisitCount == 1);
                var get      = _db.LaboratoryEstimates.Where(v => v.PatientId == patientId)
                               .First(v => v.Description == description);

                _db.Visits.First(v => v.Id == getVisit.Id && v.VisitCount == getVisit.VisitCount).LaboratoryEstimates.Add(get);
                _db.SaveChanges();
            }
        }