-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #941 from mild-blue/process_excel_to_json
Process Belgian excel to json
- Loading branch information
Showing
25 changed files
with
184 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[settings] | ||
known_third_party = dacite,flask,flask_bcrypt,flask_restx,flask_sqlalchemy,graph_tool,gunicorn,itsdangerous,jinja2,jwt,mip,networkx,numpy,openapi_spec_validator,pandas,pdfkit,pyotp,requests,responses,sentry_sdk,sqlalchemy,swagger_unittest,werkzeug,yaml,yoyo | ||
known_third_party = dacite,distutils,flask,flask_bcrypt,flask_restx,flask_sqlalchemy,graph_tool,gunicorn,itsdangerous,jinja2,jwt,mip,networkx,numpy,openapi_spec_validator,pandas,pdfkit,pyotp,requests,responses,sentry_sdk,sqlalchemy,swagger_unittest,werkzeug,yaml,yoyo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import dataclasses | ||
import json | ||
import logging | ||
import os | ||
|
||
from txmatching.utils.country_enum import Country | ||
from txmatching.utils.excel_parsing.parse_excel_data import (ExcelSource, | ||
parse_excel_data) | ||
from txmatching.web import create_app | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# set the path here to excel with data | ||
PATH_TO_DATA_FOR_UPLOAD = '/home/honza/Downloads/LDEP KUL - UCL July 22..xlsx' | ||
TXM_EVENT_NAME = 'TEST-BEL-PRIVATE-2022-02' | ||
|
||
|
||
if __name__ == '__main__': | ||
app = create_app() | ||
with app.app_context(): | ||
patients = parse_excel_data(os.path.join(PATH_TO_DATA_FOR_UPLOAD), | ||
txm_event_name=TXM_EVENT_NAME, | ||
country=Country.BEL_2, | ||
excel_source=ExcelSource.BEL_2 | ||
) | ||
# here we are assuming currently for simplicity that the data is from one country only | ||
patients_together = patients[0] | ||
patients_together.add_to_existing_patients = False | ||
for patient in patients[1:]: | ||
patients_together.donors += patient.donors | ||
patients_together.recipients += patient.recipients | ||
|
||
with open('tmp.json', 'w', encoding='utf-8') as f: | ||
json.dump(dataclasses.asdict(patients_together), f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
txmatching/data_transfer_objects/patients/patient_base_dto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from dataclasses import dataclass | ||
from datetime import date | ||
from typing import Optional | ||
|
||
from txmatching.auth.exceptions import InvalidArgumentException | ||
|
||
Kilograms = float | ||
Centimeters = int | ||
THIS_YEAR = date.today().year | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class PatientBaseDTO: | ||
height: Optional[Centimeters] = None | ||
weight: Optional[Kilograms] = None | ||
year_of_birth: Optional[int] = None | ||
|
||
def __post_init__(self): | ||
if self.weight: | ||
_is_weight_valid(self.weight) | ||
if self.height: | ||
_is_height_valid(self.height) | ||
if self.year_of_birth: | ||
_is_year_of_birth_valid(self.year_of_birth) | ||
|
||
|
||
def _is_height_valid(height: Centimeters): | ||
if height < 0: | ||
raise InvalidArgumentException(f'Invalid patient height {height}cm.') | ||
|
||
|
||
def _is_weight_valid(weight: Kilograms): | ||
if weight < 0: | ||
raise InvalidArgumentException(f'Invalid patient weight {weight}kg.') | ||
|
||
|
||
def _is_year_of_birth_valid(year_of_birth: Centimeters): | ||
if year_of_birth < 1900 or year_of_birth > THIS_YEAR: | ||
raise InvalidArgumentException(f'Invalid patient year of birth {year_of_birth}') | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class RecipientBaseDTO: | ||
previous_transplants: Optional[int] = None | ||
|
||
def __post_init__(self): | ||
if self.previous_transplants and self.previous_transplants < 0: | ||
raise InvalidArgumentException( | ||
f'Invalid recipient number of previous transplants {self.previous_transplants}.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
txmatching/data_transfer_objects/patients/update_dtos/patient_update_dto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
from txmatching.data_transfer_objects.patients.patient_base_dto import ( | ||
PatientBaseDTO, RecipientBaseDTO) | ||
from txmatching.data_transfer_objects.patients.update_dtos.hla_code_update_dtos import \ | ||
HLATypingUpdateDTO | ||
from txmatching.patients.patient_parameters import Centimeters, Kilograms | ||
from txmatching.utils.blood_groups import BloodGroup | ||
from txmatching.utils.enums import Sex | ||
|
||
|
||
@dataclass | ||
class PatientUpdateDTO: | ||
@dataclass(kw_only=True) | ||
class PatientUpdateDTO(PatientBaseDTO, RecipientBaseDTO): | ||
# pylint: disable=too-many-instance-attributes | ||
# It is reasonable to have many attributes here | ||
db_id: int | ||
etag: int | ||
blood_group: Optional[BloodGroup] = None | ||
hla_typing: Optional[HLATypingUpdateDTO] = None | ||
sex: Optional[Sex] = None | ||
height: Optional[Centimeters] = None | ||
weight: Optional[Kilograms] = None | ||
year_of_birth: Optional[int] = None | ||
note: Optional[str] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 4 additions & 22 deletions
26
txmatching/data_transfer_objects/patients/upload_dtos/recipient_upload_dto.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,23 @@ | ||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
|
||
from txmatching.data_transfer_objects.patients.patient_base_dto import ( | ||
PatientBaseDTO, RecipientBaseDTO) | ||
from txmatching.data_transfer_objects.patients.upload_dtos.hla_antibodies_upload_dto import \ | ||
HLAAntibodiesUploadDTO | ||
from txmatching.patients.patient import (is_height_valid, is_number_of_previous_transplants_valid, | ||
is_weight_valid, is_year_of_birth_valid) | ||
from txmatching.patients.patient_parameters import Centimeters, Kilograms | ||
from txmatching.utils.blood_groups import BloodGroup | ||
from txmatching.utils.enums import Sex | ||
|
||
|
||
@dataclass | ||
class RecipientUploadDTO: | ||
@dataclass(kw_only=True) | ||
class RecipientUploadDTO(PatientBaseDTO, RecipientBaseDTO): | ||
# pylint: disable=too-many-instance-attributes | ||
acceptable_blood_groups: Optional[List[BloodGroup]] | ||
medical_id: str | ||
blood_group: BloodGroup | ||
hla_typing: List[str] | ||
hla_antibodies: List[HLAAntibodiesUploadDTO] | ||
sex: Optional[Sex] = None | ||
height: Optional[Centimeters] = None | ||
weight: Optional[Kilograms] = None | ||
year_of_birth: Optional[int] = None | ||
note: str = '' | ||
waiting_since: Optional[str] = None | ||
previous_transplants: Optional[int] = None | ||
internal_medical_id: Optional[str] = None | ||
|
||
def __post_init__(self): | ||
if self.height: | ||
is_height_valid("recipient", self.height) | ||
|
||
if self.weight: | ||
is_weight_valid("recipient", self.weight) | ||
|
||
if self.year_of_birth: | ||
is_year_of_birth_valid("recipient", self.year_of_birth) | ||
|
||
if self.previous_transplants: | ||
is_number_of_previous_transplants_valid(self.previous_transplants) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.