Skip to content

Commit

Permalink
Merge pull request #149 from swiftss-org/fix-failing-build
Browse files Browse the repository at this point in the history
Fix failing build
  • Loading branch information
szigyi authored Mar 8, 2024
2 parents ed0e332 + ad12693 commit 53e8f77
Show file tree
Hide file tree
Showing 41 changed files with 302 additions and 162 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- hooks:
- id: detect-secrets
args: [ '--baseline', '.pre-commit/.secrets.baseline' ]
exclude: (config/settings/test.py|/static|.html|local|README.md)
exclude: (config/settings/test.py|/static|.html|local|README.md|.pre-commit/|test_views.py)
repo: https://github.com/Yelp/detect-secrets.git
rev: v1.4.0

Expand Down Expand Up @@ -75,6 +75,6 @@ repos:

- hooks:
- id: bandit
args: [ --verbose, -ll, --recursive, . ]
args: [ --verbose, -ll, . ]
repo: https://github.com/PyCQA/bandit
rev: 1.7.7
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ If you want to run _outside_ of Docker you will also need to:

If you are on _Windows_ and not Linux (or other *nix) you will also need to have installed:
1. [MSYS](https://www.msys2.org/) or an alternative set of Unix compatible tools that includes `make`.
1. [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) which are required to install some of the Python [Django](https://www.djangoproject.com/) dependencies.
1. [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) which are required to install some of the Python [Django](https://www.djangoproject.com/) dependencies.


### First time only

Expand All @@ -37,9 +37,9 @@ pyenv virtualenv registry-api
pyenv activate registry-api
```

Or if you prefer to use [virtualenv](https://virtualenv.pypa.io/en/latest/) directly without pyenv:
Or if you prefer to use [virtualenv](https://virtualenv.pypa.io/en/latest/) directly without pyenv:
```
# Linux
# Linux
$ virtualenv venv
$ activate venv
Expand Down
3 changes: 3 additions & 0 deletions checkInCheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

make pre-commit && make run && make test
1 change: 1 addition & 0 deletions config/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://docs.djangoproject.com/en/dev/howto/deployment/asgi/
"""

import os
import sys
from pathlib import Path
Expand Down
6 changes: 3 additions & 3 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
TemplateView.as_view(
template_name="pages/home.html",
extra_context={
"only_token_auth": True
if "production" in module_type
else False
"only_token_auth": (
True if "production" in module_type else False
)
},
),
name="home",
Expand Down
1 change: 1 addition & 0 deletions config/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
framework.
"""

import os
import sys
from pathlib import Path
Expand Down
2 changes: 1 addition & 1 deletion requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ flake8==3.8.4 # https://github.com/PyCQA/flake8
flake8-isort==4.0.0 # https://github.com/gforcada/flake8-isort
coverage==5.5 # https://github.com/nedbat/coveragepy
black==20.8b1 # https://github.com/ambv/black
pylint-django==2.4.4 # https://github.com/PyCQA/pylint-django
pylint-django==2.5.4 # https://github.com/PyCQA/pylint-django
pre-commit==2.10.1 # https://github.com/pre-commit/pre-commit
isort==4.3.21 # https://github.com/PyCQA/isort

Expand Down
8 changes: 6 additions & 2 deletions tmh_registry/common/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ def get_text_choice_value_from_label(choices, label):
if not label:
return None

values = [choice[0] for choice in choices if choice[1].upper() == label.upper()]
values = [
choice[0] for choice in choices if choice[1].upper() == label.upper()
]
if len(values) == 0:
raise IndexError('Unable to find label "{}" in choices "{}"'.format(label, choices))
raise IndexError(
'Unable to find label "{}" in choices "{}"'.format(label, choices)
)

return values[0]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
"""

from django.conf import settings
from django.db import migrations

Expand Down
18 changes: 12 additions & 6 deletions tmh_registry/registry/admin.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
from django.contrib import admin
from import_export.admin import ExportMixin
from import_export import resources
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from import_export import resources
from import_export.admin import ExportMixin

from tmh_registry.registry.models import (
Discharge,
Episode,
FollowUp,
Hospital,
Patient,
PatientHospitalMapping, Discharge, FollowUp,
PatientHospitalMapping,
)


@admin.register(Discharge)
class DischargeAdmin(ExportMixin, admin.ModelAdmin):
model = Discharge


@admin.register(FollowUp)
class FollowUpAdmin(ExportMixin, admin.ModelAdmin):
model = FollowUp


@admin.register(Hospital)
class HospitalAdmin(ExportMixin, admin.ModelAdmin):
model = Hospital
Expand All @@ -44,14 +47,17 @@ class EpisodeAdmin(ExportMixin, admin.ModelAdmin):
"""
To allow CSV export on User model
"""


class UserResource(resources.ModelResource):
class Meta:
model = User
fields = ('first_name', 'last_name', 'email')
fields = ("first_name", "last_name", "email")


class UserAdmin(ExportMixin, UserAdmin):
resource_class = UserResource
pass


admin.site.unregister(User)
admin.site.register(User, UserAdmin)
40 changes: 23 additions & 17 deletions tmh_registry/registry/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from drf_yasg.utils import swagger_serializer_method
from rest_framework.exceptions import ValidationError
from rest_framework.fields import CharField, IntegerField, BooleanField
from rest_framework.fields import BooleanField, CharField, IntegerField
from rest_framework.relations import PrimaryKeyRelatedField
from rest_framework.serializers import ModelSerializer, SerializerMethodField

Expand Down Expand Up @@ -150,9 +150,9 @@ def create(self, validated_data):

if not validated_data.get("year_of_birth", None):
if validated_data["age"]:
validated_data[
"year_of_birth"
] = Patient.get_year_of_birth_from_age(validated_data["age"])
validated_data["year_of_birth"] = (
Patient.get_year_of_birth_from_age(validated_data["age"])
)
else:
raise ValidationError(
{
Expand Down Expand Up @@ -448,7 +448,7 @@ def create(self, validated_data):
),
diathermy_used=validated_data["diathermy_used"],
antibiotic_used=validated_data["antibiotic_used"],
antibiotic_type=validated_data.get("antibiotic_type", "")
antibiotic_type=validated_data.get("antibiotic_type", ""),
)
except IndexError:
raise ValidationError(
Expand All @@ -473,7 +473,7 @@ class Meta:
"aware_of_mesh",
"infection",
"discharge_duration",
"comments"
"comments",
]


Expand All @@ -492,7 +492,7 @@ class Meta:
"aware_of_mesh",
"infection",
"discharge_duration",
"comments"
"comments",
]

def to_representation(self, instance):
Expand All @@ -515,7 +515,7 @@ def create(self, validated_data):
aware_of_mesh=validated_data["aware_of_mesh"],
infection=validated_data.get("infection", ""),
discharge_duration=validated_data.get("discharge_duration", None),
comments=validated_data.get("comments", "")
comments=validated_data.get("comments", ""),
)

return discharge
Expand All @@ -539,7 +539,7 @@ class Meta:
"infection",
"numbness",
"further_surgery_need",
"surgery_comments_box"
"surgery_comments_box",
]


Expand All @@ -551,7 +551,9 @@ class FollowUpWriteSerializer(ModelSerializer):
write_only=True, many=True, queryset=MedicalPersonnel.objects.all()
)
pain_severity = CharField()
surgery_comments_box = CharField(required=False, allow_blank=True, allow_null=True)
surgery_comments_box = CharField(
required=False, allow_blank=True, allow_null=True
)
further_surgery_need = BooleanField()

class Meta:
Expand All @@ -566,7 +568,7 @@ class Meta:
"infection",
"numbness",
"further_surgery_need",
"surgery_comments_box"
"surgery_comments_box",
]

def to_representation(self, instance):
Expand Down Expand Up @@ -596,17 +598,21 @@ def create(self, validated_data):
follow_up = FollowUp.objects.create(
episode_id=episode.id,
date=validated_data["date"],
pain_severity=get_text_choice_value_from_label(
FollowUp.PainSeverityChoices.choices, pain_severity
)
if pain_severity
else "",
pain_severity=(
get_text_choice_value_from_label(
FollowUp.PainSeverityChoices.choices, pain_severity
)
if pain_severity
else ""
),
mesh_awareness=validated_data["mesh_awareness"],
seroma=validated_data["seroma"],
infection=validated_data["infection"],
numbness=validated_data["numbness"],
further_surgery_need=validated_data["further_surgery_need"],
surgery_comments_box=validated_data.get("surgery_comments_box", "")
surgery_comments_box=validated_data.get(
"surgery_comments_box", ""
),
)

follow_up.attendees.set(attendees)
Expand Down
29 changes: 20 additions & 9 deletions tmh_registry/registry/api/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q, CharField
from django.db.models import CharField, Q
from django.db.models.functions import Cast
from django.utils.decorators import method_decorator
from django_filters import ( # pylint: disable=E0401
CharFilter,
NumberFilter,
OrderingFilter,
)
from django_filters.rest_framework import FilterSet # pylint: disable=E0401
from django.db.models.functions import Cast
from drf_yasg import openapi
from drf_yasg.openapi import IN_QUERY, TYPE_INTEGER, TYPE_STRING, Parameter
from drf_yasg.utils import swagger_auto_schema
Expand Down Expand Up @@ -68,15 +68,26 @@ def filter_hospital(self, queryset, name, value):
return queryset

def filter_search_term(self, queryset, name, value):
selected_hospital_id_value = self.data.get('hospital_id')
selected_hospital_id_value = self.data.get("hospital_id")
if value:
patient_ids = PatientHospitalMapping.objects.annotate(
patient_hospital_id_str=Cast('patient_hospital_id', CharField())
).filter(
Q(patient_hospital_id_str__contains=str(value)) & Q(hospital_id=selected_hospital_id_value)
).values_list("patient_id", flat=True)
patient_ids = (
PatientHospitalMapping.objects.annotate(
patient_hospital_id_str=Cast(
"patient_hospital_id", CharField()
)
)
.filter(
Q(patient_hospital_id_str__contains=str(value))
& Q(hospital_id=selected_hospital_id_value)
)
.values_list("patient_id", flat=True)
)
# pylint: disable=unsupported-binary-operation
queryset = queryset.filter(
Q(full_name__icontains=value) | Q(national_id__icontains=value) | Q(id__in=patient_ids)
Q(full_name__icontains=value)
| Q(national_id__iexact=value)
| Q(id__in=patient_ids)
# pylint: enable=unsupported-binary-operation
)
return queryset
return queryset
Expand Down
19 changes: 15 additions & 4 deletions tmh_registry/registry/migrations/0017_auto_20221029_1535.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@
class Migration(migrations.Migration):

dependencies = [
('registry', '0016_auto_20220222_1415'),
("registry", "0016_auto_20220222_1415"),
]

operations = [
migrations.AlterField(
model_name='episode',
name='episode_type',
field=models.CharField(choices=[('INGUINAL', 'Inguinal Mesh Hernia Repair'), ('INCISIONAL', 'Incisional Mesh Hernia Repair'), ('FEMORAL', 'Femoral Mesh Hernia Repair'), ('UMBILICAL', 'Umbilical/Periumbilicial Mesh Hernia Repair')], max_length=128),
model_name="episode",
name="episode_type",
field=models.CharField(
choices=[
("INGUINAL", "Inguinal Mesh Hernia Repair"),
("INCISIONAL", "Incisional Mesh Hernia Repair"),
("FEMORAL", "Femoral Mesh Hernia Repair"),
(
"UMBILICAL",
"Umbilical/Periumbilicial Mesh Hernia Repair",
),
],
max_length=128,
),
),
]
29 changes: 22 additions & 7 deletions tmh_registry/registry/migrations/0018_auto_20221029_1546.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@
class Migration(migrations.Migration):

dependencies = [
('registry', '0017_auto_20221029_1535'),
("registry", "0017_auto_20221029_1535"),
]

operations = [
migrations.AlterField(
model_name='episode',
name='side',
field=models.CharField(choices=[('NA', 'Not Applicable'), ('LEFT', 'Left'), ('RIGHT', 'Right')], max_length=16),
model_name="episode",
name="side",
field=models.CharField(
choices=[
("NA", "Not Applicable"),
("LEFT", "Left"),
("RIGHT", "Right"),
],
max_length=16,
),
),
migrations.AlterField(
model_name='episode',
name='type',
field=models.CharField(choices=[('NA', 'Not Applicable'), ('DIRECT', 'Direct'), ('INDIRECT', 'Indirect'), ('PANTALOON', 'Pantaloon')], max_length=16),
model_name="episode",
name="type",
field=models.CharField(
choices=[
("NA", "Not Applicable"),
("DIRECT", "Direct"),
("INDIRECT", "Indirect"),
("PANTALOON", "Pantaloon"),
],
max_length=16,
),
),
]
Loading

0 comments on commit 53e8f77

Please sign in to comment.