def _enable_phenotips_for_project(project): """Creates 2 users in PhenoTips for this project (one that will be view-only and one that'll have edit permissions for patients in the project). """ project.is_phenotips_enabled = True project.phenotips_user_id = _slugify(project.name) # view-only user username, password = _get_phenotips_uname_and_pwd_for_project(project.phenotips_user_id, read_only=True) create_phenotips_user(username, password) # user with edit permissions username, password = _get_phenotips_uname_and_pwd_for_project(project.phenotips_user_id, read_only=False) create_phenotips_user(username, password) project.save()
def _enable_phenotips_for_project(project): """Creates 2 users in PhenoTips for this project (one that will be view-only and one that'll have edit permissions for patients in the project). """ project.is_phenotips_enabled = True project.phenotips_user_id = _slugify(project.name) # view-only user username, password = _get_phenotips_uname_and_pwd_for_project( project.phenotips_user_id, read_only=True) create_phenotips_user(username, password) # user with edit permissions username, password = _get_phenotips_uname_and_pwd_for_project( project.phenotips_user_id, read_only=False) create_phenotips_user(username, password) project.save()
def handle(self, *args, **options): from_project = Project.objects.get(guid=options['from_project']) to_project = Project.objects.get(guid=options['to_project']) to_base_project = find_matching_xbrowse_model(to_project) family_ids = options['family_ids'] families = Family.objects.filter(project=from_project, family_id__in=family_ids) print('Found {} out of {} families. No match for: {}.'.format( len(families), len(set(family_ids)), set(family_ids) - set([f.family_id for f in families]))) for f in families: print("==> Moving {}".format(f)) for seqr_individual in f.individual_set.all(): base_individual = find_matching_xbrowse_model(seqr_individual) base_individual.project = to_base_project base_individual.save() # Update individuals in phenotips if _phenotips_patient_exists(seqr_individual): # make sure phenotips_patient_id is up to date data_json = _get_patient_data( from_project, seqr_individual, ) seqr_individual.phenotips_patient_id = data_json["id"] seqr_individual.save() # update permissions phenotips_readonly_username, _ = _get_phenotips_uname_and_pwd_for_project( to_project.phenotips_user_id, read_only=True) _add_user_to_patient(phenotips_readonly_username, seqr_individual.phenotips_patient_id, allow_edit=False) phenotips_readwrite_username, _ = _get_phenotips_uname_and_pwd_for_project( to_project.phenotips_user_id, read_only=False) _add_user_to_patient(phenotips_readwrite_username, seqr_individual.phenotips_patient_id, allow_edit=True) # Update individuals samples/ VCFs for from_vcf_file in base_individual.vcf_files.all(): to_vcf_file, _ = VCFFile.objects.get_or_create( project=to_base_project, elasticsearch_index=from_vcf_file.elasticsearch_index, file_path=from_vcf_file.file_path, dataset_type=from_vcf_file.dataset_type, sample_type=from_vcf_file.sample_type, loaded_date=from_vcf_file.loaded_date, ) base_individual.vcf_files.add(to_vcf_file) base_individual.vcf_files.remove(from_vcf_file) # Update variant tags/ notes saved_variants = SavedVariant.objects.filter(family=f) for variant_tag in VariantTag.objects.filter( saved_variant__in=saved_variants).select_related( 'variant_tag_type'): if variant_tag.variant_tag_type.project: to_tag_type, created = get_or_create_seqr_model( VariantTagType, project=to_project, name=variant_tag.variant_tag_type.name) if created: update_seqr_model( to_tag_type, category=variant_tag.variant_tag_type.category, description=variant_tag.variant_tag_type. description, color=variant_tag.variant_tag_type.color, order=variant_tag.variant_tag_type.order, ) update_seqr_model(variant_tag, variant_tag_type=to_tag_type) else: to_project_tag, created = ProjectTag.objects.get_or_create( project=to_base_project, tag=variant_tag.variant_tag_type.name) if created: to_project_tag.category = variant_tag.variant_tag_type.category to_project_tag.title = variant_tag.variant_tag_type.description to_project_tag.color = variant_tag.variant_tag_type.color to_project_tag.order = variant_tag.variant_tag_type.order to_project_tag.save() variant_tag.project_tag = to_project_tag variant_tag.save() base_family = find_matching_xbrowse_model(f) for note in BaseVariantNote.objects.filter(family=base_family): note.project = to_base_project note.save() # Update families update_seqr_model(f, project=to_project) print("Done.")
def handle(self, *args, **options): from_project = BaseProject.objects.get(project_id=options['from_project']) to_project = BaseProject.objects.get(project_id=options['to_project']) to_seqr_project = find_matching_seqr_model(to_project) family_ids = options['family_ids'] families = BaseFamily.objects.filter(project=from_project, family_id__in=family_ids) print('Found {} out of {} families. No match for: {}.'.format(len(families), len(set(family_ids)), set(family_ids) - set([f.family_id for f in families]))) for f in families: print("==> Moving {}".format(f)) for individual in f.individual_set.all(): individual.project = to_project individual.save() # Update individuals in phenotips if _phenotips_patient_exists(individual.seqr_individual): # make sure phenotips_patient_id is up to date seqr_individual = individual.seqr_individual data_json = _get_patient_data( from_project.seqr_project, seqr_individual, ) seqr_individual.phenotips_patient_id = data_json["id"] seqr_individual.save() # update permissions phenotips_readonly_username, _ = _get_phenotips_uname_and_pwd_for_project(to_project.seqr_project.phenotips_user_id, read_only=True) _add_user_to_patient(phenotips_readonly_username, seqr_individual.phenotips_patient_id, allow_edit=False) phenotips_readwrite_username, _ = _get_phenotips_uname_and_pwd_for_project(to_project.seqr_project.phenotips_user_id, read_only=False) _add_user_to_patient(phenotips_readwrite_username, seqr_individual.phenotips_patient_id, allow_edit=True) # Update individuals samples/ VCFs for from_vcf_file in individual.vcf_files.all(): to_vcf_file, _ = VCFFile.objects.get_or_create( project=to_project, elasticsearch_index=from_vcf_file.elasticsearch_index, file_path=from_vcf_file.file_path, dataset_type=from_vcf_file.dataset_type, sample_type=from_vcf_file.sample_type, loaded_date=from_vcf_file.loaded_date, ) individual.vcf_files.add(to_vcf_file) individual.vcf_files.remove(from_vcf_file) # Update variant tags/ notes saved_variants = set() for note in BaseVariantNote.objects.filter(family=f): seqr_note = find_matching_seqr_model(note) if seqr_note: saved_variants.add(seqr_note.saved_variant) note.project = to_project note.save() for variant_tag in BaseVariantTag.objects.filter(family=f): to_project_tag, created = get_or_create_xbrowse_model( ProjectTag, project=to_project, tag=variant_tag.project_tag.tag ) if created: update_xbrowse_model( to_project_tag, category=variant_tag.project_tag.category, title=variant_tag.project_tag.title, color=variant_tag.project_tag.color, order=variant_tag.project_tag.order, ) update_xbrowse_model(variant_tag, project_tag=to_project_tag) seqr_variant_tag = find_matching_seqr_model(variant_tag) if seqr_variant_tag: saved_variants.add(seqr_variant_tag.saved_variant) for saved_variant in saved_variants: saved_variant.project = to_seqr_project saved_variant.save() # Update families update_xbrowse_model(f, project=to_project) print("Done.")