public IHttpActionResult PostPatientCheck(PatientCheckModel patientCheck)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var dbPatientCheck = new PatientCheck();

            dbPatientCheck.Update(patientCheck);

            db.PatientChecks.Add(dbPatientCheck);

            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw new Exception("Unable to add the patient Check in", e);
            }

            patientCheck.PatientCheckID = dbPatientCheck.PatientCheckID;

            return CreatedAtRoute("DefaultApi", new { id = patientCheck.PatientCheckID }, patientCheck);
        }
Example #2
0
        public void Update(PatientCheckModel patientCheck)
        {
            if (patientCheck.PatientCheckID == 0)
            {
                CheckinDateTime = DateTime.Now;
            }

            PatientID = patientCheck.PatientID;
            SpecialtyID = patientCheck.SpecialtyID;
            CheckoutDateTime = patientCheck.CheckoutDateTime;
            PatientID = patientCheck.PatientID;
            SpecialtyID = patientCheck.SpecialtyID;
        }
        public IHttpActionResult PutPatientCheck(int id, PatientCheckModel patientCheck)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != patientCheck.PatientCheckID)
            {
                return BadRequest();
            }
            var dbPatientCheck = db.PatientChecks.Find(id);

            dbPatientCheck.Update(patientCheck);

            db.Entry(dbPatientCheck).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PatientCheckExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw new Exception("Unable to update the patient check-in");
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public void PutPatientCheckReturnPatientCheck()
        {
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<PatientCheckModel> contentResult;
            OkNegotiatedContentResult<PatientCheckModel> patientCheckResult;
            OkNegotiatedContentResult<PatientCheckModel> readContentResult;
            DateTime now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                        DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            int createdPatientID;
            int createdSpecialtyID;

            // Create a new test patient, and get its patient ID
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Testpatient",
                    LastName = "Testerson",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = new DateTime(2015, 11, 10),
                    Archived = false
                };
                result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = createdContentResult.Content.PatientID;
            }

            // Create a new test specialty, and get its specialty ID
            using (var specialtyController = new SpecialtiesController())
            {
                var specialty = new SpecialtyModel
                {
                    SpecialtyName = "Very Special Doctor"
                };
                result = specialtyController.PostSpecialty(specialty);
                CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult =
                    (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result;
                createdSpecialtyID = specialtyContentResult.Content.SpecialtyID;
            }

            using (var patientCheckController = new PatientChecksController())
            {
                var newPatientCheck = new PatientCheckModel
                {
                    PatientID = createdPatientID,
                    SpecialtyID = createdSpecialtyID,
                    CheckinDateTime = now,
                    CheckoutDateTime = now.AddHours(2)
                };

                result = patientCheckController.PostPatientCheck(newPatientCheck);

                contentResult = (CreatedAtRouteNegotiatedContentResult<PatientCheckModel>)result;

            }
            using (var SecondPatientCheckController = new PatientChecksController())
            {
                result = SecondPatientCheckController.GetPatientCheck(contentResult.Content.PatientCheckID);

                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PatientCheckModel>));

                patientCheckResult = (OkNegotiatedContentResult<PatientCheckModel>)result;
            }
            using (var ThirdPatientCheckController = new PatientChecksController())
            {
                var modifiedPatientCheck = patientCheckResult.Content;

                modifiedPatientCheck.CheckoutDateTime = now;

                result = ThirdPatientCheckController.PutPatientCheck(patientCheckResult.Content.PatientCheckID, modifiedPatientCheck);

                Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            }

            using (var FourthPatientCheckController = new PatientChecksController())
            {
                IHttpActionResult resultAlteredPatientCheck = FourthPatientCheckController.GetPatientCheck(patientCheckResult.Content.PatientCheckID);

                OkNegotiatedContentResult<PatientCheckModel> alteredResult = (OkNegotiatedContentResult<PatientCheckModel>)resultAlteredPatientCheck;

                PatientCheckModel updatedPatientCheck = (PatientCheckModel)alteredResult.Content;

                Assert.IsInstanceOfType(resultAlteredPatientCheck, typeof(OkNegotiatedContentResult<PatientCheckModel>));

                readContentResult = (OkNegotiatedContentResult<PatientCheckModel>)resultAlteredPatientCheck;

                Assert.IsTrue(readContentResult.Content.CheckoutDateTime == now);
            }

            // Delete the test patient check
            using (var FifthPatientCheckController = new PatientChecksController())
            {
                result = FifthPatientCheckController.DeletePatientCheck(readContentResult.Content.PatientCheckID);
            }

            // Delete the test patient (actual deletion, not archiving)
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }

            // Delete the test specialty
            using (var specialtyController = new SpecialtiesController())
            {
                result = specialtyController.DeleteSpecialty(createdSpecialtyID);
            }
        }
        public void DeletePatientCheck()
        {
            int createdPatientID;
            int createdSpecialtyID;
            IHttpActionResult result;
            CreatedAtRouteNegotiatedContentResult<PatientCheckModel> contentResult;

            // Create a new test patient, and get its patient ID
            using (var patientController = new PatientsController())
            {
                var patient = new PatientModel
                {
                    FirstName = "Testpatient",
                    LastName = "Testerson",
                    Birthdate = new DateTime(1968, 12, 27),
                    Email = "*****@*****.**",
                    BloodType = "A+",
                    CreatedDate = new DateTime(2015, 11, 10),
                    Archived = false
                };
                result = patientController.PostPatient(patient);
                CreatedAtRouteNegotiatedContentResult<PatientModel> createdContentResult =
                    (CreatedAtRouteNegotiatedContentResult<PatientModel>)result;
                createdPatientID = createdContentResult.Content.PatientID;
            }

            // Create a new test specialty, and get its specialty ID
            using (var specialtyController = new SpecialtiesController())
            {
                var specialty = new SpecialtyModel
                {
                    SpecialtyName = "Very Special Doctor"
                };
                result = specialtyController.PostSpecialty(specialty);
                CreatedAtRouteNegotiatedContentResult<SpecialtyModel> specialtyContentResult =
                    (CreatedAtRouteNegotiatedContentResult<SpecialtyModel>)result;
                createdSpecialtyID = specialtyContentResult.Content.SpecialtyID;
            }

            using (var patientCheckController = new PatientChecksController())
            {
                var newPatientCheck = new PatientCheckModel
                {
                    PatientID = createdPatientID,
                    SpecialtyID = createdSpecialtyID,
                    CheckinDateTime = DateTime.Now,
                    CheckoutDateTime = DateTime.Now.AddHours(2)
                };
                result = patientCheckController.PostPatientCheck(newPatientCheck);

                contentResult = (CreatedAtRouteNegotiatedContentResult<PatientCheckModel>)result;
            }
            using (var SecondPatientCheckController = new PatientChecksController())
            {
                result = SecondPatientCheckController.DeletePatientCheck(contentResult.Content.PatientCheckID);

                Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<PatientCheckModel>));
            }
            using (var ThirdPatientCheckController = new PatientChecksController())
            {
                result = ThirdPatientCheckController.GetPatientCheck(contentResult.Content.PatientCheckID);

                Assert.IsInstanceOfType(result, typeof(NotFoundResult));

            }

            // Delete the test patient (actual deletion, not archiving)
            using (MedAgendaDbContext db = new MedAgendaDbContext())
            {
                Patient dbPatient = db.Patients.Find(createdPatientID);
                db.Patients.Remove(dbPatient);
                db.SaveChanges();
            }

            // Delete the test specialty
            using (var specialtyController = new SpecialtiesController())
            {
                result = specialtyController.DeleteSpecialty(createdSpecialtyID);
            }
        }
        public IHttpActionResult ScheduleAppointment(PatientCheckModel check)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest();
            }

            try
            {
                using (var scheduler = new AppointmentScheduler(db))
                {
                   Appointment appointment = scheduler.CreateAppointment(check.PatientCheckID);
                    return Ok(Mapper.Map<AppointmentModel>(appointment));
                }

            }
            catch (Exception e)
            {
                throw new Exception("Unable to schedule the appointment", e);
            }
        }