/// <summary>
        /// Save a new NbrSurveillance and it's related CnsExploration to the database with the data from
        /// a viewmodel. If the TimeSlot is repeated, an error will be added to the modelstate of the
        /// viewmodel and the operation will not be completed.
        /// </summary>
        /// <param name="viewModel">Viewmodel with the new surveillance data.</param>
        /// <param name="patientId">Id of the patient for which the surveillance is being created.</param>
        public void Create(EditNbrSurveillanceViewModel viewModel, int patientId)
        {
            //Check that the time slot for the surveillance is not repeated
            var repeated = Repository.NbrSurveillances
                           .Where(s => s.PatientId == patientId)
                           .Any(s => s.TimeSlot == viewModel.TimeSlot);

            //If repeated show error to the user
            if (repeated)
            {
                viewModel.ModelState.AddModelError("TimeSlot", Strings.ErrorRepeated);
            }
            else
            {
                //Create a new surveillance from the viewmodel
                var surveillance = viewModel.ToNewModel();
                surveillance.PatientId = patientId;

                //Create the associated CnsExploration
                var explorationId = _cnsExplorationService.Create(viewModel.CnsExploration);
                surveillance.CnsExplorationId = explorationId;

                //Create the associated Analysis
                var analysisId = _analysisService.Create(viewModel.Analysis);
                surveillance.AnalysisId = analysisId;

                Repository.NbrSurveillances.Add(surveillance);
                Save();
            }
        }
示例#2
0
        /// <summary>
        /// Save a new Hypothermia and it's related CnsExploration to the database with the data from
        /// a viewmodel. If the TimeSlot is repeated, an error will be added to the modelstate of the
        /// viewmodel and the operation will not be completed.
        /// </summary>
        /// <param name="viewModel">Viewmodel with the new hypothermia data.</param>
        /// <param name="patientId">Id of the patient for which the hypothermia is being created.</param>
        public void Create(EditHypothermiaViewModel viewModel, int patientId)
        {
            //Check that the time slot for the hypothermia is not repeated
            var repeated = Repository.Hypothermias
                           .Where(e => e.PatientId == patientId)
                           .Any(e => e.TimeSlot == viewModel.TimeSlot);

            //If repeated show error to the user
            if (repeated)
            {
                viewModel.ModelState.AddModelError("TimeSlot", Strings.ErrorRepeated);
            }
            else
            {
                //Create a new Hypothermia from the viewmodel
                var hypothermia = viewModel.ToNewModel();
                hypothermia.PatientId = patientId;

                //Create the associated CnsExploration
                var explorationId = _cnsExplorationService.Create(viewModel.CnsExploration);
                hypothermia.CnsExplorationId = explorationId;

                //Create the associated Analysis
                var analysisId = _analysisService.Create(viewModel.Analysis);
                hypothermia.AnalysisId = analysisId;

                Repository.Hypothermias.Add(hypothermia);
                Save();
            }
        }
示例#3
0
        public void Create()
        {
            //Arrange
            var cnsExplorationViewModel = new CnsExplorationViewModel
            {
                Behavior      = Behavior.Irregular,
                CranialNerves = CranialNerves.Irregular,
                Tone          = Tone.Low,
                Position      = Position.Irregular,
                Reflexes      = Reflexes.Normal
            };

            //Act
            var explorationId = _cnsExplorationService.Create(cnsExplorationViewModel);
            var exploration   = _dataContext.CnsExplorations.SingleOrDefault(e => e.Id == explorationId);

            //Assert
            Assert.That(explorationId, Is.Not.Zero);
            Assert.That(exploration, Is.Not.Null);
        }