Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fields data type #2139

Merged
merged 3 commits into from
May 10, 2024
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
17 changes: 15 additions & 2 deletions local_units/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class LocalUnitAdmin(admin.OSMGeoAdmin):
autocomplete_fields = (
'country',
'type',
'level'
'level',
'health',
)
list_filter = (
AutocompleteFilterFactory('Country', 'country'),
Expand Down Expand Up @@ -131,7 +132,19 @@ class ProfessionalTrainingFacilityAdmin(admin.ModelAdmin):

@admin.register(HealthData)
class HealthDataAdmin(admin.ModelAdmin):
search_fields = ('affiliation__name',)
autocomplete_fields = [
'affiliation',
'functionality',
'health_facility_type',
'primary_health_care_center',
'hospital_type',
'general_medical_services',
'specialized_medical_beyond_primary_level',
'blood_services',
'professional_training_facilities',
]

search_fields = ('affiliation__name', 'health_facility_type__name')
list_filter = (
AutocompleteFilterFactory('Country', 'health_data__country'),
AutocompleteFilterFactory('Affiliation', 'affiliation'),
Expand Down
19 changes: 10 additions & 9 deletions local_units/management/commands/import_health_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def numerize(value):
'bloodcenter']
specializedmedicalservice_id_map['surgicalspecialties'] = specializedmedicalservice_id_map[
'surgicalspecialities']

primaryhcc_id_map[''] = None
hospitaltype_id_map[''] = None
generalmedicalservice_id_map[''] = None
Expand All @@ -105,15 +106,15 @@ def numerize(value):

# field order is the same as in the example CSV:
f_id = row["DATA SOURCE ID"]
f_fpe = row["Focal point email"][:90]
f_fpf = row["Focal point phone number"][:90]
f_fpp = row["Focal point position"][:90]
f_fpe = row["Focal point email"]
f_fpf = row["Focal point phone number"]
f_fpp = row["Focal point position"]
f_hft = wash(row["Health facility type"])
f_oft = row["Other facility type"][:300]
f_oft = row["Other facility type"]
f_aff = wash(row["Affilation"])
f_fun = wash(row["Functionality"])
f_phc = wash(row["Primary Health Care Centre"])
f_spc = row["Speciality"][:200]
f_spc = row["Speciality"]
f_hst = wash(row["Hospital type"])
f_ths = row["Teaching hospital"]
f_ipc = row["In-patient Capacity"]
Expand All @@ -124,7 +125,7 @@ def numerize(value):
f_cch = row["Cold chain"]
f_gms = wash_leave_space(row["General medical services"]) # m2m
f_spm = wash_leave_space(row["Specialized medical beyond primary level"]) # m2m
f_ots = row["Other Services"][:300]
f_ots = row["Other Services"]
f_bls = wash_leave_space(row["Blood Services"]) # m2m
f_tnh = numerize(row["Total number of Human Resource"])
f_gpr = numerize(row["General Practitioner"])
Expand All @@ -135,9 +136,9 @@ def numerize(value):
f_nur = numerize(row["Nursing Aid"])
f_mid = numerize(row["Midwife"])
f_omh = row["Other medical health workers"]
f_opr = row["Other Profiles"][:200]
f_fbk = row["Feedback"][:500]
f_oaf = row["Other Affiliation"][:300]
f_opr = row["Other Profiles"]
f_fbk = row["Feedback"]
f_oaf = row["Other Affiliation"]
f_ptf = wash_leave_space(row["Professional Training Facilities"]) # m2m
f_ata = row["Ambulance Type A"]
f_atb = row["Ambulance Type B"]
Expand Down
53 changes: 53 additions & 0 deletions local_units/migrations/0014_auto_20240509_0529.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 3.2.25 on 2024-05-09 05:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('local_units', '0013_localunittype_colour'),
]

operations = [
migrations.AlterField(
model_name='healthdata',
name='feedback',
field=models.TextField(blank=True, null=True, verbose_name='Feedback'),
),
migrations.AlterField(
model_name='healthdata',
name='focal_point_email',
field=models.EmailField(blank=True, max_length=255, null=True, verbose_name='Focal point email'),
),
migrations.AlterField(
model_name='healthdata',
name='focal_point_phone_number',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Focal point phone number'),
),
migrations.AlterField(
model_name='healthdata',
name='focal_point_position',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Focal point position'),
),
migrations.AlterField(
model_name='healthdata',
name='other_affiliation',
field=models.TextField(blank=True, null=True, verbose_name='Other Affiliation'),
),
migrations.AlterField(
model_name='healthdata',
name='other_facility_type',
field=models.TextField(blank=True, null=True, verbose_name='Other facility type'),
),
migrations.AlterField(
model_name='healthdata',
name='other_services',
field=models.TextField(blank=True, null=True, verbose_name='Other Services'),
),
migrations.AlterField(
model_name='healthdata',
name='speciality',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='Speciality'),
),
]
24 changes: 12 additions & 12 deletions local_units/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class HealthData(models.Model):
verbose_name=_('Affiliation'),
related_name='health_affiliation'
)
other_affiliation = models.CharField(
max_length=300, verbose_name=_('Other Affiliation'),
other_affiliation = models.TextField(
verbose_name=_('Other Affiliation'),
null=True, blank=True
)
functionality = models.ForeignKey(
Expand All @@ -147,22 +147,22 @@ class HealthData(models.Model):
related_name='health_functionality',
)
focal_point_email = models.EmailField(
max_length=90, verbose_name=_('Focal point email'), blank=True, null=True
max_length=255, verbose_name=_('Focal point email'), blank=True, null=True
)
focal_point_phone_number = models.CharField(
max_length=90, verbose_name=_('Focal point phone number'), blank=True, null=True
max_length=255, verbose_name=_('Focal point phone number'), blank=True, null=True
)
focal_point_position = models.CharField(
max_length=90, verbose_name=_('Focal point position'), blank=True, null=True
max_length=255, verbose_name=_('Focal point position'), blank=True, null=True
)
health_facility_type = models.ForeignKey(
FacilityType,
on_delete=models.CASCADE,
verbose_name=_('Health facility type'),
related_name='health_facility_type'
)
other_facility_type = models.CharField(
max_length=300, verbose_name=_('Other facility type'), blank=True, null=True
other_facility_type = models.TextField(
verbose_name=_('Other facility type'), blank=True, null=True
)
primary_health_care_center = models.ForeignKey(
PrimaryHCC,
Expand All @@ -172,7 +172,7 @@ class HealthData(models.Model):
null=True,
)
speciality = models.CharField(
max_length=200, verbose_name=_('Speciality'), blank=True, null=True
max_length=255, verbose_name=_('Speciality'), blank=True, null=True
)
hospital_type = models.ForeignKey(
HospitalType,
Expand Down Expand Up @@ -223,8 +223,8 @@ class HealthData(models.Model):
verbose_name=_('Specialized medical beyond primary level'),
blank=True,
)
other_services = models.CharField(
max_length=300, verbose_name=_('Other Services'), blank=True, null=True
other_services = models.TextField(
verbose_name=_('Other Services'), blank=True, null=True
)
blood_services = models.ManyToManyField(
BloodService,
Expand Down Expand Up @@ -262,8 +262,8 @@ class HealthData(models.Model):
other_profiles = models.CharField(
max_length=200, verbose_name=_('Other Profiles'), blank=True, null=True
)
feedback = models.CharField(
max_length=500, verbose_name=_('Feedback'), blank=True, null=True
feedback = models.TextField(
verbose_name=_('Feedback'), blank=True, null=True
)

def __str__(self):
Expand Down
13 changes: 11 additions & 2 deletions local_units/permissions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from rest_framework import permissions

from django.contrib.auth.models import Permission


class ValidateLocalUnitPermission(permissions.BasePermission):
message = "You need to be super user to validate local unit"
message = "You need to be super user/ country admin to validate local unit"

def has_object_permission(self, request, view, object):
user = request.user
if user.is_superuser:
country_admin_ids = [
codename.replace('country_admin_', '')
for codename in Permission.objects.filter(
group__user=user,
codename__startswith='country_admin_',
).values_list('codename', flat=True)
]
if user.is_superuser or object.country_id in country_admin_ids:
Comment on lines +11 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
country_admin_ids = [
codename.replace('country_admin_', '')
for codename in Permission.objects.filter(
group__user=user,
codename__startswith='country_admin_',
).values_list('codename', flat=True)
]
if user.is_superuser or object.country_id in country_admin_ids:
if user.is_superuser:
return True
country_admin_ids = [
codename.replace('country_admin_', '')
for codename in Permission.objects.filter(
group__user=user,
codename__startswith='country_admin_',
).values_list('codename', flat=True)
]
if object.country_id in country_admin_ids:

return True
return False

Expand Down