Skip to content

Commit

Permalink
Interim 5 release (#815)
Browse files Browse the repository at this point in the history
* Task/JS-151 When a juror is returned from a trial, unable to check out juror (#812)

* task/JS-151 When a juror is returned from a trial, unable to check out juror

* Update PanelRepositoryImpl.java

* Update PanelRepositoryImpl.java

* task/JS-139 Empanelled juror can show in juror in waiting (#813)

* task/JS-139 Empanelled juror can show in juror in waiting

* update to logic after testing

* task/JS-156 Confirming old trial attendance doesn't add trial number to appearance record (#814)

* Task/js 139 (#816)

* task/JS-139 Empanelled juror can show in juror in waiting

* update to logic after testing

* Update ITrialRepositoryImpl.java
  • Loading branch information
akikrahman1 authored Dec 2, 2024
1 parent 03840b7 commit 87ec170
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2164,38 +2164,43 @@ void confirmAttendanceHappy() {
assertThat(response.getStatusCode()).as("HTTP status OK expected")
.isEqualTo(OK);

// verify attendance records have been updated
Optional<Appearance> appearanceOpt =
appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate(
"415", "222222222", now().minusDays(2));
assertThat(appearanceOpt).isNotEmpty();
Appearance appearance = appearanceOpt.get();
assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30));
assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 00));
assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED);
assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456");
assertThat(appearance.getSatOnJury()).isTrue();
assertThat(appearance.isAppearanceConfirmed()).isTrue();

appearanceOpt = appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate(
"415", "333333333", now().minusDays(2));
assertThat(appearanceOpt).isNotEmpty();
appearance = appearanceOpt.get();
assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30));
assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 0));
assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED);
assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456");
assertThat(appearance.getSatOnJury()).isTrue();
assertThat(appearance.isAppearanceConfirmed()).isTrue();

// verify juror history records have been created
assertThat(jurorHistoryRepository.findByJurorNumberOrderById("222222222")
.stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE)
&& "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue();

assertThat(jurorHistoryRepository.findByJurorNumberOrderById("333333333")
.stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE)
&& "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue();
executeInTransaction(() -> {

// verify attendance records have been updated
Optional<Appearance> appearanceOpt =
appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate(
"415", "222222222", now().minusDays(2));
assertThat(appearanceOpt).isNotEmpty();
Appearance appearance = appearanceOpt.get();
assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30));
assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 00));
assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED);
assertThat(appearance.getTrialNumber()).isEqualTo("T10000001");
assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456");
assertThat(appearance.getSatOnJury()).isTrue();
assertThat(appearance.isAppearanceConfirmed()).isTrue();

appearanceOpt = appearanceRepository.findByLocCodeAndJurorNumberAndAttendanceDate(
"415", "333333333", now().minusDays(2));
assertThat(appearanceOpt).isNotEmpty();
appearance = appearanceOpt.get();
assertThat(appearance.getTimeIn()).isEqualTo(LocalTime.of(9, 30));
assertThat(appearance.getTimeOut()).isEqualTo(LocalTime.of(17, 0));
assertThat(appearance.getAppearanceStage()).isEqualTo(EXPENSE_ENTERED);
assertThat(appearance.getTrialNumber()).isEqualTo("T10000001");
assertThat(appearance.getAttendanceAuditNumber()).isEqualTo("J10123456");
assertThat(appearance.getSatOnJury()).isTrue();
assertThat(appearance.isAppearanceConfirmed()).isTrue();

// verify juror history records have been created
assertThat(jurorHistoryRepository.findByJurorNumberOrderById("222222222")
.stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE)
&& "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue();

assertThat(jurorHistoryRepository.findByJurorNumberOrderById("333333333")
.stream().anyMatch(jh -> jh.getHistoryCode().equals(HistoryCodeMod.JURY_ATTENDANCE)
&& "J10123456".equalsIgnoreCase(jh.getOtherInformationRef()))).isTrue();
});
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
insert into juror_mod.trial (trial_number, loc_code, description, judge, trial_type, trial_start_date, anonymous,
courtroom)
values ('T10000000', '415', 'TEST DEFENDANT', 999992, 'CIV', current_date, false, 99995);
values ('T10000000', '415', 'TEST DEFENDANT', 999992, 'CIV', current_date, false, 99995),
('T10000001', '415', 'TEST DEFENDANT2', 999992, 'CIV', current_date, false, 99995);

INSERT INTO juror_mod.juror_trial (loc_code, juror_number, trial_number, rand_number, date_selected, "result",
completed)
values ('415', '222222222', 'T10000000', 10, '2024-02-22 13:50:59.110', 'J', true),
('415', '333333333', 'T10000000', 5, '2024-02-22 13:50:58.821', 'J', true);
values ('415', '222222222', 'T10000001', 10, '2024-02-22 13:50:59.110', 'J', true),
('415', '333333333', 'T10000001', 5, '2024-02-22 13:50:58.821', 'J', true);

--JUROR_MOD.POOL
INSERT INTO JUROR_MOD.POOL (OWNER, POOL_NO, RETURN_DATE, TOTAL_NO_REQUIRED, NO_REQUESTED, POOL_TYPE, LOC_CODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,21 @@ private JPAQuery<Tuple> sqlFetchAppearanceRecords(String locCode, LocalDate date
.on(JUROR.jurorNumber.eq(APPEARANCE.jurorNumber)
.and(APPEARANCE.courtLocation.eq(JUROR_POOL.pool.courtLocation)))
.leftJoin(PANEL)
.on(APPEARANCE.jurorNumber.eq(PANEL.juror.jurorNumber))
.on(APPEARANCE.jurorNumber.eq(PANEL.juror.jurorNumber)
.and(APPEARANCE.trialNumber.eq(PANEL.trial.trialNumber)))
.where(APPEARANCE.courtLocation.locCode.eq(locCode))
.where(APPEARANCE.attendanceDate.eq(date))
.where(JUROR_POOL.isActive.isTrue());

if (statusGroup == JurorStatusGroup.IN_WAITING) {
query.where(APPEARANCE.attendanceAuditNumber.isNull()
.or(APPEARANCE.attendanceAuditNumber.startsWith("J").not()));
query.where(APPEARANCE.trialNumber.isNull().or(APPEARANCE.trialNumber.eq(PANEL.trial.trialNumber)
.and(PANEL.empanelledDate.isNull()
query.where(APPEARANCE.trialNumber.isNull().or(PANEL.empanelledDate.isNull()
.and(PANEL.result.isNotNull()))
.or(PANEL.returnDate.isNotNull()
.and(PANEL.empanelledDate.isNotNull())
.and(PANEL.returnDate.loe(date)
.or(PANEL.empanelledDate.after(date))))));
.or(PANEL.empanelledDate.after(date)))));

}

Expand All @@ -180,15 +180,9 @@ private JPAQuery<Tuple> sqlFetchAppearanceRecords(String locCode, LocalDate date
}

if (statusGroup == JurorStatusGroup.ON_TRIAL) {
query.where((APPEARANCE.trialNumber.isNotNull().and(APPEARANCE.trialNumber.eq(PANEL.trial.trialNumber)
.and(PANEL.empanelledDate.isNotNull()
.and(PANEL.empanelledDate.loe(date)
.and(PANEL.returnDate.isNull()
.or(PANEL.returnDate
.goe(date)))))))
.or(PANEL.empanelledDate.isNotNull()
query.where(PANEL.empanelledDate.isNotNull()
.and(PANEL.empanelledDate.loe(date))
.and(PANEL.returnDate.isNull().or(PANEL.returnDate.goe(date)))));
.and(PANEL.returnDate.isNull().or(PANEL.returnDate.after(date))));
}

return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import uk.gov.hmcts.juror.api.moj.domain.trial.QPanel;
import uk.gov.hmcts.juror.api.moj.domain.trial.QTrial;
import uk.gov.hmcts.juror.api.moj.domain.trial.Trial;
import uk.gov.hmcts.juror.api.moj.enumeration.trial.PanelResult;
import uk.gov.hmcts.juror.api.moj.utils.PaginationUtil;
import uk.gov.hmcts.juror.api.moj.utils.SecurityUtil;

Expand Down Expand Up @@ -82,7 +81,7 @@ public List<Tuple> getActiveTrialsWithJurorCount(String locationCode, LocalDate
.where(TRIAL.trialEndDate.isNull().or(TRIAL.trialEndDate.goe(attendanceDate)))
//If they are a JUROR or Panelled or have an appearance with a jury confirmation audit number
.where((PANEL.empanelledDate.isNotNull().and(PANEL.returnDate.isNull()
.or(PANEL.returnDate.goe(attendanceDate))))
.or(PANEL.returnDate.after(attendanceDate))))
.or(APPEARANCE.isNotNull())
.or(PANEL.empanelledDate.isNull().and(PANEL.result.isNull())))
.groupBy(TRIAL.trialNumber, TRIAL.description, TRIAL.trialType, TRIAL.courtroom.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.persistence.PersistenceContext;
import uk.gov.hmcts.juror.api.juror.domain.QCourtLocation;
import uk.gov.hmcts.juror.api.moj.domain.IJurorStatus;
import uk.gov.hmcts.juror.api.moj.domain.QAppearance;
import uk.gov.hmcts.juror.api.moj.domain.QJurorPool;
import uk.gov.hmcts.juror.api.moj.domain.trial.Panel;
import uk.gov.hmcts.juror.api.moj.domain.trial.QPanel;
Expand All @@ -22,6 +23,7 @@ public class PanelRepositoryImpl implements IPanelRepository {
private static final QTrial TRIAL = QTrial.trial;
private static final QCourtLocation COURT_LOCATION = QCourtLocation.courtLocation;
private static final QJurorPool JUROR_POOL = QJurorPool.jurorPool;
private static final QAppearance APPEARANCE = QAppearance.appearance;

/**
* Retrieves members that are on trial i.e. panel/jury.
Expand Down Expand Up @@ -57,13 +59,17 @@ public boolean isEmpanelledJuror(String jurorNumber, String locationCode, LocalD
.from(PANEL)
.join(JUROR_POOL)
.on(PANEL.juror.eq(JUROR_POOL.juror))
.leftJoin(APPEARANCE)
.on(PANEL.trial.trialNumber.eq(APPEARANCE.trialNumber)
.and(PANEL.juror.jurorNumber.eq(APPEARANCE.jurorNumber))
.and(APPEARANCE.attendanceDate.eq(date)))
.where(PANEL.juror.jurorNumber.eq(jurorNumber))
.where(JUROR_POOL.pool.courtLocation.locCode.eq(locationCode))
.where(JUROR_POOL.isActive.isTrue())
.where(PANEL.completed.isTrue())
.where(PANEL.empanelledDate.isNotNull().and(PANEL.empanelledDate.loe(date)
.and(PANEL.returnDate.isNull()
.or(PANEL.returnDate.goe(date)))))
.or(PANEL.returnDate.after(date)))))
.fetch().isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,11 @@ public void confirmJuryAttendance(UpdateAttendanceDto request) {
final String locCode = request.getCommonData().getLocationCode();

// see if there is an attendance record for the date to get the audit number
String trialNumber = request.getTrialNumber();
List<Appearance> appearances = appearanceRepository.findByLocCodeAndAttendanceDateAndTrialNumber(locCode,
request.getCommonData().getAttendanceDate(), request.getTrialNumber());
request.getCommonData().getAttendanceDate(),
trialNumber
);

final String juryAttendancePrefix = "J";
String juryAttendanceNumber;
Expand Down Expand Up @@ -660,15 +663,22 @@ public void confirmJuryAttendance(UpdateAttendanceDto request) {
appearance.setSatOnJury(true);

// update appearance by adding the trial number
if (IJurorStatus.JUROR == jurorPool.getStatus().getStatus()) {
// get the currently active trial the juror is on
Panel panel = panelRepository.findActivePanel(locCode, jurorNumber);
if (panel != null) {
appearance.setTrialNumber(panel.getTrial().getTrialNumber());
jurorHistoryService.createJuryAttendanceHistory(jurorPool, appearance, panel);
}
Panel panel;
if (trialNumber == null) {
panel = panelRepository.findActivePanel(locCode, jurorNumber);
} else {
panel = panelRepository.findByTrialTrialNumberAndTrialCourtLocationLocCodeAndJurorJurorNumber(
trialNumber, locCode, jurorNumber);
}

if (panel == null) {
log.info("Panel not found for juror {} on trial {}", jurorNumber, trialNumber);
throw new MojException.NotFound("Panel not found for juror " + jurorNumber, null);
}

appearance.setTrialNumber(panel.getTrial().getTrialNumber());
jurorHistoryService.createJuryAttendanceHistory(jurorPool, appearance, panel);

appearanceRepository.saveAndFlush(appearance);
jurorExpenseService.applyDefaultExpenses(appearance, jurorPool.getJuror());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public List<PanelListDto> getPanelSummary(String trialNumber, String locCode, Lo
panelRepository.findByTrialTrialNumberAndTrialCourtLocationLocCode(trialNumber, locCode);
for (Panel panel : panelList) {
if (panel.getResult() == null || panel.getResult() == PanelResult.JUROR
|| (date != null && panel.getReturnDate() != null && panel.getReturnDate().isAfter(date.minusDays(1))
|| (date != null && panel.getReturnDate() != null && panel.getReturnDate().isAfter(date)
&& date.atTime(23,59).isAfter(panel.getDateSelected()))) {
dtoList.add(createPanelListDto(panel));
}
Expand Down

0 comments on commit 87ec170

Please sign in to comment.