Skip to content
Snippets Groups Projects
Commit 52c47381 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

refactor of api

parent ca0bdb22
No related branches found
No related tags found
1 merge request!35performance on appointment list
......@@ -15,15 +15,15 @@ Including another URLconf
"""
from django.conf.urls import url
from web import api_views
from web.api_views import worker, location, subject, appointment_type
urlpatterns = [
url(r'^cities$', api_views.cities, name='web.api.cities'),
url(r'^countries$', api_views.countries, name='web.api.countries'),
url(r'^specializations$', api_views.specializations, name='web.api.specializations'),
url(r'^units$', api_views.units, name='web.api.units'),
url(r'^locations$', api_views.locations, name='web.api.locations'),
url(r'^referrals$', api_views.referrals, name='web.api.referrals'),
url(r'^appointment_types$', api_views.appointment_types, name='web.api.appointment_types'),
url(r'^subjects/(?P<type>[A-z]+)$', api_views.subjects, name='web.api.subjects'),
url(r'^cities$', subject.cities, name='web.api.cities'),
url(r'^countries$', subject.countries, name='web.api.countries'),
url(r'^specializations$', worker.specializations, name='web.api.specializations'),
url(r'^units$', worker.units, name='web.api.units'),
url(r'^locations$', location.locations, name='web.api.locations'),
url(r'^referrals$', subject.referrals, name='web.api.referrals'),
url(r'^appointment_types$', appointment_type.appointment_types, name='web.api.appointment_types'),
url(r'^subjects/(?P<type>[A-z]+)$', subject.subjects, name='web.api.subjects'),
]
# coding=utf-8
import appointment_type
import location
import subject
import worker
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from web.models import AppointmentType
@login_required
def appointment_types(request):
appointments = AppointmentType.objects.filter().all()
result = []
for appointment in appointments:
result.append({
"id": appointment.id,
"type": appointment.code,
"default_duration": appointment.default_duration,
"can_be_parallelized": appointment.can_be_parallelized,
})
return JsonResponse({
"appointment_types": result
})
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from web.models import Location
@login_required
def locations(request):
locations = Location.objects.all()
data = []
for location in locations:
data.append({"id": location.id, "name": location.name})
return JsonResponse({
"locations": data
})
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from models import Subject, Worker, AppointmentType, Location
from views import e500_error
from views.subject import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT
from views.notifications import get_subjects_with_no_visit, get_subjects_with_reminder
from web.models import Subject
from web.views import e500_error
from web.views.notifications import get_subjects_with_no_visit, get_subjects_with_reminder
from web.views.subject import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT
@login_required
......@@ -15,17 +15,6 @@ def cities(request):
})
@login_required
def locations(request):
locations = Location.objects.all()
data = []
for location in locations:
data.append({"id": location.id, "name": location.name})
return JsonResponse({
"locations": data
})
@login_required
def countries(request):
X = Subject.objects.filter(country__isnull=False).values_list('country').distinct()
......@@ -42,22 +31,6 @@ def referrals(request):
})
@login_required
def specializations(request):
X = Worker.objects.filter(specialization__isnull=False).values_list('specialization').distinct()
return JsonResponse({
"specializations": [x[0] for x in X]
})
@login_required
def units(request):
X = Worker.objects.filter(unit__isnull=False).values_list('unit').distinct()
return JsonResponse({
"units": [x[0] for x in X]
})
@login_required
def get_subjects(request, type):
if type == SUBJECT_LIST_GENERIC:
......@@ -170,6 +143,7 @@ def subjects(request, type):
except:
return e500_error(request)
def get_yes_no(val):
if val:
return "YES"
......@@ -194,19 +168,3 @@ def serialize_subject(subject):
"id": subject.id,
}
return result
@login_required
def appointment_types(request):
appointments = AppointmentType.objects.filter().all()
result = []
for appointment in appointments:
result.append({
"id": appointment.id,
"type": appointment.code,
"default_duration": appointment.default_duration,
"can_be_parallelized": appointment.can_be_parallelized,
})
return JsonResponse({
"appointment_types": result
})
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from web.models import Worker
@login_required
def specializations(request):
X = Worker.objects.filter(specialization__isnull=False).values_list('specialization').distinct()
return JsonResponse({
"specializations": [x[0] for x in X]
})
@login_required
def units(request):
X = Worker.objects.filter(unit__isnull=False).values_list('unit').distinct()
return JsonResponse({
"units": [x[0] for x in X]
})
......@@ -9,7 +9,7 @@ from django.urls import reverse
from web.tests.functions import create_subject, create_worker, create_appointment_type, create_location, \
create_get_suffix
from web.views.subject import SUBJECT_LIST_GENERIC, SUBJECT_LIST_NO_VISIT, SUBJECT_LIST_REQUIRE_CONTACT
from web.api_views import get_subjects_order, get_subjects_filtered, serialize_subject
from web.api_views.subject import get_subjects_order, get_subjects_filtered, serialize_subject
from web.models import Subject
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment