Address review comments

This commit is contained in:
jamesagnew 2024-11-18 04:27:37 -05:00
parent 020546a86b
commit 7a7ab845a5
4 changed files with 13 additions and 10 deletions

View File

@ -64,6 +64,8 @@ public interface IFhirVersion {
IIdType newIdType();
/**
* Creates a new {@link IIdType} instance for the given version with the given value
*
* @since 8.0.0
*/
default IIdType newIdType(String theValue) {

View File

@ -132,7 +132,7 @@ public class MdmLinkHelper {
}
private Patient createPatientAndTags(String theId, MDMState<Patient, JpaPid> theState) {
boolean clientAssignedId = theId.startsWith(SERVER_ASSIGNED_PREFIX);
boolean serverAssignedId = theId.startsWith(SERVER_ASSIGNED_PREFIX);
boolean previouslyExisting = false;
Patient patient = new Patient();
@ -141,10 +141,10 @@ public class MdmLinkHelper {
// we add an identifier and use a forced id
// to make test debugging a little simpler
patient.addIdentifier(new Identifier().setValue(theId));
if (clientAssignedId && theState.getForcedIdForConditionalIdPlaceholder(theId) != null) {
if (serverAssignedId && theState.getForcedIdForConditionalIdPlaceholder(theId) != null) {
patient.setId(theState.getForcedIdForConditionalIdPlaceholder(theId));
previouslyExisting = true;
} else if (!clientAssignedId) {
} else if (!serverAssignedId) {
patient.setId(theId);
}
@ -157,7 +157,7 @@ public class MdmLinkHelper {
SystemRequestDetails srd = SystemRequestDetails.forAllPartitions();
DaoMethodOutcome outcome;
if (clientAssignedId && !previouslyExisting) {
if (serverAssignedId && !previouslyExisting) {
outcome = myPatientDao.create(patient, srd);
} else {
outcome = myPatientDao.update(patient, srd);
@ -165,7 +165,7 @@ public class MdmLinkHelper {
Patient outputPatient = (Patient) outcome.getResource();
theState.addPID(theId, (JpaPid) outcome.getPersistentId());
if (clientAssignedId) {
if (serverAssignedId) {
theState.addConditionalIdPlaceholderToForcedId(theId, outputPatient.getIdPart());
}

View File

@ -3,6 +3,8 @@ package ca.uhn.fhir.jpa.mdm.helper.testmodels;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.storage.IResourcePersistentId;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import org.testcontainers.shaded.com.google.common.collect.HashMultimap;
import org.testcontainers.shaded.com.google.common.collect.Multimap;
@ -60,15 +62,13 @@ public class MDMState<T, P extends IResourcePersistentId> {
/**
* Map of forcedId -> resource persistent id for each resource created
*/
private final Map<String, P> myForcedIdToPID = new HashMap<>();
private final Map<P, String> myPIDToForcedId = new HashMap<>();
private final BiMap<String, P> myForcedIdToPID = HashBiMap.create();
private final Map<String, String> myConditionalIdPlaceholderToForcedId = new HashMap<>();
public void addPID(String theForcedId, P thePid) {
assert !myForcedIdToPID.containsKey(theForcedId);
myForcedIdToPID.put(theForcedId, thePid);
myPIDToForcedId.put(thePid, theForcedId);
}
public P getPID(String theForcedId) {
@ -76,7 +76,7 @@ public class MDMState<T, P extends IResourcePersistentId> {
}
public String getForcedId(JpaPid thePID) {
String retVal = myPIDToForcedId.get(thePID);
String retVal = myForcedIdToPID.inverse().get(thePID);
if (myConditionalIdPlaceholderToForcedId.containsKey(retVal)) {
retVal = myConditionalIdPlaceholderToForcedId.get(retVal);
}

View File

@ -184,7 +184,8 @@ public class MdmReadVirtualizationInterceptor<P extends IResourcePersistentId<?>
&& !referenceId.isLocal()
&& !referenceId.isUuid()) {
Optional<IIdType> nonExpandedId = expansionResults.getOriginalIdForExpandedId(referenceId);
if (nonExpandedId.isPresent()) {
if (nonExpandedId != null && nonExpandedId.isPresent()) {
ourLog.debug("Replacing reference at {} value {} with {}", referenceInfo.getName(), referenceInfo.getResourceReference().getReferenceElement(), nonExpandedId.get().getValue());
referenceInfo
.getResourceReference()
.setReference(nonExpandedId.get().getValue());