Skip to content

Commit

Permalink
feat: add purpose field to preparations
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdh committed Sep 19, 2024
1 parent 8cae525 commit 30f0d6b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions dataimporter/emu/views/preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ def transform(self, record: SourceRecord) -> dict:
"preparationContents": gf("EntPreContents", "PrtType", "PreBodyPart"),
"preparationProcess": get_preparation_process(record),
"preparationDate": gf("EntPreDate"),
# todo: field name?
"purpose": get_purpose(record),
}

# add specimen data if available
Expand Down Expand Up @@ -245,3 +247,23 @@ def get_preparation_process(record: SourceRecord) -> Optional[str]:
return None
else:
return re.sub(r"^killing agent:?\s*", "", process, count=1, flags=re.I)


def get_purpose(record: SourceRecord) -> Optional[str]:
"""
Given a record, extract the purpose of specimen value from a note text field. We
don't know which note text field it will be because there's no note type, so we just
look for the first note text value which starts "purpose of specimen:".
:param record: the record
:return: the purpose value or None if it was not found
"""
# find all the note text fields
note_fields = [key for key in record.data.keys() if key.startswith("NteText")]
if note_fields:
for value in record.iter_all_values(*note_fields):
if value.lower().startswith("purpose of specimen:"):
# "purpose of specimen:" is 20 chars long
return value[20:].strip()

return None

0 comments on commit 30f0d6b

Please sign in to comment.