Skip to content

Commit 30f0d6b

Browse files
committed
feat: add purpose field to preparations
1 parent 8cae525 commit 30f0d6b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

dataimporter/emu/views/preparation.py

+22
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ def transform(self, record: SourceRecord) -> dict:
174174
"preparationContents": gf("EntPreContents", "PrtType", "PreBodyPart"),
175175
"preparationProcess": get_preparation_process(record),
176176
"preparationDate": gf("EntPreDate"),
177+
# todo: field name?
178+
"purpose": get_purpose(record),
177179
}
178180

179181
# add specimen data if available
@@ -245,3 +247,23 @@ def get_preparation_process(record: SourceRecord) -> Optional[str]:
245247
return None
246248
else:
247249
return re.sub(r"^killing agent:?\s*", "", process, count=1, flags=re.I)
250+
251+
252+
def get_purpose(record: SourceRecord) -> Optional[str]:
253+
"""
254+
Given a record, extract the purpose of specimen value from a note text field. We
255+
don't know which note text field it will be because there's no note type, so we just
256+
look for the first note text value which starts "purpose of specimen:".
257+
258+
:param record: the record
259+
:return: the purpose value or None if it was not found
260+
"""
261+
# find all the note text fields
262+
note_fields = [key for key in record.data.keys() if key.startswith("NteText")]
263+
if note_fields:
264+
for value in record.iter_all_values(*note_fields):
265+
if value.lower().startswith("purpose of specimen:"):
266+
# "purpose of specimen:" is 20 chars long
267+
return value[20:].strip()
268+
269+
return None

0 commit comments

Comments
 (0)