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

Depression #84

Merged
merged 9 commits into from
Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
Binary file added .DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions backend/api/management/commands/importdepression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import bonobo
import os
import csv

from bonobo.contrib.django import ETLCommand
from api.models import Depression
from django.conf import settings


def parse_depression_data():
csvFile = open(os.path.join(settings.BASE_DIR, 'api', 'source-data', 'depression_data.csv'))
reader = csv.DictReader(csvFile)
for row in reader:
yield row

def transform_depression_data(row):
p = Depression(gender=row['gender'], agegroup=row['agegroup'], crude=row['crude'], province=row['province'])
yield p

def load_depression_data(hospital):
hospital.save()
# https://fair-acc.healthdata.be/api/3/action/group_package_show?id=469baf11-ddd1-4c30-9ad3-a21a7d0f7397
class Command(ETLCommand):
def get_graph(self, **options):
graph = bonobo.Graph()
graph.add_chain(
parse_depression_data,
transform_depression_data,
load_depression_data
)
return graph
24 changes: 24 additions & 0 deletions backend/api/migrations/0004_populationdetailed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.0.7 on 2018-07-18 13:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0003_auto_20180717_2004'),
]

operations = [
migrations.CreateModel(
name='PopulationDetailed',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=600)),
('year', models.IntegerField()),
('amount', models.IntegerField()),
('age', models.IntegerField(null=True)),
('gender', models.CharField(max_length=600, null=True)),
],
),
]
23 changes: 23 additions & 0 deletions backend/api/migrations/0005_depression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.0.7 on 2018-07-18 14:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0004_populationdetailed'),
]

operations = [
migrations.CreateModel(
name='Depression',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('gender', models.CharField(max_length=500)),
('agegroup', models.CharField(max_length=500)),
('crude', models.IntegerField()),
('province', models.CharField(max_length=500)),
],
),
]
18 changes: 18 additions & 0 deletions backend/api/migrations/0006_auto_20180718_1612.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.7 on 2018-07-18 16:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0005_depression'),
]

operations = [
migrations.AlterField(
model_name='depression',
name='crude',
field=models.DecimalField(decimal_places=5, max_digits=10),
),
]
19 changes: 16 additions & 3 deletions backend/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ def __str__(self):
return template.format(self)

class Population(models.Model):
name = models.CharField(max_length = 600)
year = models.IntegerField()
amount = models.IntegerField()
name = models.CharField(max_length = 600)
year = models.IntegerField()
amount = models.IntegerField()

class PopulationDetailed(models.Model):
name = models.CharField(max_length = 600)
year = models.IntegerField()
amount = models.IntegerField()
age = models.IntegerField(null=True)
gender = models.CharField(max_length = 600, null = True)

class Depression(models.Model):
gender = models.CharField(max_length = 500)
agegroup = models.CharField(max_length = 500)
crude = models.DecimalField(decimal_places=5, max_digits=10)
province = models.CharField(max_length = 500)
15 changes: 12 additions & 3 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework import serializers
from api.models import Hospital
from api.models import Population
from api.models import Hospital, Population, PopulationDetailed, Depression

class HospitalSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -10,4 +9,14 @@ class Meta:
class PopulationSerializer(serializers.ModelSerializer):
class Meta:
model = Population
fields = ('id', 'name', 'year', 'amount')
fields = ('id', 'name', 'year', 'amount')

class PopulationDetailedSerializer(serializers.ModelSerializer):
class Meta:
model = PopulationDetailed
fields = ('id', 'name', 'year', 'amount', 'age', 'gender')

class DepressionSerializer(serializers.ModelSerializer):
class Meta:
model = Depression
fields = ('id', 'gender', 'agegroup', 'crude', 'province')
1 change: 1 addition & 0 deletions backend/api/source-data/depression_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gender,agegroup,crude,provinceM,15-24,5.98000,antwerpM,25-34,6.45000,antwerpM,35-44,7.35000,antwerpM,45-54,8.33000,antwerpM,55-64,8.65000,antwerpM,65-74,11.23000,antwerpM,75+,7.03000,antwerpM,T,11.18000,antwerpT,T,9.20000,antwerpF,15-24,8.63000,antwerpF,25-34,9.45000,antwerpF,35-44,16.00000,antwerpF,45-54,10.30000,antwerpF,55-64,11.93000,antwerpF,65-74,13.28000,antwerpF,75+,11.30000,antwerpF,T,9.20000,antwerpM,15-24,0.78000,vlaams brabantM,25-34,1.30000,vlaams brabantM,35-44,3.08000,vlaams brabantM,45-54,3.65000,vlaams brabantM,55-64,6.40000,vlaams brabantM,65-74,6.70000,vlaams brabantM,75+,6.65000,vlaams brabantM,T,3.95000,vlaams brabantF,15-24,22.40000,vlaams brabantF,25-34,10.33000,vlaams brabantF,35-44,8.60000,vlaams brabantF,45-54,10.55000,vlaams brabantF,55-64,7.85000,vlaams brabantF,65-74,8.73000,vlaams brabantF,75+,12.23000,vlaams brabantF,T,10.75000,vlaams brabantT,T,7.58000,vlaams brabantM,15-24,2.48000,west-vlaanderenM,25-34,4.90000,west-vlaanderenM,35-44,3.03000,west-vlaanderenM,45-54,5.90000,west-vlaanderenM,55-64,8.60000,west-vlaanderenM,65-74,6.05000,west-vlaanderenM,75+,4.85000,west-vlaanderenM,T,5.05000,west-vlaanderenF,15-24,7.03000,west-vlaanderenF,25-34,8.98000,west-vlaanderenF,35-44,9.20000,west-vlaanderenF,45-54,8.58000,west-vlaanderenF,55-64,5.30000,west-vlaanderenF,65-74,10.53000,west-vlaanderenF,75+,7.43000,west-vlaanderenF,T,8.30000,west-vlaanderenT,T,6.68000,west-vlaanderenM,15-25,7.38000,oost-vlaanderenM,25-35,5.38000,oost-vlaanderenM,35-45,7.63000,oost-vlaanderenM,45-55,4.95000,oost-vlaanderenM,55-65,7.43000,oost-vlaanderenM,65-75,16.53000,oost-vlaanderenM,75+,20.73000,oost-vlaanderenM,T,8.60000,oost-vlaanderenT,T,10.53000,oost-vlaanderenF,15-25,7.98000,oost-vlaanderenF,25-35,15.10000,oost-vlaanderenF,35-45,10.88000,oost-vlaanderenF,45-55,15.93000,oost-vlaanderenF,55-65,22.63000,oost-vlaanderenF,65-75,21.03000,oost-vlaanderenF,75+,14.18000,oost-vlaanderenF,T,11.45000,oost-vlaanderenM,15-25,7.70000,limburgM,25-35,4.80000,limburgM,35-45,4.28000,limburgM,45-55,7.28000,limburgM,55-65,8.10000,limburgM,65-75,9.83000,limburgM,75+,13.03000,limburgM,T,7.23000,limburgF,T,7.80000,limburgF,15-25,10.85000,limburgF,25-35,7.58000,limburgF,35-45,15.48000,limburgF,45-55,12.85000,limburgF,55-65,9.85000,limburgF,65-75,13.20000,limburgF,75+,11.43000,limburgT,T,9.40000,limburgM,15-25,6.10000,brusselsM,25-35,8.85000,brusselsM,35-45,9.83000,brusselsM,45-55,9.43000,brusselsM,55-65,9.30000,brusselsM,65-75,10.08000,brusselsM,75+,10.98000,brusselsM,T,9.10000,brusselsF,15-25,10.80000,brusselsF,25-35,13.08000,brusselsF,35-45,16.23000,brusselsF,45-55,18.80000,brusselsF,55-65,16.35000,brusselsF,65-75,18.40000,brusselsF,75+,24.80000,brusselsF,T,16.28000,brusselsT,T,12.88000,brusselsM,15-25,2.20000,Brabant WallonM,25-35,5.73000,Brabant WallonM,35-45,4.28000,Brabant WallonM,45-55,9.30000,Brabant WallonM,55-65,3.35000,Brabant WallonM,65-75,13.23000,Brabant WallonM,75+,24.65000,Brabant WallonM,T,7.35000,Brabant WallonT,15-25,2.58000,Brabant WallonF,25-35,9.03000,Brabant WallonF,35-45,3.53000,Brabant WallonF,45-55,6.85000,Brabant WallonF,55-65,19.05000,Brabant WallonF,65-75,13.83000,Brabant WallonF,75+,15.13000,Brabant WallonF,T,9.10000,Brabant WallonF,T,8.35000,Brabant WallonM,15-26,2.90000,hainoutM,25-36,6.70000,hainoutM,35-46,6.63000,hainoutM,45-56,13.53000,hainoutM,55-66,10.18000,hainoutM,65-76,10.35000,hainoutM,75+,11.40000,hainoutM,T,8.90000,hainoutF,T,13.95000,hainoutF,15-26,12.25000,hainoutF,25-36,15.60000,hainoutF,35-46,18.15000,hainoutF,45-56,16.65000,hainoutF,55-66,17.73000,hainoutF,65-76,24.85000,hainoutF,75+,16.58000,hainoutT,T,12.90000,hainoutM,15-26,2.13000,LiegeM,25-36,12.25000,LiegeM,35-46,7.13000,LiegeM,45-56,9.23000,LiegeM,55-66,11.63000,LiegeM,65-76,7.80000,LiegeM,75+,10.78000,LiegeM,T,8.73000,LiegeF,T,8.58000,LiegeF,15-26,12.18000,LiegeF,25-36,15.58000,LiegeF,35-46,20.63000,LiegeF,45-56,15.75000,LiegeF,55-66,17.60000,LiegeF,65-76,21.38000,LiegeF,75+,15.93000,LiegeT,T,12.58000,LiegeM,15-26,6.65000,luxembourgM,25-36,5.80000,luxembourgM,35-46,5.45000,luxembourgM,45-56,11.38000,luxembourgM,55-66,13.58000,luxembourgM,65-76,6.23000,luxembourgM,75+,9.10000,luxembourgM,T,8.28000,luxembourgT,15-26,5.73000,luxembourgF,25-36,10.15000,luxembourgF,35-46,10.28000,luxembourgF,45-56,17.75000,luxembourgF,55-66,22.00000,luxembourgF,65-76,10.88000,luxembourgF,75+,13.95000,luxembourgF,T,12.75000,luxembourgF,T,10.55000,luxembourgM,15-26,3.35000,namurM,25-36,6.03000,namurM,35-46,12.40000,namurM,45-56,8.88000,namurM,55-66,7.23000,namurM,65-76,2.30000,namurM,75+,9.85000,namurM,T,7.35000,namurF,15-26,10.28000,namurF,25-36,9.80000,namurF,35-46,11.58000,namurF,45-56,19.50000,namurF,55-66,14.38000,namurF,65-76,12.10000,namurF,75+,12.68000,namurF,T,13.30000,namurT,T,10.45000,namur
Expand Down
4 changes: 4 additions & 0 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from api import views

urlpatterns = [
url('depression/(?P<pk>[0-9]+)/$', views.depression_detail),
url('depression', views.depression_data),
url('populationdetailed/(?P<pk>[0-9]+)/$', views.populationDetailed_detail),
url('populationdetailed', views.populationDetailed_data),
url('population/(?P<pk>[0-9]+)/$', views.population_detail),
url('population', views.population_data),
url('hospitals/(?P<pk>[0-9]+)/$', views.hospital_detail),
Expand Down
33 changes: 31 additions & 2 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from django.views.decorators.csrf import csrf_exempt
from rest_framework.renderers import JSONRenderer
from rest_framework.parsers import JSONParser
from api.models import Hospital, Population
from api.serializers import HospitalSerializer, PopulationSerializer
from api.models import Hospital, Population, PopulationDetailed, Depression
from api.serializers import HospitalSerializer, PopulationSerializer, PopulationDetailedSerializer, DepressionSerializer

def isInt(value):
try:
Expand Down Expand Up @@ -41,3 +41,32 @@ def population_detail(request, pk):
raise Http404("Population not found")
serializer = PopulationSerializer(population)
return JsonResponse(serializer.data)



def populationDetailed_data(request):
population = PopulationDetailed.objects.all()
serializer = PopulationDetailedSerializer(population, many=True)
return JsonResponse(serializer.data, safe=False)

def populationDetailed_detail(request, pk):
try:
population = PopulationDetailed.objects.get(pk=pk)
except PopulationDetailed.DoesNotExist:
raise Http404("Populationdeatiled not found")
serializer = PopulationDetailedSerializer(population)
return JsonResponse(serializer.data)


def depression_data(request):
population = Depression.objects.all()
serializer = DepressionSerializer(population, many=True)
return JsonResponse(serializer.data, safe=False)

def depression_detail(request, pk):
try:
population = Depression.objects.get(pk=pk)
except Depression.DoesNotExist:
raise Http404("Depression not found")
serializer = DepressionSerializer(population)
return JsonResponse(serializer.data)
72 changes: 63 additions & 9 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.