diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd1f215035..2afeedf00c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: 'docs|node_modules|migrations|.git|.tox' +exclude: "docs|node_modules|migrations|.git|.tox" default_stages: [commit] fail_fast: true @@ -15,7 +15,6 @@ repos: name: fix end of files. description: Ensures that a file is either empty, or ends with one newline. - - repo: https://github.com/asottile/seed-isort-config rev: v2.1.0 hooks: @@ -31,7 +30,7 @@ repos: hooks: - id: black args: [--line-length=120, --safe] - language_version: python3.7 + language_version: python3 - repo: https://github.com/myint/autoflake rev: v1.4 @@ -41,12 +40,12 @@ repos: - repo: local hooks: -# - id: flake8 -# name: flake8 -# entry: flake8 -# language: python -# types: [python] -# args: ['--config=setup.cfg'] + # - id: flake8 + # name: flake8 + # entry: flake8 + # language: python + # types: [python] + # args: ['--config=setup.cfg'] - id: pre-commit-django-migrations name: Check django migrations @@ -55,7 +54,6 @@ repos: types: [python] pass_filenames: false require_serial: true - # - id: pre-commit-django-tests # name: Run Django unit tests # entry: python manage.py test --settings=config.settings.test -n diff --git a/care/facility/api/serializers/file_upload.py b/care/facility/api/serializers/file_upload.py index 3b9b9abac3..0ee51b6ac9 100644 --- a/care/facility/api/serializers/file_upload.py +++ b/care/facility/api/serializers/file_upload.py @@ -1,22 +1,13 @@ -from care.facility.models.patient_sample import PatientSample -from care.facility.api.serializers import facility -from django.core.exceptions import ValidationError -from django.db.models import F from rest_framework import serializers - -from care.facility.models.file_upload import FileUpload - -from care.users.api.serializers.user import UserBaseMinimumSerializer -from config.serializers import ChoiceField +from care.facility.api.serializers.shifting import has_facility_permission +from care.facility.models.facility import Facility from care.facility.models.file_upload import FileUpload - from care.facility.models.patient import PatientRegistration from care.facility.models.patient_consultation import PatientConsultation - +from care.facility.models.patient_sample import PatientSample from care.users.api.serializers.user import UserBaseMinimumSerializer - -from care.facility.api.serializers.shifting import has_facility_permission +from config.serializers import ChoiceField def check_permissions(file_type, associating_id, user): @@ -57,6 +48,9 @@ def check_permissions(file_type, associating_id, user): if sample.consultation.assigned_to: if user == sample.consultation.assigned_to: return sample.id + if sample.testing_facility: + if has_facility_permission(user, Facility.objects.get(external_id=sample.testing_facility.external_id)): + return sample.id if not has_facility_permission(user, patient.facility): raise Exception("No Permission") return sample.id diff --git a/care/facility/api/serializers/patient_sample.py b/care/facility/api/serializers/patient_sample.py index 257da4f97a..e30292d366 100644 --- a/care/facility/api/serializers/patient_sample.py +++ b/care/facility/api/serializers/patient_sample.py @@ -4,7 +4,8 @@ from care.facility.api.serializers import TIMESTAMP_FIELDS from care.facility.api.serializers.facility import FacilityBasicInfoSerializer -from care.facility.models import PatientConsultation, PatientRegistration, Facility +from care.facility.api.serializers.patient import PatientDetailSerializer +from care.facility.models import Facility, PatientConsultation, PatientRegistration from care.facility.models.patient_sample import SAMPLE_TYPE_CHOICES, PatientSample, PatientSampleFlow from care.utils.serializer.external_id_field import ExternalIdSerializerField from config.serializers import ChoiceField @@ -19,6 +20,7 @@ class Meta: class PatientSampleSerializer(serializers.ModelSerializer): + patient_object = PatientDetailSerializer(source="patient", read_only=True) id = serializers.UUIDField(source="external_id", read_only=True) patient_name = serializers.CharField(read_only=True, source="patient.name") patient_has_sari = serializers.BooleanField(read_only=True, source="patient.has_SARI") diff --git a/care/facility/migrations/0272_auto_20210825_1248.py b/care/facility/migrations/0272_auto_20210825_1248.py new file mode 100644 index 0000000000..c0f9a94fe9 --- /dev/null +++ b/care/facility/migrations/0272_auto_20210825_1248.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.11 on 2021-08-25 07:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('facility', '0271_auto_20210815_1617'), + ] + + operations = [ + migrations.AlterField( + model_name='patientsample', + name='sample_type', + field=models.IntegerField(choices=[(0, 'UNKNOWN'), (1, 'BA/ETA'), (2, 'TS/NPS/NS'), (3, 'Blood in EDTA'), (4, 'Acute Sera'), (5, 'Covalescent sera'), (6, 'Biopsy'), (7, 'AMR'), (8, 'Communicable'), (9, 'OTHER TYPE')], default=0), + ), + ] diff --git a/care/facility/migrations/0273_auto_20210825_1829.py b/care/facility/migrations/0273_auto_20210825_1829.py new file mode 100644 index 0000000000..b20d658523 --- /dev/null +++ b/care/facility/migrations/0273_auto_20210825_1829.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.11 on 2021-08-25 12:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('facility', '0272_auto_20210825_1248'), + ] + + operations = [ + migrations.AlterField( + model_name='patientsample', + name='sample_type', + field=models.IntegerField(choices=[(0, 'UNKNOWN'), (1, 'BA/ETA'), (2, 'TS/NPS/NS'), (3, 'Blood in EDTA'), (4, 'Acute Sera'), (5, 'Covalescent sera'), (6, 'Biopsy'), (7, 'AMR'), (8, 'Communicable Diseases'), (9, 'OTHER TYPE')], default=0), + ), + ] diff --git a/care/facility/models/patient_sample.py b/care/facility/models/patient_sample.py index 977bf651dc..6ede20d417 100644 --- a/care/facility/models/patient_sample.py +++ b/care/facility/models/patient_sample.py @@ -10,7 +10,10 @@ (3, "Blood in EDTA"), (4, "Acute Sera"), (5, "Covalescent sera"), - (6, "OTHER TYPE"), + (6, "Biopsy"), + (7, "AMR"), + (8, "Communicable Diseases"), + (9, "OTHER TYPE"), ] @@ -40,13 +43,16 @@ class PatientSample(FacilityBaseModel): SAMPLE_TEST_FLOW_CHOICES = [(v, k) for k, v in SAMPLE_TEST_FLOW_MAP.items()] SAMPLE_FLOW_RULES = { # previous rule # next valid rules - "REQUEST_SUBMITTED": {"APPROVED", "DENIED",}, + "REQUEST_SUBMITTED": { + "APPROVED", + "DENIED", + }, "APPROVED": {"SENT_TO_COLLECTON_CENTRE", "RECEIVED_AND_FORWARED", "RECEIVED_AT_LAB", "COMPLETED"}, "DENIED": {"REQUEST_SUBMITTED"}, "SENT_TO_COLLECTON_CENTRE": {"RECEIVED_AND_FORWARED", "RECEIVED_AT_LAB", "COMPLETED"}, "RECEIVED_AND_FORWARED": {"RECEIVED_AT_LAB", "COMPLETED"}, "RECEIVED_AT_LAB": {"COMPLETED"}, - "COMPLETED" : {"COMPLETED"} + "COMPLETED": {"COMPLETED"}, } patient = models.ForeignKey(PatientRegistration, on_delete=models.PROTECT) diff --git a/setup.cfg b/setup.cfg index 2d3729bdc6..7733221c3f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,4 +26,4 @@ django_settings_module = config.settings.test ignore_errors = True [isort] -known_third_party = allauth,boto3,celery,crispy_forms,dateparser,dateutil,django,django_filters,django_rest_passwordreset,djangoql,djqscsv,drf_extra_fields,drf_yasg,dry_rest_permissions,environ,fernet_fields,freezegun,hardcopy,location_field,multiselectfield,partial_index,phonenumber_field,phonenumbers,pytz,pywebpush,ratelimit,requests,rest_framework,rest_framework_nested,rest_framework_simplejwt,sentry_sdk,simple_history +known_third_party = allauth,boto3,celery,crispy_forms,dateparser,dateutil,django,django_filters,django_rest_passwordreset,djangoql,djqscsv,drf_extra_fields,drf_yasg,dry_rest_permissions,environ,fernet_fields,freezegun,hardcopy,jsonschema,location_field,multiselectfield,partial_index,phonenumber_field,phonenumbers,pytz,pywebpush,ratelimit,requests,rest_framework,rest_framework_nested,rest_framework_simplejwt,sentry_sdk,simple_history