Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the error message during conditional reference #4691

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
9 changes: 9 additions & 0 deletions src/Microsoft.Health.Fhir.Core/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/Microsoft.Health.Fhir.Core/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@
<value>Given conditional reference '{0}' does not resolve to a resource.</value>
<comment>{0} is the conditional reference parameter.</comment>
</data>
<data name="InvalidConditionalReferenceToMultipleResources" xml:space="preserve">
<value>Given conditional reference '{0}' resolved to multiple resources.</value>
<comment>{0} is the conditional reference parameter.</comment>
</data>
<data name="InvalidConditionalReferenceParameters" xml:space="preserve">
<value>Resource type and query parameter must be present in a given request '{0}'.</value>
<comment>{0} is the request url.</comment>
Expand Down Expand Up @@ -744,4 +748,4 @@
<value>The FHIR Server ran out of memory while processing an export job. Please use the _maxCount parameter when requesting an export job to reduce the number of resources exported at one time. The count used in this job was {0}</value>
<comment>'{0}' the value of _maxCount used for this export job.</comment>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,32 @@ public async Task GivenATransactionBundleWithConditionalReferences_WhenNotResolv
var requestBundle = Samples.GetJsonSample("Bundle-TransactionWithConditionalReferenceInResourceBody");
var bundle = requestBundle.ToPoco<Hl7.Fhir.Model.Bundle>();

IEnumerable<SearchResultEntry> searchResultEntries = Enumerable.Empty<SearchResultEntry>();

var expectedMessage = "Given conditional reference 'Patient?identifier=12345' does not resolve to a resource.";

var searchResult = new SearchResult(searchResultEntries, null, null, new Tuple<string, string>[0]);
_searchService.SearchAsync("Patient", Arg.Any<IReadOnlyList<Tuple<string, string>>>(), CancellationToken.None).Returns(searchResult);

var referenceIdDictionary = new Dictionary<string, (string resourceId, string resourceType)>();
foreach (var entry in bundle.Entry)
{
var requestUrl = (entry.Request != null) ? entry.Request.Url : null;
var exception = await Assert.ThrowsAsync<RequestNotValidException>(() => _referenceResolver.ResolveReferencesAsync(entry.Resource, referenceIdDictionary, requestUrl, CancellationToken.None));
Assert.Equal(exception.Message, expectedMessage);
}
}

[Fact]
public async Task GivenATransactionBundleWithConditionalReferences_WhenResolvedToMultipleResources_ThenRequestNotValidExceptionShouldBeThrown()
{
var requestBundle = Samples.GetJsonSample("Bundle-TransactionWithConditionalReferenceInResourceBody");
var bundle = requestBundle.ToPoco<Hl7.Fhir.Model.Bundle>();

SearchResultEntry mockSearchEntry = GetMockSearchEntry("123", KnownResourceTypes.Patient);
SearchResultEntry mockSearchEntry1 = GetMockSearchEntry("123", KnownResourceTypes.Patient);

var expectedMessage = "Given conditional reference 'Patient?identifier=12345' does not resolve to a resource.";
var expectedMessage = "Given conditional reference 'Patient?identifier=12345' resolved to multiple resources.";

var searchResult = new SearchResult(new[] { mockSearchEntry, mockSearchEntry1 }, null, null, new Tuple<string, string>[0]);
_searchService.SearchAsync("Patient", Arg.Any<IReadOnlyList<Tuple<string, string>>>(), CancellationToken.None).Returns(searchResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ public async Task ResolveReferencesAsync(Resource resource, IDictionary<string,

var results = await GetExistingResourceId(requestUrl, resourceType, conditionalQueries, cancellationToken);

if (results == null || results.Count != 1)
if (results == null || results.Count == 0)
{
throw new RequestNotValidException(string.Format(Core.Resources.InvalidConditionalReference, reference.Reference));
}
else if (results.Count > 1)
{
throw new RequestNotValidException(string.Format(Core.Resources.InvalidConditionalReferenceToMultipleResources, reference.Reference));
}

string resourceId = results.First().Resource.ResourceId;

Expand Down
Loading