Skip to content

Commit

Permalink
Merge pull request #614 from Apurva-Nagar/master
Browse files Browse the repository at this point in the history
Sample Test: added sample choices, patient object for sample report details and file permissions for staff user
  • Loading branch information
vigneshhari authored Aug 28, 2021
2 parents f58aeb3 + 3d354c5 commit e2b28d6
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 28 deletions.
18 changes: 8 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: 'docs|node_modules|migrations|.git|.tox'
exclude: "docs|node_modules|migrations|.git|.tox"
default_stages: [commit]
fail_fast: true

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
20 changes: 7 additions & 13 deletions care/facility/api/serializers/file_upload.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion care/facility/api/serializers/patient_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
18 changes: 18 additions & 0 deletions care/facility/migrations/0272_auto_20210825_1248.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
18 changes: 18 additions & 0 deletions care/facility/migrations/0273_auto_20210825_1829.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
12 changes: 9 additions & 3 deletions care/facility/models/patient_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]


Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e2b28d6

Please sign in to comment.