def update_individual_hpo_terms(request, individual_guid): individual = Individual.objects.get(guid=individual_guid) project = individual.family.project check_permissions(project, request.user, CAN_EDIT) features = json.loads(request.body) _create_patient_if_missing(project, individual) patient_json = _get_patient_data(project, individual) patient_json["features"] = features patient_json_string = json.dumps(patient_json) url = phenotips_patient_url(individual) auth_tuple = get_phenotips_uname_and_pwd_for_project(project.phenotips_user_id, read_only=False) make_phenotips_api_call('PUT', url, data=patient_json_string, auth_tuple=auth_tuple, expected_status_code=204) phenotips_patient_id = patient_json['id'] phenotips_eid = patient_json.get('external_id') individual.phenotips_data = json.dumps(patient_json) individual.phenotips_patient_id = phenotips_patient_id individual.phenotips_eid = phenotips_eid individual.save() return create_json_response({ individual.guid: { 'phenotipsData': patient_json, 'phenotipsPatientId': phenotips_patient_id, 'phenotipsEid': phenotips_eid } })
def _get_patient_data(project, individual): """Retrieves patient data from PhenoTips and returns a json obj. Args: project (Model): seqr Project - used to retrieve PhenoTips credentials individual (Model): seqr Individual Returns: dict: json dictionary containing all PhenoTips information for this patient Raises: PhenotipsException: if unable to retrieve data from PhenoTips """ url = phenotips_patient_url(individual) auth_tuple = get_phenotips_uname_and_pwd_for_project(project.phenotips_user_id) return make_phenotips_api_call('GET', url, auth_tuple=auth_tuple, verbose=False)