Skip to content

Commit

Permalink
Mismo patient Matching integration, with new Flavour named "MISMO"
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbeor committed Apr 30, 2024
1 parent 42b7e9b commit dff1fb4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void exportPollStatus(
RequestPartitionId partitionId = partitionCreationInterceptor.partitionIdentifyRead(theRequestDetails);
// myRequestPartitionHelperService.determineReadPartitionForRequest(theRequestDetails, null);
// myRequestPartitionHelperService.validateHasPartitionPermissions(theRequestDetails, "Binary", partitionId);
ourLog.info("part {} {} {}", theRequestDetails.getTenantId(), partitionId, parameters.getPartitionId());
// ourLog.info("part {} {} {}", theRequestDetails.getTenantId(), partitionId, parameters.getPartitionId());
if (!parameters.getPartitionId().getFirstPartitionNameOrNull().equals(partitionId.getFirstPartitionNameOrNull())) {
throw new InvalidRequestException(
Msg.code(2304) + "Invalid partition in request for Job ID " + theJobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.mdm.svc.MdmMatchFinderSvcImpl;
import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmCandidateSearchSvc;
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.mdm.api.IMdmMatchFinderSvc;
Expand All @@ -20,7 +21,14 @@
import org.hl7.fhir.r5.model.Immunization;
import org.hl7.fhir.r5.model.ResourceType;
import org.immregistries.iis.kernal.fhir.annotations.OnR5Condition;
import org.immregistries.iis.kernal.fhir.security.ServletHelper;
import org.immregistries.iis.kernal.mapping.forR5.ImmunizationMapperR5;
import org.immregistries.iis.kernal.model.ProcessingFlavor;
import org.immregistries.iis.kernal.servlet.PatientMatchingDatasetConversionController;
import org.immregistries.mismo.match.PatientMatchDetermination;
import org.immregistries.mismo.match.PatientMatchResult;
import org.immregistries.mismo.match.PatientMatcher;
import org.immregistries.mismo.match.model.Patient;
import org.immregistries.vaccination_deduplication.computation_classes.Deterministic;
import org.immregistries.vaccination_deduplication.reference.ComparisonResult;
import org.immregistries.vaccination_deduplication.reference.ImmunizationSource;
Expand All @@ -44,25 +52,42 @@
/**
* Custom, based on MdmMatchFinderSvcImpl from Hapi-fhir v6.2.4, to allow for Immunization matching with external library
*/
//@Component
//@Conditional(OnR5Condition.class)
public class MdmCustomMatchFinderSvcR5 extends MdmMatchFinderSvcImpl implements IMdmMatchFinderSvc {
private static final Logger ourLog = Logs.getMdmTroubleshootingLog();
@Autowired
IFhirResourceDao<Immunization> immunizationDao;
@Autowired
private MdmCandidateSearchSvc myMdmCandidateSearchSvc;
@Autowired
private MdmResourceMatcherSvc myMdmResourceMatcherSvc;
@Autowired
IFhirResourceDao<Immunization> immunizationDao;
private PatientMatchingDatasetConversionController patientMatchingDatasetConversionController;

@Override
@Nonnull
@Transactional
public List<MatchedTarget> getMatchedTargets(String theResourceType, IAnyResource theResource, RequestPartitionId theRequestPartitionId) {
if (theResourceType.equals(ResourceType.Immunization.name())){
List<MatchedTarget> matches = matchImmunization((Immunization) theResource,theRequestPartitionId);
if (theResourceType.equals(ResourceType.Immunization.name())) {
List<MatchedTarget> matches = matchImmunization((Immunization) theResource, theRequestPartitionId);
ourLog.trace("Found {} matched targets for {}.", matches.size(), idOrType(theResource, theResourceType));
return matches;
} else if (theResourceType.equals(ResourceType.Patient.name()) && ProcessingFlavor.getProcessingStyle(theRequestPartitionId.getFirstPartitionNameOrNull()).contains(ProcessingFlavor.MISMO)) {

/**
* flavour check activating patient Matching with Mismo match
*/
Collection<IAnyResource> targetCandidates = myMdmCandidateSearchSvc.findCandidates(theResourceType, theResource, theRequestPartitionId);
PatientMatcher mismoMatcher = new PatientMatcher();
Patient mismoPatient = patientMatchingDatasetConversionController.convertFromR5((org.hl7.fhir.r5.model.Patient) theResource);

List<MatchedTarget> matches = targetCandidates.stream()
.map((candidate) -> {
Patient mismoPatientCandidate = patientMatchingDatasetConversionController.convertFromR5((org.hl7.fhir.r5.model.Patient) candidate);
return new MatchedTarget(candidate, mismoResultToMdmMatchOutcome(mismoMatcher.match(mismoPatient, mismoPatientCandidate)));
}).collect(Collectors.toList());

ourLog.info("Found {} matched targets for {} with mismo.", matches.size(), idOrType(theResource, theResourceType));
ourLog.trace("Found {} matched targets for {}.", matches.size(), idOrType(theResource, theResourceType));
return matches;
} else {
Collection<IAnyResource> targetCandidates = myMdmCandidateSearchSvc.findCandidates(theResourceType, theResource, theRequestPartitionId);
Expand Down Expand Up @@ -122,14 +147,14 @@ private List<MatchedTarget> matchImmunization(Immunization immunization, Request

}

private org.immregistries.vaccination_deduplication.Immunization toVaccDedupImmunization(Immunization immunization, RequestPartitionId theRequestPartitionId){
private org.immregistries.vaccination_deduplication.Immunization toVaccDedupImmunization(Immunization immunization, RequestPartitionId theRequestPartitionId) {
org.immregistries.vaccination_deduplication.Immunization i1 = new org.immregistries.vaccination_deduplication.Immunization();
i1.setCVX(immunization.getVaccineCode().getCode(ImmunizationMapperR5.CVX));
if(immunization.hasManufacturer()){
if (immunization.hasManufacturer()) {
i1.setMVX(immunization.getManufacturer().getReference().getIdentifier().getValue());
}
try {
if (immunization.hasOccurrenceStringType()){
if (immunization.hasOccurrenceStringType()) {
i1.setDate(immunization.getOccurrenceStringType().getValue()); // TODO parse correctly
} else if (immunization.hasOccurrenceDateTimeType()) {
i1.setDate(immunization.getOccurrenceDateTimeType().getValue());
Expand Down Expand Up @@ -167,4 +192,23 @@ private org.immregistries.vaccination_deduplication.Immunization toVaccDedupImmu
return i1;
}

private MdmMatchOutcome mismoResultToMdmMatchOutcome(PatientMatchResult patientMatchResult) {
switch (patientMatchResult.getDetermination()) {
case MATCH: {
return MdmMatchOutcome.EID_MATCH;
// return MdmMatchOutcome.NEW_GOLDEN_RESOURCE_MATCH;
}
case POSSIBLE_MATCH: {
return MdmMatchOutcome.POSSIBLE_MATCH;
}
case NO_MATCH: {
return MdmMatchOutcome.NO_MATCH;
}
default: {
return MdmMatchOutcome.NO_MATCH;
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Set;

public enum ProcessingFlavor {
MISMO("Mismo", "Uses Mismo Model for Patient Matching"),
LIME("Lime", "Missing non-critical required fields"),
COCONUT("Coconut", "Forecast never returned"),
ORANGE("Orange", "Z32 is returned for query matches"),
Expand Down Expand Up @@ -66,8 +67,12 @@ public static Set<ProcessingFlavor> getProcessingStyle(String label) {
|| label.endsWith(" " + key)
|| label.indexOf(" " + key + " ") > 0) {
processingFlavorSet.add(ps);
}
}
} else if (label.startsWith(key + "_")
|| label.endsWith("_" + key)
|| label.indexOf("_" + key + "_") > 0) {
processingFlavorSet.add(ps);
}
}
}
return processingFlavorSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private String patientCsvLine(Patient patient) {
.collect(Collectors.joining(","));
}

private Patient convertFromR5(org.hl7.fhir.r5.model.Patient patient) {
public Patient convertFromR5(org.hl7.fhir.r5.model.Patient patient) {
Patient mismo = new Patient();
org.hl7.fhir.r5.model.Identifier identifier = MappingHelper.filterIdentifierR5(patient.getIdentifier(), "http://codi.mitre.org");
if (identifier != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ iis:
api:
app:
jwtSecret: "sFiKu+qZpnyJBWzQjzYfne7t1IcIfNAixd+S2c1r+EF9kyoug1K9kJD948ZSiBC9fLkJBMirUPVqdwaidffb0OkYZhGLUPdb2M56QPJtoV+1dbbce2Q6FM7suRt7p90G4J4OR/b/zbK0Y30CnK/7gzLU0ph4KtjrVuHCgq9Di0NtxiFg3Icud92G0Bg0utaam70uOc5nrDMYCOHsg/vxUDQ9+g3fizwbrQmdJA=="
jwtExpirationMs: 300000
jwtExpirationMs: 900000
# TODO change secret
spring:
security:
Expand Down

0 comments on commit dff1fb4

Please sign in to comment.