(self, requests, case, case_config)
return [ps.patient for ps in patients_scores]
Matches cases to patients. Returns a list of patients, each
        with a confidence score >= self.threshold
Matches cases to patients. Returns a list of patients, each
        with a confidence score >= self.threshold
Matches cases to patients . Returns a list of patients each with a confidence score > = self . threshold
def find_patients(self, requests, case, case_config):
        """
        Matches cases to patients. Returns a list of patients, each
        with a confidence score >= self.threshold
        """
        from corehq.motech.openmrs.openmrs_config import get_property_map
        from corehq.motech.openmrs.repeater_helpers import search_patients

        self._property_map = get_property_map(case_config)

        candidates = {}  # key on OpenMRS UUID to filter duplicates
        for prop in self.searchable_properties:
            value = case.get_case_property(prop)
            if value:
                response_json = search_patients(requests, value)
                for patient in response_json['results']:
                    score = self.get_score(patient, case)
                    if score >= self.threshold:
                        candidates[patient['uuid']] = PatientScore(patient, score)
        if not candidates:
            logger.info(
                'Unable to match case "%s" (%s): No candidate patients found.',
                case.name, case.get_id,
            )
            return []
        if len(candidates) == 1:
            patient = list(candidates.values())[0].patient
            logger.info(
                'Matched case "%s" (%s) to ONLY patient candidate: \n%s',
                case.name, case.get_id, pformat(patient, indent=2),
            )
            return [patient]
        patients_scores = sorted(candidates.values(), key=lambda candidate: candidate.score, reverse=True)
        if patients_scores[0].score / patients_scores[1].score > 1 + self.confidence_margin:
            # There is more than a `confidence_margin` difference
            # (defaults to 66.7%) in score between the best-ranked
            # patient and the second-best-ranked patient. Let's go with
            # Patient One.
            patient = patients_scores[0].patient
            logger.info(
                'Matched case "%s" (%s) to BEST patient candidate: \n%s',
                case.name, case.get_id, pformat(patients_scores, indent=2),
            )
            return [patient]
        # We can't be sure. Just send them all.
        logger.info(
            'Unable to match case "%s" (%s) to patient candidates: \n%s',
            case.name, case.get_id, pformat(patients_scores, indent=2),
        )
        return [ps.patient for ps in patients_scores]
def find_patients ( self , requests , case , case_config ) : from corehq . motech . openmrs . openmrs_config import get_property_map from corehq . motech . openmrs . repeater_helpers import search_patients self . _property_map = get_property_map ( case_config ) candidates = { } # key on OpenMRS UUID to filter duplicates for prop in self . searchable_properties : value = case . get_case_property ( prop ) if value : response_json = search_patients ( requests , value ) for patient in response_json [ 'results' ] : score = self . get_score ( patient , case ) if score >= self . threshold : candidates [ patient [ 'uuid' ] ] = PatientScore ( patient , score ) if not candidates : logger . info ( 'Unable to match case "%s" (%s): No candidate patients found.' , case . name , case . get_id , ) return [ ] if len ( candidates ) == 1 : patient = list ( candidates . values ( ) ) [ 0 ] . patient logger . info ( 'Matched case "%s" (%s) to ONLY patient candidate: \n%s' , case . name , case . get_id , pformat ( patient , indent = 2 ) , ) return [ patient ] patients_scores = sorted ( candidates . values ( ) , key = lambda candidate : candidate . score , reverse = True ) if patients_scores [ 0 ] . score / patients_scores [ 1 ] . score > 1 + self . confidence_margin : # There is more than a `confidence_margin` difference # (defaults to 66.7%) in score between the best-ranked # patient and the second-best-ranked patient. Let's go with # Patient One. patient = patients_scores [ 0 ] . patient logger . info ( 'Matched case "%s" (%s) to BEST patient candidate: \n%s' , case . name , case . get_id , pformat ( patients_scores , indent = 2 ) , ) return [ patient ] # We can't be sure. Just send them all. logger . info ( 'Unable to match case "%s" (%s) to patient candidates: \n%s' , case . name , case . get_id , pformat ( patients_scores , indent = 2 ) , ) return [ ps . patient for ps in patients_scores ]