Skip to content

Commit a80fbde

Browse files
Fix the nex measurement calculations. Before it considers only the time after the moment. Now it considers the time after the moment and after the last measurement scheduling.
1 parent fbef3cd commit a80fbde

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

Backend/protocol/api/views/ProtocolViewSet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def run(self, request):
112112

113113
#Next assigment
114114
protocol = assignment.protocol
115-
ExecutedProtocol.new(protocol=protocol, patient=patient)
115+
last_execution = assignment.schedule_time
116+
ExecutedProtocol.new(protocol=protocol, patient=patient, last_execution=last_execution)
116117

117118
return Response({"results": result})
118119

Backend/protocol/models/ExecutedProtocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def getResult(self):
5050
return actionsResult
5151

5252
@staticmethod
53-
def new(protocol, patient):
54-
schedule_time, scheduleTitle = protocol.getNextScheduleTime()
53+
def new(protocol, patient, last_execution=None):
54+
schedule_time, scheduleTitle = protocol.getNextScheduleTime(last_execution)
5555
scheduleObj = Schedule.objects.get(title=scheduleTitle)
5656
protocol = ExecutedProtocol.objects.create(protocol=protocol,
5757
patient=patient,

Backend/protocol/models/Protocol.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def all():
6969

7070
return tmpAll.order_by('title')
7171

72-
def getNextScheduleTime(self):
72+
def getNextScheduleTime(self, last_execution=None):
7373
'''
7474
Returns next schedule time
7575
:return: tuple (datetime, schedule title)
@@ -81,16 +81,26 @@ def getNextScheduleTime(self):
8181
nextScheduleTime = None
8282
nextScheduleTitle = None
8383
allPossibleTimes = sorted(allPossibleTimes)
84-
8584
for timeObj, scheduleTitle in allPossibleTimes:
86-
if(datetime.now().time() < timeObj.time): #the time is after now
87-
if(nextScheduleTime):
88-
if (timeObj.time < nextScheduleTime.time):
85+
if(last_execution):
86+
if(timeObj.time.hour != last_execution.hour or timeObj.time.minute != last_execution.minute):
87+
if(datetime.now().time() < timeObj.time and last_execution.time() < timeObj.time): #the time is after now
88+
if(nextScheduleTime):
89+
if (timeObj.time < nextScheduleTime.time):
90+
nextScheduleTime = timeObj
91+
nextScheduleTitle = scheduleTitle
92+
else:
93+
nextScheduleTime = timeObj
94+
nextScheduleTitle = scheduleTitle
95+
else:
96+
if (datetime.now().time() < timeObj.time): # the time is after now
97+
if (nextScheduleTime):
98+
if (timeObj.time < nextScheduleTime.time):
99+
nextScheduleTime = timeObj
100+
nextScheduleTitle = scheduleTitle
101+
else:
89102
nextScheduleTime = timeObj
90103
nextScheduleTitle = scheduleTitle
91-
else:
92-
nextScheduleTime = timeObj
93-
nextScheduleTitle = scheduleTitle
94104

95105
if(nextScheduleTime == None):
96106
nextScheduleTime, nextScheduleTitle = allPossibleTimes[0]

0 commit comments

Comments
 (0)