From bc0ee995a26440fbe7c0c185f806dfe7516ff5c2 Mon Sep 17 00:00:00 2001 From: TynerGjs <132295567+TynerGjs@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:44:36 -0400 Subject: [PATCH] Resolve MDM query links operation score field imprecise value (#5332) * - Fixed precision error and rounded to 4 decimal places - Removed the vector field from the return value of mdmlink toJSON - modified tests for the above changes. * changed to use BigDecimal instead of Precision to round score * reformatted file --- .../java/ca/uhn/fhir/util/ParametersUtil.java | 2 +- ...operation-score-field-imprecise-value.yaml | 5 ++++ .../java/ca/uhn/fhir/jpa/entity/MdmLink.java | 2 ++ .../jpa/mdm/svc/MdmModelConverterSvcImpl.java | 11 ++++++-- .../mdm/svc/MdmModelConverterSvcImplTest.java | 27 +++++++++++++++---- 5 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5331-mdm-query-links-operation-score-field-imprecise-value.yaml diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java index 3b091f9ff08..44d26280759 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java @@ -403,7 +403,7 @@ public class ParametersUtil { public static void addPartDecimal(FhirContext theContext, IBase theParameter, String theName, Double theValue) { IPrimitiveType value = (IPrimitiveType) theContext.getElementDefinition("decimal").newInstance(); - value.setValue(theValue == null ? null : new BigDecimal(theValue)); + value.setValue(theValue == null ? null : BigDecimal.valueOf(theValue)); addPart(theContext, theParameter, theName, value); } diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5331-mdm-query-links-operation-score-field-imprecise-value.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5331-mdm-query-links-operation-score-field-imprecise-value.yaml new file mode 100644 index 00000000000..136783fbe82 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5331-mdm-query-links-operation-score-field-imprecise-value.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 5331 +title: "Previously, the score field returned by $mdm-query-links operation would contain imprecise decimal values. This +is now fixed and rounded to 4 decimal places." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java index 08be50ccfa9..24e5063ab0c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/MdmLink.java @@ -25,6 +25,7 @@ import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.mdm.api.IMdmLink; import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; import ca.uhn.fhir.mdm.api.MdmMatchResultEnum; +import com.fasterxml.jackson.annotation.JsonIgnore; import org.apache.commons.lang3.builder.ToStringBuilder; import org.hibernate.envers.AuditTable; import org.hibernate.envers.Audited; @@ -161,6 +162,7 @@ public class MdmLink extends AuditableBasePartitionable implements IMdmLink>> revision = new MdmLinkWithRevision<>(mdmLink, new EnversRevision(RevisionType.ADD, revisionNumber, revisionTimestamp)); final MdmLinkWithRevisionJson actualMdmLinkWithRevisionJson = myMdmModelConverterSvc.toJson(revision); final MdmLinkWithRevisionJson expectedMdmLinkWithRevisionJson = - new MdmLinkWithRevisionJson(getExepctedMdmLinkJson(mdmLink.getGoldenResourcePersistenceId().getId(), mdmLink.getSourcePersistenceId().getId(), MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource), revisionNumber, revisionTimestamp); + new MdmLinkWithRevisionJson(getExepctedMdmLinkJson(mdmLink.getGoldenResourcePersistenceId().getId(), mdmLink.getSourcePersistenceId().getId(), MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource, scoreRounded), revisionNumber, revisionTimestamp); assertMdmLinkRevisionsEqual(expectedMdmLinkWithRevisionJson, actualMdmLinkWithRevisionJson); } @@ -77,12 +88,14 @@ public class MdmModelConverterSvcImplTest extends BaseMdmR4Test { assertEquals(expectedMdmLink.getSourceId(), actualMdmLink.getSourceId()); assertEquals(expectedMdmLink.getMatchResult(), actualMdmLink.getMatchResult()); assertEquals(expectedMdmLink.getLinkSource(), actualMdmLink.getLinkSource()); + assertEquals(expectedMdmLink.getScore(), actualMdmLink.getScore()); + assertEquals(expectedMdmLink.getVector(), actualMdmLink.getVector()); assertEquals(theExpectedMdmLinkWithRevisionJson.getRevisionNumber(), theActualMdmLinkWithRevisionJson.getRevisionNumber()); assertEquals(theExpectedMdmLinkWithRevisionJson.getRevisionTimestamp(), theActualMdmLinkWithRevisionJson.getRevisionTimestamp()); } - private MdmLinkJson getExepctedMdmLinkJson(Long theGoldenPatientId, Long theSourceId, MdmMatchResultEnum theMdmMatchResultEnum, MdmLinkSourceEnum theMdmLinkSourceEnum, String version, Date theCreateTime, Date theUpdateTime, boolean theLinkCreatedNewResource) { + private MdmLinkJson getExepctedMdmLinkJson(Long theGoldenPatientId, Long theSourceId, MdmMatchResultEnum theMdmMatchResultEnum, MdmLinkSourceEnum theMdmLinkSourceEnum, String version, Date theCreateTime, Date theUpdateTime, boolean theLinkCreatedNewResource, double theScore) { final MdmLinkJson mdmLinkJson = new MdmLinkJson(); mdmLinkJson.setGoldenResourceId("Patient/" + theGoldenPatientId); @@ -93,6 +106,10 @@ public class MdmModelConverterSvcImplTest extends BaseMdmR4Test { mdmLinkJson.setCreated(theCreateTime); mdmLinkJson.setUpdated(theUpdateTime); mdmLinkJson.setLinkCreatedNewResource(theLinkCreatedNewResource); + mdmLinkJson.setScore(theScore); + + // make sure vector is not converted + mdmLinkJson.setVector(null); return mdmLinkJson; }