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 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); }