public Hl7.Fhir.Model.Resource LoadConformanceResourceByUrl(string url) { if (url == null) throw Error.ArgumentNull("identifier"); if (!ResourceIdentity.IsRestResourceIdentity(url)) return null; // Weakness in FhirClient, need to have the base :-( So return null if we cannot determine it. var id = new ResourceIdentity(url); // [WMR 20150810] Use custom FhirClient factory if specified var client = _clientFactory != null ? _clientFactory(id.BaseUri) : new FhirClient(id.BaseUri) { Timeout = 5000 }; try { return client.Read<Resource>(id); } catch (FhirOperationException) { return null; } catch (WebException) { return null; } }
public void TestCollection() { ResourceIdentity identity; identity = new ResourceIdentity("http://localhost/fhir/Patient/3"); Assert.AreEqual("Patient", identity.Collection); identity = new ResourceIdentity("http://localhost/fhir/Organization/3/_history/98"); Assert.AreEqual("Organization", identity.Collection); // Test that the case sensitivity of the resource name is honoured //EK: Still think that's not ResourceIdentifier's problem, but the calling subsystem should check with available metadata //EK: Hardwiring this into ResourceIdentifier means you cannot use it in "dynamic" scenario's where you don't have compile-time metadata // identity = new ResourceIdentity("http://localhost/fhir/organization/3/_history/98"); // Assert.AreEqual(null, identity.Collection); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/Patient/3/"); Assert.AreEqual("Patient", identity.Collection); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/Organization/3/_history/98"); Assert.AreEqual("Organization", identity.Collection); identity = new ResourceIdentity("http://localhost/fhir"); Assert.AreEqual(null, identity.Collection); identity = new ResourceIdentity("http://localhost/fhir/_history"); Assert.AreEqual(null, identity.Collection); // This is expected to return null, as this is not a valid use of the Resource Identity class identity = new ResourceIdentity("http://localhost/fhir/organization/_history"); Assert.AreEqual(null, identity.Collection); }
public void TestBase() { var identity = new ResourceIdentity("http://localhost/services/fhir/v012/Patient/3"); Assert.AreEqual(new Uri("http://localhost/services/fhir/v012/"), identity.BaseUri); identity = new ResourceIdentity("http://localhost/fhir/Patient/3"); Assert.AreEqual("http://localhost/fhir/", identity.BaseUri.OriginalString); identity = new ResourceIdentity("http://localhost/fhir/Organization/508x/_history/98"); Assert.AreEqual("http://localhost/fhir/", identity.BaseUri.OriginalString); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/Patient/B256/"); Assert.AreEqual("http://localhost/some/sub/path/fhir/", identity.BaseUri.OriginalString); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/Organization/3/_history/X98"); Assert.AreEqual("http://localhost/some/sub/path/fhir/", identity.BaseUri.OriginalString); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/Organization/3/_history/X98/pipo/clown"); Assert.AreEqual("http://localhost/some/sub/path/fhir/", identity.BaseUri.OriginalString); identity = new ResourceIdentity("Patient/3"); Assert.IsNull(identity.BaseUri); Assert.IsFalse(identity.HasBaseUri); identity = new ResourceIdentity("urn:oid:1.2.3.4.5.6"); Assert.AreEqual(new Uri("urn:oid:"), identity.BaseUri); identity = new ResourceIdentity("#myid"); Assert.IsFalse(identity.HasBaseUri); }
public void TestBuild() { var id = new ResourceIdentity("http://localhost/services/fhir/v012/Patient/3"); var idb = ResourceIdentity.Build(new Uri("http://localhost/services/fhir/v012"), "Patient", "3"); Assert.AreEqual("http://localhost/services/fhir/v012/Patient/3", id.ToString()); Assert.AreEqual(id, idb); id = new ResourceIdentity("Patient/3"); idb = ResourceIdentity.Build("Patient", "3"); Assert.AreEqual("Patient/3", id.ToString()); Assert.AreEqual(id, idb); id = ResourceIdentity.Build("Patient", "A100", "H2"); Assert.AreEqual("Patient/A100/_history/H2", id.ToString()); id = new ResourceIdentity("urn:oid:1.2.3.4.5.6"); idb = ResourceIdentity.Build(UrnType.OID, "1.2.3.4.5.6"); Assert.AreEqual("urn:oid:1.2.3.4.5.6", id.ToString()); Assert.AreEqual(id, idb); id = new ResourceIdentity("#myid"); idb = ResourceIdentity.Build("myid"); Assert.AreEqual("#myid", id.ToString()); Assert.AreEqual(id, idb); }
public void DeleteTagsOnVersionUsingDelete() { var identity = new ResourceIdentity(latest.SelfLink); var delete = new Tag(NUTAG, Tag.FHIRTAGSCHEME_GENERAL); var existing = new Tag(_otherTag, Tag.FHIRTAGSCHEME_GENERAL); HttpTests.AssertSuccess(client, () => client.DeleteTags(identity, new List<Tag> { delete })); var result = client.Read<Patient>(latest.Id); if (result.Tags.Count() != 1) TestResult.Fail("delete resulted in an unexpected number of remaining tags"); if (!result.Tags.Any(t => t.Equals(existing))) TestResult.Fail("delete removed an existing tag the should be untouched"); if (result.Tags.Any(t => t.Equals(delete))) TestResult.Fail("delete did not remove the tag"); if (result.SelfLink != latest.SelfLink) TestResult.Fail("deleting the tags created a new version"); //TODO: Check whether taglists on older versions remain unchanged }
public void TestResourceType() { var identity = new ResourceIdentity("http://localhost/fhir/Patient/3"); Assert.AreEqual("Patient", identity.ResourceType); identity = new ResourceIdentity("http://localhost/fhir/Organization/3/_history/98"); Assert.AreEqual("Organization", identity.ResourceType); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/Patient/3/"); Assert.AreEqual("Patient", identity.ResourceType); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/Organization/3/_history/98"); Assert.AreEqual("Organization", identity.ResourceType); identity = new ResourceIdentity("Patient/3"); Assert.AreEqual("Patient", identity.ResourceType); identity = new ResourceIdentity("urn:oid:1.2.3.4.5.6"); Assert.IsNull(identity.ResourceType); identity = new ResourceIdentity("#myid"); Assert.IsNull(identity.ResourceType); identity = new ResourceIdentity("http://localhost/fhir/Patient/45?param=x"); Assert.AreEqual("Patient", identity.ResourceType); }
public static void DebugDumpBundle(Hl7.Fhir.Model.Bundle b) { System.Diagnostics.Trace.WriteLine(String.Format("--------------------------------------------\r\nBundle Type: {0} ({1} total items, {2} included)", b.Type.ToString(), b.Total, (b.Entry != null ? b.Entry.Count.ToString() : "-"))); if (b.Entry != null) { foreach (var item in b.Entry) { if (item.Request != null) { System.Diagnostics.Trace.WriteLine(String.Format(" {0}: {1}", item.Request.Method.ToString(), item.Request.Url)); } if (item.Response != null && item.Response.Status != null) { System.Diagnostics.Trace.WriteLine(String.Format(" {0}", item.Response.Status)); } if (item.Resource != null && item.Resource is Hl7.Fhir.Model.DomainResource) { if (item.Resource.Meta != null && item.Resource.Meta.LastUpdated.HasValue) { System.Diagnostics.Trace.WriteLine(String.Format(" Last Updated:{0}, [{1}]", item.Resource.Meta.LastUpdated.Value, item.Resource.Meta.LastUpdated.Value.ToString("HH:mm:ss.FFFF"))); } Hl7.Fhir.Rest.ResourceIdentity ri = new Hl7.Fhir.Rest.ResourceIdentity(item.FullUrl); System.Diagnostics.Trace.WriteLine(String.Format(" {0}", (item.Resource as Hl7.Fhir.Model.DomainResource).ResourceIdentity(ri.BaseUri).OriginalString)); } } } }
public static string GetResourceTypeName(this BundleEntry entry) { ResourceIdentity identity; if (entry is ResourceEntry) { return (entry as ResourceEntry).Resource.GetCollectionName(); } else if (Key.IsHttpScheme(entry.Id)) { identity = new ResourceIdentity(entry.Id); if (identity.Collection != null) return identity.Collection; } else if (Key.IsHttpScheme(entry.SelfLink)) { identity = new ResourceIdentity(entry.SelfLink); if (identity.Collection != null) return identity.Collection; } else if (entry.SelfLink != null) { string[] segments = entry.SelfLink.ToString().Split('/'); return segments[0]; } throw new InvalidOperationException("Encountered a entry without an id, self-link or content that indicates the resource's type"); }
public void Read() { FhirClient client = new FhirClient(testEndpoint); var loc = client.Read<Location>("Location/1"); Assert.IsNotNull(loc); Assert.AreEqual("Den Burg", loc.Resource.Address.City); string version = new ResourceIdentity(loc.SelfLink).VersionId; Assert.IsNotNull(version); string id = new ResourceIdentity(loc.Id).Id; Assert.AreEqual("1", id); try { var random = client.Read(new Uri("Location/45qq54", UriKind.Relative)); Assert.Fail(); } catch (FhirOperationException) { Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.NotFound); } var loc2 = client.Read<Location>(ResourceIdentity.Build("Location","1", version)); Assert.IsNotNull(loc2); Assert.AreEqual(FhirSerializer.SerializeBundleEntryToJson(loc), FhirSerializer.SerializeBundleEntryToJson(loc2)); var loc3 = client.Read<Location>(loc.SelfLink); Assert.IsNotNull(loc3); Assert.AreEqual(FhirSerializer.SerializeBundleEntryToJson(loc), FhirSerializer.SerializeBundleEntryToJson(loc3)); }
public static Uri HistoryKeyFor(this IGenerator generator, Uri key) { var identity = new ResourceIdentity(key); string vid = generator.NextVersionId(identity.ResourceType); Uri result = identity.WithVersion(vid); return result; }
public static Key ExtractKey(Uri uri) { var identity = new ResourceIdentity(uri); string _base = (identity.HasBaseUri) ? identity.BaseUri.ToString() : null; Key key = new Key(_base, identity.ResourceType, identity.Id, identity.VersionId); return key; }
public void QueueNewResourceEntry(Uri id, ResourceEntry entry) { if (id == null) throw new ArgumentNullException("id"); if (!id.IsAbsoluteUri) throw new ArgumentException("Uri for new resource must be absolute"); var location = new ResourceIdentity(id); var title = String.Format("{0} resource with id {1}", location.Collection, location.Id); var newEntry = BundleEntryFactory.CreateFromResource(entry.Resource, id, DateTimeOffset.Now, title); newEntry.Tags = entry.Tags; queue.Add(newEntry); }
public static void AssertContentLocationValidIfPresent(FhirClient client) { if (!String.IsNullOrEmpty(client.LastResponseDetails.ContentLocation)) { var rl = new ResourceIdentity(client.LastResponseDetails.ContentLocation); if (rl.Id == null) TestResult.Fail("Content-Location does not have an id in it"); if (rl.VersionId == null) TestResult.Fail("Content-Location is not a version-specific url"); } }
internal static Bundle.EntryComponent ToBundleEntry(this HttpWebResponse response, byte[] body) { var result = new Bundle.EntryComponent(); result.Response = new Bundle.ResponseComponent(); result.Response.Status = ((int)response.StatusCode).ToString(); result.Response.SetHeaders(response.Headers); var contentType = getContentType(response); var charEncoding = getCharacterEncoding(response); result.Response.Location = response.Headers[HttpUtil.LOCATION] ?? response.Headers[HttpUtil.CONTENTLOCATION]; #if PORTABLE45 if (!String.IsNullOrEmpty(response.Headers[HttpUtil.LASTMODIFIED])) result.Response.LastModified = DateTimeOffset.Parse(response.Headers[HttpUtil.LASTMODIFIED]); #else result.Response.LastModified = response.LastModified; #endif result.Response.Etag = getETag(response); if (body != null) { result.Response.SetBody(body); if (IsBinaryResponse(response.ResponseUri.OriginalString, contentType)) { result.Resource = makeBinaryResource(body, contentType); if (result.Response.Location != null) { var ri = new ResourceIdentity(result.Response.Location); result.Resource.Id = ri.Id; result.Resource.Meta = new Meta(); result.Resource.Meta.VersionId = ri.VersionId; result.Resource.ResourceBase = ri.BaseUri; } } else { var bodyText = DecodeBody(body, charEncoding); var resource = parseResource(bodyText, contentType); result.Resource = resource; if (result.Response.Location != null) result.Resource.ResourceBase = new ResourceIdentity(result.Response.Location).BaseUri; } } return result; }
/// <summary> /// When a ResourceReference is relative, use the parent resource's fullUrl (e.g. from a Bundle's entry) /// to make it absolute. /// </summary> /// <param name="reference">The ResourceReference to get the (possibily relative) url from</param> /// <param name="parentResourceUri">Absolute uri representing the location of the resource this reference is in.</param> /// <remarks>Implements (part of the logic) as described in bundle.html#6.7.4.1</remarks> /// <returns></returns> public static Uri GetAbsoluteUriForReference(this ResourceReference reference, Uri parentResourceUri) { if (parentResourceUri == null) throw Error.ArgumentNull("parentResourceUri"); if (reference == null) throw Error.ArgumentNull("reference"); if (reference.Reference == null) return null; // Don't need to do anything when Uri is absolute var referenceUri = new Uri(reference.Reference, UriKind.RelativeOrAbsolute); if (referenceUri.IsAbsoluteUri) return referenceUri; if (!ResourceIdentity.IsRestResourceIdentity(parentResourceUri)) throw Error.Argument("parentResourceUri", "Must be an absolute FHIR REST identity when reference is relative"); var parent = new ResourceIdentity(parentResourceUri); return HttpUtil.MakeAbsoluteToBase(referenceUri, parent.BaseUri); }
public static ResourceEntry CreateResourceEntryFromId(Uri id) { // Figure out the resource type from the id ResourceIdentity rid = new ResourceIdentity(id); if (rid.Collection != null) { var inspector = SerializationConfig.Inspector; var classMapping = inspector.FindClassMappingForResource(rid.Collection); return ResourceEntry.Create(classMapping.NativeType); } else throw Error.Format("BundleEntry's id '{0}' does not specify the type of resource: cannot determine Resource type in parser.", null, id.ToString()); }
public void PostBundle() { var bundle = DemoData.GetDemoXdsBundle(); postResult = client.Transaction(bundle); HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(postResult); if (postResult.Entries.Count != 5) TestResult.Fail(String.Format("Bundle response contained {0} entries in stead of 5", postResult.Entries.Count)); postResult = client.RefreshBundle(postResult); HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(postResult); var entries = postResult.Entries.ToList(); connDoc = entries[0]; if (new ResourceIdentity(connDoc.Id).Id==null) TestResult.Fail("failed to assign id to new xds document"); if (new ResourceIdentity(connDoc.SelfLink).VersionId == null) TestResult.Fail("failed to assign a version id to new xds document"); patDoc = entries[1]; if (new ResourceIdentity(patDoc.Id) == null) TestResult.Fail("failed to assign id to new patient"); prac1Doc = entries[2]; if (new ResourceIdentity(prac1Doc.Id).Id == null) TestResult.Fail("failed to assign id to new practitioner (#1)"); if (new ResourceIdentity(prac1Doc.SelfLink).VersionId == null) TestResult.Fail("failed to assign a version id to new practitioner (#1)"); prac2Doc = entries[3]; if (new ResourceIdentity(prac2Doc.Id).Id == null) TestResult.Fail("failed to assign id to new practitioner (#2)"); if (new ResourceIdentity(prac2Doc.SelfLink).VersionId == null) TestResult.Fail("failed to assign a version id to new practitioner (#2)"); binDoc = entries[4]; if (new ResourceIdentity(binDoc.Id).Id == null) TestResult.Fail("failed to assign id to new binary"); if (new ResourceIdentity(binDoc.SelfLink).VersionId == null) TestResult.Fail("failed to assign a version id to new binary"); var docResource = ((ResourceEntry<DocumentReference>)connDoc).Resource; if (!prac1Doc.Id.ToString().Contains(docResource.Author[0].Reference)) TestResult.Fail("doc reference's author[0] does not reference newly created practitioner #1"); if (!prac2Doc.Id.ToString().Contains(docResource.Author[1].Reference)) TestResult.Fail("doc reference's author[1] does not reference newly created practitioner #2"); var binRl = new ResourceIdentity(binDoc.Id); if (!docResource.Text.Div.Contains(binRl.OperationPath.ToString())) TestResult.Fail("href in narrative was not fixed to point to newly created binary"); }
public Hl7.Fhir.Model.Resource LoadConformanceResourceByUrl(string url) { if (url == null) throw Error.ArgumentNull("identifier"); var id = new ResourceIdentity(url); var client = new FhirClient(id.BaseUri); client.Timeout = 5000; //ms try { return client.Read<Resource>(id); } catch(FhirOperationException) { return null; } }
public void TestCollection() { ResourceIdentity identity; identity = new ResourceIdentity("http://localhost/fhir/patient/3"); Assert.AreEqual("patient", identity.Collection); identity = new ResourceIdentity("http://localhost/fhir/organization/3/_history/98"); Assert.AreEqual("organization", identity.Collection); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/patient/3/"); Assert.AreEqual("patient", identity.Collection); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/organization/3/_history/98"); Assert.AreEqual("organization", identity.Collection); identity = new ResourceIdentity("http://localhost/fhir"); Assert.AreEqual(null, identity.Collection); }
public void TestId() { ResourceIdentity identity; identity = new ResourceIdentity("http://localhost/fhir/patient/3"); Assert.AreEqual("3", identity.Id); identity = new ResourceIdentity("http://localhost/fhir/organization/508x/_history/98"); Assert.AreEqual("508x", identity.Id); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/patient/B256/"); Assert.AreEqual("B256", identity.Id); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/organization/3/_history/98"); Assert.AreEqual("3", identity.Id); identity = new ResourceIdentity("http://localhost/fhir"); Assert.AreEqual(null, identity.Id); }
public void TestVersionId() { ResourceIdentity identity; identity = new ResourceIdentity("http://localhost/fhir/patient/3"); Assert.AreEqual(null, identity.VersionId); identity = new ResourceIdentity("http://localhost/fhir/organization/508x/_history/98"); Assert.AreEqual("98", identity.VersionId); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/patient/B256/"); Assert.AreEqual(null, identity.VersionId); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/organization/3/_history/X98"); Assert.AreEqual("X98", identity.VersionId); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/organization/3/_history/X98/pipo/clown"); Assert.AreEqual("X98", identity.VersionId); identity = new ResourceIdentity("http://localhost/fhir"); Assert.AreEqual(null, identity.VersionId); }
public Model.Resource ReadResourceArtifact(Uri artifactId) { if (artifactId == null) throw Error.ArgumentNull("artifactId"); if (!artifactId.IsAbsoluteUri) Error.Argument("artifactId", "Uri must be absolute"); var id = new ResourceIdentity(artifactId); var client = new FhirClient(id.Endpoint); client.Timeout = 5000; //ms try { var artifactEntry = client.Read(id); return artifactEntry != null ? artifactEntry.Resource : null; } catch { return null; } }
public static void ValidateCorrectUpdate(Uri mostRecentUpdateUri, Uri updatedUri) { var mostRecent = new ResourceIdentity(mostRecentUpdateUri); // If we require version-aware updates and no version to update was indicated, // we need to return a Precondition Failed. if (requiresVersionAwareUpdate(mostRecent.Collection) && updatedUri == null) throw new SparkException(HttpStatusCode.PreconditionFailed, "This resource requires version-aware updates and no Content-Location was given"); // Validate the updatedUri against the current version if (updatedUri != null) { var update = new ResourceIdentity(updatedUri); //if (mostRecent.OperationPath != update.OperationPath) if (mostRecent.VersionId != update.VersionId) { throw new SparkException(HttpStatusCode.Conflict, "There is an update conflict: update referred to version {0}, but current version is {1}", update, mostRecent); } } }
public void WriteMetaData(ResourceEntry entry, int level, Resource resource) { if (level == 0) { Write(InternalField.ID, container_id); string selflink = entry.Links.SelfLink.ToString(); Write(InternalField.SELFLINK, selflink); var resloc = new ResourceIdentity(container_id); Write(InternalField.JUSTID, resloc.Id); /* //For testing purposes: string term = resloc.Id; List<Tag> tags = new List<Tag>() { new Tag(term, "http://tags.hl7.org", "labello"+term) } ; tags.ForEach(Collect); /* */ if (entry.Tags != null) { entry.Tags.ToList().ForEach(Collect); } } else { string id = resource.Id; Write(InternalField.ID, container_id + "#" + id); } string category = resource.GetCollectionName(); //ModelInfo.GetResourceNameForType(resource.GetType()).ToLower(); Write(InternalField.RESOURCE, category); Write(InternalField.LEVEL, level); }
public Hl7.Fhir.Model.Resource LoadConformanceResourceByUrl(string url) { if (url == null) throw Error.ArgumentNull("identifier"); if (!ResourceIdentity.IsRestResourceIdentity(url)) throw Error.Argument("url", "Canonical url must be a FHIR REST identity"); var id = new ResourceIdentity(url); // [WMR 20150810] Use custom FhirClient factory if specified var client = _clientFactory != null ? _clientFactory(id.BaseUri) : new FhirClient(id.BaseUri) { Timeout = 5000 }; try { return client.Read<Resource>(id); } catch (FhirOperationException) { return null; } catch (WebException) { return null; } }
public void SearchAsync() { FhirClient client = new FhirClient(testEndpoint); Bundle result; result = client.SearchAsync<DiagnosticReport>().Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count() > 10, "Test should use testdata with more than 10 reports"); result = client.SearchAsync<DiagnosticReport>(pageSize: 10).Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count <= 10); var withSubject = result.Entry.ByResourceType<DiagnosticReport>().FirstOrDefault(dr => dr.Resource.Subject != null); Assert.IsNotNull(withSubject, "Test should use testdata with a report with a subject"); ResourceIdentity ri = new ResourceIdentity(withSubject.Id); result = client.SearchByIdAsync<DiagnosticReport>(ri.Id, includes: new string[] { "DiagnosticReport.subject" }).Result; Assert.IsNotNull(result); Assert.AreEqual(2, result.Entry.Count); // should have subject too Assert.IsNotNull(result.Entry.Single(entry => new ResourceIdentity(entry.Id).Collection == typeof(DiagnosticReport).GetCollectionName())); Assert.IsNotNull(result.Entry.Single(entry => new ResourceIdentity(entry.Id).Collection == typeof(Patient).GetCollectionName())); result = client.SearchAsync<Patient>(new string[] { "name=Everywoman", "name=Eve" }).Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count > 0); }
private static Parameters validateCodeForValueSetId(FhirClient client, string valueSetId, Parameters par) { ResourceIdentity location = new ResourceIdentity("ValueSet/" + valueSetId); return(expect <Parameters>(client.InstanceOperation(location.WithoutVersion().MakeRelative(), Operation.VALIDATE_CODE, par))); }
public static ResourceIdentity Core(FHIRDefinedType type) { return(ResourceIdentity.Core(type.GetLiteral())); }
public HttpResponseMessage Get(string ResourceName, string id, string vid) { try { var buri = this.CalculateBaseURI("{ResourceName}"); if (!Id.IsValidValue(id)) { throw new FhirServerException(HttpStatusCode.BadRequest, "ID [" + id + "] is not a valid FHIR Resource ID"); } var Inputs = GetInputs(buri); IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, Inputs); Hl7.Fhir.Rest.SummaryType summary = GetSummaryParameter(Request); Resource resource = model.Get(id, vid, summary); if (resource != null) { var baseResource = new Hl7.Fhir.Rest.ResourceIdentity(Request.RequestUri); resource.ResourceBase = new Uri(string.Format("http://{0}", baseResource.Authority)); if (resource is DomainResource) { DomainResource dr = resource as DomainResource; switch (summary) { case Hl7.Fhir.Rest.SummaryType.False: break; case Hl7.Fhir.Rest.SummaryType.True: // summary doesn't have the text in it. dr.Text = null; // there are no contained references in the summary form dr.Contained = null; // Add in the Meta Tag that indicates that this resource is only a partial resource.Meta.Tag = new List <Coding> { new Coding("http://hl7.org/fhir/v3/ObservationValue", "SUBSETTED") }; break; case Hl7.Fhir.Rest.SummaryType.Text: // what do we need to filter here break; case Hl7.Fhir.Rest.SummaryType.Data: // summary doesn't have the text in it. dr.Text = null; // Add in the Meta Tag that indicates that this resource is only a partial resource.Meta.Tag = new List <Coding> { new Coding("http://hl7.org/fhir/v3/ObservationValue", "SUBSETTED") }; break; } } if (ResourceName == "Binary") { // We need to reset the accepts type so that the correct formatter is used on the way out. string formatParam = this.ControllerContext.Request.GetParameter("_format"); if (string.IsNullOrEmpty(formatParam)) { this.ControllerContext.Request.Headers.Accept.Clear(); this.ControllerContext.Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue((resource as Binary).ContentType)); } } var msg = Request.ResourceResponse(resource, HttpStatusCode.OK); msg.Headers.Location = resource.ResourceIdentity().WithBase(resource.ResourceBase); msg.Headers.Add("ETag", String.Format("\"{0}\"", resource.Meta.VersionId)); if (ResourceName == "Binary") { // We need to reset the accepts type so that the correct formatter is used on the way out. string formatParam = this.ControllerContext.Request.GetParameter("_format"); if (string.IsNullOrEmpty(formatParam)) { msg.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = String.Format("fhir_binary_{0}_{1}.{2}", resource.Id, resource.Meta != null ? resource.Meta.VersionId : "0", GetFileExtensionForMimeType((resource as Binary).ContentType)) }; } } return(msg); } // this request is a "you wanted what?" return(Request.CreateResponse(HttpStatusCode.NotFound)); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return(null); } }
public static async Task <OperationOutcome> ValidateDeleteAsync(this FhirClient client, ResourceIdentity location) { if (location == null) { throw Error.ArgumentNull(nameof(location)); } var par = new Parameters().Add("mode", new Code("delete")); return(OperationResult <OperationOutcome>(await client.InstanceOperationAsync(location.WithoutVersion().MakeRelative(), RestOperation.VALIDATE_RESOURCE, par).ConfigureAwait(false))); }
public static void AssertLocationPresentAndValid(FhirClient client) { if (String.IsNullOrEmpty(client.LastResponseDetails.Location)) TestResult.Fail("Mandatory Location header missing"); var rl = new ResourceIdentity(client.LastResponseDetails.Location); if (rl.Id == null) TestResult.Fail("Location does not have an id in it"); if (rl.VersionId == null) TestResult.Fail("Location is not a version-specific url"); }
public static OperationOutcome ValidateDelete(this FhirClient client, ResourceIdentity location) { return(ValidateDeleteAsync(client, location).WaitResult()); }
internal static bool IsBinaryResponse(string responseUri) { if (ResourceIdentity.IsRestResourceIdentity(responseUri)) { var id = new ResourceIdentity(responseUri); if (id.ResourceType != ResourceType.Binary.ToString()) return false; if (id.Id != null && Id.IsValidValue(id.Id)) return true; if (id.VersionId != null && Id.IsValidValue(id.VersionId)) return true; } return false; }
public void TestResourceIdentity() { ResourceIdentity id = new ResourceIdentity("http://localhost/services/fhir/v012/patient/3"); Assert.AreEqual("http://localhost/services/fhir/v012/patient/3", id.ToString()); Assert.AreEqual("patient", id.Collection); }
public void TestRelativeUri() { ResourceIdentity identity; identity = new ResourceIdentity("patient/8"); Assert.AreEqual("patient", identity.Collection); Assert.AreEqual("8", identity.Id); identity = new ResourceIdentity("patient/8/_history/H30"); Assert.AreEqual("patient", identity.Collection); Assert.AreEqual("8", identity.Id); Assert.AreEqual("H30", identity.VersionId); identity = new ResourceIdentity(new Uri("patient/8", UriKind.Relative)); Assert.AreEqual("patient", identity.Collection); Assert.AreEqual("8", identity.Id); identity = new ResourceIdentity(new Uri("patient/8/_history/H30", UriKind.Relative)); Assert.AreEqual("patient", identity.Collection); Assert.AreEqual("8", identity.Id); Assert.AreEqual("H30", identity.VersionId); }
public void AddVersionNumberToExistingIdentifier() { var identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/patient/B256/"); var newIdentity = identity.WithVersion("3141"); Assert.AreEqual("B256", newIdentity.Id); Assert.AreEqual("3141", newIdentity.VersionId); identity = new ResourceIdentity("http://localhost/some/sub/path/fhir/organization/3/_history/X98"); newIdentity = identity.WithVersion("3141"); Assert.AreEqual("3", newIdentity.Id); Assert.AreEqual("3141", newIdentity.VersionId); // mh: relativ uri's: identity = new ResourceIdentity("organization/3"); newIdentity = identity.WithVersion("3141"); Assert.AreEqual("3", newIdentity.Id); Assert.AreEqual("3141", newIdentity.VersionId); identity = new ResourceIdentity("organization/3/_history/X98"); newIdentity = identity.WithVersion("3141"); Assert.AreEqual("3", newIdentity.Id); Assert.AreEqual("3141", newIdentity.VersionId); }