Пример #1
0
def test_backend_remove_patient(gpx4_patients, database):
    """ Test adding 2 test patients and then removing them using label or ID """

    # test conversion to format required for the database:
    test_mme_patients = [ mme_patient(json_patient=patient) for patient in gpx4_patients]

    # make sure 2 json patient are correctly parsed
    assert len(test_mme_patients) == 2

    # insert the 2 patients into the database
    inserted_ids = [ backend_add_patient(mongo_db=database, patient=mme_patient, match_external=False) for mme_patient in test_mme_patients ]
    assert len(inserted_ids) == 2

    # make sure that inserted patients contain computed phenotypes from Monarch
    a_patient = database['patients'].find_one()
    assert a_patient

    # test removing a patient by ID:
    remove_query = {'_id' : 'P0001058'}
    deleted = delete_by_query(remove_query, database, 'patients')
    db_patients = database['patients'].find()
    assert db_patients.count() == 1

    # test removing a patient by label:
    remove_query = {'label' : '350_2-test'}
    deleted = delete_by_query(remove_query, database, 'patients')
    db_patients = database['patients'].find()
    assert db_patients.count() == 0
Пример #2
0
def client(id):
    """Remove a client from database by providing its ID"""

    query = {"_id": id}
    n_removed = delete_by_query(query=query,
                                mongo_db=current_app.db,
                                mongo_collection="clients")
    click.echo("Number of clients removed from database:{}".format(n_removed))
Пример #3
0
def node(id):
    """Remove a node from database by providing its ID"""

    query = {'_id': id}
    n_removed = delete_by_query(query=query,
                                mongo_db=current_app.db,
                                mongo_collection='nodes')
    click.echo('Number of nodes removed from database:{}'.format(n_removed))
Пример #4
0
def delete_patient(database, patient_id):
    """Remove a patient by ID"""
    message = ''

    # first delete all matches in database for this patient:
    query = {'data.patient.id' : patient_id}
    deleted = delete_by_query(query, database, 'matches')
    LOG.info('deleted {} matche/s triggered by this patient'.format(deleted))


    query = {'_id' : patient_id}
    deleted = delete_by_query(query, database, 'patients')
    message = {}
    if deleted == 1:
        message['message'] = 'Patient and its matches were successfully deleted from database'
    else:
        message['message'] = 'ERROR. Could not delete a patient with ID {} from database'.format(patient_id)
    return message
def delete_patient(database, patient_id):
    """Remove a patient by ID"""
    message = ""

    # first delete all matches in database for this patient:
    query = {"data.patient.id": patient_id}
    deleted = delete_by_query(query, database, "matches")
    LOG.info("deleted {} matche/s triggered by this patient".format(deleted))

    query = {"_id": patient_id}
    deleted = delete_by_query(query, database, "patients")
    message = {}
    if deleted == 1:
        message["message"] = "Patient and its matches were successfully deleted from database"
    else:
        message["message"] = "ERROR. Could not delete a patient with ID {} from database".format(
            patient_id
        )
    return message
Пример #6
0
def patient(id, label, remove_matches):
    """Removing a patient from patientMatcher providing its ID"""

    if not id and not label:
        click.echo(
            "Error: either ID and/or label should be provided to delete a patient."
        )
        raise click.Abort()

    if remove_matches and not id:
        click.echo(
            "Please provide patient ID and not label to remove all its matches."
        )
        raise click.Abort()

    query = {}
    if id:
        query["_id"] = id
    if label:
        query["label"] = label

    n_removed = delete_by_query(query=query,
                                mongo_db=current_app.db,
                                mongo_collection="patients")
    click.echo("Number of patients removed from database:{}".format(n_removed))

    if remove_matches:
        # this will remove ONLY matches where this patient was the query patient
        # NOT those where patient was among the matching results
        query = {"data.patient.id": id}
        n_removed = delete_by_query(query=query,
                                    mongo_db=current_app.db,
                                    mongo_collection="matches")
        click.echo(
            "Number of matches for this patient removed from database:{}".
            format(n_removed))