Skip to content

Commit

Permalink
test: simple pylint adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Jan 11, 2024
1 parent 4ea07ca commit f0eb8e2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
59 changes: 30 additions & 29 deletions api/app/routers/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from app.dependencies import get_current_active_user
from app.pydantic_models import PatientModel, PatientConditionListModel, CompletePatientModel
from app.models import (
User, DataSource, Patient, City, Race, Gender, Nationality, Address, Telecom, PatientCondition, ConditionCode
User, Patient, City, Race, Gender, Nationality, Address,
Telecom, PatientCondition, ConditionCode
)

PatientOutput = pydantic_model_creator(Patient, name="PatientOutput")
Expand All @@ -22,43 +23,43 @@ async def create_or_update_patient(
_: Annotated[User, Depends(get_current_active_user)],
patient: PatientModel,
) -> PatientOutput:
input = patient.dict()
patient_data = patient.dict()

birth_city = await City.get_or_none(
code = input['birth_city'],
state__code = input['birth_state'],
state__country__code = input['birth_country']
code = patient_data['birth_city'],
state__code = patient_data['birth_state'],
state__country__code = patient_data['birth_country']
)
new_data = {
'patient_cpf' : input.get('patient_cpf'),
'birth_date' : input.get('birth_date'),
'active' : input.get('active'),
'protected_person' : input.get('protected_person'),
'deceased' : input.get('deceased'),
'deceased_date' : input.get('deceased_date'),
'name' : input.get('name'),
'mother_name' : input.get('mother'),
'father_name' : input.get('father'),
'naturalization' : input.get('naturalization'),
'patient_cpf' : patient_data.get('patient_cpf'),
'birth_date' : patient_data.get('birth_date'),
'active' : patient_data.get('active'),
'protected_person' : patient_data.get('protected_person'),
'deceased' : patient_data.get('deceased'),
'deceased_date' : patient_data.get('deceased_date'),
'name' : patient_data.get('name'),
'mother_name' : patient_data.get('mother'),
'father_name' : patient_data.get('father'),
'naturalization' : patient_data.get('naturalization'),
'birth_city' : birth_city,
'race' : await Race.get_or_none(slug = input['race']),
'gender' : await Gender.get_or_none(slug = input['gender']),
'nationality' : await Nationality.get_or_none(slug = input['nationality']),
'race' : await Race.get_or_none(slug = patient_data['race']),
'gender' : await Gender.get_or_none(slug = patient_data['gender']),
'nationality' : await Nationality.get_or_none(slug = patient_data['nationality']),
}

patient = await Patient.get_or_none(
patient_cpf = input.get('patient_cpf')
patient_cpf = patient_data.get('patient_cpf')
).prefetch_related('address_patient_periods','telecom_patient_periods')

if patient != None:
if patient is not None:
await patient.update_from_dict(new_data).save()
else:
patient = await Patient.create(**new_data)

# Reset de Address
for instance in patient.address_patient_periods.related_objects:
await instance.delete()
for address in input.get("address_list"):
for address in patient_data.get("address_list"):
address_city = await City.get_or_none(
code = address['city'],
state__code = address['state'],
Expand All @@ -71,7 +72,7 @@ async def create_or_update_patient(
# Reset de Telecom
for instance in patient.telecom_patient_periods.related_objects:
await instance.delete()
for telecom in input.get("telecom_list"):
for telecom in patient_data.get("telecom_list"):
telecom['patient'] = patient
await Telecom.create(**telecom)

Expand All @@ -83,25 +84,25 @@ async def create_or_update_patientcondition(
_: Annotated[User, Depends(get_current_active_user)],
patientcondition: PatientConditionListModel,
) -> list[PatientConditionOutput]:
input = patientcondition.dict()
patient_data = patientcondition.dict()

patient = await Patient.get_or_none(
patient_cpf=input.get('patient_cpf')
patient_cpf=patient_data.get('patient_cpf')
).prefetch_related('patientconditions')

if patient == None:
if patient is None:
raise HTTPException(status_code=400, detail="Patient don't exist")

# Reset Patient Conditions
for instance in patient.patientconditions.related_objects:
await instance.delete()

conditions = []
for condition in input.get('conditions'):
for condition in patient_data.get('conditions'):
condition_code = await ConditionCode.get_or_none(
value=condition.get('code')
)
if condition_code == None:
if condition_code is None:
raise HTTPException(
status_code=400,
detail=f"Condition Code {condition.get('code')} don't exist"
Expand All @@ -116,7 +117,7 @@ async def create_or_update_patientcondition(
@router.get("/patient/{patient_cpf}", response_model=CompletePatientModel)
async def get_patient(
patient_cpf : int,
current_user: Annotated[User, Depends(get_current_active_user)],
_: Annotated[User, Depends(get_current_active_user)],
) -> list[CompletePatientModel]:

patient = await Patient.get_or_none(patient_cpf=patient_cpf).prefetch_related(
Expand Down Expand Up @@ -163,4 +164,4 @@ async def get_patient(
patient_data['condition_list'] = condition_list
patient_data['cns_list'] = cns_list

return patient_data
return patient_data
10 changes: 7 additions & 3 deletions api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def event_loop():

@pytest.fixture(scope="session")
async def client():
async with AsyncClient(app=app, base_url="http://test") as client:
yield client
async with AsyncClient(app=app, base_url="http://test") as client_object:
yield client_object


@pytest.fixture(scope="session", autouse=True)
Expand All @@ -54,7 +54,11 @@ async def initialize_tests(patient_cpf: str):
await Address.all().delete()
await Telecom.all().delete()

datasource = await DataSource.create(description="test_datasource", system="vitacare", cnes="1234567")
datasource = await DataSource.create(
description="test_datasource",
system="vitacare",
cnes="1234567"
)
country = await Country.create(name="Brasil", code="00001")
state = await State.create(name="Rio de Janeiro", country=country, code="00001")
city = await City.create(name="Rio de Janeiro", state=state, code="00001")
Expand Down

0 comments on commit f0eb8e2

Please sign in to comment.