Skip to content

Commit

Permalink
Fixing black and flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Filienko committed Dec 14, 2023
1 parent 5207690 commit 44e22e2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
9 changes: 6 additions & 3 deletions patientsearch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
internal_patient_search,
new_resource_hook,
sync_bundle,
restore_patient
restore_patient,
)
from patientsearch.extensions import oidc
from patientsearch.jsonify_abort import jsonify_abort
Expand Down Expand Up @@ -505,7 +505,9 @@ def external_search(resource_type):
# See if local match already exists
patient = resource_from_args(resource_type, request.args)
try:
internal_bundle = internal_patient_search(token, patient, not reinstate_patient)
internal_bundle = internal_patient_search(
token, patient, not reinstate_patient
)
except (RuntimeError, ValueError) as error:
return jsonify_abort(status_code=400, message=str(error))
local_fhir_patient = None
Expand Down Expand Up @@ -535,7 +537,8 @@ def external_search(resource_type):
)
patient["active"] = True
local_fhir_patient = HAPI_request(
token=token, method=method, resource_type="Patient", resource=patient)
token=token, method=method, resource_type="Patient", resource=patient
)
except (RuntimeError, ValueError) as error:
return jsonify_abort(status_code=400, message=str(error))
audit_entry(
Expand Down
2 changes: 1 addition & 1 deletion patientsearch/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"internal_patient_search",
"new_resource_hook",
"sync_bundle",
"restore_patient"
"restore_patient",
]
16 changes: 9 additions & 7 deletions patientsearch/models/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ def different(src, dest):

if not different(src_patient, internal_patient):
# If patient is active, proceed. If not, re-activate
if internal_patient.get("active") != True:
if internal_patient.get("active") is not True:
return internal_patient

params = patient_as_search_params(internal_patient)
# Ensure it is active
internal_patient["active"] = True
Expand All @@ -226,7 +226,7 @@ def different(src, dest):
)


def patient_as_search_params(patient, active_only = False):
def patient_as_search_params(patient, active_only=False):
"""Generate HAPI search params from patient resource"""

# Use same parameters sent to external src looking for existing Patient
Expand All @@ -249,7 +249,7 @@ def patient_as_search_params(patient, active_only = False):
("birthDate", "birthdate", "eq"),
("active", True, "eq"),
)

search_params = {}

for path, queryterm, compstr in search_map:
Expand All @@ -259,12 +259,15 @@ def patient_as_search_params(patient, active_only = False):
return search_params


def internal_patient_search(token, patient, active_only = False):
def internal_patient_search(token, patient, active_only=False):
"""Look up given patient from "internal" HAPI store, returns bundle"""
params = patient_as_search_params(patient, active_only)

return HAPI_request(
token=token, method="GET", resource_type="Patient", params=params
token=token,
method="GET",
resource_type="Patient",
params=params
)


Expand Down Expand Up @@ -303,7 +306,6 @@ def sync_patient(token, patient):
)

internal_patient = internal_search["entry"][0]["resource"]
#TODO: ask whether they prefer to merge and update active value or to start a new Patient for each sync attempt toward a non-active patient.
merged_patient = _merge_patient(
src_patient=patient, internal_patient=internal_patient, token=token
)
Expand Down
45 changes: 21 additions & 24 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ def internal_patient_duplicate_mismatch(datadir):
def internal_patient_duplicate_inactive_match(datadir):
return load_json(datadir, "internal_patient_duplicate_inactive_match.json")


def test_new_upsert(
client,
mocker,
faux_token,
external_patient_search,
internal_patient_miss,
new_patient,
):
):
"""Without finding a matching patient, should insert new and return"""

# Mock HAPI search failing to find a matching patient
Expand All @@ -119,8 +120,8 @@ def test_new_upsert_active(
faux_token,
external_patient_search_active,
internal_patient_miss,
new_patient_active
):
new_patient_active,
):
"""Without finding a matching patient, should insert new and return"""

# Mock HAPI search failing to find a matching patient
Expand All @@ -146,7 +147,7 @@ def test_upsert_inactive(
external_patient_search_active,
internal_patient_miss,
new_patient_active
):
):
"""Finding a matching inactive patient, user chose to generate new patient"""

# Mock HAPI search finding a matching inactive
Expand Down Expand Up @@ -176,11 +177,11 @@ def test_adding_identifier(external_patient_search):


def test_existing(
client,
mocker,
faux_token,
external_patient_search,
internal_patient_match,
client,
mocker,
faux_token,
external_patient_search,
internal_patient_match,
):
"""Finding a matching patient, return existing"""

Expand All @@ -195,11 +196,11 @@ def test_existing(


def test_existing_active(
client,
mocker,
faux_token,
client,
mocker,
faux_token,
external_patient_search_active,
internal_patient_active_match,
internal_patient_active_match,
):
"""Finding a matching active patient from active external search, return existing"""

Expand All @@ -211,14 +212,14 @@ def test_existing_active(

result = sync_bundle(faux_token, external_patient_search_active)
assert result != internal_patient_active_match["entry"][0]["resource"]

Check failure on line 215 in tests/test_sync.py

View workflow job for this annotation

GitHub Actions / Flake8

tests/test_sync.py#L215

Blank line contains whitespace (W293)

def test_existing_inactive(
client,
mocker,
faux_token,
client,
mocker,
faux_token,
external_patient_search_active,
internal_patient_inactive_match
internal_patient_inactive_match,
):
"""Finding a matching inactive patient from active external search, return existing restored"""

Expand All @@ -234,11 +235,7 @@ def test_existing_inactive(


def test_existing_modified(
client,
mocker,
faux_token,
external_patient_search,
internal_patient_match
client, mocker, faux_token, external_patient_search, internal_patient_match
):
"""Confirm modified external details get synchronized"""

Expand Down Expand Up @@ -270,6 +267,7 @@ def test_existing_modified(
assert result == identified_internal
assert result["identifier"] == [found_identifier]


def test_duplicate(
client,
mocker,
Expand Down Expand Up @@ -328,4 +326,3 @@ def test_duplicate_inactive(
# Shouldn't kill the process, but return the first
result = sync_bundle(faux_token, external_patient_search_active)
assert result == internal_patient_duplicate_inactive_match["entry"][0]["resource"]

0 comments on commit 44e22e2

Please sign in to comment.