Skip to content

Commit b24d95d

Browse files
authored
Merge pull request #455 from smart-on-fhir/mikix/upload-date
upload-notes: add a date metadata field, for downstream scripting
2 parents 6e5cb27 + 6fcbc46 commit b24d95d

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

cumulus_etl/upload_notes/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def group_notes_by_unique_id(notes: Collection[LabelStudioNote]) -> list[LabelSt
300300
group_notes[0].encounter_id,
301301
group_notes[0].anon_encounter_id,
302302
text=grouped_text,
303+
date=group_notes[0].date,
303304
doc_mappings=grouped_doc_mappings,
304305
doc_spans=grouped_doc_spans,
305306
ctakes_matches=grouped_ctakes_matches,

cumulus_etl/upload_notes/labelstudio.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def _format_task_for_note(self, note: LabelStudioNote) -> dict:
160160
"anon_patient_id": note.anon_patient_id,
161161
"encounter_id": note.encounter_id,
162162
"anon_encounter_id": note.anon_encounter_id,
163+
"date": note.date and note.date.isoformat(),
163164
"docref_mappings": note.doc_mappings,
164165
# json doesn't natively have tuples, so convert spans to lists
165166
"docref_spans": {k: list(v) for k, v in note.doc_spans.items()},

tests/upload_notes/test_upload_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ async def test_grouped_datetime(self):
502502
self.assertEqual(1, len(notes))
503503
note = notes[0]
504504

505+
self.assertEqual(note.date.isoformat(), "2018-01-01T00:00:00")
506+
505507
# The order will be oldest->newest (None placed last)
506508
self.assertEqual(
507509
self.wrap_note("Document", "DocRef 3", date="01/01/18")

tests/upload_notes/test_upload_labelstudio.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for cumulus.upload_notes.labelstudio.py"""
22

3+
import datetime
34
from unittest import mock
45

56
import ddt
@@ -26,7 +27,11 @@ def setUp(self):
2627

2728
@staticmethod
2829
def make_note(
29-
*, unique_id: str = "unique", ctakes: bool = True, philter_label: bool = True
30+
*,
31+
unique_id: str = "unique",
32+
ctakes: bool = True,
33+
philter_label: bool = True,
34+
**kwargs,
3035
) -> LabelStudioNote:
3136
text = "Normal note text"
3237
note = LabelStudioNote(
@@ -38,6 +43,7 @@ def make_note(
3843
doc_mappings={"doc": "doc-anon"},
3944
doc_spans={"doc": (0, len(text))},
4045
text=text,
46+
**kwargs,
4147
)
4248
if ctakes:
4349
note.ctakes_matches = ctakesmock.fake_ctakes_extract(note.text).list_match(
@@ -71,7 +77,7 @@ def get_pushed_task(self) -> dict:
7177
return imported_tasks[0]
7278

7379
async def test_basic_push(self):
74-
await self.push_tasks(self.make_note())
80+
await self.push_tasks(self.make_note(date=datetime.datetime(2010, 10, 10)))
7581
self.assertEqual(
7682
{
7783
"data": {
@@ -81,6 +87,7 @@ async def test_basic_push(self):
8187
"anon_patient_id": "patient-anon",
8288
"encounter_id": "enc",
8389
"anon_encounter_id": "enc-anon",
90+
"date": "2010-10-10T00:00:00",
8491
"docref_mappings": {"doc": "doc-anon"},
8592
"docref_spans": {"doc": [0, 16]},
8693
"mylabel": [{"value": "Itch"}, {"value": "Nausea"}],
@@ -174,6 +181,7 @@ async def test_no_predictions(self):
174181
"anon_patient_id": "patient-anon",
175182
"encounter_id": "enc",
176183
"anon_encounter_id": "enc-anon",
184+
"date": None,
177185
"docref_mappings": {"doc": "doc-anon"},
178186
"docref_spans": {"doc": [0, 16]},
179187
"mylabel": [],
@@ -198,6 +206,7 @@ async def test_dynamic_labels(self, label_type):
198206
"anon_patient_id": "patient-anon",
199207
"encounter_id": "enc",
200208
"anon_encounter_id": "enc-anon",
209+
"date": None,
201210
"docref_mappings": {"doc": "doc-anon"},
202211
"docref_spans": {"doc": [0, 16]},
203212
"mylabel": [
@@ -218,6 +227,7 @@ async def test_dynamic_labels_no_predictions(self):
218227
"anon_patient_id": "patient-anon",
219228
"encounter_id": "enc",
220229
"anon_encounter_id": "enc-anon",
230+
"date": None,
221231
"docref_mappings": {"doc": "doc-anon"},
222232
"docref_spans": {"doc": [0, 16]},
223233
"mylabel": [], # this needs to be sent, or the server will complain
@@ -276,6 +286,7 @@ async def test_push_highlights(self):
276286
"anon_patient_id": "patient-anon",
277287
"encounter_id": "enc",
278288
"anon_encounter_id": "enc-anon",
289+
"date": None,
279290
"docref_mappings": {"doc": "doc-anon"},
280291
"docref_spans": {"doc": [0, 16]},
281292
"mylabel": [{"value": "Label1"}, {"value": "Label2"}],

0 commit comments

Comments
 (0)