Exemplo n.º 1
0
def individual(case_id, ind, key, value):
    """Update information on individual level in Scout"""

    case_obj = store.case(case_id)
    if not case_obj:
        click.echo(f"Could not find case {case_id}")
        return
    individuals = {
        ind_info["display_name"]: ind_info
        for ind_info in case_obj["individuals"]
    }
    # If ind name is empty, print available individual names for this case to help the user to build the command
    if ind is None:
        click.echo(
            f"Please specify individual name with '-n' option. Available individuals for this case:{list(individuals.keys())}"
        )
        return
    if ind not in individuals:
        click.echo(
            f"Could not find individual '{ind}' in case individuals. Available individuals for this case: {list(individuals.keys())}"
        )
        return
    # If key is null or non-valid, print a list of all the keys that can be updated using this function
    if key is None or not key in UPDATE_KEYS:
        click.echo(
            f"Please specify a valid key to update. Valid keys:{ UPDATE_KEYS }"
        )
        return
    if value is None:
        click.echo(f"Please specify a file path for key {key}")
        return
    file_path = Path(value)
    # If file is not found on the server, ask if user wants to update the key anyway
    if file_path.exists() is False:
        click.confirm(
            "The provided path was not found on the server, update key anyway?",
            abort=True,
        )
    # perform the update
    for ind_obj in case_obj["individuals"]:
        if ind_obj["display_name"] == ind:
            ind_obj[key] = value

    store.update_case(case_obj)
Exemplo n.º 2
0
def _update_case(store, case_obj, user_obj, institute_obj, verb):
    """Update case with new sample data, and create an associated event"""
    store.update_case(case_obj, keep_date=True)

    link = url_for(
        "cases.case",
        institute_id=institute_obj["_id"],
        case_name=case_obj["display_name"],
    )

    store.create_event(
        institute=institute_obj,
        case=case_obj,
        user=user_obj,
        link=link,
        category="case",
        verb=verb,
        subject=case_obj["display_name"],
    )
Exemplo n.º 3
0
def test_matchmaker_matches(app, institute_obj, case_obj, mme_submission,
                            user_obj, monkeypatch):

    # Given a case object with a MME submission
    case_obj["mme_submission"] = mme_submission
    store.update_case(case_obj)

    res = store.case_collection.find({"mme_submission": {"$exists": True}})
    assert sum(1 for i in res) == 1

    # Monkeypatch response with MME matches
    def mock_matches(*args, **kwargs):
        return {"institute": institute_obj, "case": case_obj, "matches": {}}

    monkeypatch.setattr(controllers, "mme_matches", mock_matches)

    # GIVEN an initialized app
    # GIVEN a valid institute and a user with mme_submitter role
    store.user_collection.update_one({"_id": user_obj["_id"]},
                                     {"$set": {
                                         "roles": ["mme_submitter"]
                                     }})

    with app.test_client() as client:
        # GIVEN that the user could be logged in
        resp = client.get(url_for("auto_login"))
        assert resp.status_code == 200

        # Given mock MME connection parameters
        current_app.config["MME_URL"] = "http://fakey_mme_url:fakey_port"
        current_app.config["MME_TOKEN"] = "test_token"

        # WHEN accessing the case page
        resp = client.get(
            url_for(
                "cases.matchmaker_matches",
                institute_id=institute_obj["internal_id"],
                case_name=case_obj["display_name"],
            ))

        # Then a successful response should be generated
        assert resp.status_code == 200
Exemplo n.º 4
0
def test_matchmaker_match(app, institute_obj, case_obj, mme_submission,
                          user_obj, monkeypatch):

    # Given a case object with a MME submission
    case_obj["mme_submission"] = mme_submission
    store.update_case(case_obj)

    res = store.case_collection.find({"mme_submission": {"$exists": True}})
    assert sum(1 for i in res) == 1

    # Monkeypatch response with MME match
    def mock_match(*args, **kwargs):
        return [{"status_code": 200}]

    monkeypatch.setattr(controllers, "mme_match", mock_match)

    # GIVEN an initialized app
    # GIVEN a valid institute and a user with mme_submitter role
    store.user_collection.update_one({"_id": user_obj["_id"]},
                                     {"$set": {
                                         "roles": ["mme_submitter"]
                                     }})
    with app.test_client() as client:
        # GIVEN that the user could be logged in
        resp = client.get(url_for("auto_login"))
        assert resp.status_code == 200

        # Given mock MME connection parameters
        current_app.config["MME_URL"] = "http://fakey_mme_url:fakey_port"
        current_app.config["MME_TOKEN"] = "test_token"

        # WHEN sending a POST request to match a patient
        resp = client.post(
            url_for(
                "cases.matchmaker_match",
                institute_id=institute_obj["internal_id"],
                case_name=case_obj["display_name"],
                target="mock_node_id",
            ))
        # page redirects in the views anyway, so it will return a 302 code
        assert resp.status_code == 302