@@ -330,13 +330,41 @@ def import_records(
330330 def delete_records (
331331 self ,
332332 records : List [str ],
333+ arm : Optional [str ] = None ,
334+ instrument : Optional [str ] = None ,
335+ event : Optional [str ] = None ,
336+ repeat_instance : Optional [int ] = None ,
337+ delete_logging : bool = False ,
333338 return_format_type : Literal ["json" , "csv" , "xml" ] = "json" ,
334339 ):
340+ # pylint: disable=line-too-long
335341 """
336342 Delete records from the project.
337343
338344 Args:
339345 records: List of record IDs to delete from the project
346+ arm:
347+ the arm number of the arm in which the record(s) should be deleted.
348+ (This can only be used if the project is longitudinal with more than one arm.)
349+ NOTE: If the arm parameter is not provided, the specified records will be
350+ deleted from all arms in which they exist. Whereas, if arm is provided,
351+ they will only be deleted from the specified arm.
352+ instrument:
353+ the unique instrument name (column B in the Data Dictionary) of an
354+ instrument (as a string) if you wish to delete the data for all fields
355+ on the specified instrument for the records specified.
356+ event:
357+ the unique event name - only for longitudinal projects. NOTE: If
358+ instrument is provided for a longitudinal project, the event parameter
359+ is mandatory.
360+ repeat_instance:
361+ the repeating instance number for a repeating instrument or repeating event.
362+ NOTE: If project has repeating instruments/events, it will remove only the
363+ data for that repeating instance.
364+ delete_logging:
365+ provide a value of False ("keep logging") or True ("delete logging"). This
366+ activity when deleting the record?" setting enabled by an administrator on
367+ the Edit Project Settings page. The default value for PyCap is False
340368 return_format_type:
341369 Response format. By default, response will be json-decoded.
342370
@@ -352,11 +380,38 @@ def delete_records(
352380 {'count': 2}
353381 >>> proj.delete_records(["3", "4"])
354382 2
383+ >>> new_record = [
384+ ... {"record_id": 3, "redcap_event_name": "event_1_arm_1", "redcap_repeat_instance": 1, "field_1": 1,},
385+ ... {"record_id": 3, "redcap_event_name": "event_1_arm_1", "redcap_repeat_instance": 2, "field_1": 0,},
386+ ... ]
387+ >>> proj.import_records(new_record)
388+ {'count': 1}
389+ >>> proj.delete_records(records=["3"], event="event_1_arm_1", repeat_instance=2)
390+ 1
391+ >>> proj.export_records(records=["3"])
392+ [{'record_id': '3', 'redcap_event_name': 'event_1_arm_1', 'redcap_repeat_instrument': '', 'redcap_repeat_instance': 1,
393+ 'field_1': '1', 'checkbox_field___1': '0', 'checkbox_field___2': '0', 'upload_field': '', 'form_1_complete': '0'}]
394+ >>> proj.delete_records(records=["3"])
395+ 1
355396 """
397+ # pylint: enable=line-too-long
356398 payload = self ._initialize_payload (
357399 content = "record" , return_format_type = return_format_type
358400 )
359401 payload ["action" ] = "delete"
402+ if delete_logging :
403+ payload ["delete_logging" ] = "1"
404+ else :
405+ payload ["delete_logging" ] = "0"
406+
407+ if arm :
408+ payload ["arm" ] = arm
409+ if instrument :
410+ payload ["instrument" ] = instrument
411+ if event :
412+ payload ["event" ] = event
413+ if repeat_instance :
414+ payload ["repeat_instance" ] = repeat_instance
360415 # Turn list of records into dict, and append to payload
361416 records_dict = {
362417 f"records[{ idx } ]" : record for idx , record in enumerate (records )
0 commit comments