コード例 #1
0
        public async Task <CivilAppearanceDetail> DetailedAppearanceAsync(string fileId, string appearanceId)
        {
            async Task <CivilFileDetailResponse> FileDetails() => await _filesClient.FilesCivilGetAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, fileId);
            async Task <CivilFileContent> FileContent() => await _filesClient.FilesCivilFilecontentAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, null, null, null, null, fileId);
            async Task <CivilFileAppearancePartyResponse> AppearanceParty() => await _filesClient.FilesCivilAppearancePartiesAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, appearanceId);
            async Task <CivilFileAppearanceApprMethodResponse> AppearanceMethods() => await _filesClient.FilesCivilAppearanceAppearancemethodsAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, appearanceId);
            async Task <CivilAppearanceResponse> Appearances() => await PopulateDetailAppearancesAsync(FutureYN2.Y, HistoryYN2.Y, fileId);

            var fileDetailTask        = _cache.GetOrAddAsync($"CivilFileDetail-{fileId}-{_requestAgencyIdentifierId}", FileDetails);
            var appearancePartyTask   = _cache.GetOrAddAsync($"CivilAppearanceParty-{fileId}-{appearanceId}-{_requestAgencyIdentifierId}", AppearanceParty);
            var fileContentTask       = _cache.GetOrAddAsync($"CivilFileContent-{fileId}-{_requestAgencyIdentifierId}", FileContent);
            var appearanceMethodsTask = _cache.GetOrAddAsync($"CivilAppearanceMethods-{fileId}-{appearanceId}-{_requestAgencyIdentifierId}", AppearanceMethods);
            var appearancesTask       = _cache.GetOrAddAsync($"CivilAppearancesFull-{fileId}-{_requestAgencyIdentifierId}", Appearances);

            var detail      = await fileDetailTask;
            var appearances = await appearancesTask;
            var agencyId    = await _locationService.GetLocationAgencyIdentifier(detail?.HomeLocationAgenId);

            var fileContent = await fileContentTask;

            var targetAppearance = appearances?.ApprDetail?.FirstOrDefault(app => app.AppearanceId == appearanceId);

            if (targetAppearance == null || detail == null)
            {
                return(null);
            }

            //Sometimes we can have a bogus location, querying court list wont work.
            ClCivilCourtList civilCourtList = null;

            if (agencyId != null)
            {
                async Task <CourtList> CourtList() => await _filesClient.FilesCourtlistAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, agencyId, targetAppearance.CourtRoomCd, targetAppearance.AppearanceDt, "CV", detail.FileNumberTxt);

                var courtListTask = _cache.GetOrAddAsync($"CivilCourtList-{agencyId}-{targetAppearance.CourtRoomCd}-{targetAppearance.AppearanceDt}-{detail.FileNumberTxt}-{_requestAgencyIdentifierId}", CourtList);
                var courtList     = await courtListTask;
                civilCourtList = courtList.CivilCourtList.FirstOrDefault(cl => cl.AppearanceId == appearanceId);
            }

            var appearanceParty           = await appearancePartyTask;
            var appearanceMethodsResponse = await appearanceMethodsTask;
            var appearanceMethods         = appearanceMethodsResponse.AppearanceMethod;

            var appearanceDetail     = appearances.ApprDetail?.FirstOrDefault(app => app.AppearanceId == appearanceId);
            var fileDetailDocuments  = detail.Document.Where(doc => doc.Appearance != null && doc.Appearance.Any(app => app.AppearanceId == appearanceId)).ToList();
            var fileContentCivilFile = fileContent?.CivilFile?.FirstOrDefault(cf => cf.PhysicalFileID == fileId);
            var previousAppearance   = fileContentCivilFile?.PreviousAppearance.FirstOrDefault(pa => pa?.AppearanceId == appearanceId);

            var detailedAppearance = new CivilAppearanceDetail
            {
                PhysicalFileId       = fileId,
                AgencyId             = await _locationService.GetLocationAgencyIdentifier(detail.HomeLocationAgenId),
                AppearanceId         = appearanceId,
                AppearanceResultCd   = appearanceDetail?.AppearanceResultCd,
                AppearanceReasonCd   = appearanceDetail?.AppearanceReasonCd,
                AppearanceReasonDesc = await _lookupService.GetCivilAppearanceReasonsDescription(appearanceDetail?.AppearanceReasonCd),
                AppearanceResultDesc = await _lookupService.GetCivilAppearanceResultsDescription(appearanceDetail?.AppearanceResultCd),
                CourtRoomCd          = targetAppearance.CourtRoomCd,
                FileNumberTxt        = detail.FileNumberTxt,
                AppearanceDt         = targetAppearance.AppearanceDt,
                AppearanceMethod     = await PopulateAppearanceMethods(appearanceMethods),
                Party       = await PopulateDetailedAppearancePartiesAsync(appearanceParty.Party, civilCourtList?.Parties, previousAppearance, appearanceMethods),
                Document    = await PopulateDetailedAppearanceDocuments(fileDetailDocuments),
                Adjudicator = await PopulateDetailedAppearanceAdjudicator(previousAppearance, appearanceMethods),
                //AdjudicatorComment = previousAppearance?.AdjudicatorComment,
                CourtLevelCd = detail.CourtLevelCd
            };

            return(detailedAppearance);
        }