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

Creating new resources with multiple contained resources which lack id returns 500 Internal Server Error #510

Open
JeremiahSanders opened this issue Oct 5, 2022 · 0 comments

Comments

@JeremiahSanders
Copy link

Describe the bug
When creating a new resource (Organization in executed tests) with multiple contained resources which lack a defined id, a 500 Internal Server Error is returned. This is triggered by an exception: ArgumentException: An item with the same key has already been added. Key: #. The exception appears to occur in Spark.Engine.Service.FhirServiceExtensions.IndexService.MakeContainedReferencesUnique().

To Reproduce

The following code, which uses the Spark reference server, shows the behavior.

Note that the resources in this example are minimal and not representative of a full model. However, they are sufficient to exhibit the error.

Uri baseUri = new Uri("https://spark.incendi.no/fhir/", UriKind.Absolute);
var httpClient = new HttpClient();
var settings = new FhirClientSettings
{
	VerifyFhirVersion = false,
	PreferredReturn = Prefer.ReturnRepresentation,
	PreferredFormat = ResourceFormat.Json
};
var fhirClient = new FhirClient(baseUri, httpClient, settings);
var organization = new Organization
{
	Name = "An Organization",
	Identifier = {
		new Identifier("http://a-fake-system", "a value")
	}
};

// Removal of EITHER contained resource (below) results in success. The error only occurs when multiple lack id.
organization.Contained.Add(new Endpoint
{
    Identifier = {
	        new Hl7.Fhir.Model.Identifier {
		    System = "http://not-a-real-system",
		    Value = "endpoint-1-identifier"
		}
	},
});
organization.Contained.Add(new Endpoint
{
	Identifier = {
		new Hl7.Fhir.Model.Identifier {
			System = "http://not-a-real-system",
			Value = "endpoint-2-identifier"
		}
	},
});

var createdOrg = await fhirClient.CreateAsync(organization);

Expected behavior
If the resource is valid, then a 201 Created should be returned. If the resource is invalid, then a 400-class response should be returned.

Spark version

  • Version: 1.5.14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant