public void Test_GetAlertProfile_Successful()
        {
            var alertInputParam = new AlertInputParm {
                PatientInfo = new PatientInfo {
                    Hkid = "H0002520"
                }
            };

            var relateivePath = string.Format(@"Data\AP\{0}.json", alertInputParam.PatientInfo.Hkid);
            var fileName      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relateivePath);

            var expectedProfile = JsonHelper.JsonToObjectFromFile <AlertProfileResult>(fileName);

            Assert.IsNotNull(expectedProfile);
            var expectedProfileJSONStr = JsonHelper.ToJson(expectedProfile);


            var actualProfile = parser.GetAlertProfile(alertInputParam);

            Assert.IsNotNull(expectedProfile);

            var actualProfileJSONStr = JsonHelper.ToJson(actualProfile);

            Assert.AreEqual(expectedProfileJSONStr, actualProfileJSONStr);
        }
        public AlertProfileResult Post([FromBody] AlertInputParm alertInputParm)
        {
            if (alertInputParm == null)
            {
                this.ThrowHttpResponseExceptions(HttpStatusCode.BadRequest, "alertInputParm is null!");
            }

            ValidateRequestHeaders();

            //invalid HKID
            if (alertInputParm.PatientInfo == null ||
                string.IsNullOrEmpty(alertInputParm.PatientInfo.Hkid) ||
                alertInputParm.PatientInfo.Hkid.ToUpper().StartsWith("INVALID_HKID"))
            {
                return(JsonFromFile("INVALID_HKID"));
            }
            var tempHKID = alertInputParm.PatientInfo.Hkid.ToUpper();

            if (HKIDs.Contains(tempHKID))
            {
                return(JsonFromFile(tempHKID));
            }
            //invalid Patient info
            else
            {
                return(JsonFromFile("INVALID_PATIENT"));
            }
        }
        public IEnumerable <Allergies> GetAllergies(AlertInputParm alertinput)
        {
            var apr = allergiesParser.GetAlertProfile(alertinput);

            var result = apr.ToConvert();

            return(result);
        }
        public void Test_GetAlertProfile_Invalid_AccessCode()
        {
            var caseNumber = new AlertInputParm {
                PatientInfo = new PatientInfo {
                    Hkid = "INVALID_ACCESSCODE"
                }
            };

            var actualProfile = parser.GetAlertProfile(caseNumber);
        }
        public void Test_GetAlertProfile_Service_Unavailable()
        {
            var alertInput = new AlertInputParm {
            };

            var httpStatusCode = HttpStatusCode.ServiceUnavailable;

            var localParser     = new RestParserSvc("http://localhost:3181/pms-asa/invalidurl/", "CLIENT_SECRET", "CLIENT_ID", "PATHOSPCODE");
            var actualException = Assert.ThrowsException <AMException>(() => localParser.GetAlertProfile(alertInput));

            Assert.AreEqual(actualException.HttpStatusCode, httpStatusCode);
        }
        public void Test_GetAlertProfile_Service_NotFound()
        {
            var alertInput = new AlertInputParm {
            };

            var httpStatusCode = HttpStatusCode.NotFound;

            var localParser     = new RestParserSvc(restUri + @"invalidurl/", "CLIENT_SECRET", "CLIENT_ID", "PATHOSPCODE");
            var actualException = Assert.ThrowsException <AMException>(() => localParser.GetAlertProfile(alertInput));

            Assert.AreEqual(actualException.HttpStatusCode, httpStatusCode);
        }
        public async Task <AlertProfileResult> PostAsync()
        {
            var contenttype = Request.Content.Headers.ContentType;

            System.Diagnostics.Debug.WriteLine(Request.Content.Headers.ToString());

            string result = await Request.Content.ReadAsStringAsync();

            if (string.IsNullOrWhiteSpace(result))
            {
                this.ThrowHttpResponseExceptions(HttpStatusCode.BadRequest, "alertInputParm is null!");
            }

            AlertInputParm alertInputParm = null;

            try
            {
                alertInputParm = XmlHelper.XmlDeserialize <AlertInputParm>(result);
            }
            catch
            {
                this.ThrowHttpResponseExceptions(HttpStatusCode.BadRequest, "alertInputParm is null!");
            }


            if (alertInputParm == null)
            {
                this.ThrowHttpResponseExceptions(HttpStatusCode.BadRequest, "alertInputParm is null!");
            }

            ValidateRequestHeaders();

            //invalid HKID
            if (alertInputParm.PatientInfo == null ||
                string.IsNullOrEmpty(alertInputParm.PatientInfo.Hkid) ||
                alertInputParm.PatientInfo.Hkid.ToUpper().StartsWith("INVALID_HKID"))
            {
                return(JsonFromFile("INVALID_HKID"));
            }
            var tempHKID = alertInputParm.PatientInfo.Hkid.ToUpper();

            if (HKIDs.Contains(tempHKID))
            {
                return(JsonFromFile(tempHKID));
            }
            //invalid Patient info
            else
            {
                return(JsonFromFile("INVALID_PATIENT"));
            }
        }
        public void Test_GetAlertProfile_Invalid_Client_Secret()
        {
            var alertInput = new AlertInputParm {
                PatientInfo = new PatientInfo {
                    Hkid = "INVALID_CLIENT_SECRET"
                }
            };
            var errorMessage   = "Unauthorized";
            var httpStatusCode = HttpStatusCode.Unauthorized;

            var localParser = new RestParserSvc(restUri, "INVALID_CLIENT_SECRET", "CLIENT_ID", "PATHOSPCODE");

            var actualException = Assert.ThrowsException <AMException>(() => localParser.GetAlertProfile(alertInput));

            Assert.AreEqual(actualException.HttpStatusCode, httpStatusCode);
            Assert.AreEqual(actualException.Message, errorMessage);
        }
        public void Test_GetAlertProfile_Invalid_HKID()
        {
            var caseNumber = new AlertInputParm {
                PatientInfo = new PatientInfo {
                    Hkid = "INVALID_HKID"
                }
            };

            try
            {
                var actualProfile = parser.GetAlertProfile(caseNumber);
            }
            catch (AMException e)
            {
                Assert.IsTrue(e.Message.Contains("Invalid Request:20001"));
            }
        }
Exemplo n.º 10
0
        public AlertProfileResult Post([FromBody] AlertInputParm alertInputParm)
        {
            ValidateHeaders();

            return(new AlertProfileResult
            {
                AdrProfile = new List <AdrProfile> {
                },
                AlertProfile = new List <AlertProfile> {
                },
                AllergyProfile = new List <AllergyProfile> {
                },
                SimpleDisplayFormat = new List <SimpleDisplayFormat> {
                },
                ErrorMessage = new List <object> {
                }
            });
        }
        public void Test_GetAlertProfile_Invalid_PatientInfo()
        {
            var caseNumber = new AlertInputParm {
                PatientInfo = new PatientInfo {
                    Hkid = "INVALID_PATIENT"
                }
            };

            var actualProfile = parser.GetAlertProfile(caseNumber);

            //Assert.IsNotNull(actualProfile);
            //Assert.AreEqual(actualProfile.AdrProfile.Count, 0);
            //Assert.AreEqual(actualProfile.AlertProfile.Count, 0);
            //Assert.AreEqual(actualProfile.AllergyProfile.Count, 0);

            //Assert.IsNull(actualProfile.MoePatientSteroidTag);

            //Assert.IsNotNull(actualProfile.ErrorMessage);
            //Assert.IsNotNull(actualProfile.ErrorMessage[0].MsgCode, "20002");
        }
        public AlertProfileResult GetAlertProfile(AlertInputParm alertInputParm)
        {
            //invalid HKID
            if (alertInputParm.PatientInfo == null ||
                string.IsNullOrEmpty(alertInputParm.PatientInfo.Hkid) ||
                alertInputParm.PatientInfo.Hkid.ToUpper().StartsWith("INVALID_HKID"))
            {
                return(JsonFromFile("INVALID_HKID"));
            }
            var tempHKID = alertInputParm.PatientInfo.Hkid.ToUpper();

            // ValidateRequestHeaders();

            if (HKIDs.Contains(tempHKID))
            {
                return(JsonFromFile(tempHKID));
            }
            //invalid Patient info
            else
            {
                return(JsonFromFile("INVALID_PATIENT"));
            }
        }
Exemplo n.º 13
0
        public AlertProfileResult GetAlertProfile(AlertInputParm alertinput)
        {
            var client  = new RestClient(restUri);
            var request = new RestRequest("alertProfile", Method.POST);

            request.AddHeader("client_secret", client_secret);
            request.AddHeader("client_id", client_id);
            request.AddHeader("pathospcode", pathospcode);

            request.XmlSerializer = new DotNetXmlSerializer();

            var xmlRequestBody = XmlHelper.XmlSerializeToString(alertinput);

            request.AddParameter("application/json", xmlRequestBody, ParameterType.RequestBody);

            logger.Info(string.Format("allergy request:{0}{1}", Environment.NewLine, XmlHelper.XmlSerializeToString(alertinput)));
            var response = client.Execute <AlertProfileResult>(request);

            if (!response.IsSuccessful())
            {
                response.ThrowException();
            }

            var result = response.Data;

            logger.Info(string.Format("allergy response:{0}{1}", Environment.NewLine, JsonHelper.ToJson(result)));

            if (IsInvalidResponseResult(result))
            {
                var errorMsg = string.Format("Invalid Request:{0}-{1}", result.ErrorMessage[0].MsgCode, result.ErrorMessage[0].MsgText);

                throw new AMException(HttpStatusCode.Unauthorized, errorMsg, null);
            }

            return(result);
        }