private void ProcessQueue() { while (WaitHandle.WaitAny(wHandles) != 1) { try { QueueProcessorRunning = true; lock (queueLock) { CohortRuleCheckData currCohortRuleCheckData = null; if (_cohortRuleCheckDataTeamQueue.TryDequeue(out currCohortRuleCheckData) && currCohortRuleCheckData != null) { ApplyCohortRules(currCohortRuleCheckData); } } } catch (Exception ex) { _logger.Log(ex); } } QueueProcessorRunning = false; }
private void ApplyCohortRules(CohortRuleCheckData cohortRuleCheckData) { CareTeam careTeam = null; var careTeamData = EndpointUtil.GetCareTeam(new GetCareTeamRequest { ContactId = cohortRuleCheckData.ContactId, ContractNumber = cohortRuleCheckData.ContractNumber, UserId = cohortRuleCheckData.UserId }); if (careTeamData == null) { return; } careTeam = Mapper.Map <CareTeam>(careTeamData); var userList = GetAllUsersIds(cohortRuleCheckData.ContractNumber, cohortRuleCheckData.UserId, cohortRuleCheckData.Version); cohortRuleCheckData.UsersContactIds = userList; var rules = CareMemberCohortRuleFactory.GenerateEngageCareMemberCohortRules(); foreach (var rule in rules) { rule.Run(careTeam, cohortRuleCheckData); } }
public CohortRuleResponse Run(CareTeam careTeam, CohortRuleCheckData data) { var response = new CohortRuleResponse(); if (careTeam == null) { throw new ArgumentNullException("careTeam"); } try { var activeCorePCM = _cohortRuleUtil.GetCareTeamActiveCorePCM(careTeam); if (activeCorePCM != null) { //We need to add Active Core PCM from the CohortPatientView for the referenced individual if (!data.UsersContactIds.IsNullOrEmpty()) { _contactEndpointUtil.AddPCMToCohortPatientView(data.PatientId, activeCorePCM.ContactId, data.Version, data.ContractNumber, data.UserId, data.UsersContactIds.Contains(activeCorePCM.ContactId)); } } response.IsSuccessful = true; } catch (Exception ex) { response.IsSuccessful = false; response.ErrorCode = "UnAssignedPCMRule.Cohort.Error"; response.Message = ex.Message; _logger.Log(ex); } return(response); }
public CohortRuleResponse Run(CareTeam careTeam, CohortRuleCheckData data) { var response = new CohortRuleResponse(); try { if (careTeam == null) { throw new ArgumentNullException("careTeam"); } //Check if any of the members have active core PCM role. if (!_cohortRuleUtil.CheckIfCareTeamHasActiveCorePCM(careTeam)) { //Add to UnAssigned PCM. var isSuccessful = _contactEndpointUtil.RemovePCMCohortPatientView(data.PatientId, data.Version, data.ContractNumber, data.UserId); response.IsSuccessful = isSuccessful; } } catch (Exception ex) { response.IsSuccessful = false; response.ErrorCode = "UnAssignedPCMRule.Cohort.Error"; response.Message = ex.Message; _logger.Log(ex); } return(response); }
public void EnqueueCohorRuleCheck(CohortRuleCheckData cohortRuleCheckData) { if (!QueueProcessorRunning) { throw new ApplicationException("CohortRulesProcessor: The Cohort Rules Queue Processor is not running"); } lock (queueLock) { _cohortRuleCheckDataTeamQueue.Enqueue(cohortRuleCheckData); _queuEvent.Set(); } }
public DeleteCareTeamMemberResponse DeleteCareTeamMember(DeleteCareTeamMemberRequest request) { var response = new DeleteCareTeamMemberResponse(); if (request == null) { throw new ArgumentNullException("request"); } try { var dataResponse = EndpointUtil.DeleteCareTeamMember(request); if (dataResponse != null) { //TODO: Refactor. var contact = GetContactByContactId(new GetContactByContactIdRequest { ContractNumber = request.ContractNumber, ContactId = request.ContactId, UserId = request.UserId, Version = request.Version }); if (contact == null) { throw new ApplicationException(string.Format("Contact with id: {0} does not exist", request.ContactId)); } var cohortRuleCheckData = new CohortRuleCheckData() { ContactId = request.ContactId, ContractNumber = request.ContractNumber, UserId = request.UserId, PatientId = contact.PatientId }; CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData); } } catch (WebServiceException wse) { throw new WebServiceException("AD:DeleteCareTeamMemberResponse()::" + wse.Message, wse.InnerException); } return(response); }
public string GetCareTeamActiveCorePCMId(CohortRuleCheckData cohortRuleCheckData) { string res = null; var careTeamData = EndpointUtil.GetCareTeam(new GetCareTeamRequest { ContactId = cohortRuleCheckData.ContactId, ContractNumber = cohortRuleCheckData.ContractNumber, UserId = cohortRuleCheckData.UserId }); if (careTeamData != null) { var careTeam = Mapper.Map <CareTeam>(careTeamData); var m = _cohortRuleUtil.GetCareTeamActiveCorePCM(careTeam); if (m != null) { res = m.Id; } } return(res); }
public CohortRuleResponse Run(CareTeam careTeam, CohortRuleCheckData data) { var response = new CohortRuleResponse(); try { if (careTeam == null) { throw new ArgumentNullException("careTeam"); } //For each member in the careteam that is a user, add an ATO cohort for the referenced individual var contactIdsToAdd = new List <string>(); foreach (var member in careTeam.Members) { if (member.StatusId == (int)CareTeamMemberStatus.Active) { if (data.UsersContactIds.Contains(member.ContactId)) { contactIdsToAdd.Add(member.ContactId); } } } _contactEndpointUtil.AssignContactsToCohortPatientView(data.PatientId, contactIdsToAdd.Distinct().ToList(), data.Version, data.ContractNumber, data.UserId); response.IsSuccessful = true; } catch (Exception ex) { response.IsSuccessful = false; response.ErrorCode = "AssignedToMeRule.Cohort.Error"; response.Message = ex.Message; _logger.Log(ex); } return(response); }
public AddCareTeamMemberResponse AddCareTeamMember(AddCareTeamMemberRequest request) { var response = new AddCareTeamMemberResponse(); if (request == null) { throw new ArgumentNullException("request"); } ValidateCareTeamMemberFields(request.CareTeamMember); var careTeamData = EndpointUtil.GetCareTeam(new GetCareTeamRequest { ContactId = request.ContactId, ContractNumber = request.ContractNumber, UserId = request.UserId, Version = request.Version }); if (careTeamData == null) { throw new ApplicationException(string.Format("No care team exists for contact {0}", request.ContactId)); } var members = careTeamData.Members; if (!members.IsNullOrEmpty()) { var mappedMembers = members.Select(Mapper.Map <Member>).ToList(); mappedMembers.Add(request.CareTeamMember); var careTeam = new CareTeam { Members = mappedMembers, ContactId = request.ContactId, Id = careTeamData.Id }; if (CohortRuleUtil.HasMultipleActiveCorePCM(careTeam)) { throw new ApplicationException("The Care team cannot have multiple Active, Core PCMs"); } if (CohortRuleUtil.HasMultipleActiveCorePCP(careTeam)) { throw new ApplicationException("The Care team cannot have multiple Active, Core PCPs"); } } var contact = GetContactByContactId(new GetContactByContactIdRequest { ContractNumber = request.ContractNumber, ContactId = request.ContactId, UserId = request.UserId, Version = request.Version }); if (contact == null) { throw new ApplicationException(string.Format("Contact with id: {0} does not exist", request.ContactId)); } var cohortRuleCheckData = new CohortRuleCheckData() { ContactId = request.ContactId, ContractNumber = request.ContractNumber, UserId = request.UserId, PatientId = contact.PatientId }; try { var domainResponse = EndpointUtil.AddCareTeamMember(request); if (domainResponse != null) { response.Id = domainResponse.Id; CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData); } } catch (Exception ex) { throw new Exception("AD:UpdateCareTeamMember()::" + ex.Message, ex.InnerException); } return(response); }
public UpdateCareTeamMemberResponse UpdateCareTeamMember(UpdateCareTeamMemberRequest request) { var response = new UpdateCareTeamMemberResponse(); if (request == null) { throw new ArgumentNullException("request"); } if (request.CareTeamMember == null) { throw new ArgumentNullException("CareTeamMemberData is Null", "request"); } if (string.IsNullOrEmpty(request.ContactId)) { throw new ArgumentNullException("Null or empty ContactId", "request"); } if (string.IsNullOrEmpty(request.CareTeamId)) { throw new ArgumentNullException("Null or empty CareTeamId", "request"); } if (string.IsNullOrEmpty(request.Id)) { throw new ArgumentNullException("Null or empty MemberId", "request"); } if (request.Id != request.CareTeamMember.Id) { throw new ArgumentNullException("CareTeamMemberData.Id and Id are different", "request"); } var contact = GetContactByContactId(new GetContactByContactIdRequest { ContractNumber = request.ContractNumber, ContactId = request.ContactId, UserId = request.UserId, Version = request.Version }); if (contact == null) { throw new ApplicationException(string.Format("Contact with id: {0} does not exist", request.ContactId)); } var cohortRuleCheckData = new CohortRuleCheckData() { ContactId = request.ContactId, ContractNumber = request.ContractNumber, UserId = request.UserId, PatientId = contact.PatientId }; //Get the currentActiveCore TeamMember Id. string currentActiveCorePCMId = CohortRules.GetCareTeamActiveCorePCMId(cohortRuleCheckData); if (currentActiveCorePCMId != null && request.CareTeamMember.Core && currentActiveCorePCMId != request.Id & request.CareTeamMember.RoleId == Constants.PCMRoleId && request.CareTeamMember.StatusId == (int)CareTeamMemberStatus.Active) { throw new ArgumentNullException("Care Team already has an Active Core PCM", "request"); } ValidateCareTeamMemberFields(request.CareTeamMember); try { var domainResponse = EndpointUtil.UpdateCareTeamMember(request); if (domainResponse != null) { response.Status = domainResponse.Status; CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData); } } catch (Exception ex) { throw new Exception("AD:UpdateCareTeamMember()::" + ex.Message, ex.InnerException); } return(response); }
public SaveCareTeamResponse SaveCareTeam(SaveCareTeamRequest request) { var response = new SaveCareTeamResponse(); if (request == null) { throw new ArgumentNullException("request"); } if (request.CareTeam == null) { throw new ArgumentNullException("request.CareTeam"); } //if(request.CareTeam.Members.IsNullOrEmpty()) // throw new ApplicationException(string.Format("CareTeam should have atleast one or more members.")); if (string.IsNullOrEmpty(request.ContactId)) { throw new ArgumentException(string.Format("ContactId is null or empty"), "request"); } foreach (var member in request.CareTeam.Members) { ValidateCareTeamMemberFields(member); if (!string.IsNullOrEmpty(member.RoleId) && !string.IsNullOrEmpty(member.CustomRoleName)) { member.RoleId = null; } } //TODO: Refactor. var contact = GetContactByContactId(new GetContactByContactIdRequest { ContractNumber = request.ContractNumber, ContactId = request.ContactId, UserId = request.UserId, Version = request.Version }); if (contact == null) { throw new ApplicationException(string.Format("Contact with id: {0} does not exist.", request.ContactId)); } if (!contact.IsPatient) { throw new ApplicationException(string.Format("Contact with id: {0} is not a patient.", request.ContactId)); } if (CohortRuleUtil.HasMultipleActiveCorePCM(request.CareTeam)) { throw new ApplicationException("The Care team cannot have multiple Active, Core PCMs"); } if (CohortRuleUtil.HasMultipleActiveCorePCP(request.CareTeam)) { throw new ApplicationException("The Care team cannot have multiple Active, Core PCPs"); } try { var domainResponse = EndpointUtil.SaveCareTeam(request); if (domainResponse != null) { response.CareTeam = Mapper.Map <CareTeam>(domainResponse.CareTeamData); #region Populate Contact object for each care team member. if (response.CareTeam != null) { if (!response.CareTeam.Members.IsNullOrEmpty()) { var contactIds = response.CareTeam.Members.Select(a => a.ContactId).ToList(); var contactsData = EndpointUtil.GetContactsByContactIds(contactIds, request.Version, request.ContractNumber, request.UserId); if (contactsData != null) { foreach (var member in response.CareTeam.Members) { var data = contactsData.FirstOrDefault(c => c.Id == member.ContactId); if (data == null) { throw new ApplicationException(string.Format("Contact card for a care team member with contact id = {0} was not found", member.ContactId)); } else { member.Contact = Mapper.Map <Contact>(data); } } } } } #endregion var cohortRuleCheckData = new CohortRuleCheckData() { ContactId = request.ContactId, ContractNumber = request.ContractNumber, UserId = request.UserId, PatientId = contact.PatientId }; CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData); } } catch (Exception ex) { throw new Exception("AD:SaveCareTeam()::" + ex.Message, ex.InnerException); } return(response); }