public async Task <IEnumerable <FamilyClientMessage> > Load(Guid?htsClientId = null, params LoadAction[] actions) { var messages = new List <FamilyClientMessage>(); if (!actions.Any()) { actions = new[] { LoadAction.All } } ; // Set Facility var facility = _practiceRepository.GetDefault(); if (null == facility) { throw new Exception($"Default Faciltity Not found"); } // MESSAGE_HEADER var facilityCode = facility.Code; var header = MESSAGE_HEADER.Create(facilityCode); // CLIENT var familyMembers = _clientStageRelationshipRepository.GetAll(x => !x.IsPartner); if (!htsClientId.IsNullOrEmpty()) { familyMembers = familyMembers.Where(x => x.SecondaryClientId == htsClientId); } foreach (var familyMember in familyMembers) { var stagedClient = _clientStageRepository.GetQueued(familyMember.SecondaryClientId); if (null != stagedClient && !stagedClient.IsIndex) { header.UpdateMfl(stagedClient.SiteCode); #region PATIENT_IDENTIFICATION var pid = PARTNER_FAMILY_PATIENT_IDENTIFICATION.Create(stagedClient, familyMember.IndexClientId, familyMember.Relation); #endregion FAMILY_ENCOUNTER encounter = null; if (!actions.Contains(LoadAction.RegistrationOnly)) { PLACER_DETAIL placerDetail = null; FAMILY_SCREENING familyScreening = null; List <FAMILY_TRACING> familyTracings = new List <FAMILY_TRACING>(); #region ENCOUNTERS var screening = await _clientFamilyScreeningStageExtractor.Extract(stagedClient.ClientId); var screeningStage = screening.OrderBy(x => x.ScreeningDate).LastOrDefault(); // PLACER_DETAIL if (null != screeningStage) { placerDetail = PLACER_DETAIL.Create(screeningStage.UserId, screeningStage.Id); // FAMILY_SCREENING if (actions.Contains(LoadAction.All) || actions.Contains(LoadAction.ContactScreenig)) { familyScreening = FAMILY_SCREENING.Create(screeningStage); } } // FAMILY_TRACING if (actions.Contains(LoadAction.All) || actions.Contains(LoadAction.ContactTracing)) { var allTracing = await _clientFamilyTracingStageExtractor.Extract(stagedClient.ClientId); if (allTracing.Any()) { familyTracings = FAMILY_TRACING.Create(allTracing.ToList()); } } #endregion encounter = new FAMILY_ENCOUNTER(placerDetail, familyScreening, familyTracings); } messages.Add(new FamilyClientMessage(header, new List <FAMILY> { new FAMILY(pid, encounter) }, stagedClient.ClientId)); } } return(messages); }
public FamilyScreening(MESSAGE_HEADER messageHeader, Guid clientId, List <INTERNAL_PATIENT_ID> patientIds, PLACER_DETAIL placerDetail, FAMILY_SCREENING familyScreening) : base(messageHeader, clientId) { INTERNAL_PATIENT_ID = patientIds; PLACER_DETAIL = placerDetail; FAMILY_SCREENING = familyScreening; }