private static void RemoveAllProfilesRelatedToConflict(PatientProfileMatch proposedMatch, IList <PatientProfileMatch> matches, IList <PatientProfileMatch> conflicts)
 {
     foreach (PatientProfileMatch otherProfilesInConflictingPatient in matches)
     {
         if (otherProfilesInConflictingPatient.PatientProfile.Patient == proposedMatch.PatientProfile.Patient)
         {
             conflicts.Add(otherProfilesInConflictingPatient);
         }
     }
 }
        public IList <PatientProfileMatch> FindReconciliationMatches(PatientProfile targetProfile, IPersistenceContext context)
        {
            /* User needs to resort to manual linking of patient records from multiple HIS when automatic MPI fails.
             *
             * Allow user to to select 2 or more patient records from different hospitals and merge into an MPI.
             *
             * Display High-Probability match/search results from muliple HIS of patients with various Mrns when
             * field: healthcard # is matched/identical.
             *
             * Display Moderate-Probability match/search results from multiple HIS of patients with various Mrns when fields: surname,
             * given name, DOB, gender are matched/identical.
             *
             */
            IPatientProfileBroker broker = context.GetBroker <IPatientProfileBroker>();

            IList <PatientProfileMatch> matches = new List <PatientProfileMatch>();

            IList <PatientProfileMatch> highMatches = new List <PatientProfileMatch>();

            if (targetProfile.Healthcard != null && !string.IsNullOrEmpty(targetProfile.Healthcard.Id))
            {
                PatientProfileSearchCriteria high = new PatientProfileSearchCriteria();
                high.Healthcard.Id.EqualTo(targetProfile.Healthcard.Id);

                highMatches = PatientProfileMatch.CreateList(targetProfile, broker.Find(high), PatientProfileMatch.ScoreValue.High);
            }

            PatientProfileSearchCriteria moderateViaName = new PatientProfileSearchCriteria();

            if (targetProfile.Name.FamilyName != null && !string.IsNullOrEmpty(targetProfile.Name.FamilyName))
            {
                moderateViaName.Name.FamilyName.EqualTo(targetProfile.Name.FamilyName);
            }

            if (targetProfile.Name.GivenName != null && !string.IsNullOrEmpty(targetProfile.Name.GivenName))
            {
                moderateViaName.Name.GivenName.EqualTo(targetProfile.Name.GivenName);
            }

            if (targetProfile.DateOfBirth != null)
            {
                moderateViaName.DateOfBirth.EqualTo(targetProfile.DateOfBirth);
            }

            moderateViaName.Sex.EqualTo(targetProfile.Sex);

            IList <PatientProfileMatch> moderateMatchesViaName = PatientProfileMatch.CreateList(targetProfile, broker.Find(moderateViaName), PatientProfileMatch.ScoreValue.Moderate);

            matches = PatientProfileMatch.Combine(highMatches, moderateMatchesViaName);

            RemoveConflicts(targetProfile.Patient, matches);

            return(matches);
        }
        public ReconciliationCandidate CreateReconciliationCandidate(PatientProfileMatch profileMatch, IPersistenceContext context)
        {
            var rc = new ReconciliationCandidate();

            var profileAssembler = new PatientProfileAssembler();
            rc.PatientProfile = profileAssembler.CreatePatientProfileSummary(profileMatch.PatientProfile, context);
            switch (profileMatch.Score)
            {
                case PatientProfileMatch.ScoreValue.High:
                    rc.Score = ReconciliationCandidate.ProbabilityScore.High;
                    break;
                case PatientProfileMatch.ScoreValue.Moderate:
                    rc.Score = ReconciliationCandidate.ProbabilityScore.Moderate;
                    break;
                case PatientProfileMatch.ScoreValue.Low:
                    rc.Score = ReconciliationCandidate.ProbabilityScore.Low;
                    break;
            }
            return rc;
        }
 private static void RemoveAllProfilesRelatedToConflict(PatientProfileMatch proposedMatch, IList<PatientProfileMatch> matches, IList<PatientProfileMatch> conflicts)
 {
     foreach (PatientProfileMatch otherProfilesInConflictingPatient in matches)
     {
         if (otherProfilesInConflictingPatient.PatientProfile.Patient == proposedMatch.PatientProfile.Patient)
         {
             conflicts.Add(otherProfilesInConflictingPatient);
         }
     }
 }