public async Task <Models.CourtList.CourtList> CourtListAsync(string agencyId, string roomCode, DateTime proceeding, string divisionCode, string fileNumber) { var proceedingDateString = proceeding.ToString("yyyy-MM-dd"); var agencyCode = await _locationService.GetLocationCodeFromId(agencyId); async Task <CourtList> CourtList() => await _filesClient.FilesCourtlistAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, agencyId, roomCode, proceedingDateString, divisionCode, fileNumber); async Task <CourtCalendarDetailByDay> CourtCalendarDetailByDay() => await _filesClient.FilesCourtcalendardetailsbydayAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, agencyCode, proceeding.ToString("yyyy-MM-dd HH:mm:ss.S"), roomCode); var courtCalendarDetailsTask = _cache.GetOrAdd($"CourtCalendarDetails-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}-{_requestAgencyIdentifierId}", CourtCalendarDetailByDay); var originalCourtListTask = _cache.GetOrAddAsync($"CourtList-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}-{_requestAgencyIdentifierId}", CourtList); //Query by courtCalendarDetails, because it returns quite a bit faster than the courtList. var courtCalendarDetails = await courtCalendarDetailsTask; if (courtCalendarDetails.ResponseCd != "0") { _logger.LogInformation("Court calendar details returned responseCd != 0"); } ValidUserHelper.CheckIfValidUser(courtCalendarDetails.ResponseMessageTxt); var civilCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.I); var criminalCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.R); var civilFileIds = civilCourtCalendarAppearances.SelectToList(ccl => ccl.PhysicalFileId); var criminalFileIds = criminalCourtCalendarAppearances.SelectToList(ccl => ccl.MdocJustinNo); if (civilFileIds.Count == 0 && criminalFileIds.Count == 0) { return(new Models.CourtList.CourtList()); } //Start file details tasks. var civilFileDetailTasks = CivilFileDetailTasks(civilFileIds); var criminalFileDetailTasks = CriminalFileDetailTasks(criminalFileIds); //Start appearances tasks. var civilAppearanceTasks = CivilAppearancesTasks(proceeding, civilFileIds); var criminalAppearanceTasks = CriminalAppearancesTasks(proceeding, criminalFileIds); //Start file content tasks. var civilFileContentTasks = CivilFileContentTasks(civilFileIds); //Await our asynchronous requests. var civilFileDetails = (await civilFileDetailTasks.WhenAll()).ToList(); var criminalFileDetails = (await criminalFileDetailTasks.WhenAll()).ToList(); var civilAppearances = (await civilAppearanceTasks.WhenAll()).ToList(); var criminalAppearances = (await criminalAppearanceTasks.WhenAll()).ToList(); var civilFileContents = (await civilFileContentTasks.WhenAll()).ToList(); var originalCourtList = await originalCourtListTask; //Note, there is test data that doesn't have a CourtList, but may have CourtCalendarDetails. //If this is the case with real data, or becomes an issue with testing, I'll have to //create a blank courtList object and overlay CourtCalendarDetails on top of it. //Some overlap happens already, but some of the fields aren't passed over (they already exist in CourtList). //PCSS for example isn't aware of CourtList, it only uses CourtCalendarDetails where as SCV uses the CourtList + CourtCalendarDetails. var courtList = _mapper.Map <Models.CourtList.CourtList>(originalCourtList); courtList.CivilCourtList = await PopulateCivilCourtListFromFileDetails(courtList.CivilCourtList, civilFileDetails); courtList.CriminalCourtList = await PopulateCriminalCourtListFromFileDetails(courtList.CriminalCourtList, criminalFileDetails); courtList.CivilCourtList = await PopulateCivilCourtListFromAppearances(courtList.CivilCourtList, civilAppearances); courtList.CriminalCourtList = await PopulateCriminalCourtListFromAppearances(courtList.CriminalCourtList, criminalAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromCourtCalendarDetails(courtList.CivilCourtList, civilCourtCalendarAppearances); courtList.CriminalCourtList = PopulateCriminalCourtListFromCourtCalendarDetails(courtList.CriminalCourtList, criminalCourtCalendarAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromFileContent(courtList.CivilCourtList, civilFileContents); return(courtList); }
public async Task <Models.CourtList.CourtList> CourtListAsync(string agencyId, string roomCode, DateTime proceeding, string divisionCode, string fileNumber) { var proceedingDateString = proceeding.ToString("yyyy-MM-dd"); var agencyCode = await _locationService.GetLocationCodeFromId(agencyId); async Task <CourtList> CourtList() => await _filesClient.FilesCourtlistAsync(agencyId, roomCode, proceedingDateString, divisionCode, fileNumber); async Task <CourtCalendarDetailByDay> CourtCalendarDetailByDay() => await _filesClient.FilesCourtCalendarDetailsByDayAsync(_requestAgencyIdentifierId, _requestPartId, agencyCode, proceeding.ToString("yyyy-MM-dd HH:mm:ss.S"), roomCode); var courtCalendarDetailsTask = _cache.GetOrAdd($"CivilCourtCalendarDetails-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}", CourtCalendarDetailByDay); var originalCourtListTask = _cache.GetOrAddAsync($"CourtList-{agencyId}-{roomCode}-{proceedingDateString}-{fileNumber}", CourtList); //Query by courtCalendarDetails, because it returns quite a bit faster than the courtList. var courtCalendarDetails = await courtCalendarDetailsTask; var civilCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.I); var criminalCourtCalendarAppearances = courtCalendarDetails?.Appearance .WhereToList(app => app.CourtDivisionCd == CourtCalendarDetailAppearanceCourtDivisionCd.R); var civilFileIds = civilCourtCalendarAppearances.SelectToList(ccl => ccl.PhysicalFileId); var criminalFileIds = criminalCourtCalendarAppearances.SelectToList(ccl => ccl.MdocJustinNo); if (civilFileIds.Count == 0 && criminalFileIds.Count == 0) { return(new Models.CourtList.CourtList()); } //Start file details tasks. var civilFileDetailTasks = CivilFileDetailTasks(civilFileIds); var criminalFileDetailTasks = CriminalFileDetailTasks(criminalFileIds); //Start appearances tasks. var civilAppearanceTasks = CivilAppearancesTasks(proceeding, civilFileIds); var criminalAppearanceTasks = CriminalAppearancesTasks(proceeding, criminalFileIds); //Start file content tasks. var civilFileContentTasks = CivilFileContentTasks(civilFileIds); //Await our asynchronous requests. var civilFileDetails = (await civilFileDetailTasks.WhenAll()).ToList(); var criminalFileDetails = (await criminalFileDetailTasks.WhenAll()).ToList(); var civilAppearances = (await civilAppearanceTasks.WhenAll()).ToList(); var criminalAppearances = (await criminalAppearanceTasks.WhenAll()).ToList(); var civilFileContents = (await civilFileContentTasks.WhenAll()).ToList(); var originalCourtList = await originalCourtListTask; var courtList = _mapper.Map <Models.CourtList.CourtList>(originalCourtList); courtList.CivilCourtList = await PopulateCivilCourtListFromFileDetails(courtList.CivilCourtList, civilFileDetails); courtList.CriminalCourtList = await PopulateCriminalCourtListFromFileDetails(courtList.CriminalCourtList, criminalFileDetails); courtList.CivilCourtList = await PopulateCivilCourtListFromAppearances(courtList.CivilCourtList, civilAppearances); courtList.CriminalCourtList = await PopulateCriminalCourtListFromAppearances(courtList.CriminalCourtList, criminalAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromCourtCalendarDetails(courtList.CivilCourtList, civilCourtCalendarAppearances); courtList.CriminalCourtList = PopulateCriminalCourtListFromCourtCalendarDetails(courtList.CriminalCourtList, criminalCourtCalendarAppearances); courtList.CivilCourtList = PopulateCivilCourtListFromFileContent(courtList.CivilCourtList, civilFileContents); return(courtList); }
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); }
public async Task <CriminalAppearanceDetail> AppearanceDetailAsync(string fileId, string appearanceId, string partId) { async Task <CriminalFileDetailResponse> FileDetails() => await _filesClient.FilesCriminalGetAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, fileId); async Task <CriminalFileContent> FileContent() => await _filesClient.FilesCriminalFilecontentAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, null, null, null, null, fileId); async Task <CriminalFileAppearances> Appearances() => await PopulateDetailsAppearancesAsync(fileId, FutureYN.Y, HistoryYN.Y); async Task <CriminalFileAppearanceCountResponse> AppearanceCounts() => await _filesClient.FilesCriminalAppearanceCountsAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, appearanceId); async Task <CriminalFileAppearanceApprMethodResponse> AppearanceMethods() => await _filesClient.FilesCriminalAppearanceAppearancemethodsAsync(_requestAgencyIdentifierId, _requestPartId, _applicationCode, appearanceId); var appearancesTask = _cache.GetOrAddAsync($"CriminalAppearancesFull-{fileId}-{_requestAgencyIdentifierId}", Appearances); var fileDetailTask = _cache.GetOrAddAsync($"CriminalFileDetail-{fileId}-{_requestAgencyIdentifierId}", FileDetails); var fileContentTask = _cache.GetOrAddAsync($"CriminalFileContent-{fileId}-{_requestAgencyIdentifierId}", FileContent); var appearanceCountTask = _cache.GetOrAddAsync($"CriminalAppearanceCounts-{fileId}-{appearanceId}-{_requestAgencyIdentifierId}", AppearanceCounts); var appearanceMethodsTask = _cache.GetOrAddAsync($"CriminalAppearanceMethods-{fileId}-{appearanceId}-{_requestAgencyIdentifierId}", 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(_requestAgencyIdentifierId, _requestPartId, _applicationCode, agencyId, targetAppearance.CourtRoomCd, targetAppearance.AppearanceDt, "CR", detail.FileNumberTxt); var courtList = await _cache.GetOrAddAsync($"CriminalCourtList-{agencyId}-{targetAppearance.CourtRoomCd}-{targetAppearance.AppearanceDt}-{detail.FileNumberTxt}-{_requestAgencyIdentifierId}", 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 = GetInitiatingDocuments(accusedFile.Document), CourtLevelCd = detail.CourtLevelCd }; return(appearanceDetail); }