Exemplo n.º 1
0
        public void should_Extract()
        {
            var clients = _stageExtractor.Extract().Result.ToList();

            Assert.True(clients.Count > 0);
            foreach (var clientStage in clients)
            {
                Console.WriteLine(clientStage);
            }
        }
        public async Task <IEnumerable <PartnerClientMessage> > Load(Guid?htsClientId = null, params LoadAction[] actions)
        {
            var messages = new List <PartnerClientMessage>();

            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 clientPartners = _clientStageRelationshipRepository.GetAll(x => x.IsPartner);

            if (!htsClientId.IsNullOrEmpty())
            {
                clientPartners = clientPartners.Where(x => x.SecondaryClientId == htsClientId);
            }

            foreach (var clientPartner in clientPartners)
            {
                var stagedClient = _clientStageRepository.GetQueued(clientPartner.SecondaryClientId);

                if (null != stagedClient && !stagedClient.IsIndex)
                {
                    header.UpdateMfl(stagedClient.SiteCode);

                    #region PATIENT_IDENTIFICATION

                    var pid = PARTNER_FAMILY_PATIENT_IDENTIFICATION.Create(stagedClient, clientPartner.IndexClientId,
                                                                           clientPartner.Relation);

                    #endregion

                    PARTNER_ENCOUNTER encounter = null;

                    if (!actions.Contains(LoadAction.RegistrationOnly))
                    {
                        PLACER_DETAIL          placerDetail     = null;
                        PARTNER_SCREENING      partnerScreening = null;
                        List <PARTNER_TRACING> partnerTracings  = new List <PARTNER_TRACING>();

                        #region ENCOUNTERS

                        var screening = await _clientPartnerScreeningStageExtractor.Extract(stagedClient.ClientId);

                        var screeningStage = screening.OrderBy(x => x.ScreeningDate).LastOrDefault();

                        //  PLACER_DETAIL

                        if (null != screeningStage)
                        {
                            placerDetail = PLACER_DETAIL.Create(screeningStage.UserId, screeningStage.Id);

                            //  PARTNER_SCREENING

                            if (actions.Contains(LoadAction.All) || actions.Contains(LoadAction.ContactScreenig))
                            {
                                partnerScreening = PARTNER_SCREENING.Create(screeningStage);
                            }
                        }

                        //  Partner_TRACING
                        if (actions.Contains(LoadAction.All) || actions.Contains(LoadAction.ContactTracing))
                        {
                            var allTracing = await _clientPartnerTracingStageExtractor.Extract(stagedClient.ClientId);

                            if (allTracing.Any())
                            {
                                partnerTracings = PARTNER_TRACING.Create(allTracing.ToList());
                            }
                        }

                        #endregion

                        encounter = new PARTNER_ENCOUNTER(placerDetail, partnerScreening, partnerTracings);
                    }

                    messages.Add(new PartnerClientMessage(header,
                                                          new List <PARTNER> {
                        new PARTNER(pid, encounter)
                    }, stagedClient.ClientId));
                }
            }

            return(messages);
        }