5231 MDM Link History gives 404 after MDM clear and submit (#5232)

* fix + tests

* remove comments

* docs + changelog

* spotless

* edit changelog

---------

Co-authored-by: justindar <justin.dar@smilecdr.com>
This commit is contained in:
jdar8 2023-08-25 12:59:44 -07:00 committed by GitHub
parent db6d8092f2
commit 6a7340a879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 5231
title: "Previously, the `$mdm-link-history` operation would result in a 404 response when it was executed after a
`$mdm-clear`. This has now been fixed by removing link history on `$mdm-clear`."

View File

@ -839,7 +839,8 @@ your ruleset. It permits the user to reset the state of their MDM system without
and Golden Resources.
After the operation is complete, all targeted MDM links are removed from the system, and their related Golden Resources
are deleted and expunged from the server.
are deleted and expunged from the server. Additionally, the link history for targeted links and their related golden
resources will also be expunged.
This operation takes two optional Parameters.

View File

@ -50,6 +50,13 @@ public interface IMdmLinkJpaRepository
@Query("DELETE FROM MdmLink f WHERE myGoldenResourcePid IN (:goldenPids) OR mySourcePid IN (:goldenPids)")
void deleteLinksWithAnyReferenceToPids(@Param("goldenPids") List<Long> theResourcePids);
@Modifying
@Query(
value =
"DELETE FROM MPI_LINK_AUD f WHERE GOLDEN_RESOURCE_PID IN (:goldenPids) OR TARGET_PID IN (:goldenPids)",
nativeQuery = true)
void deleteLinksHistoryWithAnyReferenceToPids(@Param("goldenPids") List<Long> theResourcePids);
@Query("SELECT ml2.myGoldenResourcePid as goldenPid, ml2.mySourcePid as sourcePid FROM MdmLink ml2 "
+ "WHERE ml2.myMatchResult=:matchResult "
+ "AND ml2.myGoldenResourcePid IN ("

View File

@ -350,6 +350,7 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
List<List<Long>> chunks = ListUtils.partition(goldenResourcePids, 500);
for (List<Long> chunk : chunks) {
myMdmLinkDao.deleteLinksWithAnyReferenceToPids(chunk);
myMdmLinkDao.deleteLinksHistoryWithAnyReferenceToPids(chunk);
}
}

View File

@ -4,14 +4,15 @@ import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
import ca.uhn.fhir.mdm.api.IMdmLink;
import ca.uhn.fhir.mdm.api.MdmHistorySearchParameters;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
import ca.uhn.fhir.mdm.api.MdmLinkWithRevision;
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Nonnull;
import java.io.IOException;
@ -71,4 +72,12 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test {
protected List<? extends IMdmLink> getPatientLinks() {
return myMdmLinkDaoSvc.findMdmLinksBySourceResource(myPatient);
}
protected List<MdmLinkWithRevision<MdmLink>> getHistoricalLinks(List<String> theGoldenResourceIds, List<String> theResourceIds) {
MdmHistorySearchParameters historySearchParameters = new MdmHistorySearchParameters()
.setGoldenResourceIds(theGoldenResourceIds)
.setSourceIds(theResourceIds);
return myMdmLinkDaoSvc.findMdmLinkHistory(historySearchParameters);
}
}

View File

@ -30,6 +30,7 @@ import org.mockito.ArgumentCaptor;
import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -171,6 +172,7 @@ public class MdmProviderClearLinkR4Test extends BaseLinkR4Test {
assertLinkCount(2);
clearMdmLinks();
assertNoLinksExist();
assertNoHistoricalLinksExist(List.of(myPractitionerGoldenResourceId.getValueAsString(), mySourcePatientId.getValueAsString()), new ArrayList<>());
}
private void assertNoLinksExist() {
@ -182,6 +184,10 @@ public class MdmProviderClearLinkR4Test extends BaseLinkR4Test {
assertThat(getPatientLinks(), hasSize(0));
}
private void assertNoHistoricalLinksExist(List<String> theGoldenResourceIds, List<String> theResourceIds) {
assertThat(getHistoricalLinks(theGoldenResourceIds, theResourceIds), hasSize(0));
}
private void assertNoPractitionerLinksExist() {
assertThat(getPractitionerLinks(), hasSize(0));
}