private async Task <bool> CreateResourceIfNotExists(string databaseName, Hl7.Fhir.Model.Resource r) { try { if (r == null) { return(false); } string fh = historystore.InsertResourceHistoryItem(r); if (fh == null) { Trace.TraceError("Failed to update resource history...Upsert aborted for {0}-{1}", Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType), r.Id); return(false); } //Overflow remove attachments or error if (fh.Length > 500000) { } JObject obj = JObject.Parse(fh); var inserted = await this.client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType)), obj); return(true); } catch (DocumentClientException de) { Trace.TraceError("Error creating resource: {0}-{1}-{2} Message: {3}", databaseName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType), r.Id, de.Message); historystore.DeleteResourceHistoryItem(r); Trace.TraceInformation("Resource history entry for {0}-{1} version {2} rolledback due to document creation error.", Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType), r.Id, r.Meta.VersionId); return(false); } }
public async Task DeleteFHIRResource(Hl7.Fhir.Model.Resource r) { if (!_initTask.IsCompleted) { await _initTask; } //TODO Implement Delete by Identity }
public async Task <int> UpsertFHIRResource(Hl7.Fhir.Model.Resource r) { await CreateDocumentCollectionIfNotExists(DBName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType)); var x = await CreateResourceIfNotExists(DBName, r); return(x); }
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(); }
public async Task <bool> UpsertFHIRResource(Hl7.Fhir.Model.Resource r) { if (!_initTask.IsCompleted) { await _initTask; } await CreateDocumentCollectionIfNotExists(DBName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType)); var x = await CreateResourceIfNotExists(DBName, r); return(x); }
public static string Serialize(Hl7.Fhir.Model.Resource fhirResource, string mimeFormat, bool summary) { string payload = string.Empty; if (mimeFormat.IndexOf("JSON", StringComparison.InvariantCultureIgnoreCase) >= 0) { payload = FhirSerializer.SerializeResourceToJson(fhirResource, summary); } else { payload = FhirSerializer.SerializeResourceToXml(fhirResource, summary); } return(payload); }
private Hl7.Fhir.Model.Resource ConvertDocument(Document doc) { var obj = (JObject)(dynamic)doc; string rt = (string)obj["resourceType"]; string id = (string)obj["id"]; string version = (string)obj["meta"]["versionId"]; //if this had attachments removed for size then retrieve and send the history version which has full attachment data if (obj["_fhirattach"] != null) { obj = JObject.Parse(historystore.GetResourceHistoryItem(rt, id, version)); } obj.Remove("_rid"); obj.Remove("_self"); obj.Remove("_etag"); obj.Remove("_attachments"); obj.Remove("_ts"); Hl7.Fhir.Model.Resource t = (Hl7.Fhir.Model.Resource)parser.Parse(obj.ToString(Newtonsoft.Json.Formatting.None), FhirHelper.ResourceTypeFromString(rt)); return(t); }
public override object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) { string resourceString = string.Empty; Hl7.Fhir.Model.Resource resource = null; using (StreamReader reader = new StreamReader(readStream)) { resourceString = reader.ReadToEnd(); } if (FhirParser.ProbeIsXml(resourceString)) { resource = FhirParser.ParseResourceFromXml(resourceString) as Hl7.Fhir.Model.Resource; } return(resource); }
public async Task <bool> DeleteFHIRResource(Hl7.Fhir.Model.Resource r) { //TODO Implement Delete by Identity await CreateDocumentCollectionIfNotExists(DBName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType)); try { if (!fixeddb) { await this.client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(DBName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType), r.Id), new RequestOptions { PartitionKey = new PartitionKey(r.Id) }); } else { await this.client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(DBName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType), r.Id)); } return(true); } catch (DocumentClientException de) { //Trace.TraceError("Error deleting resource type: {0} Id: {1} Message: {2}", r.ResourceType, r.Id, de.Message); return(false); } }
private async Task <int> CreateResourceIfNotExists(string databaseName, Hl7.Fhir.Model.Resource r) { int retstatus = -1; //Error try { if (r == null) { return(retstatus); } string fh = historystore.InsertResourceHistoryItem(r); if (fh == null) { Trace.TraceError("Failed to update resource history...Upsert aborted for {0}-{1}", Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType), r.Id); return(retstatus); } JObject obj = JObject.Parse(fh); //Overflow remove attachments flagged to pull from history if (fh.Length > imaxdocsize) { string rt = Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType); obj = FhirAttachments.Instance.RemoveAttachementData(rt, obj); } var inserted = await this.client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType)), obj); retstatus = (inserted.StatusCode == HttpStatusCode.Created ? 1 : 0); return(retstatus); } catch (DocumentClientException de) { //Trace.TraceError("Error creating resource: {0}-{1}-{2} Message: {3}", databaseName,Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType),r.ResourceType),r.Id,de.Message); historystore.DeleteResourceHistoryItem(r); //Trace.TraceInformation("Resource history entry for {0}-{1} version {2} rolledback due to document creation error.", Enum.GetName(typeof(Hl7.Fhir.Model.ResourceType), r.ResourceType), r.Id, r.Meta.VersionId); return(retstatus); } }
public ResourceResponse(Hl7.Fhir.Model.Resource resource, int resp) { this.Resource = resource; this.Response = resp; }
public void UpdateResourceContent(Hl7.Fhir.Model.Resource modelResource, ResourceContent resourceContent) { }
public void UpdateResource(Hl7.Fhir.Model.Resource modelResource, Resource resource) { }
public ResourceContent CreatResourceContent(Hl7.Fhir.Model.Resource modelResource) { return(_content); }
public static MappedResource FromResource(Resource resource) { return(new MappedResource { Id = resource.Id, VersionId = resource.VersionId, TypeName = resource.TypeName, Payload = resource.ToJson() }); }