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 Test_GetRefreshToken(string RefreshToken) { //Arrange Uri FhirGatewayEndpoint = new Uri("https://apinams.ehealthvendortest.health.gov.au"); var RefreshTokenRequest = new RefreshTokenRequest() { Client_id = "28198d27-c475-4695-83d3-1f1f8256e01b", Client_secret = "1c73a74b-45fc-4ee4-a400-15a398e46143", RefreshToken = RefreshToken, }; FhirApi Api = new FhirApi(FhirGatewayEndpoint); //Act TokenResponse TokenResponse = Api.GetRefreshToken(RefreshTokenRequest); //Assert Assert.Equal(TokenResponse.StatusCode, System.Net.HttpStatusCode.OK); Assert.NotNull(TokenResponse.RefreshToken); Assert.NotNull(TokenResponse.AccessToken); Assert.NotNull(TokenResponse.AccessExpires); Assert.NotNull(TokenResponse.RefreshExpires); Assert.NotNull(TokenResponse.Scope); Assert.NotNull(TokenResponse.TokenType); Assert.Null(TokenResponse.ErrorResponse); }
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); } } }
public bool GetRefeashToken(ViewModel.UserAccountView ViewCurrentUserAccount) { //If the Access token expires in 1 hour get a new one. if (ViewCurrentUserAccount.AccessExpires < DateTime.Now.AddHours(1)) { if (!string.IsNullOrWhiteSpace(ViewCurrentUserAccount.RefreshToken)) { FhirApi FhirApi = new FhirApi(FhirGatewayEndpoint); var RefreshTokenRequest = new RefreshTokenRequest(); RefreshTokenRequest.Client_id = ApplicationStore.App_id; RefreshTokenRequest.Client_secret = ApplicationStore.App_secret; RefreshTokenRequest.RefreshToken = ViewCurrentUserAccount.RefreshToken; TokenResponse TokenResponse = FhirApi.GetRefreshToken(RefreshTokenRequest); if (TokenResponse.StatusCode == System.Net.HttpStatusCode.OK) { ViewCurrentUserAccount.AccessExpires = TokenResponse.AccessExpires; ViewCurrentUserAccount.AccessToken = TokenResponse.AccessToken; ViewCurrentUserAccount.RefreshExpires = TokenResponse.RefreshExpires; ViewCurrentUserAccount.RefreshToken = TokenResponse.RefreshToken; ViewCurrentUserAccount.Scope = TokenResponse.Scope; if (ApplicationStore.UserList.SingleOrDefault(x => x.Username == ViewCurrentUserAccount.Username) != null) { var TargetAccount = ApplicationStore.UserList.SingleOrDefault(x => x.Username == ViewCurrentUserAccount.Username); TargetAccount.AccessExpires = ViewCurrentUserAccount.AccessExpires; TargetAccount.AccessToken = ViewCurrentUserAccount.AccessToken; TargetAccount.RefreshExpires = ViewCurrentUserAccount.RefreshExpires; TargetAccount.RefreshToken = ViewCurrentUserAccount.RefreshToken; TargetAccount.Scope = ViewCurrentUserAccount.Scope; SaveApplicationStore(); } return(true); } else { if (TokenResponse.ErrorResponse != null) { this.ErrorMessage = $"Refresh Token request failed with message: Http Status: {TokenResponse.StatusCode.ToString()}, Error: {TokenResponse.ErrorResponse.Error}, ErrorMessage: {TokenResponse.ErrorResponse.Description}"; } else { this.ErrorMessage = $"Refresh Token request failed with no error message returned message, http status was: {TokenResponse.StatusCode.ToString()}"; } return(false); } } else { throw new FormatException($"No CurrectUserAccount.AuthorisationCode found for access token request."); } } return(true); }
public void Test_GetRecordList(string RefreshToken) { //Arrange Uri FhirGatewayEndpoint = new Uri("https://apinams.ehealthvendortest.health.gov.au"); FhirApi Api = new FhirApi(FhirGatewayEndpoint); Api.Format = FhirApi.FhirFormat.Xml; //Act RecordListResponse RecordListResponse = Api.GetRecordList(); //Assert Assert.Equal(RecordListResponse.StatusCode, System.Net.HttpStatusCode.OK); Assert.Equal(RecordListResponse.Format, FhirApi.FhirFormat.Xml); Assert.NotNull(RecordListResponse.Body); Assert.Null(RecordListResponse.ErrorResponse); }
public bool GetAccessToken() { if (!string.IsNullOrWhiteSpace(CurrectUserAccount.AuthorisationCode)) { FhirApi FhirApi = new FhirApi(FhirGatewayEndpoint); var AccessTokenRequest = new AccessTokenRequest(); AccessTokenRequest.Client_id = ApplicationStore.App_id; AccessTokenRequest.Client_secret = ApplicationStore.App_secret; AccessTokenRequest.Code = CurrectUserAccount.AuthorisationCode; TokenResponse TokenResponse = FhirApi.GetAccessToken(AccessTokenRequest); if (TokenResponse.StatusCode == System.Net.HttpStatusCode.OK) { this.CurrectUserAccount.AccessExpires = TokenResponse.AccessExpires; this.CurrectUserAccount.AccessToken = TokenResponse.AccessToken; this.CurrectUserAccount.RefreshExpires = TokenResponse.RefreshExpires; this.CurrectUserAccount.RefreshToken = TokenResponse.RefreshToken; this.CurrectUserAccount.Scope = TokenResponse.Scope; if (ApplicationStore.UserList.SingleOrDefault(x => x.Username == CurrectUserAccount.Username) == null) { ApplicationStore.UserList.Add(this.CurrectUserAccount); SaveApplicationStore(); } return(true); } else { if (TokenResponse.ErrorResponse != null) { this.ErrorMessage = $"Access Token request failed with message: Http Status: {TokenResponse.StatusCode.ToString()}, Error: {TokenResponse.ErrorResponse.Error}, ErrorMessage: {TokenResponse.ErrorResponse.Description}"; } else { this.ErrorMessage = $"Access Token request failed with no error message returned message, http status was: {TokenResponse.StatusCode.ToString()}"; } return(false); } } else { throw new FormatException($"No CurrectUserAccount.AuthorisationCode found for access token request."); } }
static void Main(string[] args) { Console.WriteLine("HTTP Client"); //MyGov login widget page URL //https://apinams.ehealthvendortest.health.gov.au/api/oauth/authorize/login?client_id=28198d27-c475-4695-83d3-1f1f8256e01b&response_type=code&redirect_uri=https://localhost/oauth_callback&scope=https://localhost:8090/pcehr+offline_access //MyGov Details //User Name: VH429777 //Password: Welcome123 //Secret: //1) What is the name of the first street I lived in? //Answer: street //2) What was the model of the car I learnt to drive in? //Answer: car //3) What was my favourite subject at school? //Answer: subject Uri FhirGatewayEndpoint = new Uri("https://apinams.ehealthvendortest.health.gov.au"); var TokenRequest = new AccessTokenRequest() { Client_id = "28198d27-c475-4695-83d3-1f1f8256e01b", Client_secret = "1c73a74b-45fc-4ee4-a400-15a398e46143", Code = "Q9O6sy0XTiEI5U8xc0xmVNzKY9j4aZ" }; FhirApi Api = new FhirApi(FhirGatewayEndpoint); TokenResponse TokenResponse = Api.GetAccessToken(TokenRequest); if (TokenResponse.StatusCode == System.Net.HttpStatusCode.OK) { Console.WriteLine($"HttpStatus: {TokenResponse.StatusCode.ToString()}"); Console.WriteLine($"AccessToken: {TokenResponse.AccessToken}"); Console.WriteLine($"RefreshToken: {TokenResponse.RefreshToken}"); Console.ReadKey(); } else { Console.WriteLine($"HttpStatus: {TokenResponse.StatusCode.ToString()}"); Console.WriteLine($"Error: {TokenResponse.ErrorResponse.Error}"); Console.WriteLine($"Description: {TokenResponse.ErrorResponse.Description}"); Console.ReadKey(); } //Client.ContentType = "application/x-www-form-urlencoded"; //HttpResponseMessage response; //response = Client.PostFormUrlEncodedContent(RequestAccessTokenQuery, RequestParametersList).Result; ////Client.Accept = "application/fhir+xml"; //string test2 = response.Content.ReadAsStringAsync().Result; //string StatusCode = response.StatusCode.ToString(); //Console.WriteLine("Http Status: " + StatusCode); //Console.Write(test); //Console.ReadKey(); ////"access_token": "EEMhwH8qjmD23G4bz3itub0np2mXXMtnHtHiDhLGDdmSXQQ20HE58v", //"token_type": "Bearer", //"expires_in": "15552000", //"refresh_token": "cUOlXUQuG7dkBPJBxDubnCah61xT3apsXYXGhHG7ahRwbe", //"scope": "https://localhost:8090/pcehr" //GET Example //HttpResponseMessage response; //response = Client.Get("]/api/oauth/token").Result; //Client.ContentType = "application/x-www-form-urlencoded"; //Client.Accept = "application/fhir+xml"; //string test = response.Content.ReadAsStringAsync().Result; //string StatusCode = response.StatusCode.ToString(); //Console.WriteLine("Http Status: " + StatusCode); //Console.Write(test); //Console.ReadKey(); }