コード例 #1
0
        public ActionResult <IEnumerable <dynamic> > IsAlert([Microsoft.AspNetCore.Mvc.FromBody] MedicalStatusDataModel status)
        {
            PatientDataModel     patientInfo;
            IEnumerable <string> alertingDevice;

            int[] layout;
            try
            {
                patientInfo = _patientDataRepository.FetchPatientInfoFromBedId(status.BedId);
                CheckPatientValid(patientInfo);

                alertingDevice = _deviceDataRepository.Alert(status);
                layout         = _deviceDataRepository.FetchBedLayoutInfo(status.BedId);
            }
            catch (ArgumentException)
            {
                return(BadRequest("Invalid Request Body"));
            }

            var responseData = new Dictionary <string, dynamic>
            {
                { "patientId", patientInfo.PatientId },
                { "email", patientInfo.Email },
                { "address", patientInfo.Address },
                { "mobile", patientInfo.Mobile },
                { "Bed Id", status.BedId },
                { "Alert Device", alertingDevice },
                { "Row", layout[0] },
                { "Column", layout[1] }
            };

            return(!alertingDevice.Any() ? Ok("Patient Condition OK") : Ok(responseData));
        }
コード例 #2
0
        public IEnumerable <string> Alert(MedicalStatusDataModel medicalStatus)
        {
            var alertingDevice = new List <string>();

            foreach (var medicalDevice in medicalStatus.MedicalDevice)
            {
                var values = _medicalDeviceDataRepository.FetchMedicalDevice(medicalDevice.Key);
                if (values == null)
                {
                    throw new ArgumentException("Invalid medical device");
                }
                if (IsAlert(values.MinValue, values.MaxValue, medicalDevice.Value))
                {
                    BedOnAlert bed = new BedOnAlert
                    {
                        BedId      = medicalStatus.BedId,
                        DeviceName = medicalDevice.Key,
                        Value      = medicalDevice.Value
                    };
                    TurnOnAlert(bed);
                    alertingDevice.Add(medicalDevice.Key);
                }
            }

            return(alertingDevice);
        }
コード例 #3
0
        public void TestAlertInvalidMedicalDeviceThrowException()
        {
            var medicalDeviceBusinessLogic = new MedicalDeviceBusinessLogic(_repo);
            var status = new MedicalStatusDataModel
            {
                BedId = "1", MedicalDevice = new Dictionary <string, int> {
                    { "BP", 29 }
                }
            };

            Assert.Throws <ArgumentException>(() => medicalDeviceBusinessLogic.Alert(status));
        }
コード例 #4
0
        public void TestAlertIfValueExceedRange()
        {
            var medicalDeviceBusinessLogic = new MedicalDeviceBusinessLogic(_repo);
            var status = new MedicalStatusDataModel
            {
                BedId = "1", MedicalDevice = new Dictionary <string, int> {
                    { "Oxymeter", 100 }
                }
            };
            var alertingDevice = medicalDeviceBusinessLogic.Alert(status);

            Assert.NotNull(alertingDevice);
        }
コード例 #5
0
        public IEnumerable <string> Alert(MedicalStatusDataModel medicalStatus)
        {
            if (medicalStatus.BedId == "1B1")
            {
                throw new ArgumentException("");
            }
            if (medicalStatus.BedId == "1C1")
            {
                throw new Exception("");
            }
            var alertingDevice = new List <string> {
                "Oxymeter"
            };

            return(alertingDevice);
        }
コード例 #6
0
        public void TestAlertDeviceInvalidDevice(string bedId)
        {
            var controller = new MedicalDeviceController(_deviceRepo, _patientRepo);
            var model      = new MedicalStatusDataModel {
                BedId = bedId
            };
            var medicalDevice = new Dictionary <string, int> {
                { "deviceName", 50 }
            };

            model.MedicalDevice = medicalDevice;
            var actualResponse       = controller.IsAlert(model);
            var actualResponseObject = actualResponse.Result as BadRequestObjectResult;

            Assert.NotNull(actualResponseObject);
            Assert.Equal(400, actualResponseObject.StatusCode);
        }
コード例 #7
0
        public void TestAlertDeviceSuccessfully(string deviceName)
        {
            var controller = new MedicalDeviceController(_deviceRepo, _patientRepo);
            var model      = new MedicalStatusDataModel {
                BedId = "1A1"
            };
            var medicalDevice = new Dictionary <string, int>();

            if (deviceName != "")
            {
                medicalDevice.Add(deviceName, 50);
            }
            model.MedicalDevice = medicalDevice;
            var actualResponse       = controller.IsAlert(model);
            var actualResponseObject = actualResponse.Result as OkObjectResult;

            Assert.NotNull(actualResponseObject);
            Assert.Equal(200, actualResponseObject.StatusCode);
        }
コード例 #8
0
        public void TestAlertIsGeneratedForInvalidData()
        {
            string alertUrl   = url + "/Alert";
            var    deviceInfo = new Dictionary <string, int>();

            deviceInfo.Add("HeartMachine", 60);
            IRestClient  restClient  = new RestClient();
            IRestRequest restRequest = new RestRequest()
            {
                Resource = alertUrl
            };
            var isAlertGenerated = new MedicalStatusDataModel()
            {
                BedId         = "8A3",
                MedicalDevice = deviceInfo
            };

            restRequest.AddHeader("Content-Type", "application/json");
            restRequest.AddJsonBody(isAlertGenerated);
            IRestResponse restResponse = restClient.Post(restRequest);

            Assert.AreEqual(restResponse.StatusCode, HttpStatusCode.BadRequest);
        }
コード例 #9
0
        public void TestAlertIsNotGenerated()
        {
            string alertUrl   = url + "/Alert";
            var    deviceInfo = new Dictionary <string, int>();

            deviceInfo.Add("device", 110);
            IRestClient  restClient  = new RestClient();
            IRestRequest restRequest = new RestRequest()
            {
                Resource = alertUrl
            };
            var isAlertGenerated = new MedicalStatusDataModel()
            {
                BedId         = "1A1",
                MedicalDevice = deviceInfo
            };

            restRequest.AddHeader("Content-Type", "application/json");
            restRequest.AddJsonBody(isAlertGenerated.ToJsonString());
            IRestResponse restResponse = restClient.Post(restRequest);

            Assert.AreEqual((int)restResponse.StatusCode, 400);
        }