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 IList<PatientProfile> ListPatientProfiles(PatientProfileSearchCriteria criteria) { IPatientProfileBroker profileBroker = this.CurrentContext.GetBroker<IPatientProfileBroker>(); return profileBroker.Find(criteria); }
private List<OrderNoteboxItem> BuildOrderNoteboxItems(List<NoteboxItem> inboxItems) { if (inboxItems.Count == 0) return new List<OrderNoteboxItem>(); // Get all the patients for all the items var patients = CollectionUtils.Unique(CollectionUtils.Map<NoteboxItem, Patient>(inboxItems, item => item.Patient)); var patientQuery = new HqlProjectionQuery(new HqlFrom(typeof(PatientProfile).Name, "pp")); var patientCriteria = new PatientProfileSearchCriteria(); patientCriteria.Patient.In(patients); patientQuery.Conditions.AddRange(HqlCondition.FromSearchCriteria("pp", patientCriteria)); var profiles = ExecuteHql<PatientProfile>(patientQuery); // Have to manually get the postings (and later their recipients) to work around a Hibernate fetch="subselect" issue. // The subselect somehow removed the "top(100)" and "order by" clause. Making the query slow. // Load all the postings for all the notes. There may be more than one postings per orderNote. // Therefore it is inappropriate to just use the postings in the base query. var notes = CollectionUtils.Unique(CollectionUtils.Map<NoteboxItem, Note>(inboxItems, item => item.Note)); var postingQuery = new HqlProjectionQuery(new HqlFrom(typeof(NotePosting).Name, "np")); var postingCriteria = new NotePostingSearchCriteria(); postingCriteria.Note.In(notes); postingQuery.Conditions.AddRange(HqlCondition.FromSearchCriteria("np", postingCriteria)); postingQuery.Froms[0].Joins.Add(new HqlJoin("np.Recipient", null, HqlJoinMode.Left, true)); var postings = ExecuteHql<NotePosting>(postingQuery); // Build order notebox items var orderNoteboxItems = CollectionUtils.Map(inboxItems, delegate(NoteboxItem item) { // Find the appropriate patient profile based on OrderingFacility var profile = CollectionUtils.SelectFirst(profiles, pp => pp.Patient.Equals(item.Patient) && pp.Mrn.AssigningAuthority.Code.Equals(item.OrderingFacilityInformationAuthority.Code)); // Find all the recipients var postingsForThisNote = CollectionUtils.Select(postings, np => np.Note.Equals(item.Note)); var recipients = CollectionUtils.Map<NotePosting, object>(postingsForThisNote, posting => posting is StaffNotePosting ? (object)((StaffNotePosting)posting).Recipient : (object)((GroupNotePosting)posting).Recipient); return new OrderNoteboxItem(item.Note, item.Order, item.Patient, profile, item.Author, recipients, item.DiagnosticServiceName, item.NotePostingAcknowledged); }); return orderNoteboxItems; }