///------------------------------------------------------------------------------------------------- /// <summary>Gets topics bundle.</summary> /// /// <remarks>Gino Canessa, 11/6/2019.</remarks> /// /// <param name="wrapInBasic">(Optional) True to wrap in basic.</param> /// /// <returns>The topics bundle.</returns> ///------------------------------------------------------------------------------------------------- private fhir.Bundle _GetTopicsBundle(bool wrapInBasic = false) { fhir.Bundle bundle = new fhir.Bundle() { Type = "searchset", Total = (uint)_titleTopicDict.Count, Meta = new fhir.Meta() { LastUpdated = string.Format("{0:o}", DateTime.Now.ToUniversalTime()) }, Entry = new BundleEntry[_idTopicDict.Count] }; fhir.SubscriptionTopic[] topics = _idTopicDict.Values.ToArray <fhir.SubscriptionTopic>(); if (wrapInBasic) { for (int index = 0; index < topics.Length; index++) { // **** add this topic **** bundle.Entry[index] = new BundleEntry() { FullUrl = Program.UrlForResourceId("Topic", topics[index].Id), Resource = WrapInBasic(topics[index]), Search = new BundleEntrySearch() { Mode = "match" }, //Response = new BundleEntryResponse() { Status = "201 Created"} }; } } else { for (int index = 0; index < topics.Length; index++) { // **** add this topic **** bundle.Entry[index] = new BundleEntry() { FullUrl = Program.UrlForResourceId("Topic", topics[index].Id), Resource = topics[index], Search = new BundleEntrySearch() { Mode = "match" }, //Response = new BundleEntryResponse() { Status = "201 Created"} }; } } // **** return our bundle **** return(bundle); }
/// <summary>Creates patient if required.</summary> /// <returns>An asynchronous result that yields true if it succeeds, false if it fails.</returns> public static async Task <bool> CreatePatientIfRequired() { // try to get a our patient try { // create a patient id _patientId = Guid.NewGuid().ToString(); // build our request HttpRequestMessage request = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = GetFhirUri($"Patient/{_patientId}"), Headers = { Accept = { new MediaTypeWithQualityHeaderValue("application/fhir+json") }, } }; // make our request HttpResponseMessage response = await _restClient.SendAsync(request); // check the status code if (response.StatusCode != System.Net.HttpStatusCode.OK) { return(await CreatePatient()); } string content = await response.Content.ReadAsStringAsync(); // deserialize fhir.Bundle bundle = JsonConvert.DeserializeObject <fhir.Bundle>(content); // check for values if ((bundle.Entry == null) || (bundle.Entry.Length == 0)) { return(await CreatePatient()); } // good here return(true); } catch (Exception ex) { Console.WriteLine($"Failed to Get Patient/{_patientId}: {ex.Message}"); return(await CreatePatient()); } }
/// <summary>Gets subscription topics from the server.</summary> /// <returns>The topics.</returns> public static async Task <List <fhir.SubscriptionTopic> > GetTopics() { List <fhir.SubscriptionTopic> topics = new List <fhir.SubscriptionTopic>(); // try to get a list of topics try { // build our request HttpRequestMessage request = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = GetFhirUri("SubscriptionTopic"), Headers = { Accept = { new MediaTypeWithQualityHeaderValue("application/fhir+json") }, } }; // make our request HttpResponseMessage response = await _restClient.SendAsync(request); // check the status code if (response.StatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine($" Could not get SubscriptionTopics: {request.RequestUri.ToString()} returned: {response.StatusCode}"); return(topics); } string content = await response.Content.ReadAsStringAsync(); // deserialize fhir.Bundle bundle = JsonConvert.DeserializeObject <fhir.Bundle>(content, new fhir.ResourceConverter()); // check for values if ((bundle.Entry == null) || (bundle.Entry.Length == 0)) { return(topics); } // traverse topics foreach (fhir.BundleEntry entry in bundle.Entry) { if (entry.Resource == null) { continue; } // add this topic (should error check here) topics.Add((fhir.SubscriptionTopic)entry.Resource); } } catch (Exception ex) { Console.WriteLine($"Failed to Get SubscriptionTopics: {ex.Message}"); return(topics); } // return our list return(topics); }