def handle(self, *args, **options): project_id = options.get('project_id') print("Deleting phenotips records in project: %s" % project_id) try: proj = Project.objects.get(deprecated_project_id=project_id) except ObjectDoesNotExist: raise CommandError("Project %s not found." % project_id) for family in Family.objects.filter(project=proj): for individual in Individual.objects.filter(family=family): print("Deleting records for %s - %s" % (family.family_id, individual.individual_id)) delete_patient(proj, individual) print("Deleted all phenotips records for %s!" % project_id)
def delete_individuals(project, individual_guids): """Delete one or more individuals Args: project (object): Django ORM model for project individual_guids (list): GUIDs of individuals to delete Returns: list: Family objects for families with deleted individuals """ individuals_to_delete = Individual.objects.filter( family__project=project, guid__in=individual_guids) samples_to_delete = Sample.objects.filter( individual__family__project=project, individual__guid__in=individual_guids) for sample in samples_to_delete: logger.info("Deleting sample: %s" % sample) sample.delete() families = {} for individual in individuals_to_delete: families[individual.family.family_id] = individual.family # delete phenotips records try: delete_patient(project, individual.phenotips_eid, is_external_id=True) except (PhenotipsException, ValueError) as e: logger.error( "Error: couldn't delete patient from phenotips: %s %s", individual.phenotips_eid, individual) # delete Individual individual.delete() _deprecated_delete_individual(project, individual) update_pedigree_images(families.values()) families_with_deleted_individuals = list(families.values()) return families_with_deleted_individuals
def delete_individuals(project, individual_guids): """Delete one or more individuals Args: project (object): Django ORM model for project individual_guids (list): GUIDs of individuals to delete Returns: list: Family objects for families with deleted individuals """ individuals_to_delete = Individual.objects.filter( family__project=project, guid__in=individual_guids) samples_to_delete = Sample.objects.filter( individual__family__project=project, individual__guid__in=individual_guids) for sample in samples_to_delete: logger.info("Deleting sample: %s" % sample) sample.delete() families = {} for individual in individuals_to_delete: families[individual.family.family_id] = individual.family # delete phenotips records try: delete_patient(project, individual) except (PhenotipsException, ValueError) as e: logger.error("Error: couldn't delete patient from phenotips: %s %s", individual.phenotips_eid, individual) # delete Individual delete_seqr_model(individual) update_pedigree_images(families.values()) families_with_deleted_individuals = list(families.values()) return families_with_deleted_individuals