Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 36 additions & 18 deletions src/Hl7.Fhir.Core.Tests/Rest/FhirClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class FhirClientTests
//public static Uri testEndpoint = new Uri("http://fhirtest.uhn.ca/baseDstu3");
//public static Uri testEndpoint = new Uri("http://localhost:49911/fhir");
//public static Uri testEndpoint = new Uri("http://sqlonfhir-stu3.azurewebsites.net/fhir");
public static Uri testEndpoint = new Uri("https://vonk.fire.ly/r3");
public static Uri testEndpoint = new Uri("https://server.fire.ly/r3");

//public static Uri _endpointSupportingSearchUsingPost = new Uri("http://localhost:49911/fhir");
public static Uri _endpointSupportingSearchUsingPost = new Uri("http://localhost:4080");
Expand Down Expand Up @@ -87,7 +87,7 @@ private static void CreateItems()
Family = "Donald",
}
},
Id = "pat1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better approach to make the identifiers dependent on the FhirVersion, like for example:

"pat1" + ModelInfo.Version

Make this a variable and use them in the tests.

Id = "pat1stu3",
Identifier = new List<Identifier>()
{
new Identifier()
Expand All @@ -104,7 +104,7 @@ private static void CreateItems()
{
City = "Den Burg"
},
Id = "1"
Id = "loc1stu3"
};

// Create the patient
Expand Down Expand Up @@ -281,7 +281,7 @@ private void testReadWithFormat(BaseFhirClient client)
public void ReadWrongResourceType()
{
LegacyFhirClient client = new LegacyFhirClient(testEndpoint);
var loc = client.Read<Patient>("Location/1");
var loc = client.Read<Patient>("Location/loc1stu3");
}

[TestMethod, TestCategory("FhirClient"), TestCategory("IntegrationTest")]
Expand All @@ -294,7 +294,7 @@ public void ReadWrongResourceTypeHttpClient()

private void testReadWrongResourceType(BaseFhirClient client)
{
var loc = client.Read<Patient>("Location/1");
var loc = client.Read<Patient>("Location/loc1stu3");
}

[TestMethod, TestCategory("FhirClient"), TestCategory("IntegrationTest")]
Expand All @@ -315,14 +315,14 @@ public void ReadHttpClient()

private void testReadClient(BaseFhirClient client)
{
var loc = client.Read<Location>("Location/1");
var loc = client.Read<Location>("Location/loc1stu3");
Assert.IsNotNull(loc);
Assert.AreEqual("Den Burg", loc.Address.City);

Assert.AreEqual("1", loc.Id);
Assert.IsNotNull(loc.Meta.VersionId);

var loc2 = client.Read<Location>(ResourceIdentity.Build("Location", "1", loc.Meta.VersionId));
var loc2 = client.Read<Location>(ResourceIdentity.Build("Location", "loc1stu3", loc.Meta.VersionId));
Assert.IsNotNull(loc2);
Assert.AreEqual(loc2.Id, loc.Id);
Assert.AreEqual(loc2.Meta.VersionId, loc.Meta.VersionId);
Expand All @@ -338,7 +338,7 @@ private void testReadClient(BaseFhirClient client)
Assert.AreEqual("404", client.LastResult.Status);
}

var loc3 = client.Read<Location>(ResourceIdentity.Build("Location", "1", loc.Meta.VersionId));
var loc3 = client.Read<Location>(ResourceIdentity.Build("Location", "loc1stu3", loc.Meta.VersionId));
Assert.IsNotNull(loc3);
var jsonSer = new FhirJsonSerializer();
Assert.AreEqual(jsonSer.SerializeToString(loc),
Expand Down Expand Up @@ -370,11 +370,11 @@ public void ReadRelativeHttpClient()

private void testReadRelative(BaseFhirClient client)
{
var loc = client.Read<Location>(new Uri("Location/1", UriKind.Relative));
var loc = client.Read<Location>(new Uri("Location/loc1stu3", UriKind.Relative));
Assert.IsNotNull(loc);
Assert.AreEqual("Den Burg", loc.Address.City);

var ri = ResourceIdentity.Build(testEndpoint, "Location", "1");
var ri = ResourceIdentity.Build(testEndpoint, "Location", "loc1stu3");
loc = client.Read<Location>(ri);
Assert.IsNotNull(loc);
Assert.AreEqual("Den Burg", loc.Address.City);
Expand All @@ -399,11 +399,11 @@ public void ReadRelativeAsyncHttpClient()

private void testRelativeAsyncClient(BaseFhirClient client)
{
var loc = client.ReadAsync<Location>(new Uri("Location/1", UriKind.Relative)).Result;
var loc = client.ReadAsync<Location>(new Uri("Location/loc1stu3", UriKind.Relative)).Result;
Assert.IsNotNull(loc);
Assert.AreEqual("Den Burg", loc.Address.City);

var ri = ResourceIdentity.Build(testEndpoint, "Location", "1");
var ri = ResourceIdentity.Build(testEndpoint, "Location", "loc1stu3");
loc = client.ReadAsync<Location>(ri).Result;
Assert.IsNotNull(loc);
Assert.AreEqual("Den Burg", loc.Address.City);
Expand Down Expand Up @@ -732,7 +732,7 @@ private static void testCreateAndFullRepresentation(BaseFhirClient client)
{
client.Settings.PreferredReturn = Prefer.ReturnRepresentation; // which is also the default

var pat = client.Read<Patient>("Patient/pat1");
var pat = client.Read<Patient>("Patient/pat1stu3");
ResourceIdentity ri = pat.ResourceIdentity().WithBase(client.Endpoint);
pat.Id = null;
pat.Identifier.Clear();
Expand Down Expand Up @@ -793,7 +793,7 @@ private void testCreateEditDelete(BaseFhirClient client)
{
// client.CompressRequestBody = true;

var pat = client.Read<Patient>("Patient/pat1");
var pat = client.Read<Patient>("Patient/pat1stu3");
pat.Id = null;
pat.Identifier.Clear();
pat.Identifier.Add(new Identifier("http://hl7.org/test/2", "99999"));
Expand Down Expand Up @@ -1322,7 +1322,7 @@ public void CallsCallbacks()
status = e.RawResponse.StatusCode;
};

var pat = client.Read<Patient>("Patient/pat1");
var pat = client.Read<Patient>("Patient/pat1stu3");
Assert.IsTrue(calledBefore);
Assert.IsNotNull(status);
Assert.IsNotNull(body);
Expand Down Expand Up @@ -1366,7 +1366,7 @@ public void CallsCallbacksHttpClient()
status = e.RawResponse.StatusCode;
};

var pat = client.Read<Patient>("Patient/pat1");
var pat = client.Read<Patient>("Patient/pat1stu3");
Assert.IsTrue(calledBefore);
Assert.IsNotNull(status);
Assert.IsNotNull(body);
Expand Down Expand Up @@ -1494,7 +1494,7 @@ public void TestRefreshHttpClient()

private static void clientReadRefresh(BaseFhirClient client)
{
var result = client.Read<Patient>("Patient/pat1");
var result = client.Read<Patient>("Patient/pat1stu3");

var orig = result.Name[0].FamilyElement.Value;

Expand Down Expand Up @@ -1763,6 +1763,24 @@ public void TestCreatingBinaryResourceHttpClient()
}
}

/// <summary>
/// Test for showing issue https://github.com/FirelyTeam/firely-net-sdk/issues/1681
/// </summary>
[TestMethod, TestCategory("IntegrationTest"), TestCategory("FhirClient")]
public void TestPreferOperationOutcome()
{
FhirClient client = new FhirClient(testEndpoint);
client.Settings.PreferredReturn = Prefer.OperationOutcome;

var pat = new Patient()
{
Name = new List<HumanName> { new HumanName().WithGiven("testy").AndFamily("McTestFace") }
};

var oo = client.Create<Patient>(pat);
Assert.IsNotNull(client.LastResult.Outcome);
}

[Ignore]
[TestMethod, TestCategory("IntegrationTest"), TestCategory("FhirClient")]
public void TestOperationEverything()
Expand Down Expand Up @@ -1840,7 +1858,7 @@ public void TestMultipleMessageHandlersInFhirClient()
};

using var client = new FhirClient(testEndpoint, settings: FhirClientSettings.CreateDefault(), testDegatingHandler);
var loc = client.Read<Location>("Location/1");
var loc = client.Read<Location>("Location/loc1stu3");
Assert.IsNotNull(testDegatingHandler.LastRequest);
Assert.IsNotNull(testMessageHandler.LastResponse);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Hl7.Fhir.Core/Rest/TypedEntryResponseToBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public static Bundle.EntryComponent ToBundleEntry(this TypedEntryResponse entry,
{
result.Resource = new BaseFhirParser(parserSettings).Parse<Resource>(entry.TypedElement);

//if the response is an operation outcome, add it to response.outcome. This is necessary for when a client uses return=OperationOutcome as a prefer header.
// see also issue #1681
if (result.Resource is OperationOutcome)
{
result.Response.Outcome = result.Resource;
}

if (result.Response.Location != null)
result.Resource.ResourceBase = new ResourceIdentity(result.Response.Location).BaseUri;
}
Expand Down