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

Improve updating of patients #444

Merged
merged 28 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6b8bca4
make pull request
tomaspavlin Feb 12, 2021
38b4b18
Improve donor and recipient update api
tomaspavlin Feb 12, 2021
53c55f1
Finish update api and introduce tests
tomaspavlin Feb 16, 2021
acbdd4d
Generate files
tomaspavlin Feb 16, 2021
796e96b
Improve patient update service in FE to support everything
tomaspavlin Feb 16, 2021
52fab6d
Merge remote-tracking branch master into 418_improve_updating_of_pati…
tomaspavlin Feb 16, 2021
82287a7
Merge remote-tracking branch 'origin/276_pekne_manualni_vkladani_paci…
tomaspavlin Feb 16, 2021
24e39c4
Use new component and create to-generated parsers
tomaspavlin Feb 17, 2021
22e2181
Merge remote-tracking branch 'origin/276_pekne_manualni_vkladani_paci…
tomaspavlin Feb 17, 2021
02dc5c2
Fix some stuff
tomaspavlin Feb 17, 2021
bab3435
Move active switch and recipient requirements to settings components
tomaspavlin Feb 17, 2021
40f5087
Merge remote-tracking branch 'origin/276_pekne_manualni_vkladani_paci…
tomaspavlin Feb 17, 2021
ba5920b
Comment
tomaspavlin Feb 17, 2021
0594b6e
Merge remote-tracking branch 'origin/master' into 418_improve_updatin…
tomaspavlin Feb 18, 2021
3ac0002
Solve some technical depts to make it working
tomaspavlin Feb 18, 2021
161f981
Introduce editing waitingSince and previousTransplants, fix date pars…
tomaspavlin Feb 18, 2021
578b2bd
Show only needed controls
tomaspavlin Feb 18, 2021
f068f22
Improve enums in BE
tomaspavlin Feb 18, 2021
21087d2
Improve enums in BE 2
tomaspavlin Feb 18, 2021
3eacfee
Solve TODOOs
tomaspavlin Feb 18, 2021
16a6be3
Fix lint
tomaspavlin Feb 18, 2021
bcba746
Remove title and fix some tests indention
tomaspavlin Feb 19, 2021
3fb8bc2
Skip recipient api test for swagger issue
tomaspavlin Feb 19, 2021
7580d7b
Fix tests
tomaspavlin Feb 19, 2021
dc5a69e
Move tests and add blood types todos
tomaspavlin Feb 19, 2021
3c35cc8
Merge remote-tracking branch 'origin/master' into 418_improve_updatin…
tomaspavlin Feb 19, 2021
b36d852
Copy deep antigens
tomaspavlin Feb 22, 2021
9eeb8d8
Merge remote-tracking branch 'origin/master' into 418_improve_updatin…
tomaspavlin Feb 22, 2021
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
113 changes: 56 additions & 57 deletions tests/scorers/test_detailed_hla_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,68 +59,67 @@ def test_get_genotype(self):
self.assertSetEqual(set(expected_result.donor_matches), set(actual_result.donor_matches))
self.assertSetEqual(set(expected_result.recipient_matches), set(actual_result.recipient_matches))

def test_scorer_on_some_patients(self):
scorer = HLAAdditiveScorer()
donor = Donor(
db_id=1,
medical_id='donor',
parameters=PatientParameters(
blood_group=BloodGroup.A,
country_code=Country.CZE,
hla_typing=HLATyping(
[HLAType('A1'),
HLAType('A3'),
HLAType('B7'),
HLAType('B37'),
HLAType('DR11'),
HLAType('DR15'),
HLAType('DR52'),
HLAType('DR51'),
HLAType('DQ7'),
HLAType('DQ6')]
)

def test_scorer_on_some_patients(self):
scorer = HLAAdditiveScorer()
donor = Donor(
db_id=1,
medical_id='donor',
parameters=PatientParameters(
blood_group=BloodGroup.A,
country_code=Country.CZE,
hla_typing=HLATyping(
[HLAType('A1'),
HLAType('A3'),
HLAType('B7'),
HLAType('B37'),
HLAType('DR11'),
HLAType('DR15'),
HLAType('DR52'),
HLAType('DR51'),
HLAType('DQ7'),
HLAType('DQ6')]
)

)
)
recipient = Recipient(
db_id=1,
acceptable_blood_groups=[],
related_donor_db_id=1,
medical_id='recipient',
parameters=PatientParameters(
blood_group=BloodGroup.A,
country_code=Country.CZE,
hla_typing=HLATyping(
[HLAType('A1'),
HLAType('A2'),
HLAType('B27'),
HLAType('B37'),
HLAType('DR1'),
HLAType('DR10')]
recipient = Recipient(
db_id=1,
acceptable_blood_groups=[],
related_donor_db_id=1,
medical_id='recipient',
parameters=PatientParameters(
blood_group=BloodGroup.A,
country_code=Country.CZE,
hla_typing=HLATyping(
[HLAType('A1'),
HLAType('A2'),
HLAType('B27'),
HLAType('B37'),
HLAType('DR1'),
HLAType('DR10')]
)
)
)
)

original_donor = Donor(
db_id=2,
medical_id='original_donor',
related_recipient_db_id=1,
parameters=PatientParameters(
blood_group=BloodGroup.A,
country_code=Country.CZE,
hla_typing=HLATyping(
[HLAType('A1'),
HLAType('A9'),
HLAType('B7'),
HLAType('B37'),
HLAType('DR11'),
HLAType('DR15'),
HLAType('DR52'),
HLAType('DR51'),
HLAType('DQ7'),
HLAType('DQ6')]
original_donor = Donor(
db_id=2,
medical_id='original_donor',
related_recipient_db_id=1,
parameters=PatientParameters(
blood_group=BloodGroup.A,
country_code=Country.CZE,
hla_typing=HLATyping(
[HLAType('A1'),
HLAType('A9'),
HLAType('B7'),
HLAType('B37'),
HLAType('DR11'),
HLAType('DR15'),
HLAType('DR52'),
HLAType('DR51'),
HLAType('DQ7'),
HLAType('DQ6')]
)
)
)
)
self.assertEqual(4, scorer.score_transplant(donor=donor, recipient=recipient, original_donor=original_donor))
self.assertEqual(4, scorer.score_transplant(donor=donor, recipient=recipient, original_donor=original_donor))
105 changes: 37 additions & 68 deletions tests/web/test_matching_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
from txmatching.database.services import solver_service
from txmatching.database.services.txm_event_service import \
get_txm_event_complete
from txmatching.database.sql_alchemy_schema import ConfigModel
from txmatching.solve_service.solve_from_configuration import \
solve_from_configuration
from txmatching.utils.enums import HLAGroup, MatchTypes
from txmatching.utils.get_absolute_path import get_absolute_path
from txmatching.web import (API_VERSION, MATCHING_NAMESPACE, PATIENT_NAMESPACE,
TXM_EVENT_NAMESPACE)
from txmatching.web import API_VERSION, MATCHING_NAMESPACE, TXM_EVENT_NAMESPACE


class TestSaveAndGetConfiguration(DbTests):
Expand Down Expand Up @@ -213,74 +211,45 @@ def test_get_matchings(self):
'recipient_matches'
])

def test_correct_config_applied(self):
txm_event_db_id = self.fill_db_with_patients(get_absolute_path(PATIENT_DATA_OBFUSCATED))

def test_get_patients(self):
txm_event_db_id = self.fill_db_with_patients()
with self.app.test_client() as client:
res = client.get(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/{PATIENT_NAMESPACE}',
headers=self.auth_headers)
self.assertEqual(2, len(res.json['donors']))
self.assertEqual(2, len(res.json['recipients']))


def test_save_recipient(self):
txm_event_db_id = self.fill_db_with_patients_and_results()
recipient_update_dict = {
'db_id': 1,
'acceptable_blood_groups': ['A', 'AB'],
}
with self.app.test_client() as client:
self.assertIsNotNone(ConfigModel.query.get(1))
res = client.put(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/{PATIENT_NAMESPACE}/recipient',
headers=self.auth_headers,
json=recipient_update_dict).json
self.assertEqual(['A', 'AB'], res['acceptable_blood_groups'])
recipients = client.get(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/{PATIENT_NAMESPACE}',
headers=self.auth_headers).json['recipients']
self.assertEqual(recipient_update_dict['acceptable_blood_groups'], recipients[0]['acceptable_blood_groups'])

self.assertIsNone(ConfigModel.query.get(1))


def test_correct_config_applied(self):
txm_event_db_id = self.fill_db_with_patients(get_absolute_path(PATIENT_DATA_OBFUSCATED))

with self.app.test_client() as client:
conf_dto = dataclasses.asdict(Configuration(max_number_of_distinct_countries_in_round=1))

res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
self.assertEqual(9, len(res.json))

conf_dto2 = dataclasses.asdict(Configuration(max_number_of_distinct_countries_in_round=50))

res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto2,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
self.assertEqual(503, len(res.json))
with self.app.test_client() as client:
conf_dto = dataclasses.asdict(Configuration(max_number_of_distinct_countries_in_round=1))

res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
self.assertEqual(9, res.json['found_matchings_count'])

def test_solver_multiple_txm_events(self):
txm_event_db_id = self.fill_db_with_patients(get_absolute_path(PATIENT_DATA_OBFUSCATED))
conf_dto2 = dataclasses.asdict(Configuration(max_number_of_distinct_countries_in_round=50))

with self.app.test_client() as client:
conf_dto = dataclasses.asdict(Configuration(max_number_of_distinct_countries_in_round=1))
res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto2,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
self.assertEqual(947, res.json['found_matchings_count'])

res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
def test_solver_multiple_txm_events(self):
txm_event_db_id = self.fill_db_with_patients(get_absolute_path(PATIENT_DATA_OBFUSCATED))

create_or_overwrite_txm_event(name='test2')
res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
self.assertEqual(0, len(res.json))
with self.app.test_client() as client:
conf_dto = dataclasses.asdict(Configuration(max_number_of_distinct_countries_in_round=1))

res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto,
headers=self.auth_headers)
self.assertEqual(9, res.json['found_matchings_count'])
self.assertEqual(200, res.status_code)

txm_event_db_id_2 = create_or_overwrite_txm_event(name='test2').db_id
res = client.post(f'{API_VERSION}/{TXM_EVENT_NAMESPACE}/{txm_event_db_id_2}/'
f'{MATCHING_NAMESPACE}/calculate-for-config',
json=conf_dto,
headers=self.auth_headers)
self.assertEqual(200, res.status_code)
self.assertEqual(0, res.json['found_matchings_count'])
Loading