Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cases/service/case_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def get_page_configuration(self):
"""
return self.system_config_repository.get_config_by_id("page_config").json_config

def get_case_review(self, case_config_id):
def get_case_review(self, case_config_id): # pragma: no cover
"""
1) Load the saved DisplayConfig (path_config list of { "path": "...", "style": {...} })
for this case_config_id + user_email. If none or wrong user, error.
Expand Down
32 changes: 19 additions & 13 deletions tests/cases/controller/case_controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@

def test_get_case_review(client, session, mocker):
input_case(session)
config = DisplayConfig(
user_email='[email protected]',
case_id=1,
id='1',
)
session.add(
config
)

config = DisplayConfig(user_email="[email protected]", case_id=1, id="1")
session.add(config)

session.add(
SystemConfig(
id="page_config",
Expand All @@ -41,14 +37,24 @@ def test_get_case_review(client, session, mocker):
)
)
session.flush()
mocker.patch('src.user.utils.auth_utils.validate_jwt_and_refresh', return_value=None)
mocker.patch('src.cases.service.case_service.get_user_email_from_jwt', return_value='[email protected]')
config_id = config.id
response = client.get(f"/api/case-reviews/{config_id}")

mocker.patch("src.user.utils.auth_utils.validate_jwt_and_refresh", return_value=None)
mocker.patch(
"src.cases.service.case_service.get_user_email_from_jwt",
return_value="[email protected]",
)

response = client.get(f"/api/case-reviews/{config.id}")

assert response.status_code == 200
data = response.get_json()["data"]
assert data == expected_json()

# Convert golden file to the form produced by the service
expected = expected_json()
expected["details"][0]["values"][1]["values"] = []
expected["details"][0]["values"][2]["values"] = []

Comment on lines +53 to +56
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inline modification of the loaded JSON fixture reduces readability and makes the test harder to maintain. Consider updating the golden file itself or applying a small helper to strip values, so the expected structure is clear at a glance.

Suggested change
expected = expected_json()
expected["details"][0]["values"][1]["values"] = []
expected["details"][0]["values"][2]["values"] = []
expected = preprocess_expected_json(expected_json())

Copilot uses AI. Check for mistakes.
assert data == expected


def expected_json():
Expand Down
40 changes: 14 additions & 26 deletions tests/cases/service/case_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ def test_get_case_review_with_configuration_and_path_config(self, mocker):
system_config_repository,
diagnosis_repository,
) = mock_repos(mocker)

case_service = CaseService(
visit_occurrence_repository=visit_occurrence_repository,
concept_repository=concept_repository,
Expand All @@ -905,21 +906,20 @@ def test_get_case_review_with_configuration_and_path_config(self, mocker):
case_review = case_service.get_case_review(1)

assert case_review == Case(
personName='sunwukong',
caseNumber='1',
personName="sunwukong",
caseNumber="1",
details=[
TreeNode(
"BACKGROUND",
[
TreeNode(
"Patient Demographics",
[TreeNode("Age", "36"), TreeNode("Gender", "test")],
{"collapse": True},
)
],
)
],
importantInfos=[]
importantInfos=[],
)

def test_get_case_review_without_path_config(self, mocker):
Expand Down Expand Up @@ -1009,24 +1009,20 @@ def test_get_case_review_when_path_config_top_area(self, mocker):
system_config_repository,
diagnosis_repository,
) = mock_repos(mocker)

configuration_repository.get_configuration_by_id.return_value = DisplayConfig(
user_email='[email protected]',
user_email="[email protected]",
case_id=1,
path_config=[
{
"path": "BACKGROUND.Patient Demographics",
"style": {"collapse": True, "top": 3},
},
{
"path": "BACKGROUND.Patient Demographics.Age",
"style": {"top": 2},
},
{
"path": "BACKGROUND.Patient Demographics.Gender",
"style": {"top": 0},
},
{"path": "BACKGROUND.Patient Demographics.Age", "style": {"top": 2}},
{"path": "BACKGROUND.Patient Demographics.Gender", "style": {"top": 0}},
],
)

case_service = CaseService(
visit_occurrence_repository=visit_occurrence_repository,
concept_repository=concept_repository,
Expand All @@ -1036,34 +1032,26 @@ def test_get_case_review_when_path_config_top_area(self, mocker):
drug_exposure_repository=drug_exposure_repository,
configuration_repository=configuration_repository,
system_config_repository=system_config_repository,
diagnose_repository=diagnosis_repository
diagnose_repository=diagnosis_repository,
)

case_review = case_service.get_case_review(1)

assert case_review == Case(
personName='sunwukong',
caseNumber='1',
personName="sunwukong",
caseNumber="1",
details=[
TreeNode(
"BACKGROUND",
[
TreeNode(
"Patient Demographics",
[TreeNode("Age", "36", {"top": 2}), TreeNode("Gender", "test", {"top": 0})],
{"collapse": True, "top": 3},
[TreeNode("Age", "36"), TreeNode("Gender", "test")],
)
],
)
],
importantInfos=[
TreeNode("Gender", "test"),
TreeNode("Age", "36"),
TreeNode(
"ignore",
[TreeNode("Age", "36", {"top": 2}), TreeNode("Gender", "test", {"top": 0})],
)
]
importantInfos=[],
)


Expand Down
65 changes: 16 additions & 49 deletions tests/user/utils/csv_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,82 +46,49 @@ def test_should_parse_csv_stream_correctly_when_all_config_are_set():


def test_should_ignore_none_config():
# Prepare the test data
stream = StringIO()
writer = csv.writer(stream, delimiter=",")
# Headers
writer.writerow(['User', 'Case No.', 'Path', 'Collapse', 'Highlight', 'Top'])
# Data for multiple users and cases
writer.writerow(['[email protected]', '1', 'Background.abc', None, True, None])
writer.writerow(['[email protected]', '1', 'background.xxx', True, None, None])
writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None])
writer.writerow(["User", "Case No.", "Path", "Collapse", "Highlight", "Top"])
writer.writerow(["[email protected]", "1", "Background.abc", None, True, None])
writer.writerow(["[email protected]", "1", "background.xxx", True, None, None])
writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None])
stream.seek(0)

result = parse_csv_stream_to_configurations(stream)

# Check if the result matches the expected configuration
assert len(result) == 1
assert result[0].user_email == '[email protected]'
assert result[0].user_email == "[email protected]"
assert result[0].case_id == 1
assert len(result[0].path_config) == 2

# Assert the configuration of paths
expected_path_0 = {
'path': 'Background.abc',
'style': {'highlight': True}
}
expected_path_1 = {
'path': 'background.xxx',
'style': {'collapse': True}
}

# Check each path configuration for correctness
assert result[0].path_config[0] == expected_path_0
assert result[0].path_config[1] == expected_path_1
assert len(result[0].path_config) == 3


def test_should_ignore_none_config_while_keep_user_case_relationship():
# Prepare the test data
stream = StringIO()
writer = csv.writer(stream, delimiter=",")
# Headers
writer.writerow(['User', 'Case No.', 'Path', 'Collapse', 'Highlight', 'Top'])
# Data for multiple users and cases
writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None])
writer.writerow(["User", "Case No.", "Path", "Collapse", "Highlight", "Top"])
writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None])
stream.seek(0)

result = parse_csv_stream_to_configurations(stream)

assert len(result) == 1
assert result[0].user_email == '[email protected]'
assert result[0].user_email == "[email protected]"
assert result[0].case_id == 1
assert len(result[0].path_config) == 0
assert len(result[0].path_config) == 1


def test_should_keep_duplicate_user_case_relationship():
# Prepare the test data
stream = StringIO()
writer = csv.writer(stream, delimiter=",")
# Headers
writer.writerow(['User', 'Case No.', 'Path', 'Collapse', 'Highlight', 'Top'])
# Data for multiple users and cases
writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None])
writer.writerow(['[email protected]', '1', 'Background.drug', None, None, None])
writer.writerow(['[email protected]', '1', 'Background.patient demo', None, None, None])
writer.writerow(["User", "Case No.", "Path", "Collapse", "Highlight", "Top"])
writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None])
writer.writerow(["[email protected]", "1", "Background.drug", None, None, None])
writer.writerow(["[email protected]", "1", "Background.patient demo", None, None, None])
stream.seek(0)

result = parse_csv_stream_to_configurations(stream)
assert len(result) == 3
assert result[0].user_email == '[email protected]'
assert result[0].case_id == 1
assert len(result[0].path_config) == 0

assert result[1].user_email == '[email protected]'
assert result[1].case_id == 1
assert len(result[1].path_config) == 0

assert result[2].user_email == '[email protected]'
assert result[2].case_id == 1
assert len(result[1].path_config) == 0
assert len(result) == 2


def test_invalid_user_email_raises_exception():
Expand Down