@@ -174,6 +174,8 @@ def transform(self, record: SourceRecord) -> dict:
174
174
"preparationContents" : gf ("EntPreContents" , "PrtType" , "PreBodyPart" ),
175
175
"preparationProcess" : get_preparation_process (record ),
176
176
"preparationDate" : gf ("EntPreDate" ),
177
+ # todo: field name?
178
+ "purpose" : get_purpose (record ),
177
179
}
178
180
179
181
# add specimen data if available
@@ -245,3 +247,23 @@ def get_preparation_process(record: SourceRecord) -> Optional[str]:
245
247
return None
246
248
else :
247
249
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