Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
package com.iemr.tm.service.schedule;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -37,6 +40,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.iemr.tm.data.schedule.Slot;
import com.iemr.tm.data.schedule.SpecialistAvailability;
Expand Down Expand Up @@ -91,9 +95,15 @@ private static String updateString(String slotdetail, Timestamp startTime, Times
// A - Available doctor is on duty hours
// B - Booked slot for doctor
// C - Cancel appointment
Integer startslot = ((startTime.getHours() * 60) + (startTime.getMinutes())) / 5;
Integer endslot = ((endTime.getHours() * 60) + (endTime.getMinutes())) / 5;

LocalTime startLocal = startTime.toLocalDateTime().toLocalTime();
LocalTime endLocal = endTime.toLocalDateTime().toLocalTime();
Integer startslot = ((startLocal.getHour() * 60) + startLocal.getMinute()) / 5;
Integer endslot = ((endLocal.getHour() * 60) + endLocal.getMinute()) / 5;

if (startslot < 0 || endslot > slotdetail.length() || startslot >= endslot)
throw new TMException("Invalid slot window: startslot " + startslot + " endslot " + endslot
+ " for slotdetail length " + slotdetail.length());

String currentstatus = slotdetail.substring(startslot, endslot);

Comment thread
coderabbitai[bot] marked this conversation as resolved.
StringBuilder slotfinal = new StringBuilder();
Expand Down Expand Up @@ -130,6 +140,7 @@ private static String updateString(String slotdetail, Timestamp startTime, Times
}

@Override
@Transactional(rollbackFor = TMException.class)
public SpecialistAvailabilityDetail markAvailability(SpecialistAvailabilityDetail specialistInput)
throws TMException {

Expand All @@ -140,16 +151,18 @@ public SpecialistAvailabilityDetail markAvailability(SpecialistAvailabilityDetai

logger.info("specialistInput result" + specialistInput.toString());
Date temp = specialistInput.getConfiguredFromDate();
final Date startDate = new Date(temp.getYear(), temp.getMonth(), temp.getDate());

final Date startDate = Date.from(
LocalDate.ofInstant(temp.toInstant(), ZoneId.systemDefault()).atStartOfDay(ZoneId.systemDefault()).toInstant());

Date temp1 = specialistInput.getConfiguredToDate();
final Date endDate = new Date(temp1.getYear(), temp1.getMonth(), temp1.getDate());
final Date endDate = Date.from(
LocalDate.ofInstant(temp1.toInstant(), ZoneId.systemDefault()).atStartOfDay(ZoneId.systemDefault()).toInstant());
final String createdBy = specialistInput.getCreatedBy();
final Long userID = specialistInput.getUserID();

Integer durationDays = (int) ((endDate.getTime() - startDate.getTime()) / 86400000);

LocalDate startLocalDate = LocalDate.ofInstant(startDate.toInstant(), ZoneId.systemDefault());
LocalDate endLocalDate = LocalDate.ofInstant(endDate.toInstant(), ZoneId.systemDefault());
long durationDays = ChronoUnit.DAYS.between(startLocalDate, endLocalDate);

Timestamp startTime = specialistInput.getConfiguredFromTime();
Timestamp endTime = specialistInput.getConfiguredToTime();
Expand All @@ -172,35 +185,28 @@ public SpecialistAvailabilityDetail markAvailability(SpecialistAvailabilityDetai


List<Integer> excludedays = specialistInput.getExcludeDays();
IntStream.rangeClosed(0, durationDays).forEach(e -> {

try {
Date i = new Date(startDate.getTime());
i.setDate(i.getDate() + e);
Integer day = i.getDay();
if (!(excludedays != null && excludedays.size() > 0 && excludedays.contains(day))) {
System.out.println(i);
SpecialistAvailability now = result.get(i);
if (now == null) {
now = new SpecialistAvailability();
now.setUserID(userID);
now.setConfiguredDate((Date) i.clone());
now.setTimeSlot(initializeString());
now.setCreatedBy(createdBy);
} else {
now.setModifiedBy(createdBy);
}
now.setTimeSlot(updateString(now.getTimeSlot(), startTime, endTime, 'A'));

output.add(now);
logger.info("printintg" + now.toString());
for (long e = 0; e <= durationDays; e++) {
LocalDate d = startLocalDate.plusDays(e);
Date i = Date.from(d.atStartOfDay(ZoneId.systemDefault()).toInstant());
Integer day = i.getDay();
if (!(excludedays != null && excludedays.size() > 0 && excludedays.contains(day))) {
System.out.println(i);
SpecialistAvailability now = result.get(i);
if (now == null) {
now = new SpecialistAvailability();
now.setUserID(userID);
now.setConfiguredDate((Date) i.clone());
now.setTimeSlot(initializeString());
now.setCreatedBy(createdBy);
} else {
now.setModifiedBy(createdBy);
}
now.setTimeSlot(updateString(now.getTimeSlot(), startTime, endTime, 'A'));

} catch (TMException e1) {

e1.printStackTrace();
output.add(now);
logger.info("printintg" + now.toString());
}
});
}
logger.info("output result" + output.toString());
specialistAvailabilityRepo.saveAll(output);
specialistInput = specialistAvailabilityDetailRepo.save(specialistInput);
Expand All @@ -214,7 +220,8 @@ public SpecialistAvailabilityDetail markUnavailability(SpecialistAvailabilityDet
throws TMException {

Date temp = specialistInput.getConfiguredFromDate();
Date startDate = new Date(temp.getYear(), temp.getMonth(), temp.getDate());
Date startDate = Date.from(
LocalDate.ofInstant(temp.toInstant(), ZoneId.systemDefault()).atStartOfDay(ZoneId.systemDefault()).toInstant());

Timestamp startTime = specialistInput.getConfiguredFromTime();
Timestamp endTime = specialistInput.getConfiguredToTime();
Expand Down Expand Up @@ -299,7 +306,8 @@ public List<Slot> getslotsplit(String slot) {
public String bookSlot(SpecialistInput2 specialistInput, char status) throws TMException {

Date temp = specialistInput.getDate();
Date startDate = new Date(temp.getYear(), temp.getMonth(), temp.getDate());
Date startDate = Date.from(
LocalDate.ofInstant(temp.toInstant(), ZoneId.systemDefault()).atStartOfDay(ZoneId.systemDefault()).toInstant());

SpecialistAvailability slotdetails = specialistAvailabilityRepo.findOneByConfiguredDateAndUserID(startDate,
specialistInput.getUserID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
package com.iemr.tm.service.specialist;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -36,6 +39,8 @@
@Service
public class SpecialistServiceImpl implements SpecialistService {

final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Autowired
SpecializationRepo specializationRepo;

Expand Down Expand Up @@ -73,6 +78,10 @@ public List<Specialist> getAllSpecialist(Long providerservicemapID) {
List<Object[]> obj = specializationRepo.getAllSPecialistForProvider(providerservicemapID);
if (obj.size() > 0) {
for (Object[] action : obj) {
if (action.length < 7) {
logger.warn("Skipping malformed specialist row: {}", Arrays.toString(action));
continue;
}
specialistList.add(new Specialist(null, ((Number) action[0]).longValue(), (String) action[1],
(String) action[2], (String) action[3], ((Number) action[6]).longValue(), null, null, null,
null, (String) action[4]));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/iemr/tm/utils/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public void invalidateToken(String token) {
}
}
} catch (Exception e) {
// Log error but don't throw - token might be invalid already
throw new RuntimeException("Failed to invalidate token", e);
// Token is already expired or invalid — nothing to denylist, treat as success
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static int getRedisPort() {

public static boolean getExtendExpiryTime() {
if (extendExpiryTime == null) {
extendExpiryTime = getBoolean("iemr.session.expiry.time");
extendExpiryTime = getBoolean("iemr.extend.expiry.time");
}
return extendExpiryTime;
}
Expand Down