예제 #1
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();
            }
        }
예제 #2
0
        /// <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();
            }
        }
예제 #3
0
        public void Create()
        {
            //Arrange
            var analysisViewModel = new AnalysisViewModel
            {
                Hemoglobin    = 150,
                Hematocrit    = 0.35,
                PlateletCount = 150000,
                Alt           = 5,
                Ast           = 20,
                Cpk           = 50,
                Proteins      = 70,
                Sodium        = 150,
                Potassium     = 4,
                Chloride      = 100
            };

            //Act
            var analysisId = _analysisService.Create(analysisViewModel);
            var analysis   = _dataContext.Analyses.SingleOrDefault(a => a.Id == analysisId);

            //Assert
            Assert.That(analysisId, Is.Not.Zero);
            Assert.That(analysis, Is.Not.Null);
        }