private void btnfhirSearchPatient_Click(object sender, EventArgs e) { String strLastName = txtLastName.Text.ToString().TrimEnd(); String strFirstName = txtFirstName.Text.ToString().TrimEnd(); Hl7.Fhir.Rest.FhirClient client = new Hl7.Fhir.Rest.FhirClient(_fhirServerUrl); client.OnBeforeRequest += Client_OnBeforeRequest; client.PreferredFormat = Hl7.Fhir.Rest.ResourceFormat.Json; List <string> paramsList = new List <string>(); if (string.IsNullOrEmpty(strLastName) == false) { paramsList.Add("family=" + strLastName); } if (string.IsNullOrEmpty(strFirstName) == false) { paramsList.Add("given=" + strFirstName); } var bundle = client.Search <Hl7.Fhir.Model.Patient>(paramsList.ToArray()); txtPatientResponse.Text = new FhirJsonSerializer().SerializeToString(bundle); }
/// <summary> /// Program to access a SMART FHIR Server with a local webserver for redirection /// </summary> /// <param name="fhirServerUrl">FHIR R4 endpoint URL</param> /// <returns></returns> static int Main( string fhirServerUrl ) { if (string.IsNullOrEmpty(fhirServerUrl)) { fhirServerUrl = _defaultFhirServerUrl; } System.Console.WriteLine($" FHIR Server: {fhirServerUrl}"); Hl7.Fhir.Rest.FhirClient fhirClient = new Hl7.Fhir.Rest.FhirClient(fhirServerUrl); if (!FhirUtils.TryGetSmartUrls(fhirClient, out string authorizeUrl, out string tokenUrl)) { System.Console.WriteLine($"Failed to discover SMART URLs"); return(-1); } System.Console.WriteLine($"Authorize URL: {authorizeUrl}"); System.Console.WriteLine($" Token URL: {tokenUrl}"); _tokenUrl = tokenUrl; Task.Run(() => CreateHostBuilder().Build().Run()); int listenPort = GetListenPort().Result; System.Console.WriteLine($" Listening on: {listenPort}"); _redirectUrl = $"http://127.0.0.1:{listenPort}"; // https://ehr/authorize? // response_type=code& // client_id=app-client-id& // redirect_uri=https%3A%2F%2Fapp%2Fafter-auth& // launch=xyz123& // scope=launch+patient%2FObservation.read+patient%2FPatient.read+openid+fhirUser& // state=98wrghuwuogerg97& // aud=https://ehr/fhir string url = $"{authorizeUrl}" + $"?response_type=code" + $"&client_id={_clientId}" + $"&redirect_uri={HttpUtility.UrlEncode(_redirectUrl)}" + $"&scope={HttpUtility.UrlEncode("openid fhirUser profile launch/patient patient/*.read")}" + $"&state=local_state" + $"&aud={fhirServerUrl}"; LaunchUrl(url); // http://127.0.0.1:54678/?code=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb250ZXh0Ijp7Im5lZWRfcGF0aWVudF9iYW5uZXIiOnRydWUsInNtYXJ0X3N0eWxlX3VybCI6Imh0dHBzOi8vbGF1bmNoLnNtYXJ0aGVhbHRoaXQub3JnL3NtYXJ0LXN0eWxlLmpzb24iLCJwYXRpZW50IjoiMmNkYTVhYWQtZTQwOS00MDcwLTlhMTUtZTFjMzVjNDZlZDVhIn0sImNsaWVudF9pZCI6ImZoaXJfZGVtb19pZCIsInNjb3BlIjoib3BlbmlkIGZoaXJVc2VyIHByb2ZpbGUgbGF1bmNoL3BhdGllbnQgcGF0aWVudC8qLnJlYWQiLCJ1c2VyIjoiUHJhY3RpdGlvbmVyL2VmYjVkNGNlLWRmZmMtNDdkZi1hYTZkLTA1ZDM3MmZkYjQwNyIsImlhdCI6MTYwNDMzMjkxNywiZXhwIjoxNjA0MzMzMjE3fQ.RkZEP3eKVydMLc5wW0FJEtTqYoTOuwgtoTcjhjevAC0&state=local_state for (int loops = 0; loops < 30; loops++) { System.Threading.Thread.Sleep(1000); } return(0); }
private void SearchPatients() { //Regular search by patient family and given name WorkingMessage(); listCandidates.Items.Clear(); string FHIR_EndPoint = this.txtFHIREndpoint.Text.ToString(); var client = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint); try { string family = txtFamilyName.Text.ToString(); string given = txtGivenName.Text.ToString(); var p = new Hl7.Fhir.Rest.SearchParams(); p.Add("family", family); if (given != "") { p.Add("given", given); } var results = client.Search <Patient>(p); this.UseWaitCursor = false; lblErrorMessage.Text = ""; while (results != null) { if (results.Total == 0) { lblErrorMessage.Text = "No patients found"; } btnShowDevices.Enabled = true; foreach (var entry in results.Entry) { var Pat = (Patient)entry.Resource; string Fam = Pat.Name[0].Family; string Giv = Pat.Name[0].GivenElement[0].ToString(); string ideS = Pat.Identifier[0].System; string ideV = Pat.Identifier[0].Value; string Content = Fam + " " + Giv + " (" + ideS + "-" + ideV + ")"; ListViewItem l = new ListViewItem(); l.Text = Content; l.Tag = entry.Resource.Id; listCandidates.Items.Add(l); } // get the next page of results results = client.Continue(results); } } catch (Exception err) { lblErrorMessage.Text = "Error:" + err.Message.ToString(); } if (lblErrorMessage.Text != "") { lblErrorMessage.Visible = true; } }
static void Main(string[] args) { //The fhir server end point address string ServiceRootUrl = "https://api-v5-stu3.hspconsortium.org/MX1STU3/open"; //string ServiceRootUrl = "http://sqlonfhir-stu3.azurewebsites.net/fhir"; //Create a client to send to the server at a given endpoint. var FhirClient = new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl); // increase timeouts since the server might be powered down FhirClient.Timeout = (60 * 1000); Console.WriteLine("Press any key to send to server: " + ServiceRootUrl); Console.WriteLine(); Console.ReadKey(); try { //Attempt to send the resource to the server endpoint UriBuilder UriBuilderx = new UriBuilder(ServiceRootUrl); UriBuilderx.Path = "Patient/MY_PATIENT_ID"; Hl7.Fhir.Model.Resource ReturnedResource = FhirClient.InstanceOperation(UriBuilderx.Uri, "everything"); if (ReturnedResource is Hl7.Fhir.Model.Bundle) { Hl7.Fhir.Model.Bundle ReturnedBundle = ReturnedResource as Hl7.Fhir.Model.Bundle; Console.WriteLine("Received: " + ReturnedBundle.Total + " results, the resources are: "); foreach (var Entry in ReturnedBundle.Entry) { Console.WriteLine(string.Format("{0}/{1}", Entry.Resource.TypeName, Entry.Resource.Id)); } } else { throw new Exception("Operation call must return a bundle resource"); } Console.WriteLine(); } catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec) { //Process any Fhir Errors returned as OperationOutcome resource Console.WriteLine(); Console.WriteLine("An error message: " + FhirOpExec.Message); Console.WriteLine(); string xml = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(FhirOpExec.Outcome); XDocument xDoc = XDocument.Parse(xml); Console.WriteLine(xDoc.ToString()); } catch (Exception GeneralException) { Console.WriteLine(); Console.WriteLine("An error message: " + GeneralException.Message); Console.WriteLine(); } Console.WriteLine("Press any key to end."); Console.ReadKey(); }
private static Hl7.Fhir.Model.Patient GetPatient2(string patientId) { var baseUrl = $"http://hapi.fhir.org/baseDstu3"; var getPatientUrl = $"http://hapi.fhir.org/baseDstu3/Patient/{patientId}"; var client = new Hl7.Fhir.Rest.FhirClient(baseUrl); var version = client.VerifyFhirVersion; Console.WriteLine($"Version de FHIR:{version}"); var ret = client.Read <Hl7.Fhir.Model.Patient>(getPatientUrl); return(ret); }
static void Main(string[] args) { //The fhir server end point address //string ServiceRootUrl = "https://api-v5-stu3.hspconsortium.org/MX1STU3/open"; string ServiceRootUrl = "http://PyroHealth.net/test/stu3/fhir"; //Create a client to send to the server at a given endpoint. var FhirClient = new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl); // increase timeouts since the server might be powered down FhirClient.Timeout = (60 * 1000); Console.WriteLine("Press any key to send to server: " + ServiceRootUrl); Console.WriteLine(); Console.ReadKey(); try { //Attempt to send the resource to the server endpoint Hl7.Fhir.Model.Bundle ReturnedSearchBundle = FhirClient.Search <Hl7.Fhir.Model.Patient>(new string[] { "family=Fhirman" }); Console.WriteLine(string.Format("Found: {0} Fhirman patients.", ReturnedSearchBundle.Total.ToString())); Console.WriteLine("Their logical IDs are:"); foreach (var Entry in ReturnedSearchBundle.Entry) { Console.WriteLine("ID: " + Entry.Resource.Id); } Console.WriteLine(); } catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec) { //Process any Fhir Errors returned as OperationOutcome resource Console.WriteLine(); Console.WriteLine("An error message: " + FhirOpExec.Message); Console.WriteLine(); string xml = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(FhirOpExec.Outcome); XDocument xDoc = XDocument.Parse(xml); Console.WriteLine(xDoc.ToString()); } catch (Exception GeneralException) { Console.WriteLine(); Console.WriteLine("An error message: " + GeneralException.Message); Console.WriteLine(); } Console.WriteLine("Press any key to end."); Console.ReadKey(); }
static void Main(string[] args) { //string FhirServerEndpoint = "http://localhost:8888/Fhir"; string FhirServerEndpoint = "https://stu3.test.pyrohealth.net/fhir"; AuDefinitionsDownLoader AuDefinitionsDownLoader = new AuDefinitionsDownLoader(); List <AuDefinition> AuDefList = AuDefinitionsDownLoader.GetResourceList(); var TranBundle = new Bundle(); TranBundle.Type = Bundle.BundleType.Transaction; TranBundle.Entry = new List <Bundle.EntryComponent>(); foreach (AuDefinition Def in AuDefList) { var Entry = new Bundle.EntryComponent(); Entry.FullUrl = $"urn:uuid:{Guid.NewGuid()}"; Entry.Resource = Def.Resource; Entry.Request = new Bundle.RequestComponent(); Entry.Request.Method = Bundle.HTTPVerb.PUT; Entry.Request.Url = $"{Def.ResourceType.GetLiteral()}/{Def.FhirId}"; TranBundle.Entry.Add(Entry); } Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(FhirServerEndpoint, false); clientFhir.Timeout = 1000 * 1000; Bundle TransactionResult = null; try { Console.WriteLine($"Uploading Transaction bundle to {FhirServerEndpoint}"); TransactionResult = clientFhir.Transaction(TranBundle); Console.WriteLine("Transaction bundle commit successful"); } catch (Exception Exec) { Console.WriteLine("Error is POST of Transaction Bundle, see error below."); Console.Write(Exec.Message); } Console.WriteLine("Hit Any key to end."); Console.ReadKey(); }
public List <Patient> SearchPatients(string searchString) { var patientResults = new List <Patient>(); Hl7.Fhir.Rest.FhirClient fhirClient = FhirClientManager.CreateClientConnection(Configuration); fhirClient = FhirClientManager.CreateClientConnection(Configuration); Hl7.Fhir.Model.Bundle ReturnedSearchBundle = fhirClient.Search <Hl7.Fhir.Model.Patient>(new string[] { $"name={searchString}" }); foreach (var resource in ReturnedSearchBundle.Entry) { patientResults.Add((Patient)resource.Resource); } return(patientResults); }
public List <Prescription> FindMedication(string patientId) { var prescriptionResults = new List <Prescription>(); Hl7.Fhir.Rest.FhirClient fhirClient = FhirClientManager.CreateClientConnection(Configuration); fhirClient = FhirClientManager.CreateClientConnection(Configuration); Hl7.Fhir.Model.Bundle ReturnedSearchBundle = fhirClient.Search <Hl7.Fhir.Model.MedicationRequest>(new string[] { $"patient={patientId}" }); foreach (var resource in ReturnedSearchBundle.Entry) { var prescription = (Prescription)resource.Resource; prescriptionResults.Add(prescription); } return(prescriptionResults); }
public List <Diagnosis> FindDiagnosis(string patientId) { var diagnosticResults = new List <Diagnosis>(); Hl7.Fhir.Rest.FhirClient fhirClient = FhirClientManager.CreateClientConnection(Configuration); fhirClient = FhirClientManager.CreateClientConnection(Configuration); Hl7.Fhir.Model.Bundle ReturnedSearchBundle = fhirClient.Search <Hl7.Fhir.Model.DiagnosticReport>(new string[] { $"patient={patientId}" }); foreach (var resource in ReturnedSearchBundle.Entry) { var diagnosticReport = (DiagnosticReport)resource.Resource; foreach (var item in diagnosticReport.Contained) { diagnosticResults.Add((Diagnosis)item); } } return(diagnosticResults); }
static Hl7.Fhir.Model.Bundle GetPatient() { var baseUrl = "https://testapp.hospitalitaliano.org.ar/masterfile-federacion-service/fhir"; var client = new Hl7.Fhir.Rest.FhirClient(baseUrl); client.OnBeforeRequest += OnBeforeRequestFhirServer; client.OnAfterResponse += OnAfterResponseFhirServer; Hl7.Fhir.Model.Bundle ret = null; try { var qp = new Hl7.Fhir.Rest.SearchParams(); qp.Add("identifier", "http://www.msal.gov.ar|2222222"); ret = client.Search <Hl7.Fhir.Model.Patient>(qp); } catch (Exception ex) { Log.Error(ex.ToString()); } return(ret); }
// Process request and craft response. public override CefReturnValue ProcessRequestAsync(IRequest request, ICallback callback) { if (request.Method == "OPTIONS") { // This is the CORS request, and that's good base.StatusCode = 200; // base.Headers.Add("Access-Control-Allow-Origin", "*"); base.Headers.Add("Access-Control-Allow-Methods", "GET,POST,PUT,OPTIONS"); base.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept, authorization"); callback.Continue(); return(CefReturnValue.Continue); } var uri = new Uri(request.Url); Console.WriteLine($"-----------------\r\n{request.Url}"); try { // This is a regular request Hl7.Fhir.Rest.FhirClient server = new Hl7.Fhir.Rest.FhirClient(_externalFhirServerBaseUrl); server.OnAfterResponse += (sender, args) => { base.Charset = args.RawResponse.CharacterSet; foreach (string header in args.RawResponse.Headers.AllKeys) { if (!header.StartsWith("Access-Control")) { base.Headers.Add(header, args.RawResponse.Headers[header]); } } }; server.PreferredFormat = Hl7.Fhir.Rest.ResourceFormat.Json; string redirectedUrl = server.Endpoint.OriginalString.TrimEnd('/') + uri.PathAndQuery; System.Diagnostics.Trace.WriteLine($"{redirectedUrl}"); if (request.Method == "GET") { System.Threading.Tasks.Task <Hl7.Fhir.Model.Resource> t = server.GetAsync(redirectedUrl).ContinueWith <Hl7.Fhir.Model.Resource>(r => { if (r.Exception != null) { System.Diagnostics.Trace.WriteLine($"Error: {r.Exception.Message}"); if (r.Exception.InnerException is Hl7.Fhir.Rest.FhirOperationException fe) { base.StatusCode = (int)fe.Status; if (fe.Outcome != null) { base.Stream = new MemoryStream(new Hl7.Fhir.Serialization.FhirJsonSerializer(new Hl7.Fhir.Serialization.SerializerSettings() { Pretty = true }).SerializeToBytes(fe.Outcome)); base.MimeType = "application/fhir+json"; } callback.Continue(); System.Diagnostics.Trace.WriteLine($"Error (inner): {fe.Message}"); return(null); } } base.StatusCode = 200; if (r.Result is Hl7.Fhir.Model.CapabilityStatement cs) { // As per the documentation http://hl7.org/fhir/smart-app-launch/conformance/index.html // Update the security node with our internal security node if (cs.Rest[0].Security == null) { cs.Rest[0].Security = new Hl7.Fhir.Model.CapabilityStatement.SecurityComponent(); } Hl7.Fhir.Model.CapabilityStatement.SecurityComponent security = cs.Rest[0].Security; if (!security.Service.Any(cc => cc.Coding.Any(c => c.System == "http://hl7.org/fhir/restful-security-service" && c.Code == "SMART-on-FHIR"))) { security.Service.Add(new Hl7.Fhir.Model.CodeableConcept("http://hl7.org/fhir/restful-security-service", "SMART-on-FHIR")); } var extension = security.GetExtension("http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris"); if (extension == null) { extension = new Extension() { Url = "http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris" }; security.Extension.Add(extension); } // remove the existing authentications, and put in our own extension.Extension.Clear(); extension.AddExtension("token", new FhirUri($"https://{AuthProtocolSchemeHandlerFactory.AuthAddress(_launchContext)}/token")); extension.AddExtension("authorize", new FhirUri($"https://{AuthProtocolSchemeHandlerFactory.AuthAddress(_launchContext)}/authorize")); } base.Stream = new MemoryStream(new Hl7.Fhir.Serialization.FhirJsonSerializer(new Hl7.Fhir.Serialization.SerializerSettings() { Pretty = true }).SerializeToBytes(r.Result)); Console.WriteLine($"Success: {base.Stream.Length}"); base.MimeType = "application/fhir+json"; callback.Continue(); return(r.Result); }); } if (request.Method == "POST") { System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); client.DefaultRequestHeaders.Add("Accept", request.GetHeaderByName("Accept")); // client.DefaultRequestHeaders.Add("Content-Type", request.GetHeaderByName("Content-Type")); HttpContent content = null; if (request.PostData != null) { var data = request.PostData.Elements.FirstOrDefault(); var body = data.GetBody(); content = new System.Net.Http.StringContent(body, System.Text.Encoding.UTF8, request.GetHeaderByName("Content-Type")); } else { content = new System.Net.Http.StreamContent(null); } client.PostAsync(redirectedUrl, content).ContinueWith((System.Threading.Tasks.Task <HttpResponseMessage> r) => { if (r.Exception != null) { Console.WriteLine($"Error: {r.Exception.Message}"); //if (r.Exception.InnerException is Hl7.Fhir.Rest.FhirOperationException fe) //{ // base.StatusCode = (int)fe.Status; // if (fe.Outcome != null) // base.Stream = new MemoryStream(r.Result.Content.ReadAsStringAsync().GetAwaiter().GetResult()); // callback.Continue(); // System.Diagnostics.Trace.WriteLine($"Error (inner): {fe.Message}"); // return; //} } base.StatusCode = (int)r.Result.StatusCode; base.Stream = r.Result.Content.ReadAsStreamAsync().GetAwaiter().GetResult(); Console.WriteLine($"Success: {base.Stream.Length}"); base.MimeType = r.Result.Content.Headers.ContentType.MediaType; callback.Continue(); return; }); } if (request.Method == "PUT") { System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); client.DefaultRequestHeaders.Add("Accept", request.GetHeaderByName("Accept")); // client.DefaultRequestHeaders.Add("Content-Type", request.GetHeaderByName("Content-Type")); HttpContent content = null; if (request.PostData != null) { var data = request.PostData.Elements.FirstOrDefault(); var body = data.GetBody(); content = new System.Net.Http.StringContent(body, System.Text.Encoding.UTF8, request.GetHeaderByName("Content-Type")); } else { content = new System.Net.Http.StreamContent(null); } client.PutAsync(redirectedUrl, content).ContinueWith((System.Threading.Tasks.Task <HttpResponseMessage> r) => { if (r.Exception != null) { Console.WriteLine($"Error: {r.Exception.Message}"); //if (r.Exception.InnerException is Hl7.Fhir.Rest.FhirOperationException fe) //{ // base.StatusCode = (int)fe.Status; // if (fe.Outcome != null) // base.Stream = new MemoryStream(r.Result.Content.ReadAsStringAsync().GetAwaiter().GetResult()); // callback.Continue(); // System.Diagnostics.Trace.WriteLine($"Error (inner): {fe.Message}"); // return; //} } base.StatusCode = (int)r.Result.StatusCode; base.Stream = r.Result.Content.ReadAsStreamAsync().GetAwaiter().GetResult(); Console.WriteLine($"Success: {base.Stream.Length}"); base.MimeType = r.Result.Content.Headers.ContentType.MediaType; callback.Continue(); return; }); } return(CefReturnValue.ContinueAsync); } catch (Exception ex) { Console.WriteLine($"{ex.Message}"); callback.Dispose(); return(CefReturnValue.Cancel); } }
static void Main(string[] args) { Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient("http://ohcconnect.myhealthpoc.com:9093/org1", false); //Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient("https://r4.test.pyrohealth.net/fhir", false); clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging). try { var res = clientFhir.Get("Patient/8b2179c6-811d-492a-9c8e-6856be319af3"); } catch (Exception exec) { string m = exec.Message; } //string PatientResourceId = string.Empty; ////Add a Patient resource by Update //Patient PatientOne = new Patient(); //PatientOne.Name.Add(HumanName.ForFamily("TestPatient").WithGiven("Test")); //PatientOne.BirthDateElement = new Date("1979-09-30"); //string PatientOneMRNIdentifer = Guid.NewGuid().ToString(); //PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer)); //PatientOne.Gender = AdministrativeGender.Unknown; //Patient PatientResult = null; //try //{ // PatientResult = clientFhir.Create(PatientOne); //} //catch (Exception Exec) //{ // Assert.True(false, "Exception thrown on resource Create: " + Exec.Message); //} //Assert.NotNull(PatientResult, "Resource create by Updated returned resource of null"); //PatientResourceId = PatientResult.Id; //PatientResult = null; var Dev = new Device(); Dev.Property = new List <Device.PropertyComponent>(); var TestProp = new Device.PropertyComponent(); Dev.Property.Add(TestProp); TestProp.Type = new CodeableConcept(); TestProp.Type.Coding = new List <Coding>(); TestProp.Type.Coding.Add(new Coding() { System = "urn:iso:std:iso:11073:10101", Code = "68221" }); TestProp.Type.Text = "MDC_TIME_SYNC_ACCURACY: null"; TestProp.ValueQuantity = new List <Quantity>(); TestProp.ValueQuantity.Add(new Quantity() { Value = 120000000, Code = "us" }); FhirJsonSerializer FhirJsonSerializer = new FhirJsonSerializer(); string JasonDevice = FhirJsonSerializer.SerializeToString(Dev, Hl7.Fhir.Rest.SummaryType.False); //FhirJsonSerializer.Serialize(Resource, jsonwriter, Summary); }
private void buttonTest_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; Hl7.Fhir.Model.ValueSet vs; List<object> z = new List<object>(); if (textBoxResource.Text.Contains("$")) { // Need to handle the expension using (WebClient w = new WebClient()) { string url = string.Empty; if (!comboBoxServer.Text.EndsWith("/")) { url = comboBoxServer.Text + "/" + textBoxResource.Text; } else { url = comboBoxServer.Text + textBoxResource.Text; } string x = w.DownloadString(url); vs = (Hl7.Fhir.Model.ValueSet)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(x); textBoxResponse.Text = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(vs); } } else { var client = new Hl7.Fhir.Rest.FhirClient(comboBoxServer.Text); client.PreferredFormat = Hl7.Fhir.Rest.ResourceFormat.Json; vs = client.Read<Hl7.Fhir.Model.ValueSet>(textBoxResource.Text); textBoxResponse.Text = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(vs); } if (vs.Expansion != null) { for (int i = 0; i < vs.Expansion.Contains.Count; i++) { z.Add(vs.Expansion.Contains[i].Display); } } else { if (vs.CodeSystem != null) { for (int i = 0; i < vs.CodeSystem.Concept.Count; i++) { z.Add(vs.CodeSystem.Concept[i].Display); } } if (vs.Compose != null) { for (int i = 0; i < vs.Compose.Include.Count; i++) { for (int j = 0; j < vs.Compose.Include[i].Concept.Count; j++) { z.Add(vs.Compose.Include[i].Concept[j].Display); } } } } comboBoxValueSet.Items.Clear(); comboBoxValueSet.Items.AddRange(z.ToArray()); Cursor = Cursors.Default; }
private void buttonTest_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; Hl7.Fhir.Model.ValueSet vs; List <object> z = new List <object>(); if (textBoxResource.Text.Contains("$")) { // Need to handle the expension using (WebClient w = new WebClient()) { string url = string.Empty; if (!comboBoxServer.Text.EndsWith("/")) { url = comboBoxServer.Text + "/" + textBoxResource.Text; } else { url = comboBoxServer.Text + textBoxResource.Text; } string x = w.DownloadString(url); vs = (Hl7.Fhir.Model.ValueSet)Hl7.Fhir.Serialization.FhirParser.ParseResourceFromJson(x); textBoxResponse.Text = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(vs); } } else { var client = new Hl7.Fhir.Rest.FhirClient(comboBoxServer.Text); client.PreferredFormat = Hl7.Fhir.Rest.ResourceFormat.Json; vs = client.Read <Hl7.Fhir.Model.ValueSet>(textBoxResource.Text); textBoxResponse.Text = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToJson(vs); } if (vs.Expansion != null) { for (int i = 0; i < vs.Expansion.Contains.Count; i++) { z.Add(vs.Expansion.Contains[i].Display); } } else { if (vs.CodeSystem != null) { for (int i = 0; i < vs.CodeSystem.Concept.Count; i++) { z.Add(vs.CodeSystem.Concept[i].Display); } } if (vs.Compose != null) { for (int i = 0; i < vs.Compose.Include.Count; i++) { for (int j = 0; j < vs.Compose.Include[i].Concept.Count; j++) { z.Add(vs.Compose.Include[i].Concept[j].Display); } } } } comboBoxValueSet.Items.Clear(); comboBoxValueSet.Items.AddRange(z.ToArray()); Cursor = Cursors.Default; }
private void SearchDevices(string PatientId) { WorkingMessage(); //Empty the device list listDevices.Items.Clear(); //My FHIR Endpoint string FHIR_EndPoint = this.txtFHIREndpoint.Text.ToString(); //Connection var client = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint); try { //Find the device related to my patient var p = new Hl7.Fhir.Rest.SearchParams(); //p.Add("subject", PatientId); p.Add("patient", PatientId); var results = client.Search <Device>(p); this.UseWaitCursor = false; lblErrorMessage.Text = ""; while (results != null) { if (results.Total == 0) { lblErrorMessage.Text = "No devices found"; } //Traverse the bundle with results foreach (var entry in results.Entry) { //One Device found! var Device = (Device)entry.Resource; string Content = ""; //Fill the content to add to the list with all the device data //Just in case the UDICarrier info is not present, we show just Manufacturer and Identifier if (Device.UdiCarrier.Count > 0) { Content = Device.UdiCarrier[0].CarrierHRF + " - " + Device.UdiCarrier[0].DeviceIdentifier + " - " + Device.Manufacturer; } else { if (Device.Identifier.Count > 0) { Content = Device.Identifier[0].System + "-" + Device.Identifier[0].Value + " -" + Device.Manufacturer; } else { Content = Device.Manufacturer + " ( No Identifiers )"; } } Content = Content + Device.Type.Coding[0].Display + '-' + Device.Patient.Display; listDevices.Items.Add(Content); } // get the next page of results results = client.Continue(results); } } catch (Exception err) { lblErrorMessage.Text = "Error:" + err.Message.ToString(); } if (lblErrorMessage.Text != "") { lblErrorMessage.Visible = true; } }
static void Main(string[] args) { //The fhir server end point address string ServiceRootUrl = "http://pyrohealth.net/test/stu3/fhir"; //Create a patient resource instance var MyPatient = new Hl7.Fhir.Model.Patient(); //Patient's Name var PatientName = new Hl7.Fhir.Model.HumanName(); PatientName.Use = Hl7.Fhir.Model.HumanName.NameUse.Official; PatientName.Prefix = new string[] { "Mr" }; PatientName.Given = new string[] { "Sam" }; PatientName.Family = "Fhirman"; MyPatient.Name = new List <Hl7.Fhir.Model.HumanName>(); MyPatient.Name.Add(PatientName); //Patient Identifier var PatientIdentifier = new Hl7.Fhir.Model.Identifier(); PatientIdentifier.System = "http://ns.electronichealth.net.au/id/hi/ihi/1.0"; PatientIdentifier.Value = "8003608166690503"; MyPatient.Identifier = new List <Hl7.Fhir.Model.Identifier>(); MyPatient.Identifier.Add(PatientIdentifier); //Create a client to send to the server at a given endpoint. var FhirClient = new Hl7.Fhir.Rest.FhirClient(ServiceRootUrl); // increase timeouts since the server might be powered down FhirClient.Timeout = (60 * 1000); Console.WriteLine("Press any key to send to server: " + ServiceRootUrl); Console.ReadKey(); try { //Attempt to send the resource to the server endpoint Hl7.Fhir.Model.Patient ReturnedPatient = FhirClient.Create <Hl7.Fhir.Model.Patient>(MyPatient); Console.WriteLine(string.Format("Resource is available at: {0}", ReturnedPatient.Id)); Console.WriteLine(); Console.WriteLine("This is what we sent up: "); Console.WriteLine(); string xml = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(MyPatient); XDocument xDoc = XDocument.Parse(xml); Console.WriteLine(xDoc.ToString()); Console.WriteLine(); Console.WriteLine("This is what we received back: "); Console.WriteLine(); xml = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(ReturnedPatient); xDoc = XDocument.Parse(xml); Console.WriteLine(xDoc.ToString()); Console.WriteLine(); } catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec) { //Process any Fhir Errors returned as OperationOutcome resource Console.WriteLine(); Console.WriteLine("An error message: " + FhirOpExec.Message); Console.WriteLine(); string xml = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(FhirOpExec.Outcome); XDocument xDoc = XDocument.Parse(xml); Console.WriteLine(xDoc.ToString()); } catch (Exception GeneralException) { Console.WriteLine(); Console.WriteLine("An error message: " + GeneralException.Message); Console.WriteLine(); } Console.WriteLine("Press any key to end."); Console.ReadKey(); }
private static void CreatePatient() { //Create a patient resource instance var MyPatient = new Hl7.Fhir.Model.Patient(); //Patient's Name var patientName = new Hl7.Fhir.Model.HumanName(); patientName.Use = Hl7.Fhir.Model.HumanName.NameUse.Official; patientName.Prefix = new string[] { "Mr" }; patientName.Given = new string[] { "Sam" }; patientName.Family = "Fhirman"; MyPatient.Name = new List <Hl7.Fhir.Model.HumanName>(); MyPatient.Name.Add(patientName); //Patient Identifier var patientIdentifier = new Hl7.Fhir.Model.Identifier(); patientIdentifier.System = "http://ns.electronichealth.net.au/id/hi/ihi/1.0"; patientIdentifier.Value = Guid.NewGuid().ToString(); MyPatient.Identifier = new List <Hl7.Fhir.Model.Identifier>(); MyPatient.Identifier.Add(patientIdentifier); var service = new Hl7.Fhir.Rest.FhirClient("http://hapi.fhir.org/baseDstu3"); service.Timeout = (30 * 1000); // 30 segundos //Attempt to send the resource to the server endpoint Hl7.Fhir.Model.Patient returnedPatient = service.Create <Hl7.Fhir.Model.Patient>(MyPatient); try { //Attempt to send the resource to the server endpoint Hl7.Fhir.Model.Patient ReturnedPatient = service.Create <Hl7.Fhir.Model.Patient>(MyPatient); Console.WriteLine(string.Format("Resource is available at: {0}", ReturnedPatient.Id)); Console.WriteLine(); Console.WriteLine("This is what we sent up: "); Console.WriteLine(); var serializer = new Hl7.Fhir.Serialization.FhirXmlSerializer(); var xml = serializer.SerializeToString(MyPatient); Console.WriteLine(xml); Console.WriteLine(); Console.WriteLine("This is what we received back: "); Console.WriteLine(); xml = serializer.SerializeToString(ReturnedPatient); Console.WriteLine(xml); Console.WriteLine(); } catch (Hl7.Fhir.Rest.FhirOperationException FhirOpExec) { //Process any Fhir Errors returned as OperationOutcome resource Console.WriteLine(); Console.WriteLine("An error message: " + FhirOpExec.Message); Console.WriteLine(); var serializer = new Hl7.Fhir.Serialization.FhirXmlSerializer(); string xml = serializer.SerializeToString(FhirOpExec.Outcome); Console.WriteLine(xml); } catch (Exception GeneralException) { Console.WriteLine(); Console.WriteLine("An error message: " + GeneralException.Message); Console.WriteLine(); } Console.WriteLine("Press any key to end."); Console.ReadKey(); }
public static void Main(string[] args) { Console.WriteLine("Press any key to create Bundle resource for Transaction....."); Console.ReadLine(); Console.WriteLine("Request : "); //creating a patient resource model with hard coded values var myPatient = new Patient(); var patientName = new HumanName(); patientName.Use = HumanName.NameUse.Official; patientName.Prefix = new string[] { "Mr" }; patientName.Given = new string[] { "John" }; patientName.Family = "Doe"; myPatient.Gender = AdministrativeGender.Male; myPatient.BirthDate = "1991-05-04"; myPatient.Name = new List <HumanName>(); myPatient.Name.Add(patientName); var raceExtension = new Extension(); raceExtension.Url = "http://hl7api.sourceforge.net/hapi-fhir/res/raceExt.html"; raceExtension.Value = new Code { Value = "WHITE" }; myPatient.Extension.Add(raceExtension); //Creating a Encounter resource model with hard coded values var myEncounter = new Encounter(); myEncounter.Text = new Narrative() { Status = Narrative.NarrativeStatus.Generated, Div = "<div xmlns=\"http://www.w3.org/1999/xhtml\">Encounter with patient @example</div>" }; myEncounter.Status = Encounter.EncounterStatus.InProgress; myEncounter.Class = new Coding() { System = "http://terminology.hl7.org/CodeSystem/v3-ActCode", Code = "IMP", Display = "inpatient encounter" }; //Updating a Patient resource considering the patient ID already exist on the server //If the patient ID is not present kindly select a patient Id already existing on the server else it will give error since we are hard coding it var updatePatient = new Patient(); //1354839 updatePatient.Id = patientId; var patientNameUpdate = new HumanName(); patientNameUpdate.Use = HumanName.NameUse.Official; patientNameUpdate.Prefix = new string[] { "Mr" }; patientNameUpdate.Given = new string[] { "Smith" }; patientNameUpdate.Family = "Carl"; updatePatient.Name = new List <HumanName>(); updatePatient.Name.Add(patientNameUpdate); //creating bundle for the transaction var bundle = new Bundle(); bundle.AddResourceEntry(myPatient, "https://hapi.fhir.org/baseDstu3/Patient").Request = new Bundle.RequestComponent { Method = Bundle.HTTPVerb.POST, Url = "Patient" }; bundle.AddResourceEntry(myEncounter, "https://hapi.fhir.org/baseDstu3/Encounter").Request = new Bundle.RequestComponent { Method = Bundle.HTTPVerb.POST, Url = "Encounter" }; bundle.AddResourceEntry(updatePatient, "https://hapi.fhir.org/baseDstu3/Patient/1354839").Request = new Bundle.RequestComponent { Method = Bundle.HTTPVerb.PUT, Url = "Patient/1354839" }; //Create a client to send to the server at a given endpoint. var FhirClient = new Hl7.Fhir.Rest.FhirClient(OpenFHIRUrl); string requestData = new FhirJsonSerializer().SerializeToString(bundle); Console.Write(JValue.Parse(requestData).ToString()); //sending the Request to the server var response = FhirClient.Transaction(bundle); Console.WriteLine(); Console.WriteLine("Press any key to get the response from the server....."); Console.ReadLine(); Console.WriteLine("Response : "); string responseData = new FhirJsonSerializer().SerializeToString(response); Console.Write(JValue.Parse(responseData).ToString()); Console.ReadKey(); }