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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repos:

# https://docs.astral.sh/ruff/integrations/#pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.9
rev: v0.14.11
hooks:
# Run the linter with fixes
- id: ruff
Expand Down
9 changes: 6 additions & 3 deletions opal/caregivers/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class GetRegistrationEncryptionInfoView(RetrieveAPIView[RegistrationCode]):
"""Class handling gets requests for registration encryption values."""

queryset = (
RegistrationCode.objects.select_related(
RegistrationCode.objects
.select_related(
'relationship',
'relationship__patient',
)
Expand Down Expand Up @@ -198,7 +199,8 @@ def get_queryset(self) -> QuerySet[RegistrationCode]:
"""
code = self.kwargs.get('code') if hasattr(self, 'kwargs') else None
return (
RegistrationCode.objects.select_related(
RegistrationCode.objects
.select_related(
'relationship__caregiver',
'relationship__caregiver__user',
)
Expand Down Expand Up @@ -523,7 +525,8 @@ def _get_email_address(self, relationship: Relationship, caregiver_data: dict[st
# use the last one
email_verifications: Manager[EmailVerification] = relationship.caregiver.email_verifications
email_verification = (
email_verifications.filter(
email_verifications
.filter(
is_verified=True,
)
.order_by('-sent_at')
Expand Down
12 changes: 4 additions & 8 deletions opal/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,9 @@ def django_db_setup(
Yields:
None
"""
with Path('opal/tests/sql/questionnairedb_functions.sql').open(encoding='utf-8') as handle:
sql_content = handle.read()
sql_content = Path('opal/tests/sql/questionnairedb_functions.sql').read_text(encoding='utf-8')

with Path('opal/tests/sql/questionnairedb_cleanup.sql').open(encoding='utf-8') as handle:
sql_cleanup = handle.read()
sql_cleanup = Path('opal/tests/sql/questionnairedb_cleanup.sql').read_text(encoding='utf-8')

with django_db_blocker.unblock(), connections['questionnaire'].cursor() as conn:
conn.execute(sql_content)
Expand Down Expand Up @@ -410,11 +408,9 @@ def questionnaire_data(django_db_blocker: DjangoDbBlocker) -> Generator[None]:
Yields:
None
"""
with Path('opal/tests/sql/questionnairedb_data.sql').open(encoding='utf-8') as handle:
sql_data = handle.read()
sql_data = Path('opal/tests/sql/questionnairedb_data.sql').read_text(encoding='utf-8')

with Path('opal/tests/sql/questionnairedb_cleanup.sql').open(encoding='utf-8') as handle:
sql_cleanup = handle.read()
sql_cleanup = Path('opal/tests/sql/questionnairedb_cleanup.sql').read_text(encoding='utf-8')

with django_db_blocker.unblock(), connections['questionnaire'].cursor() as conn:
# safety check to ensure that there is no data already
Expand Down
3 changes: 2 additions & 1 deletion opal/core/drf_parsers/hl7_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def parse_pid_segment(segment: Segment) -> dict[str, Any]:
return {
'first_name': segment.pid_5.pid_5_2.to_er7(),
'last_name': segment.pid_5.pid_5_1.to_er7(),
'date_of_birth': datetime.strptime(segment.pid_7.to_er7(), FORMAT_DATE)
'date_of_birth': datetime
.strptime(segment.pid_7.to_er7(), FORMAT_DATE)
.astimezone(timezone.get_current_timezone())
.date(),
'sex': segment.pid_8.to_er7(),
Expand Down
3 changes: 2 additions & 1 deletion opal/health_data/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def post(self, request: Request) -> Response:

# Unviewed counts of patients' QuantitySamples
unviewed_counts = (
Patient.objects.select_related(
Patient.objects
.select_related(
'quantity_samples',
)
.filter(
Expand Down
6 changes: 4 additions & 2 deletions opal/health_data/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def fetch_blood_pressure_measurements(

# Add .order_by() to remove ORDER BY statement that is added by default
diastolic_measurements = (
self.filter(
self
.filter(
patient=patient,
type=quantity_sample_models.QuantitySampleType.BLOOD_PRESSURE_DIASTOLIC,
start_date=models.OuterRef('start_date'),
Expand All @@ -69,7 +70,8 @@ def fetch_blood_pressure_measurements(

# list() forces QuerySet evaluation that makes call to the database
return list(
self.filter(
self
.filter(
patient=patient,
type=quantity_sample_models.QuantitySampleType.BLOOD_PRESSURE_SYSTOLIC,
)
Expand Down
3 changes: 2 additions & 1 deletion opal/health_data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def build_all_quantity_sample_charts(patient: Patient) -> dict[str, str | None]:
# Build charts for the measurements that contain only one value
for sample_type in SINGLE_VALUE_SAMPLE_TYPES:
queryset = (
QuantitySample.objects.order_by('start_date')
QuantitySample.objects
.order_by('start_date')
.filter(
patient=patient,
type=sample_type,
Expand Down
3 changes: 1 addition & 2 deletions opal/hospital_settings/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def fixture_institution_form_files() -> dict[str, SimpleUploadedFile]:
Returns:
dictionary with two logo image files
"""
with Path('opal/tests/fixtures/test_logo.png').open(mode='rb') as image_logo:
file_content = image_logo.read()
file_content = Path('opal/tests/fixtures/test_logo.png').read_bytes()

return {
'logo_en': SimpleUploadedFile(
Expand Down
6 changes: 4 additions & 2 deletions opal/legacy/api/views/app_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:
legacy_id,
username,
).count(),
'unread_educationalmaterial_count': models.LegacyEducationalMaterial.objects.get_unread_queryset(
'unread_educationalmaterial_count': models.LegacyEducationalMaterial.objects
.get_unread_queryset(
legacy_id,
username,
)
Expand All @@ -83,7 +84,8 @@ def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:
username,
1,
).count(),
'unread_research_reference_count': models.LegacyEducationalMaterial.objects.get_unread_queryset(
'unread_research_reference_count': models.LegacyEducationalMaterial.objects
.get_unread_queryset(
legacy_id,
username,
)
Expand Down
6 changes: 4 additions & 2 deletions opal/legacy/api/views/tests/test_app_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def test_get_unread_clinical_edumaterial_count(self, admin_api_client: APIClient

# Direct function call
edumaterials = (
models.LegacyEducationalMaterial.objects.get_unread_queryset(
models.LegacyEducationalMaterial.objects
.get_unread_queryset(
self.patient.patientsernum,
self.user.username,
)
Expand All @@ -165,7 +166,8 @@ def test_get_unread_research_edumaterial_count(self, admin_api_client: APIClient

# Direct function call
edumaterials = (
models.LegacyEducationalMaterial.objects.get_unread_queryset(
models.LegacyEducationalMaterial.objects
.get_unread_queryset(
self.patient.patientsernum,
self.user.username,
)
Expand Down
6 changes: 3 additions & 3 deletions opal/legacy/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ class Meta:
normal_range_min = Faker('random_int')
normal_range_max = Faker('random_int')
normal_range = lazy_attribute(
lambda legacypatienttestresult: str(legacypatienttestresult.normal_range_min)
+ '-'
+ str(legacypatienttestresult.normal_range_max),
lambda legacypatienttestresult: (
f'{legacypatienttestresult.normal_range_min} - {legacypatienttestresult.normal_range_max}'
),
)
test_value_numeric = Faker('pyfloat', positive=True)
test_value_string = lazy_attribute(lambda legacypatienttestresult: str(legacypatienttestresult.test_value_numeric))
Expand Down
27 changes: 18 additions & 9 deletions opal/legacy/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def get_daily_appointments(self, username: str) -> models.QuerySet['LegacyAppoin
if legacy_id is not None
]
return (
self.select_related(
self
.select_related(
'aliasexpressionsernum__aliassernum__appointmentcheckin',
'aliasexpressionsernum__aliassernum__educational_material_control_ser_num',
)
Expand Down Expand Up @@ -161,7 +162,8 @@ def get_closest_appointment(self, username: str) -> Optional['LegacyAppointment'
status=RelationshipStatus.CONFIRMED,
)
return (
self.filter(
self
.filter(
scheduledstarttime__gte=timezone.localtime(timezone.now()),
patientsernum__in=patient_ids,
state='Active',
Expand Down Expand Up @@ -190,7 +192,8 @@ def get_databank_data_for_patient(

"""
return (
self.select_related(
self
.select_related(
'aliasexpressionsernum__aliassernum',
'source_database',
'patientsernum',
Expand Down Expand Up @@ -327,7 +330,8 @@ def get_unread_queryset(self, patient_sernum_list: list[int], username: str) ->
Count of unread announcement(s) records.
"""
return (
self.exclude(
self
.exclude(
readby__contains=username,
)
.filter(
Expand Down Expand Up @@ -357,7 +361,8 @@ def get_databank_data_for_patient(

"""
return (
self.filter(
self
.filter(
patientsernum=patient_ser_num,
last_updated__gt=last_synchronized,
)
Expand Down Expand Up @@ -413,7 +418,8 @@ def get_databank_data_for_patient(
Diagnosis data
"""
return (
self.filter(
self
.filter(
patient_ser_num=patient_ser_num,
last_updated__gt=last_synchronized,
)
Expand Down Expand Up @@ -452,7 +458,8 @@ def get_databank_data_for_patient(
Lab data
"""
return (
self.select_related(
self
.select_related(
'test_expression_ser_num',
'test_group_expression_ser_num',
'patient_ser_num',
Expand Down Expand Up @@ -540,7 +547,8 @@ def get_aggregated_user_app_activities(
Annotated `LegacyPatientActivityLog` records
"""
return (
self.filter(
self
.filter(
date_time__gte=start_datetime_period,
date_time__lt=end_datetime_period,
)
Expand Down Expand Up @@ -638,7 +646,8 @@ def get_aggregated_patient_app_activities(
# Whereas if Marge clicks on a TxTeamMessage from her chart page,
# PAL shows Request=Read, Parameters={"Field":"TxTeamMessages","Id":"1"}
return (
self.filter(
self
.filter(
date_time__gte=start_datetime_period,
date_time__lt=end_datetime_period,
)
Expand Down
3 changes: 2 additions & 1 deletion opal/legacy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ def generate_questionnaire_report(
patient_date_of_birth=patient.date_of_birth,
patient_ramq=patient.ramq,
patient_sites_and_mrns=list(
patient.hospital_patients.all()
patient.hospital_patients
.all()
.annotate(
site_code=models.F('site__acronym'),
)
Expand Down
6 changes: 3 additions & 3 deletions opal/patients/api/tests/test_api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ def test_demographic_update_deceased_patient(
api_client.force_login(interface_engine_user)
payload = self._get_valid_input_data()
payload['date_of_death'] = (
timezone.now()
timezone
.now()
.astimezone()
.replace(
microsecond=0,
Expand Down Expand Up @@ -1141,8 +1142,7 @@ def test_summary_saved(
saved_file = Path(settings.MEDIA_ROOT) / spy_storage_save.spy_return
assert saved_file.exists()

with Path(saved_file).open(encoding='utf-8') as f:
saved_data = f.read()
saved_data = Path(saved_file).read_text(encoding='utf-8')

# base64 URL decode to have 32 bytes of data
key_decoded = utils.base64url_decode(encryption_key.encode('utf-8'))
Expand Down
3 changes: 2 additions & 1 deletion opal/patients/management/commands/expire_relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def handle(self, *args: Any, **kwargs: Any) -> None:
number_of_updates = 0

relationships_to_check = (
Relationship.objects.select_related(
Relationship.objects
.select_related(
'patient',
'type',
)
Expand Down
9 changes: 6 additions & 3 deletions opal/patients/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ def validate_type(self) -> list[str]:
hasattr(self, 'patient')
and self.type.role_type == RoleType.SELF
# exclude the current instance to support updating it
and Relationship.objects.exclude(
and Relationship.objects
.exclude(
pk=self.pk,
)
.filter(
Expand All @@ -523,7 +524,8 @@ def validate_type(self) -> list[str]:
hasattr(self, 'caregiver')
and self.type.role_type == RoleType.SELF
# exclude the current instance to support updating it
and Relationship.objects.exclude(
and Relationship.objects
.exclude(
pk=self.pk,
)
.filter(
Expand Down Expand Up @@ -574,7 +576,8 @@ def clean(self) -> None:
hasattr(self, 'patient')
and hasattr(self, 'caregiver')
# exclude the current instance to support updating it
and Relationship.objects.exclude(
and Relationship.objects
.exclude(
pk=self.pk,
)
.filter(
Expand Down
6 changes: 4 additions & 2 deletions opal/patients/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,8 @@ def test_accessrequestrequestorform_form_filled_required_type(role_type: RoleTyp
def test_accessrequestrequestorform_relationship_type(age: int, enabled_options: list[RoleType]) -> None:
"""Ensure the relationship_type field has the correct options enabled/disabled based on the patient's age."""
relationship_types = list(
RelationshipType.objects.filter(
RelationshipType.objects
.filter(
role_type__in=enabled_options,
)
.values_list('name', flat=True)
Expand Down Expand Up @@ -955,7 +956,8 @@ def test_accessrequestrequestorform_relationship_type_existing_self() -> None:
disabled_options = [option['label'] for option in options if option['attrs'].get('disabled', '') == 'disabled']

disabled_types = list(
RelationshipType.objects.filter(
RelationshipType.objects
.filter(
role_type__in=[
RoleType.SELF,
RoleType.GUARDIAN_CAREGIVER,
Expand Down
3 changes: 2 additions & 1 deletion opal/test_results/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def generate_pathology_report(
patient_date_of_birth=patient.date_of_birth,
patient_ramq=patient.ramq or '',
patient_sites_and_mrns=list(
patient.hospital_patients.all()
patient.hospital_patients
.all()
.annotate(
site_code=models.F('site__acronym'),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def _populate_user_patient_app_activities(
# Since between the same patient and caregiver might be many different relationships,
# the query fetches only one record per patient <===> caregiver relationship with the maximum end_date
relationships = (
Relationship.objects.select_related(
Relationship.objects
.select_related(
'patient',
'caregiver__user',
)
Expand Down
Loading