Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DASHBOARD_COLUMNS to config, with defaults to match current COSRI #156

Merged
merged 10 commits into from
Nov 15, 2022
24 changes: 24 additions & 0 deletions patientsearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ def load_json_config(potential_json_string):
"Your account is not authorized for access, please contact an administrator",
)

DASHBOARD_COLUMNS = os.getenv(
"DASHBOARD_COLUMNS",
[
{
"label": "First Name",
"expr": "$.name[0].given[0]",
},
{
"label": "Last Name",
"expr": "$.name[0].family",
},
{
"label": "Birth Date",
"expr": "$.birthDate",
},
{
"label": "Last Accessed",
"defaultSort": "desc",
"expr": "$.meta.lastUpdated",
"dataType": "date",
},
],
)
ivan-c marked this conversation as resolved.
Show resolved Hide resolved

LANDING_INTRO = os.getenv("LANDING_INTRO", "")
LANDING_BUTTON_TEXT = os.getenv("LANDING_BUTTON_TEXT", "")
LANDING_BODY = os.getenv("LANDING_BODY", "")
Expand Down
55 changes: 55 additions & 0 deletions tests/test_columnconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from datetime import datetime
import jmespath
import json
import os

from pytest import fixture


def load_json(datadir, filename):
with open(os.path.join(datadir, filename), "r") as json_file:
data = json.load(json_file)
return data


@fixture
def patient_bundle(datadir):
return load_json(datadir, "patient_bundle.json")


def test_id_count(patient_bundle):
assert patient_bundle["total"] == 7
expr = jmespath.compile("entry[?resource.resourceType=='Patient'].resource.id")
results = expr.search(patient_bundle)
assert len(results) == 7


def test_max_authored_by_patient(patient_bundle):
results = {}
date_format = "%Y-%m-%d"

expr = jmespath.compile("entry[?resource.resourceType=='Patient'].resource.id")
patient_ids = expr.search(patient_bundle)

for id in patient_ids:
# from each patient ID, obtain the list of QuestionnaireResponse.authored values
expr = jmespath.compile(
f"entry[?resource.subject.reference=='Patient/{id}'].resource.authored"
)

# create a list of sortable datetime objects from authored date strings
auth_dates = [
datetime.strptime(a, date_format) for a in expr.search(patient_bundle)
]
auth_dates.sort()

# retain string form for max found for patient, or empty string
results[id] = (
datetime.strftime(auth_dates[-1], date_format) if auth_dates else ""
)

# Confirm a few known
assert len(results) == 7
assert results["53"] == "2022-11-02"
assert results["test-patient-1"] == ""
assert results["test-patient-2"] == "2022-11-02"
Loading