Source:
<code>private void checkNumberOfPatientsAndSetScreeningData(ScreeningDto screeningDto, Screening screening, Boolean ignoreLimitation) { Clinic clinic = clinicDataService.findById(Long.parseLong(screeningDto.getClinicId())); LocalDate date = LocalDate.parse(screeningDto.getDate()); Time startTime; Time endTime; if (StringUtils.isNotBlank(screeningDto.getStartTime())) { startTime = Time.valueOf(screeningDto.getStartTime()); endTime = calculateEndTime(startTime); } else { startTime = null; endTime = null; } if (!ignoreLimitation) { visitLimitationHelper.checkCapacityForScreening(date, clinic, screening.getId()); List<Screening> screeningList = screeningDataService.findByDateAndClinicId(date, clinic.getId()); if (screeningList != null) { int numberOfRooms = clinic.getNumberOfRooms(); int maxVisits = clinic.getMaxScreeningVisits(); int patients = 0; for (Screening s : screeningList) { if (s.getId().equals(screening.getId())) { maxVisits++; } else if (startTime != null) { if (startTime.isBefore(s.getStartTime())) { <START> if (s.getStartTime().isBefore(endTime)) { <END> patients++; } } else { if (startTime.isBefore(s.getEndTime())) { patients++; } } } } if (screeningList.size() >= maxVisits) { throw new LimitationExceededException("The limit of the type of the visit is reached for this day"); } if (patients >= numberOfRooms) { throw new LimitationExceededException("Too many visits at the same time"); } } } screening.setDate(date); screening.setStartTime(startTime); screening.setEndTime(endTime); screening.setClinic(clinic); }</code><technical_language>s.getStartTime() null also, need check</technical_language>

Target:
private void checkNumberOfPatientsAndSetScreeningData(ScreeningDto screeningDto, Screening screening, Boolean ignoreLimitation) { Clinic clinic = clinicDataService.findById(Long.parseLong(screeningDto.getClinicId())); LocalDate date = LocalDate.parse(screeningDto.getDate()); Time startTime; Time endTime; if (StringUtils.isNotBlank(screeningDto.getStartTime())) { startTime = Time.valueOf(screeningDto.getStartTime()); endTime = calculateEndTime(startTime); } else { startTime = null; endTime = null; } if (!ignoreLimitation) { visitLimitationHelper.checkCapacityForScreening(date, clinic, screening.getId()); List<Screening> screeningList = screeningDataService.findByDateAndClinicId(date, clinic.getId()); if (screeningList != null) { int numberOfRooms = clinic.getNumberOfRooms(); int maxVisits = clinic.getMaxScreeningVisits(); int patients = 0; for (Screening s : screeningList) { if (s.getId().equals(screening.getId())) { maxVisits++; } else if (startTime != null && s.getStartTime() != null) { if (startTime.isBefore(s.getStartTime())) { if (s.getStartTime().isBefore(endTime)) { patients++; } } else { if (startTime.isBefore(s.getEndTime())) { patients++; } } } } if (screeningList.size() >= maxVisits) { throw new LimitationExceededException("The limit of the type of the visit is reached for this day"); } if (patients >= numberOfRooms) { throw new LimitationExceededException("Too many visits at the same time"); } } } screening.setDate(date); screening.setStartTime(startTime); screening.setEndTime(endTime); screening.setClinic(clinic); }