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
This commit is contained in:
parent
10d9d9628c
commit
bc0ee995a2
|
@ -403,7 +403,7 @@ public class ParametersUtil {
|
||||||
public static void addPartDecimal(FhirContext theContext, IBase theParameter, String theName, Double theValue) {
|
public static void addPartDecimal(FhirContext theContext, IBase theParameter, String theName, Double theValue) {
|
||||||
IPrimitiveType<BigDecimal> value = (IPrimitiveType<BigDecimal>)
|
IPrimitiveType<BigDecimal> value = (IPrimitiveType<BigDecimal>)
|
||||||
theContext.getElementDefinition("decimal").newInstance();
|
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);
|
addPart(theContext, theParameter, theName, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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."
|
|
@ -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.IMdmLink;
|
||||||
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
|
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
|
||||||
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
|
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.hibernate.envers.AuditTable;
|
import org.hibernate.envers.AuditTable;
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
|
@ -161,6 +162,7 @@ public class MdmLink extends AuditableBasePartitionable implements IMdmLink<JpaP
|
||||||
private Boolean myHadToCreateNewGoldenResource;
|
private Boolean myHadToCreateNewGoldenResource;
|
||||||
|
|
||||||
@Column(name = "VECTOR")
|
@Column(name = "VECTOR")
|
||||||
|
@JsonIgnore
|
||||||
private Long myVector;
|
private Long myVector;
|
||||||
|
|
||||||
@Column(name = "SCORE")
|
@Column(name = "SCORE")
|
||||||
|
|
|
@ -26,6 +26,9 @@ import ca.uhn.fhir.mdm.model.mdmevents.MdmLinkJson;
|
||||||
import ca.uhn.fhir.mdm.model.mdmevents.MdmLinkWithRevisionJson;
|
import ca.uhn.fhir.mdm.model.mdmevents.MdmLinkWithRevisionJson;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
public class MdmModelConverterSvcImpl implements IMdmModelConverterSvc {
|
public class MdmModelConverterSvcImpl implements IMdmModelConverterSvc {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -49,9 +52,13 @@ public class MdmModelConverterSvcImpl implements IMdmModelConverterSvc {
|
||||||
retVal.setLinkSource(theLink.getLinkSource());
|
retVal.setLinkSource(theLink.getLinkSource());
|
||||||
retVal.setMatchResult(theLink.getMatchResult());
|
retVal.setMatchResult(theLink.getMatchResult());
|
||||||
retVal.setLinkCreatedNewResource(theLink.getHadToCreateNewGoldenResource());
|
retVal.setLinkCreatedNewResource(theLink.getHadToCreateNewGoldenResource());
|
||||||
retVal.setScore(theLink.getScore());
|
Double score = theLink.getScore() == null
|
||||||
|
? null
|
||||||
|
: BigDecimal.valueOf(theLink.getScore())
|
||||||
|
.setScale(4, RoundingMode.HALF_UP)
|
||||||
|
.doubleValue();
|
||||||
|
retVal.setScore(score);
|
||||||
retVal.setUpdated(theLink.getUpdated());
|
retVal.setUpdated(theLink.getUpdated());
|
||||||
retVal.setVector(theLink.getVector());
|
|
||||||
retVal.setVersion(theLink.getVersion());
|
retVal.setVersion(theLink.getVersion());
|
||||||
retVal.setRuleCount(theLink.getRuleCount());
|
retVal.setRuleCount(theLink.getRuleCount());
|
||||||
return retVal;
|
return retVal;
|
||||||
|
|
|
@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.Month;
|
import java.time.Month;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
@ -35,15 +37,19 @@ public class MdmModelConverterSvcImplTest extends BaseMdmR4Test {
|
||||||
final Date updateTime = new Date();
|
final Date updateTime = new Date();
|
||||||
final String version = "1";
|
final String version = "1";
|
||||||
final boolean isLinkCreatedResource = false;
|
final boolean isLinkCreatedResource = false;
|
||||||
|
final double score = 0.8333333333333;
|
||||||
|
final double scoreRounded = BigDecimal.valueOf(score).setScale(4, RoundingMode.HALF_UP).doubleValue();
|
||||||
|
|
||||||
final MdmLink mdmLink = createGoldenPatientAndLinkToSourcePatient(MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource);
|
MdmLink mdmLink = createGoldenPatientAndLinkToSourcePatient(MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource);
|
||||||
|
mdmLink.setScore(score);
|
||||||
|
mdmLink.setVector(61L);
|
||||||
myMdmLinkDao.save(mdmLink);
|
myMdmLinkDao.save(mdmLink);
|
||||||
|
|
||||||
final MdmLinkJson actualMdmLinkJson = myMdmModelConverterSvc.toJson(mdmLink);
|
final MdmLinkJson actualMdmLinkJson = myMdmModelConverterSvc.toJson(mdmLink);
|
||||||
|
|
||||||
ourLog.info("actualMdmLinkJson: {}", actualMdmLinkJson);
|
ourLog.info("actualMdmLinkJson: {}", actualMdmLinkJson);
|
||||||
|
|
||||||
assertEquals(getExepctedMdmLinkJson(mdmLink.getGoldenResourcePersistenceId().getId(), mdmLink.getSourcePersistenceId().getId(), MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource), actualMdmLinkJson);
|
assertEquals(getExepctedMdmLinkJson(mdmLink.getGoldenResourcePersistenceId().getId(), mdmLink.getSourcePersistenceId().getId(), MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource, scoreRounded), actualMdmLinkJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -57,15 +63,20 @@ public class MdmModelConverterSvcImplTest extends BaseMdmR4Test {
|
||||||
final String version = "1";
|
final String version = "1";
|
||||||
final boolean isLinkCreatedResource = false;
|
final boolean isLinkCreatedResource = false;
|
||||||
final long revisionNumber = 2L;
|
final long revisionNumber = 2L;
|
||||||
|
final double score = 0.8333333333333;
|
||||||
|
final double scoreRounded = BigDecimal.valueOf(score).setScale(4, RoundingMode.HALF_UP).doubleValue();
|
||||||
|
|
||||||
final MdmLink mdmLink = createGoldenPatientAndLinkToSourcePatient(MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource);
|
MdmLink mdmLink = createGoldenPatientAndLinkToSourcePatient(MdmMatchResultEnum.MATCH, MdmLinkSourceEnum.MANUAL, version, createTime, updateTime, isLinkCreatedResource);
|
||||||
|
mdmLink.setScore(score);
|
||||||
|
mdmLink.setVector(61L);
|
||||||
|
myMdmLinkDao.save(mdmLink);
|
||||||
|
|
||||||
final MdmLinkWithRevision<IMdmLink<? extends IResourcePersistentId<?>>> revision = new MdmLinkWithRevision<>(mdmLink, new EnversRevision(RevisionType.ADD, revisionNumber, revisionTimestamp));
|
final MdmLinkWithRevision<IMdmLink<? extends IResourcePersistentId<?>>> revision = new MdmLinkWithRevision<>(mdmLink, new EnversRevision(RevisionType.ADD, revisionNumber, revisionTimestamp));
|
||||||
|
|
||||||
final MdmLinkWithRevisionJson actualMdmLinkWithRevisionJson = myMdmModelConverterSvc.toJson(revision);
|
final MdmLinkWithRevisionJson actualMdmLinkWithRevisionJson = myMdmModelConverterSvc.toJson(revision);
|
||||||
|
|
||||||
final MdmLinkWithRevisionJson expectedMdmLinkWithRevisionJson =
|
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);
|
assertMdmLinkRevisionsEqual(expectedMdmLinkWithRevisionJson, actualMdmLinkWithRevisionJson);
|
||||||
}
|
}
|
||||||
|
@ -77,12 +88,14 @@ public class MdmModelConverterSvcImplTest extends BaseMdmR4Test {
|
||||||
assertEquals(expectedMdmLink.getSourceId(), actualMdmLink.getSourceId());
|
assertEquals(expectedMdmLink.getSourceId(), actualMdmLink.getSourceId());
|
||||||
assertEquals(expectedMdmLink.getMatchResult(), actualMdmLink.getMatchResult());
|
assertEquals(expectedMdmLink.getMatchResult(), actualMdmLink.getMatchResult());
|
||||||
assertEquals(expectedMdmLink.getLinkSource(), actualMdmLink.getLinkSource());
|
assertEquals(expectedMdmLink.getLinkSource(), actualMdmLink.getLinkSource());
|
||||||
|
assertEquals(expectedMdmLink.getScore(), actualMdmLink.getScore());
|
||||||
|
assertEquals(expectedMdmLink.getVector(), actualMdmLink.getVector());
|
||||||
|
|
||||||
assertEquals(theExpectedMdmLinkWithRevisionJson.getRevisionNumber(), theActualMdmLinkWithRevisionJson.getRevisionNumber());
|
assertEquals(theExpectedMdmLinkWithRevisionJson.getRevisionNumber(), theActualMdmLinkWithRevisionJson.getRevisionNumber());
|
||||||
assertEquals(theExpectedMdmLinkWithRevisionJson.getRevisionTimestamp(), theActualMdmLinkWithRevisionJson.getRevisionTimestamp());
|
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();
|
final MdmLinkJson mdmLinkJson = new MdmLinkJson();
|
||||||
|
|
||||||
mdmLinkJson.setGoldenResourceId("Patient/" + theGoldenPatientId);
|
mdmLinkJson.setGoldenResourceId("Patient/" + theGoldenPatientId);
|
||||||
|
@ -93,6 +106,10 @@ public class MdmModelConverterSvcImplTest extends BaseMdmR4Test {
|
||||||
mdmLinkJson.setCreated(theCreateTime);
|
mdmLinkJson.setCreated(theCreateTime);
|
||||||
mdmLinkJson.setUpdated(theUpdateTime);
|
mdmLinkJson.setUpdated(theUpdateTime);
|
||||||
mdmLinkJson.setLinkCreatedNewResource(theLinkCreatedNewResource);
|
mdmLinkJson.setLinkCreatedNewResource(theLinkCreatedNewResource);
|
||||||
|
mdmLinkJson.setScore(theScore);
|
||||||
|
|
||||||
|
// make sure vector is not converted
|
||||||
|
mdmLinkJson.setVector(null);
|
||||||
|
|
||||||
return mdmLinkJson;
|
return mdmLinkJson;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue