-
Notifications
You must be signed in to change notification settings - Fork 40
Description
InMemoryFhirRepository uses id.toUnqualifiedVersionless() as the inner map key for both update() (storage) and read() (lookup). Since the outer map already partitions by resource type (resource.fhirType()), the inner key only needs the ID part. However, toUnqualifiedVersionless() preserves whatever format was provided — with or without the resource type prefix.
This causes a mismatch when:
- A resource is stored via update() with a plain ID: resource.setId("test-lib") - inner key is "test-lib"
- A lookup via read() uses a relative reference: new IdType("Library/test-lib") - lookup key is "Library/test-lib"
These don't match, resulting in a ResourceNotFoundException.
This is the standard FHIR pattern - per the spec, a reference like "Library/test-lib" is a relative URL where Library is the resource type path segment and test-lib is the ID. The resource's actual ID should be "test-lib", not "Library/test-lib".
Suggested fix:
In read(), use id.getIdPart() instead of id.toUnqualifiedVersionless() for the inner map lookup. The same normalization should be applied in update(), create(), and delete() for consistency. Alternatively, normalize both sides to always include the resource type using withResourceType().
Affected file: cqf-fhir-utility/src/main/java/org/opencds/cqf/fhir/utility/repository/InMemoryFhirRepository.java