Skip to content

Commit 6c4c6a8

Browse files
authored
VED-352: Add last time of day to end date (#583)
make end period have the end time of day
1 parent 6858f5e commit 6c4c6a8

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

delta_backend/src/extractor.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,22 @@ def _get_practitioner_names(self):
7777

7878
return performing_professional_forename, performing_professional_surname
7979

80-
8180
def _is_current_period(self, name, occurrence_time):
8281
period = name.get("period")
8382
if not isinstance(period, dict):
8483
return True # If no period is specified, assume it's valid
8584

8685
start = datetime.fromisoformat(period.get("start")) if period.get("start") else None
87-
end = datetime.fromisoformat(period.get("end")) if period.get("end") else None
88-
86+
end_str = period.get("end")
87+
end = datetime.fromisoformat(period.get("end")) if end_str else None
8988
# Ensure all datetime objects are timezone-aware
9089
if start and start.tzinfo is None:
9190
start = start.replace(tzinfo=timezone.utc)
91+
if end and "T" not in end_str:
92+
# If end is a date-only string like "2025-06-12", upgrade to full end-of-day
93+
end = end.replace(hour=23, minute=59, second=59, microsecond=999999)
9294
if end and end.tzinfo is None:
95+
# If end still has no timezone info, assign UTC
9396
end = end.replace(tzinfo=timezone.utc)
9497

9598
return (not start or start <= occurrence_time) and (not end or occurrence_time <= end)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import unittest
2+
from datetime import datetime, timezone
3+
from src.extractor import Extractor
4+
5+
6+
class TestIsCurrentPeriod(unittest.TestCase):
7+
def setUp(self):
8+
self.extractor = Extractor(fhir_json_data={})
9+
self.occurrence = datetime(2025, 6, 12, 13, 0, 0, tzinfo=timezone.utc)
10+
11+
def test_valid_period_in_range(self):
12+
name = {"period": {"start": "2025-06-01", "end": "2025-06-12"}}
13+
result = self.extractor._is_current_period(name, self.occurrence)
14+
self.assertTrue(result)
15+
16+
def test_occurrence_after_end(self):
17+
name = {"period": {"start": "2025-06-01", "end": "2025-06-11"}}
18+
result = self.extractor._is_current_period(name, self.occurrence)
19+
self.assertFalse(result)
20+
21+
def test_occurrence_before_start(self):
22+
name = {"period": {"start": "2025-06-13", "end": "2025-06-20"}}
23+
result = self.extractor._is_current_period(name, self.occurrence)
24+
self.assertFalse(result)
25+
26+
def test_date_only_end(self):
27+
name = {"period": {"end": "2025-06-12"}}
28+
result = self.extractor._is_current_period(name, self.occurrence)
29+
self.assertTrue(result) # because end-of-day logic applies
30+
31+
def test_no_period(self):
32+
name = {}
33+
result = self.extractor._is_current_period(name, self.occurrence)
34+
self.assertTrue(result)
35+
36+
if __name__ == '__main__':
37+
unittest.main()

0 commit comments

Comments
 (0)