scout/server/blueprints/cases/controllers.py
def mme_add(store, user_obj, case_obj, add_gender, add_features, add_disorders, genes_only,
    mme_base_url, mme_accepts, mme_token):
    """Add a patient to MatchMaker server

    Args:
        store(adapter.MongoAdapter)
        user_obj(dict) a scout user object (to be added as matchmaker contact)
        case_obj(dict) a scout case object
        add_gender(bool) if True case gender will be included in matchmaker
        add_features(bool) if True HPO features will be included in matchmaker
        add_disorders(bool) if True OMIM diagnoses will be included in matchmaker
        genes_only(bool) if True only genes and not variants will be shared
        mme_base_url(str) base url of the MME server
        mme_accepts(str) request content accepted by MME server
        mme_token(str) auth token of the MME server

    Returns:
        submitted_info(dict) info submitted to MatchMaker and its responses
    """

    if not mme_base_url or not mme_accepts or not mme_token:
        return 'Please check that Matchmaker connection parameters are valid'
    url = ''.join([mme_base_url, '/patient/add'])
    features = []   # this is the list of HPO terms
    disorders = []  # this is the list of OMIM diagnoses
    g_features = []

     # create contact dictionary
    contact_info = {
        'name' : user_obj['name'],
        'href' : ''.join( ['mailto:',user_obj['email']] ),
        'institution' : 'Scout software user, Science For Life Laboratory, Stockholm, Sweden'
    }
    if add_features: # create features dictionaries
        features = hpo_terms(case_obj)

    if add_disorders: # create OMIM disorders dictionaries
        disorders = omim_terms(case_obj)

    # send a POST request and collect response for each affected individual in case
    server_responses = []

    submitted_info = {
        'contact' : contact_info,
        'sex' : add_gender,
        'features' : features,
        'disorders' : disorders,
        'genes_only' : genes_only,
        'patient_id' : []
    }
    for individual in case_obj.get('individuals'):
        if not individual['phenotype'] in  [2, 'affected']: # include only affected individuals
            continue

        patient = {
            'contact' : contact_info,
            'id' : '.'.join([case_obj['_id'], individual.get('individual_id')]), # This is a required field form MME
            'label' : '.'.join([case_obj['display_name'], individual.get('display_name')]),
            'features' : features,
            'disorders' : disorders
        }
        if add_gender:
            if individual['sex'] == '1':
                patient['sex'] = 'MALE'
            else:
                patient['sex'] = 'FEMALE'

        if case_obj.get('suspects'):
            g_features = genomic_features(store, case_obj, individual.get('display_name'), genes_only)
            patient['genomicFeatures'] = g_features

        # send add request to server and capture response
        resp = matchmaker_request(url=url, token=mme_token, method='POST', content_type=mme_accepts,
            accept='application/json', data={'patient':patient})

        server_responses.append({
                'patient': patient,
                'message': resp.get('message'),
                'status_code' : resp.get('status_code')
            })
    submitted_info['server_responses'] = server_responses
    return submitted_info
def mme_add(store, user_obj, case_obj, add_gender, add_features, add_disorders, genes_only,
    mme_base_url, mme_accepts, mme_token):
    """Add a patient to MatchMaker server

    Args:
        store(adapter.MongoAdapter)
        user_obj(dict) a scout user object (to be added as matchmaker contact)
        case_obj(dict) a scout case object
        add_gender(bool) if True case gender will be included in matchmaker
        add_features(bool) if True HPO features will be included in matchmaker
        add_disorders(bool) if True OMIM diagnoses will be included in matchmaker
        genes_only(bool) if True only genes and not variants will be shared
        mme_base_url(str) base url of the MME server
        mme_accepts(str) request content accepted by MME server
        mme_token(str) auth token of the MME server

    Returns:
        submitted_info(dict) info submitted to MatchMaker and its responses
    """

    if not mme_base_url or not mme_accepts or not mme_token:
        return 'Please check that Matchmaker connection parameters are valid'
    url = ''.join([mme_base_url, '/patient/add'])
    features = []   # this is the list of HPO terms
    disorders = []  # this is the list of OMIM diagnoses
    g_features = []

     # create contact dictionary
    contact_info = {
        'name' : user_obj['name'],
        'href' : ''.join( ['mailto:',user_obj['email']] ),
        'institution' : 'Scout software user, Science For Life Laboratory, Stockholm, Sweden'
    }
    if add_features: # create features dictionaries
        features = hpo_terms(case_obj)

    if add_disorders: # create OMIM disorders dictionaries
        disorders = omim_terms(case_obj)

    # send a POST request and collect response for each affected individual in case
    server_responses = []

    submitted_info = {
        'contact' : contact_info,
        'sex' : add_gender,
        'features' : features,
        'disorders' : disorders,
        'genes_only' : genes_only,
        'patient_id' : []
    }
    for individual in case_obj.get('individuals'):
        if not individual['phenotype'] in  [2, 'affected']: # include only affected individuals
            continue

        patient = {
            'contact' : contact_info,
            'id' : '.'.join([case_obj['_id'], individual.get('individual_id')]), # This is a required field form MME
            'label' : '.'.join([case_obj['display_name'], individual.get('display_name')]),
            'features' : features,
            'disorders' : disorders
        }
        if add_gender:
            if individual['sex'] == '1':
                patient['sex'] = 'MALE'
            else:
                patient['sex'] = 'FEMALE'

        if case_obj.get('suspects'):
            g_features = genomic_features(store, case_obj, individual.get('display_name'), genes_only)
            patient['genomicFeatures'] = g_features

        # send add request to server and capture response
        resp = matchmaker_request(url=url, token=mme_token, method='POST', content_type=mme_accepts,
            accept='application/json', data={'patient':patient})

        server_responses.append({
                'patient': patient,
                'message': resp.get('message'),
                'status_code' : resp.get('status_code')
            })
    submitted_info['server_responses'] = server_responses
    return submitted_info
Add a patient to MatchMaker server

    Args:
        store(adapter.MongoAdapter)
        user_obj(dict) a scout user object (to be added as matchmaker contact)
        case_obj(dict) a scout case object
        add_gender(bool) if True case gender will be included in matchmaker
        add_features(bool) if True HPO features will be included in matchmaker
        add_disorders(bool) if True OMIM diagnoses will be included in matchmaker
        genes_only(bool) if True only genes and not variants will be shared
        mme_base_url(str) base url of the MME server
        mme_accepts(str) request content accepted by MME server
        mme_token(str) auth token of the MME server

    Returns:
        submitted_info(dict) info submitted to MatchMaker and its responses