Example #1
0
        public async Task <CriminalAppearanceDetail> AppearanceDetailAsync(string fileId, string appearanceId, string partId)
        {
            async Task <CriminalFileDetailResponse> FileDetails() => await _filesClient.FilesCriminalFileIdAsync(_requestAgencyIdentifierId, _requestPartId, _requestApplicationCode, fileId);
            async Task <CriminalFileContent> FileContent() => await _filesClient.FilesCriminalFilecontentAsync(null, null, null, null, fileId);
            async Task <CriminalFileAppearances> Appearances() => await PopulateDetailsAppearancesAsync(fileId, FutureYN.Y, HistoryYN.Y);
            async Task <CriminalFileAppearanceCountResponse> AppearanceCounts() => await _filesClient.FilesCriminalAppearanceAppearanceIdCountsAsync(_requestAgencyIdentifierId, _requestPartId, appearanceId);
            async Task <CriminalFileAppearanceApprMethodResponse> AppearanceMethods() => await _filesClient.FilesCriminalAppearanceAppearanceIdAppearancemethodsAsync(_requestAgencyIdentifierId, _requestPartId, appearanceId);

            var appearancesTask       = _cache.GetOrAddAsync($"CriminalAppearancesFull-{fileId}", Appearances);
            var fileDetailTask        = _cache.GetOrAddAsync($"CriminalFileDetail-{fileId}", FileDetails);
            var fileContentTask       = _cache.GetOrAddAsync($"CriminalFileContent-{fileId}", FileContent);
            var appearanceCountTask   = _cache.GetOrAddAsync($"CriminalAppearanceCounts-{fileId}-{appearanceId}", AppearanceCounts);
            var appearanceMethodsTask = _cache.GetOrAddAsync($"CriminalAppearanceMethods-{fileId}-{appearanceId}", AppearanceMethods);

            //Probably cached, user has the path: FileDetails -> Appearances -> AppearanceDetails.
            var appearances = await appearancesTask;
            var detail      = _mapper.Map <RedactedCriminalFileDetailResponse>(await fileDetailTask);
            var agencyId    = await _locationService.GetLocationAgencyIdentifier(detail.HomeLocationAgenId);

            detail.Witness = await PopulateDetailWitnesses(detail);

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

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

            async Task <CourtList> CourtList() => await _filesClient.FilesCourtlistAsync(agencyId, targetAppearance.CourtRoomCd, targetAppearance.AppearanceDt, "CR", detail.FileNumberTxt);

            var courtList = await _cache.GetOrAddAsync($"CriminalCourtList-{agencyId}-{targetAppearance.CourtRoomCd}-{targetAppearance.AppearanceDt}-{detail.FileNumberTxt}", CourtList);

            var fileContent       = await fileContentTask;
            var appearanceCount   = await appearanceCountTask;
            var appearanceMethods = await appearanceMethodsTask;

            var accusedFile           = fileContent?.AccusedFile.FirstOrDefault(af => af.MdocJustinNo == fileId && af.PartId == partId);
            var criminalParticipant   = detail?.Participant.FirstOrDefault(x => x.PartId == partId);
            var appearanceFromAccused = accusedFile?.Appearance.FirstOrDefault(a => a?.AppearanceId == appearanceId);
            var targetCourtList       = courtList.CriminalCourtList.FirstOrDefault(cl => cl.CriminalAppearanceID == appearanceId);
            var attendanceMethods     = targetCourtList?.AttendanceMethod;

            //CourtList AttendanceMethod is present state, AppearanceMethod is past state they look to be the same values, but haven't found any test data on DEV where they differ.
            if (criminalParticipant == null || accusedFile == null || appearanceFromAccused == null)
            {
                return(null);
            }

            var appearanceDetail = new CriminalAppearanceDetail
            {
                JustinNo             = fileId,
                AgencyId             = await _locationService.GetLocationAgencyIdentifier(detail.HomeLocationAgenId),
                AppearanceId         = appearanceId,
                PartId               = targetAppearance.PartId,
                ProfSeqNo            = targetAppearance.ProfSeqNo,
                CourtRoomCd          = targetAppearance.CourtRoomCd,
                FileNumberTxt        = detail.FileNumberTxt,
                AppearanceMethods    = await PopulateAppearanceMethods(appearanceMethods.AppearanceMethod),
                AppearanceDt         = targetAppearance.AppearanceDt,
                AppearanceNote       = appearanceFromAccused.AppearanceNote?.ReturnNullIfEmpty(),
                JudgesRecommendation = appearanceFromAccused.JudgesRecommendation,
                EstimatedTimeHour    = appearanceFromAccused.EstimatedTimeHour?.ReturnNullIfEmpty(),
                EstimatedTimeMin     = appearanceFromAccused.EstimatedTimeMin?.ReturnNullIfEmpty(),
                Accused              = await PopulateAppearanceCriminalAccused(criminalParticipant.FullName, appearanceFromAccused, attendanceMethods, partId, appearanceMethods.AppearanceMethod),
                Prosecutor           = await PopulateAppearanceDetailProsecutor(appearanceFromAccused, attendanceMethods, appearanceMethods.AppearanceMethod),
                Adjudicator          = await PopulateAppearanceDetailAdjudicator(appearanceFromAccused, attendanceMethods, appearanceMethods.AppearanceMethod),
                JustinCounsel        = await PopulateAppearanceDetailJustinCounsel(criminalParticipant, appearanceFromAccused, attendanceMethods, appearanceMethods.AppearanceMethod),
                Charges              = await PopulateCharges(appearanceCount.ApprCount),
                InitiatingDocuments  = GetInitiatingDocumentsImageIds(accusedFile.Document)
            };

            return(appearanceDetail);
        }