Skip to content

Commit a8a63e9

Browse files
kateryna-mironovaLong Ma
authored andcommitted
cherry-picked mr 5868
1 parent 6210ec4 commit a8a63e9

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: fix
3+
issue: 5867
4+
backport: 6.8.8
5+
title: "Previously, when adding multiple resources and defining a golden resource using MDM, the golden resource's tags were removed. This has been fixed"

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/JpaStorageResourceParser.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* HAPI FHIR JPA Server
44
* %%
5-
* Copyright (C) 2014 - 2023 Smile CDR, Inc.
5+
* Copyright (C) 2014 - 2024 Smile CDR, Inc.
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import ca.uhn.fhir.context.FhirVersionEnum;
2424
import ca.uhn.fhir.context.RuntimeResourceDefinition;
2525
import ca.uhn.fhir.i18n.Msg;
26+
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
2627
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
2728
import ca.uhn.fhir.jpa.api.dao.IDao;
2829
import ca.uhn.fhir.jpa.dao.data.IResourceHistoryTableDao;
@@ -55,6 +56,7 @@
5556
import ca.uhn.fhir.parser.LenientErrorHandler;
5657
import ca.uhn.fhir.rest.api.Constants;
5758
import ca.uhn.fhir.util.MetaUtil;
59+
import org.apache.commons.collections.CollectionUtils;
5860
import org.apache.commons.lang3.Validate;
5961
import org.hl7.fhir.instance.model.api.IAnyResource;
6062
import org.hl7.fhir.instance.model.api.IBaseCoding;
@@ -241,7 +243,7 @@ private <R extends IBaseResource> void populateResourcePartitionInformation(
241243
myPartitionLookupSvc.getPartitionById(partitionId.getPartitionId());
242244
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, persistedPartition.toRequestPartitionId());
243245
} else {
244-
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, null);
246+
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, RequestPartitionId.defaultPartition());
245247
}
246248
}
247249
}
@@ -394,11 +396,14 @@ private <R extends IResource> R populateResourceMetadataHapi(
394396
secLabel.setSystem(nextTag.getSystem());
395397
secLabel.setCode(nextTag.getCode());
396398
secLabel.setDisplay(nextTag.getDisplay());
397-
// wipmb these technically support userSelected and version
399+
secLabel.setVersion(nextTag.getVersion());
400+
Boolean userSelected = nextTag.getUserSelected();
401+
if (userSelected != null) {
402+
secLabel.setUserSelected(userSelected);
403+
}
398404
securityLabels.add(secLabel);
399405
break;
400406
case TAG:
401-
// wipmb check xml, etc.
402407
Tag e = new Tag(nextTag.getSystem(), nextTag.getCode(), nextTag.getDisplay());
403408
e.setVersion(nextTag.getVersion());
404409
// careful! These are Boolean, not boolean.
@@ -459,7 +464,7 @@ private <R extends IBaseResource> R populateResourceMetadataRi(
459464
res.getMeta().setLastUpdated(theEntity.getUpdatedDate());
460465
IDao.RESOURCE_PID.put(res, theEntity.getResourceId());
461466

462-
if (theTagList != null) {
467+
if (CollectionUtils.isNotEmpty(theTagList)) {
463468
res.getMeta().getTag().clear();
464469
res.getMeta().getProfile().clear();
465470
res.getMeta().getSecurity().clear();
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ca.uhn.fhir.jpa.dao;
2+
3+
import ca.uhn.fhir.context.FhirContext;
4+
import ca.uhn.fhir.context.FhirVersionEnum;
5+
import ca.uhn.fhir.jpa.entity.ResourceSearchView;
6+
import ca.uhn.fhir.jpa.model.entity.BaseTag;
7+
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
8+
import ca.uhn.fhir.model.primitive.IdDt;
9+
import ca.uhn.fhir.rest.api.Constants;
10+
import org.hl7.fhir.r4.hapi.ctx.FhirR4;
11+
import org.hl7.fhir.r4.model.Coding;
12+
import org.hl7.fhir.r4.model.Patient;
13+
import org.junit.jupiter.api.Test;
14+
import org.junit.jupiter.api.extension.ExtendWith;
15+
import org.mockito.InjectMocks;
16+
import org.mockito.Mock;
17+
import org.mockito.Mockito;
18+
import org.mockito.junit.jupiter.MockitoExtension;
19+
20+
import java.util.Collections;
21+
import java.util.List;
22+
23+
import static org.junit.jupiter.api.Assertions.*;
24+
25+
@ExtendWith(MockitoExtension.class)
26+
public class JpaStorageResourceParserTest {
27+
28+
@Mock
29+
private FhirContext myFhirContext;
30+
31+
@Mock
32+
private ResourceSearchView patientSearchView;
33+
@InjectMocks
34+
private final JpaStorageResourceParser jpaStorageResourceParser = new JpaStorageResourceParser();
35+
36+
@Test
37+
public void testPopulateResourceMeta_doesNotRemoveTags_whenTagListIsEmpty() {
38+
Mockito.when(myFhirContext.getVersion()).thenReturn(new FhirR4());
39+
Mockito.when(patientSearchView.getIdDt()).thenReturn(new IdDt("Patient/test-patient/_history/1"));
40+
41+
Coding coding = new Coding("system", "code", "display");
42+
List<BaseTag> tagList = Collections.emptyList();
43+
boolean forHistoryOperation = false;
44+
long version = 1L;
45+
Patient resourceTarget = new Patient();
46+
resourceTarget.getMeta().addTag(coding);
47+
48+
Patient actualResult = jpaStorageResourceParser
49+
.populateResourceMetadata(patientSearchView, forHistoryOperation, tagList, version, resourceTarget);
50+
51+
List<Coding> actualTagList = actualResult.getMeta().getTag();
52+
assertFalse(actualTagList.isEmpty());
53+
assertEquals(actualTagList.size(), 1);
54+
assertTrue(actualTagList.get(0).equals(coding));
55+
}
56+
}

0 commit comments

Comments
 (0)