def _process_result(result, project): result.update({ 'projectCategoryGuids': [c.guid for c in project.projectcategory_set.all()] if add_project_category_guids_field else [], 'canEdit': has_project_permissions(project, user, can_edit=True), })
def _parse_mme_results(submission, saved_results, user, additional_genes=None, response_json=None): results = [] contact_institutions = set() prefetch_related_objects(saved_results, 'originating_submission__individual__family__project') for result_model in saved_results: result = result_model.result_data result['matchStatus'] = _get_json_for_model(result_model) if result_model.originating_submission: originating_family = result_model.originating_submission.individual.family if has_project_permissions(originating_family.project, user): result['originatingSubmission'] = { 'originatingSubmissionGuid': result_model.originating_submission.guid, 'familyGuid': originating_family.guid, 'projectGuid': originating_family.project.guid, } results.append(result) contact_institutions.add(result['patient']['contact'].get('institution', '').strip().lower()) additional_hpo_ids = {feature['id'] for feature in (submission.features or []) if feature.get('id')} if not additional_genes: additional_genes = set() additional_genes.update({gene_feature['gene']['id'] for gene_feature in (submission.genomic_features or [])}) hpo_terms_by_id, genes_by_id, gene_symbols_to_ids = get_mme_genes_phenotypes_for_results( results, additional_genes=additional_genes, additional_hpo_ids=additional_hpo_ids) parsed_results = [_parse_mme_result(res, hpo_terms_by_id, gene_symbols_to_ids, submission.guid) for res in results] parsed_results_gy_guid = {result['matchStatus']['matchmakerResultGuid']: result for result in parsed_results} contact_notes = {note.institution: _get_json_for_model(note, user=user) for note in MatchmakerContactNotes.objects.filter(institution__in=contact_institutions)} submission_json = get_json_for_matchmaker_submission( submission, individual_guid=submission.individual.guid, additional_model_fields=['contact_name', 'contact_href', 'submission_id'] ) submission_json.update({ 'mmeResultGuids': list(parsed_results_gy_guid.keys()), 'phenotypes': parse_mme_features(submission.features, hpo_terms_by_id), 'geneVariants': parse_mme_gene_variants(submission.genomic_features, gene_symbols_to_ids), }) response = { 'mmeResultsByGuid': parsed_results_gy_guid, 'mmeContactNotes': contact_notes, 'mmeSubmissionsByGuid': {submission.guid: submission_json}, 'individualsByGuid': {submission.individual.guid: {'mmeSubmissionGuid': submission.guid}}, 'genesById': genes_by_id, } if response_json: response.update(response_json) return create_json_response(response)
def update_individual_handler(request, individual_guid): """Updates a single field in an Individual record. Args: request (object): Django HTTP Request object. individual_guid (string): GUID of the Individual. Request: body should be a json dictionary like: { 'value': xxx } Response: json dictionary representing the updated individual like: { <individualGuid> : { individualId: xxx, sex: xxx, affected: xxx, ... } } """ individual = Individual.objects.get(guid=individual_guid) project = individual.family.project check_project_permissions(project, request.user) can_edit = has_project_permissions(project, request.user, can_edit=True) request_json = json.loads(request.body) update_json = request_json if can_edit else { k: v for k, v in request_json.items() if k in {'notes'} } update_individual_from_json(individual, update_json, user=request.user, allow_unknown_keys=True) return create_json_response( {individual.guid: _get_json_for_individual(individual, request.user)})