public void Delete_HappyPath()
        {
            // obtains a valid patient
            Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db);
            this.db.SaveChanges();
            var patientId = this.db.Patients.First().Id;

            var formModel = new AnamneseViewModel()
            {
                PatientId = patientId,
                Conclusion = "This is my anamnese",
                DiagnosticHypotheses = new List<DiagnosticHypothesisViewModel>() {
                        new DiagnosticHypothesisViewModel() { Text = "Text", Cid10Code = "Q878" },
                        new DiagnosticHypothesisViewModel() { Text = "Text2", Cid10Code = "Q879" }
                   }
            };

            var mr = new MockRepository(true);
            var controller = mr.CreateController<AnamnesesController>();
            controller.Create(new[] { formModel });

            Assert.IsTrue(controller.ModelState.IsValid);

            // get's the newly created anamnese
            var newlyCreatedAnamnese = this.db.Anamnese.First();

            // tries to delete the anamnese
            var result = controller.Delete(newlyCreatedAnamnese.Id);
            JsonDeleteMessage deleteMessage = (JsonDeleteMessage)result.Data;

            Assert.AreEqual(true, deleteMessage.success);
            Assert.AreEqual(0, this.db.Anamnese.Count());
        }
 public ActionResult Create(AnamneseViewModel[] anamneses)
 {
     return this.Edit(anamneses);
 }
        public ActionResult Edit(AnamneseViewModel[] anamneses)
        {
            var formModel = anamneses.Single();

            Debug.Assert(formModel.PatientId != null, "formModel.PatientId != null");
            if (this.ModelState.IsValid)
            {
                Anamnese anamnese = null;
                if (formModel.Id == null)
                {

                    anamnese = new Anamnese
                    {
                        CreatedOn = this.GetUtcNow(),
                        PatientId = formModel.PatientId.Value,
                        PracticeId = this.DbUser.PracticeId,
                    };
                    this.db.Anamnese.AddObject(anamnese);
                }
                else
                    anamnese = this.db.Anamnese.First(a => a.Id == formModel.Id);

                anamnese.Patient.IsBackedUp = false;
                anamnese.Allergies = formModel.Allergies;
                anamnese.ChiefComplaint = formModel.ChiefComplaint;
                anamnese.Conclusion = formModel.Conclusion;
                anamnese.FamilyDiseases = formModel.FamilyDeseases;
                anamnese.HistoryOfThePresentIllness = formModel.HistoryOfThePresentIllness;
                anamnese.PastMedicalHistory = formModel.PastMedicalHistory;
                anamnese.RegularAndAcuteMedications = formModel.RegularAndAcuteMedications;
                anamnese.ReviewOfSystems = formModel.ReviewOfSystems;
                anamnese.SexualHistory = formModel.SexualHistory;
                anamnese.SocialDiseases = formModel.SocialHistory;
                anamnese.MedicalRecordDate = this.ConvertToUtcDateTime(formModel.MedicalRecordDate.Value);

                this.db.SaveChanges();

                // todo: this shoud be a redirect... so that if user press F5 in browser, the object will no be saved again.
                return this.View("Details", GetViewModel(anamnese, this.GetToLocalDateTimeConverter()));
            }

            return this.View("Edit", formModel);
        }
        public ActionResult Edit(int? id, int? patientId, int? y, int? m, int? d)
        {
            AnamneseViewModel viewModel = null;

            if (id != null)
                viewModel = GetViewModel(
                    (from a in this.db.Anamnese where a.Id == id select a).First(),
                    this.GetToLocalDateTimeConverter());
            else
            {
                viewModel = new AnamneseViewModel
                {
                    Id = null,
                    PatientId = patientId,
                    MedicalRecordDate = DateTimeHelper.CreateDate(y, m, d) ?? this.GetPracticeLocalNow(),
                };
            }

            return this.View("Edit", viewModel);
        }
        public void Edit_HappyPath()
        {
            AnamnesesController controller;
            AnamneseViewModel formModel;
            try
            {
                // obtains a valid patient
                Firestarter.CreateFakePatients(this.db.Doctors.First(), this.db, 1);
                this.db.SaveChanges();
                var patientId = this.db.Patients.First().Id;

                formModel = new AnamneseViewModel()
                    {
                        PatientId = patientId,
                        Conclusion = "This is my anamnese",
                        DiagnosticHypotheses = new List<DiagnosticHypothesisViewModel>()
                            {
                                new DiagnosticHypothesisViewModel() {Text = "Text", Cid10Code = "Q878"},
                                new DiagnosticHypothesisViewModel() {Text = "Text2", Cid10Code = "Q879"}
                            }
                    };

                var mr = new MockRepository(true);
                controller = mr.CreateController<AnamnesesController>();
            }
            catch
            {
                Assert.Inconclusive("Test initialization has failed.");
                return;
            }

            // executing the test
            controller.Create(new[] { formModel });

            Assert.IsTrue(controller.ModelState.IsValid);

            var anamneses = this.db.Anamnese.ToList();
            var diagnosticHypotheses = this.db.DiagnosticHypotheses.ToList();

            Assert.AreEqual(1, anamneses.Count);
            Assert.AreEqual(2, diagnosticHypotheses.Count);
        }