2543 - Fix issue where versionned references are not being returned properly. (#2544)

* 2543 - Fix issue where versionned references are not being returned properly.

* 2543 - Added changelog entries for this fix plus a previous fix for 2533.
This commit is contained in:
Kevin Dougan SmileCDR 2021-04-14 08:45:49 -04:00 committed by GitHub
parent 129df5dc14
commit b45ddcc3da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
type: fix
issue: 2533
title: "When issuing a request for a specific Resource and also specifying an _include param,
the referenced resource is not returned when there is only 1 version of the referenced resource available.
When there are more than 1 versions available, the referenced resource is returned in the response bundle."

View File

@ -0,0 +1,8 @@
---
type: fix
issue: 2543
title: "When issuing a request for a specific Resource and also specifying an _include param,
the proper historical referenced resource is not returned when there are more than 1 versions of the
referenced resource available, after the reference has been changed from the original version 1 to some other version.
When there are more than 1 versions available, and the referring resource had previously referred to version 1
but now refers to version 4, the resource returned in the response bundle is for version 1."

View File

@ -444,6 +444,84 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
assertEquals(conditionId.withVersion("1").getValue(), resources.get(1).getIdElement().getValue()); assertEquals(conditionId.withVersion("1").getValue(), resources.get(1).getIdElement().getValue());
} }
@Test
public void testSearchAndIncludeVersionedReference_WhenMultipleVersionsExist() {
HashSet<String> refPaths = new HashSet<String>();
refPaths.add("Task.basedOn");
myFhirCtx.getParserOptions().setDontStripVersionsFromReferencesAtPaths(refPaths);
myModelConfig.setRespectVersionsForSearchIncludes(true);
myFhirCtx.getParserOptions().setStripVersionsFromReferences(false);
// Create a Condition
Condition condition = new Condition();
IIdType conditionId = myConditionDao.create(condition).getId().toUnqualified();
// Now, update the Condition 3 times to generate a 4th version of it
condition.setRecordedDate(new Date(System.currentTimeMillis()));
conditionId = myConditionDao.update(condition).getId();
condition.setRecordedDate(new Date(System.currentTimeMillis() + 1000000));
conditionId = myConditionDao.update(condition).getId();
condition.setRecordedDate(new Date(System.currentTimeMillis() + 2000000));
conditionId = myConditionDao.update(condition).getId();
// Create a Task which is basedOn that Condition
Task task = new Task();
task.setBasedOn(Arrays.asList(new Reference(conditionId)));
IIdType taskId = myTaskDao.create(task).getId().toUnqualified();
// Search for the Task using an _include=Task.basedOn and make sure we get the Condition resource in the Response
IBundleProvider outcome = myTaskDao.search(SearchParameterMap.newSynchronous().addInclude(Task.INCLUDE_BASED_ON));
assertEquals(2, outcome.size());
List<IBaseResource> resources = outcome.getResources(0, 2);
assertEquals(2, resources.size(), resources.stream().map(t->t.getIdElement().toUnqualified().getValue()).collect(Collectors.joining(", ")));
assertEquals(taskId.getValue(), resources.get(0).getIdElement().getValue());
assertEquals(conditionId.getValue(), ((Task)resources.get(0)).getBasedOn().get(0).getReference());
assertEquals(conditionId.withVersion("4").getValue(), resources.get(1).getIdElement().getValue());
}
@Test
public void testSearchAndIncludeVersionedReference_WhenPreviouslyReferencedVersionOne() {
HashSet<String> refPaths = new HashSet<String>();
refPaths.add("Task.basedOn");
myFhirCtx.getParserOptions().setDontStripVersionsFromReferencesAtPaths(refPaths);
myModelConfig.setRespectVersionsForSearchIncludes(true);
myFhirCtx.getParserOptions().setStripVersionsFromReferences(false);
// Create a Condition
Condition condition = new Condition();
IIdType conditionId = myConditionDao.create(condition).getId().toUnqualified();
ourLog.info("conditionId: \n{}", conditionId);
// Create a Task which is basedOn that Condition
Task task = new Task();
task.setBasedOn(Arrays.asList(new Reference(conditionId)));
IIdType taskId = myTaskDao.create(task).getId().toUnqualified();
// Now, update the Condition 3 times to generate a 4th version of it
condition.setRecordedDate(new Date(System.currentTimeMillis()));
conditionId = myConditionDao.update(condition).getId();
ourLog.info("UPDATED conditionId: \n{}", conditionId);
condition.setRecordedDate(new Date(System.currentTimeMillis() + 1000000));
conditionId = myConditionDao.update(condition).getId();
ourLog.info("UPDATED conditionId: \n{}", conditionId);
condition.setRecordedDate(new Date(System.currentTimeMillis() + 2000000));
conditionId = myConditionDao.update(condition).getId();
ourLog.info("UPDATED conditionId: \n{}", conditionId);
// Now, update the Task to refer to the latest version 4 of the Condition
task.setBasedOn(Arrays.asList(new Reference(conditionId)));
taskId = myTaskDao.update(task).getId();
ourLog.info("UPDATED taskId: \n{}", taskId);
// Search for the Task using an _include=Task.basedOn and make sure we get the Condition resource in the Response
IBundleProvider outcome = myTaskDao.search(SearchParameterMap.newSynchronous().addInclude(Task.INCLUDE_BASED_ON));
assertEquals(2, outcome.size());
List<IBaseResource> resources = outcome.getResources(0, 2);
assertEquals(2, resources.size(), resources.stream().map(t->t.getIdElement().toUnqualified().getValue()).collect(Collectors.joining(", ")));
assertEquals(taskId.getValue(), resources.get(0).getIdElement().getValue());
assertEquals(conditionId.getValue(), ((Task)resources.get(0)).getBasedOn().get(0).getReference());
assertEquals(conditionId.withVersion("4").getValue(), resources.get(1).getIdElement().getValue());
}
@Test @Test
public void testSearchAndIncludeUnersionedReference_Asynchronous() { public void testSearchAndIncludeUnersionedReference_Asynchronous() {

View File

@ -138,6 +138,7 @@ public class ResourceLink extends BaseResourceIndex {
b.append(mySourceResource, obj.mySourceResource); b.append(mySourceResource, obj.mySourceResource);
b.append(myTargetResourceUrl, obj.myTargetResourceUrl); b.append(myTargetResourceUrl, obj.myTargetResourceUrl);
b.append(myTargetResourceType, obj.myTargetResourceType); b.append(myTargetResourceType, obj.myTargetResourceType);
b.append(myTargetResourceVersion, obj.myTargetResourceVersion);
b.append(getTargetResourceId(), obj.getTargetResourceId()); b.append(getTargetResourceId(), obj.getTargetResourceId());
return b.isEquals(); return b.isEquals();
} }
@ -150,6 +151,7 @@ public class ResourceLink extends BaseResourceIndex {
myTargetResourceId = source.getTargetResourceId(); myTargetResourceId = source.getTargetResourceId();
myTargetResourcePid = source.getTargetResourcePid(); myTargetResourcePid = source.getTargetResourcePid();
myTargetResourceType = source.getTargetResourceType(); myTargetResourceType = source.getTargetResourceType();
myTargetResourceVersion = source.getTargetResourceVersion();
myTargetResourceUrl = source.getTargetResourceUrl(); myTargetResourceUrl = source.getTargetResourceUrl();
} }
@ -244,6 +246,7 @@ public class ResourceLink extends BaseResourceIndex {
b.append(mySourcePath); b.append(mySourcePath);
b.append(mySourceResource); b.append(mySourceResource);
b.append(myTargetResourceUrl); b.append(myTargetResourceUrl);
b.append(myTargetResourceVersion);
b.append(getTargetResourceType()); b.append(getTargetResourceType());
b.append(getTargetResourceId()); b.append(getTargetResourceId());
return b.toHashCode(); return b.toHashCode();
@ -257,6 +260,7 @@ public class ResourceLink extends BaseResourceIndex {
b.append(", src=").append(mySourceResourcePid); b.append(", src=").append(mySourceResourcePid);
b.append(", target=").append(myTargetResourcePid); b.append(", target=").append(myTargetResourcePid);
b.append(", targetType=").append(myTargetResourceType); b.append(", targetType=").append(myTargetResourceType);
b.append(", targetVersion=").append(myTargetResourceVersion);
b.append(", targetUrl=").append(myTargetResourceUrl); b.append(", targetUrl=").append(myTargetResourceUrl);
b.append("]"); b.append("]");