fixed golden resource tag bug (#5868)

This commit is contained in:
kateryna-mironova 2024-04-23 10:08:32 -04:00 committed by GitHub
parent cd4560390c
commit 90201095c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 5867
title: "Previously, when adding multiple resources and defining a golden resource using MDM, the golden resource's tags were removed. This has been fixed"

View File

@ -58,6 +58,7 @@ import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.util.IMetaTagSorter;
import ca.uhn.fhir.util.MetaUtil;
import jakarta.annotation.Nullable;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseCoding;
@ -470,7 +471,7 @@ public class JpaStorageResourceParser implements IJpaStorageResourceParser {
res.getMeta().setLastUpdated(theEntity.getUpdatedDate());
IDao.RESOURCE_PID.put(res, theEntity.getResourceId());
if (theTagList != null) {
if (CollectionUtils.isNotEmpty(theTagList)) {
res.getMeta().getTag().clear();
res.getMeta().getProfile().clear();
res.getMeta().getSecurity().clear();

View File

@ -0,0 +1,56 @@
package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jpa.entity.ResourceSearchView;
import ca.uhn.fhir.jpa.model.entity.BaseTag;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.Constants;
import org.hl7.fhir.r4.hapi.ctx.FhirR4;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@ExtendWith(MockitoExtension.class)
public class JpaStorageResourceParserTest {
@Mock
private FhirContext myFhirContext;
@Mock
private ResourceSearchView patientSearchView;
@InjectMocks
private final JpaStorageResourceParser jpaStorageResourceParser = new JpaStorageResourceParser();
@Test
public void testPopulateResourceMeta_doesNotRemoveTags_whenTagListIsEmpty() {
Mockito.when(myFhirContext.getVersion()).thenReturn(new FhirR4());
Mockito.when(patientSearchView.getIdDt()).thenReturn(new IdDt("Patient/test-patient/_history/1"));
Coding coding = new Coding("system", "code", "display");
List<BaseTag> tagList = Collections.emptyList();
boolean forHistoryOperation = false;
long version = 1L;
Patient resourceTarget = new Patient();
resourceTarget.getMeta().addTag(coding);
Patient actualResult = jpaStorageResourceParser
.populateResourceMetadata(patientSearchView, forHistoryOperation, tagList, version, resourceTarget);
List<Coding> actualTagList = actualResult.getMeta().getTag();
assertFalse(actualTagList.isEmpty());
assertEquals(actualTagList.size(), 1);
assertTrue(actualTagList.get(0).equals(coding));
}
}