Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
a2826f71
Commit
a2826f71
authored
May 18, 2020
by
Jonathan Christopher Jakub
Browse files
[GREEN] Implement case count views
parent
4eafe7c7
Pipeline
#47432
failed with stages
in 1 minute and 44 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/exportables/urls.py
0 → 100644
View file @
a2826f71
from
django.urls
import
path
from
apps.exportables.views
import
StatisticsView
urlpatterns
=
[
path
(
""
,
StatisticsView
.
as_view
()),
]
apps/exportables/views.py
0 → 100644
View file @
a2826f71
from
django.http
import
JsonResponse
from
rest_framework
import
status
from
rest_framework.views
import
APIView
from
apps.cases.models
import
(
CaseSubject
,
InvestigationCase
,
)
from
apps.exportables.constants
import
(
AGE
,
DISTRICT
,
DISTRICTS
,
FEMALE
,
MALE
,
NEGATIVE
,
POSITIVE
,
SEX
,
TOTAL
,
UNDERTERMINED
)
from
apps.exportables.utils
import
(
generate_initial_counts
,
generate_initial_groups
,
map_outcome
,
map_sex
,
)
class
StatisticsView
(
APIView
):
def
get
(
self
,
request
,
format
=
None
):
case_subjects
=
CaseSubject
.
objects
.
all
()
investigation_case_subjects
=
InvestigationCase
.
objects
\
.
order_by
(
"case_subject__id"
,
"-created_at"
)
\
.
distinct
(
"case_subject"
)
outcomes
=
{}
for
investigation_case_subject
in
investigation_case_subjects
:
related_case_subject_id
=
investigation_case_subject
.
case_subject
.
id
outcomes
[
related_case_subject_id
]
=
investigation_case_subject
.
is_positive
age_groups
,
sex_groups
,
district_groups
=
generate_initial_groups
()
for
case_subject
in
case_subjects
:
outcome
=
outcomes
.
get
(
case_subject
.
id
)
outcome
=
map_outcome
(
outcome
)
# Age Group
subject_age
=
str
(
case_subject
.
age
)
if
age_groups
.
get
(
subject_age
)
is
None
:
age_groups
[
subject_age
]
=
generate_initial_counts
()
age_groups
[
subject_age
][
outcome
]
+=
1
age_groups
[
subject_age
][
TOTAL
]
+=
1
# District Group
subject_district
=
case_subject
.
district
if
district_groups
.
get
(
subject_district
)
is
None
:
district_groups
[
subject_district
]
=
generate_initial_counts
()
district_groups
[
subject_district
][
outcome
]
+=
1
district_groups
[
subject_district
][
TOTAL
]
+=
1
# Sex Group
subject_sex
=
case_subject
.
is_male
subject_sex
=
map_sex
(
subject_sex
)
sex_groups
[
subject_sex
][
outcome
]
+=
1
sex_groups
[
subject_sex
][
TOTAL
]
+=
1
data
=
{
AGE
:
age_groups
,
DISTRICT
:
district_groups
,
SEX
:
sex_groups
,
TOTAL
:
len
(
case_subjects
),
}
return
JsonResponse
(
data
=
data
,
status
=
status
.
HTTP_200_OK
)
project/settings.py
View file @
a2826f71
...
...
@@ -52,6 +52,7 @@ INSTALLED_APPS = [
# Apps
"apps.accounts"
,
"apps.cases"
,
"apps.exportables"
,
"apps.logs"
,
]
...
...
project/urls.py
View file @
a2826f71
...
...
@@ -10,4 +10,5 @@ urlpatterns = [
path
(
"logs/"
,
include
(
"apps.logs.urls"
)),
path
(
"auth/token/"
,
obtain_auth_token
,
name
=
"api_token_auth"
),
path
(
"auth/"
,
include
(
"django.contrib.auth.urls"
)),
path
(
"exportables/"
,
include
(
"apps.exportables.urls"
)),
]
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment