public bool GetPatientDetails(ViewModel.Presenter Presenter) { FhirApi FhirApi = new FhirApi(FhirGatewayEndpoint); ApiRequestHeader ApiRequestHeader = new ApiRequestHeader(Presenter.CurrentUserAccount.AccessToken, this.ApplicationStore.App_id, this.ApplicationStore.App_Version); FhirApi.ApiRequestHeader = ApiRequestHeader; try { PatientDetailsResponse PatientDetailsResponse = FhirApi.GetPatientDetails(Presenter.CurrentUserAccount.SelectedUserAccountRecord.Ihi); Presenter.PatientBanerViewModel = new ViewModel.PatientBanerViewModel(); if (PatientDetailsResponse.StatusCode == System.Net.HttpStatusCode.OK) { if (PatientDetailsResponse.ApiPatient.Dob.HasValue) { Presenter.PatientBanerViewModel.Dob = PatientDetailsResponse.ApiPatient.Dob.Value.ToShortDateString(); } else { Presenter.PatientBanerViewModel.Dob = "Unknown"; } Presenter.PatientBanerViewModel.Family = PatientDetailsResponse.ApiPatient.Family; Presenter.PatientBanerViewModel.Given = PatientDetailsResponse.ApiPatient.Given; Presenter.PatientBanerViewModel.Sex = PatientDetailsResponse.ApiPatient.Sex; Presenter.PatientBanerViewModel.Ihi = PatientDetailsResponse.ApiPatient.Ihi; Presenter.PatientBanerViewModel.IndigenousStatus = PatientDetailsResponse.ApiPatient.IndigenousStatusDescription; //Not that RelationshipDescription and RelationshipType is not returned by GetPatient only by GetRecordLisy if (PatientDetailsResponse.Format == FhirApi.FhirFormat.Xml) { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.Xml; } else if (PatientDetailsResponse.Format == FhirApi.FhirFormat.Json) { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.Json; } else { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.None; } Presenter.TextEditorViewModel.Text = PatientDetailsResponse.Body; //PatientDetailsResponse.ApiPatient.RelationshipDescription; return(true); } else { if (PatientDetailsResponse.ErrorResponse != null) { Presenter.PatientBanerViewModel.Family = PatientDetailsResponse.ErrorResponse.Description; } else { Presenter.PatientBanerViewModel.Family = $"Unknown error, HTTPStatus: {PatientDetailsResponse.StatusCode.ToString()}"; } return(true); } } catch (Exception Exec) { throw new Exception("GetPatientDetails failed.", Exec); } }
public void GetPbsItems(ViewModel.Presenter Presenter) { FhirApi FhirApi = new FhirApi(FhirGatewayEndpoint); ApiRequestHeader ApiRequestHeader = new ApiRequestHeader(Presenter.CurrentUserAccount.AccessToken, this.ApplicationStore.App_id, this.ApplicationStore.App_Version); FhirApi.ApiRequestHeader = ApiRequestHeader; PbsItemsResponse PbsItemsResponse = FhirApi.GetPbsItems(Presenter.CurrentUserAccount.SelectedUserAccountRecord.Ihi, null, null); }
public bool GetRecordList(ViewModel.UserAccountView UserAccountView, ViewModel.Presenter Presenter) { FhirApi FhirApi = new FhirApi(FhirGatewayEndpoint); ApiRequestHeader ApiRequestHeader = new ApiRequestHeader(UserAccountView.AccessToken, this.ApplicationStore.App_id, this.ApplicationStore.App_Version); FhirApi.ApiRequestHeader = ApiRequestHeader; RecordListResponse RecordListResponse = FhirApi.GetRecordList(); if (RecordListResponse.StatusCode == System.Net.HttpStatusCode.OK) { if (RecordListResponse.Format == FhirApi.FhirFormat.Xml) { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.Xml; } else if (RecordListResponse.Format == FhirApi.FhirFormat.Json) { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.Json; } else { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.None; } Presenter.TextEditorViewModel.Text = RecordListResponse.Body; Presenter.CurrentUserAccount.UserAccountRecordList = new System.Collections.ObjectModel.ObservableCollection <ViewModel.UserAccountRecord>(); foreach (var Person in RecordListResponse.ApiRelatedPersonList) { var RecordItem = new ViewModel.UserAccountRecord(); RecordItem.Family = Person.Family; RecordItem.Given = Person.Given; RecordItem.Ihi = Person.Ihi; RecordItem.RelationshipTypeDescription = Person.RelationshipDescription; Presenter.CurrentUserAccount.UserAccountRecordList.Add(RecordItem); } if (Presenter.CurrentUserAccount != null && Presenter.CurrentUserAccount.UserAccountRecordList != null && Presenter.CurrentUserAccount.UserAccountRecordList.Count > 0) { Presenter.CurrentUserAccount.SelectedUserAccountRecord = Presenter.CurrentUserAccount.UserAccountRecordList[0]; } return(true); } else { if (RecordListResponse.ErrorResponse != null) { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.None; Presenter.TextEditorViewModel.Text = RecordListResponse.ErrorResponse.Description; return(false); } else { Presenter.TextEditorViewModel.FormatType = Extensions.AvalonEditSyntaxTypes.None; Presenter.TextEditorViewModel.Text = $"Unknown Error, Status code {RecordListResponse.StatusCode.ToString()}"; return(false); } } }
/// <summary> /// 从请求头信息中验证外部接口调用验证 /// </summary> /// <param name="context"></param> /// <returns></returns> private ResponseModel GetExternalHeaderData(HttpContext context) { //请求头信息验证未通过 var resultobj = new ResponseModel(ResponseCode.BadRequest, "头信息验证失败"); //实例化接口请求头信息 var requestHeader = new ApiRequestHeader(context); if (requestHeader == null) { return(resultobj); } var msg = ""; //获取平台所有的应用信息 var userinfo_key = "applyitems"; var applyItems = CacheManager.Create().Get <List <AppLyInfo> >(userinfo_key); if (applyItems == null || !applyItems.Any()) { //数据库获取应用信息 applyItems = this.Query <AppLyInfo>() .Where("数据标识", 1) .GetModelList(); if (applyItems != null && applyItems.Any()) { var obj = CacheManager.Create().Set(userinfo_key, applyItems); } } if (applyItems == null || !applyItems.Any()) { resultobj.msg = msg + "没有找到平台的应用信息"; return(resultobj); } //获取请求的平台应用信息 var applyInfo = applyItems.FirstOrDefault(t => t.APPID == requestHeader.appid); if (applyInfo == null) { resultobj.msg = requestHeader.appid + "非法!"; return(resultobj); } //请求验证成功 resultobj.code = ResponseCode.Success.ToInt32(); return(resultobj); }
/// <summary> /// 复写父类的该方法。执行控制器中的方法之前先执行该方法。从而实现过滤的功能。 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { //调用父类的该方法。 base.OnActionExecuting(filterContext); begintime = DateTime.Now; requestHeader = new ApiRequestHeader(); var headers = Request.Headers; //获取nginx代理配置的客户ip信息 ---nginx必须配置 proxy set header X-Real-IP $remote addr ipaddress = filterContext.HttpContext.Request.Headers["X-Real-IP"].FirstOrDefault(); if (ipaddress.IsNullOrEmpty()) { //获取IP地址 ipaddress = filterContext.HttpContext.Connection.RemoteIpAddress.ToString(); } //获取登录用户信息 loginUser = this.GetUserInfo(); //获取请求来源信息 userAppLyInfo = this.GetUserAppLyInfo(); }
/// <summary> /// 从请求头信息中获取不解密加密请求的消息信息 /// </summary> /// <param name="context"></param> /// <returns></returns> private ResponseModel GetNoEnRequestHeaderData(HttpContext context) { //请求头信息验证未通过 var resultobj = new ResponseModel(ResponseCode.BadRequest, "头信息验证失败"); //实例化接口请求头信息 var requestHeader = new ApiRequestHeader(context, false); if (requestHeader == null) { return(resultobj); } var msg = ""; //请求验签成功 resultobj.code = ResponseCode.Success.ToInt32(); resultobj.msg = "请求验证成功"; //return resultobj; //判断必填参数 var required_result = RequiredAttribute.ValidateRequired(requestHeader, ref msg); //必填验证通过 if (!required_result) { resultobj.msg = msg + "当前验证无法通过"; return(resultobj); } //获取平台所有的应用信息 var userinfo_key = "applyitems"; var applyItems = CacheManager.Create().Get <List <AppLyInfo> >(userinfo_key); if (applyItems == null || !applyItems.Any()) { //数据库获取应用信息 applyItems = this.Query <AppLyInfo>() .Where("数据标识", 1) .GetModelList(); if (applyItems != null && applyItems.Any()) { var obj = CacheManager.Create().Set(userinfo_key, applyItems); } } if (applyItems == null || !applyItems.Any()) { resultobj.msg = msg + "没有找到平台的应用信息"; return(resultobj); } //获取请求的平台应用信息 var applyInfo = applyItems.FirstOrDefault(t => t.APPID == requestHeader.appid); if (applyInfo == null) { resultobj.msg = requestHeader.appid + "非法!"; return(resultobj); } else { //缓存当前登录的应用信息 UserAppLyInfo userAppLyInfo = new UserAppLyInfo() { app_id = applyInfo.APPID, app_name = applyInfo.应用名称, private_key = applyInfo.私钥, public_key = applyInfo.公钥, sourse = applyInfo.使用平台 }; var userApplyinfo_key = "user_applyitem:" + requestHeader.appid; var obj = CacheManager.Create().Set(userApplyinfo_key, userAppLyInfo.ToJson()); //请求验签成功 resultobj.code = ResponseCode.Success.ToInt32(); resultobj.msg = "请求验证成功"; } return(resultobj); }
/// <summary> /// 从请求头信息中获取加密请求的消息信息 /// </summary> /// <param name="context"></param> /// <returns></returns> private ResponseModel GetEnRequestHeaderData(HttpContext context) { //请求头信息验证未通过 var resultobj = new ResponseModel(ResponseCode.BadRequest, "头信息验证失败"); //实例化接口请求头信息 var requestHeader = new ApiRequestHeader(context); if (requestHeader == null) { return(resultobj); } var msg = ""; //判断必填参数 var required_result = RequiredAttribute.ValidateRequired(requestHeader, ref msg); //必填验证通过 if (!required_result) { resultobj.msg = msg + "当前验证无法通过"; return(resultobj); } //获取平台所有的应用信息 var userinfo_key = "applyitems"; var applyItems = CacheManager.Create().Get <List <AppLyInfo> >(userinfo_key); if (applyItems == null || !applyItems.Any()) { //数据库获取应用信息 applyItems = this.Query <AppLyInfo>() .Where("数据标识", 1) .GetModelList(); if (applyItems != null && applyItems.Any()) { var obj = CacheManager.Create().Set(userinfo_key, applyItems); } } if (applyItems == null || !applyItems.Any()) { resultobj.msg = msg + "没有找到平台的应用信息"; return(resultobj); } //获取请求的平台应用信息 var applyInfo = applyItems.FirstOrDefault(t => t.APPID == requestHeader.appid); if (applyInfo == null) { resultobj.msg = requestHeader.appid + "非法!"; return(resultobj); } string decrypt_timestamp = ""; try { var decryptData = GetRequestRsaData(applyInfo, requestHeader.sign); //解密失败 if (decryptData.code != ResponseCode.Success.ToInt32()) { resultobj = decryptData; return(resultobj); } decrypt_timestamp = decryptData.data.ToString(); } catch (Exception ex) { Logger.Instance.Error("RSA解密发生异常", ex); resultobj.msg = "请求参数签名不合法"; return(resultobj); } //签名参数校验不通过 if (decrypt_timestamp != requestHeader.timestamp) { resultobj.msg = "请求参数签名不合法"; return(resultobj); } //请求验签成功 resultobj.code = ResponseCode.Success.ToInt32(); if (!requestHeader.biz_content.IsNullOrEmpty()) { try { //json参数需要解密 string bodyData = HttpUtility.UrlDecode(requestHeader.biz_content, System.Text.Encoding.UTF8); //AES解密请求的参数信息,秘钥长度必须32位,"以0左补齐" string bodystring = AESEncryptWeb.DecryptByAES(bodyData, requestHeader.timestamp); string content = bodystring; //UrlHelper.ParameterToJsonString(bodystring); resultobj.data = content; Logger.Instance.Info("接口请求信息" + content); } catch (Exception ex) { Logger.Instance.Error("参数异常", ex); resultobj.code = ResponseCode.Error.ToInt32(); resultobj.msg = ex.Message; } } return(resultobj); }