public CareTeam GetCareTeam(GetCareTeamRequest request) { CareTeam careTeam = null; if (request == null) { throw new ArgumentNullException("request"); } if (string.IsNullOrEmpty(request.ContactId)) { throw new ArgumentNullException("request.ContactId"); } try { CareTeamData careTeamData = EndpointUtil.GetCareTeam(request); if (careTeamData != null) { careTeam = Mapper.Map <CareTeam>(careTeamData); #region Populate Contact object for each care team member. if (careTeam.Members != null && careTeam.Members.Count > 0) { List <string> contactIds = careTeam.Members.Select(a => a.ContactId).ToList(); List <ContactData> contactsData = EndpointUtil.GetContactsByContactIds(contactIds, request.Version, request.ContractNumber, request.UserId); if (contactsData != null) { foreach (var member in careTeam.Members) { ContactData 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 } return(careTeam); } catch (Exception ex) { throw ex; } }
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); }