Fix vector map bug i just wrote. woopsie doopsie

This commit is contained in:
Tadgh 2020-11-11 16:36:54 -05:00
parent 84d9d080df
commit ae3040415c
7 changed files with 41 additions and 27 deletions

View File

@ -39,7 +39,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
@Service
public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
@ -65,7 +64,7 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
// myPersonHelper.mergeFields(theFrom, theTo);
mergeSourceResourceLinks(theFrom, theTo, toPid, theEmpiTransactionContext);
removeTargetLinks(theFrom);
//removeTargetLinks(theFrom);
refreshLinksAndUpdatePerson(theTo, theEmpiTransactionContext);
@ -90,7 +89,7 @@ public class EmpiPersonMergerSvcImpl implements IEmpiPersonMergerSvc {
List<EmpiLink> empiLinksByTargetAndSource = myEmpiLinkDaoSvc.findEmpiLinksByTarget(theFrom);
empiLinksByTargetAndSource
.stream()
.filter(Predicate.not(EmpiLink::isManual))
.filter(EmpiLink::isAuto)
.forEach(l -> {
theEmpiTransactionContext.addTransactionLogMessage(String.format("Deleting link %s", l));
myEmpiLinkDaoSvc.deleteLink(l);

View File

@ -3,12 +3,10 @@ package ca.uhn.fhir.jpa.empi.provider;
import ca.uhn.fhir.empi.api.EmpiConstants;
import com.google.common.collect.Ordering;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Medication;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.codesystems.MatchGrade;
import org.junit.jupiter.api.BeforeEach;
@ -65,9 +63,9 @@ public class EmpiProviderMatchR4Test extends BaseProviderR4Test {
myOrganizationDao.update(org);
Medication medication = buildMedication();
Medication medication = buildMedication("Organization/mfr");
Medication createdMedication = createMedication(medication);
Medication newMedication = buildMedication();
Medication newMedication = buildMedication("Organization/mfr");
Bundle result = myEmpiProviderR4.serverMatch(newMedication, new StringType("Medication"));
assertEquals(1, result.getEntry().size());

View File

@ -9,7 +9,6 @@ import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.empi.util.EmpiUtil;
import ca.uhn.fhir.empi.util.PersonHelper;
import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.dao.data.IEmpiLinkDao;
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
import ca.uhn.fhir.jpa.entity.EmpiLink;
@ -17,7 +16,6 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.TokenParam;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.Identifier;
@ -418,6 +416,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test {
IBundleProvider bundle = myPatientDao.search(buildGoldenRecordSearchParameterMap());
assertEquals(1, bundle.size());
Patient sourcePatient = (Patient) bundle.getResources(0, 1).get(0);
//assertEquals(Person.IdentityAssuranceLevel.LEVEL2, sourcePatient.getLink().get(0).getAssurance());
//assertEquals(Person.IdentityAssuranceLevel.LEVEL1, sourcePatient.getLink().get(1).getAssurance());
//assertEquals(Person.IdentityAssuranceLevel.LEVEL1, sourcePatient.getLink().get(2).getAssurance());

View File

@ -5,7 +5,6 @@ import ca.uhn.fhir.empi.api.EmpiMatchOutcome;
import ca.uhn.fhir.empi.api.EmpiMatchResultEnum;
import ca.uhn.fhir.empi.api.IEmpiPersonMergerSvc;
import ca.uhn.fhir.empi.model.EmpiTransactionContext;
import ca.uhn.fhir.empi.util.EIDHelper;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test;
import ca.uhn.fhir.jpa.empi.helper.EmpiLinkHelper;
@ -29,7 +28,6 @@ import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat;
@ -345,7 +343,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test {
List<EmpiLink> sourcePatientLinks = myEmpiLinkDaoSvc.findEmpiLinksBySourceResource(myToSourcePatient);
// assertEquals(3, myToSourcePatient.getLink().size());
assertEquals(3, sourcePatientLinks.stream().filter(Predicate.not(EmpiLink::isManual)).count());
assertEquals(3, sourcePatientLinks.stream().filter(EmpiLink::isAuto).count());
}
@Test

View File

@ -41,7 +41,7 @@
],
"matchFields": [
{
"name": "cosine-code",
"name": "matched-medication-code",
"resourceType": "Medication",
"resourcePath": "code.coding.code",
"matcher": {
@ -112,7 +112,7 @@
"cosine-given-name,jaro-last-name": "MATCH",
"cosine-given-name-pract": "POSSIBLE_MATCH",
"cosine-given-name-pract,jaro-last-name-pract": "MATCH",
"cosine-code": "MATCH"
"matched-medication-code": "MATCH"
},
"eidSystem": "http://company.io/fhir/NamingSystem/custom-eid-system"
}

View File

@ -43,12 +43,14 @@ public class EmpiResourceFieldMatcher {
private final String myResourceType;
private final String myResourcePath;
private final EmpiRulesJson myEmpiRulesJson;
private final String myName;
public EmpiResourceFieldMatcher(FhirContext theFhirContext, EmpiFieldMatchJson theEmpiFieldMatchJson, EmpiRulesJson theEmpiRulesJson) {
myFhirContext = theFhirContext;
myEmpiFieldMatchJson = theEmpiFieldMatchJson;
myResourceType = theEmpiFieldMatchJson.getResourceType();
myResourcePath = theEmpiFieldMatchJson.getResourcePath();
myName = theEmpiFieldMatchJson.getName();
myEmpiRulesJson = theEmpiRulesJson;
}
@ -108,4 +110,8 @@ public class EmpiResourceFieldMatcher {
public String getResourcePath() {
return myResourcePath;
}
public String getName() {
return myName;
}
}

View File

@ -38,7 +38,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* The EmpiResourceComparator is in charge of performing actual comparisons between left and right records.
@ -118,24 +117,39 @@ public class EmpiResourceMatcherSvc {
private EmpiMatchOutcome getMatchOutcome(IBaseResource theLeftResource, IBaseResource theRightResource) {
long vector = 0;
double score = 0.0;
//TODO GGG MDM: This grabs ALL comparators, not just the ones we care about (e.g. the ones for Medication)
String resourceType = myFhirContext.getResourceType(theLeftResource);
List<EmpiResourceFieldMatcher> resourceRelevantFieldMatchers = myFieldMatchers.stream()
.filter(comp -> comp.getResourceType().equalsIgnoreCase(EmpiConstants.ALL_RESOURCE_SEARCH_PARAM_TYPE) || comp.getResourceType().equalsIgnoreCase(resourceType))
.collect(Collectors.toList());
int appliedRuleCount = 0;
for (int i = 0; i < resourceRelevantFieldMatchers.size(); ++i) {
//TODO GGG MDM: This grabs ALL comparators, not just the ones we care about (e.g. the ones for Medication)
String resourceType = myFhirContext.getResourceType(theLeftResource);
for (int i = 0; i < myFieldMatchers.size(); ++i) {
//any that are not for the resourceType in question.
EmpiResourceFieldMatcher fieldComparator = resourceRelevantFieldMatchers.get(i);
EmpiMatchEvaluation matchEvaluation = fieldComparator.match(theLeftResource, theRightResource);
if (matchEvaluation.match) {
vector |= (1 << i);
EmpiResourceFieldMatcher fieldComparator = myFieldMatchers.get(i);
if (!isValidResourceType(resourceType, fieldComparator.getResourceType())) {
ourLog.debug("Matcher {} is not valid for resource type: {}. Skipping it.", fieldComparator.getName(), resourceType);
continue;
} else {
ourLog.debug("Matcher {} is valid for resource type: {}. Evaluating match.", fieldComparator.getName(), resourceType);
EmpiMatchEvaluation matchEvaluation = fieldComparator.match(theLeftResource, theRightResource);
if (matchEvaluation.match) {
vector |= (1 << i);
}
score += matchEvaluation.score;
appliedRuleCount += 1;
}
score += matchEvaluation.score;
}
EmpiMatchOutcome retVal = new EmpiMatchOutcome(vector, score);
retVal.setEmpiRuleCount(resourceRelevantFieldMatchers.size());
retVal.setEmpiRuleCount(appliedRuleCount);
return retVal;
}
private boolean isValidResourceType(String theResourceType, String theFieldComparatorType) {
return (
theFieldComparatorType.equalsIgnoreCase(EmpiConstants.ALL_RESOURCE_SEARCH_PARAM_TYPE)
|| theFieldComparatorType.equalsIgnoreCase(theResourceType)
);
}
}