From dd0fb658617aa08674917ffc85c6f0cef6594cb1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 13 Feb 2017 15:41:26 -0800 Subject: [PATCH 1/9] medication app created. model structure with fixture subfolder and json file. --- .gitignore | 1 + neuropy/medication/__init__.py | 0 neuropy/medication/admin.py | 3 + neuropy/medication/apps.py | 7 +++ neuropy/medication/fixtures/medication.json | 64 +++++++++++++++++++++ neuropy/medication/medication.json | 64 +++++++++++++++++++++ neuropy/medication/migrations/__init__.py | 0 neuropy/medication/models.py | 23 ++++++++ neuropy/medication/tests.py | 3 + neuropy/medication/views.py | 3 + 10 files changed, 168 insertions(+) create mode 100644 neuropy/medication/__init__.py create mode 100644 neuropy/medication/admin.py create mode 100644 neuropy/medication/apps.py create mode 100644 neuropy/medication/fixtures/medication.json create mode 100644 neuropy/medication/medication.json create mode 100644 neuropy/medication/migrations/__init__.py create mode 100644 neuropy/medication/models.py create mode 100644 neuropy/medication/tests.py create mode 100644 neuropy/medication/views.py diff --git a/.gitignore b/.gitignore index adb7f0d..a1122b4 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ var/ .installed.cfg *.egg neuroEnv/ +.DS_Store # PyInstaller # Usually these files are written by a python script from a template diff --git a/neuropy/medication/__init__.py b/neuropy/medication/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/neuropy/medication/admin.py b/neuropy/medication/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/neuropy/medication/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/neuropy/medication/apps.py b/neuropy/medication/apps.py new file mode 100644 index 0000000..e095071 --- /dev/null +++ b/neuropy/medication/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class MedicationConfig(AppConfig): + name = 'medication' diff --git a/neuropy/medication/fixtures/medication.json b/neuropy/medication/fixtures/medication.json new file mode 100644 index 0000000..f64f0ef --- /dev/null +++ b/neuropy/medication/fixtures/medication.json @@ -0,0 +1,64 @@ +[{ + "fields": { + "name": "Adderall", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 1, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 0 + }, + { + "fields": { + "name": "Concerta", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 2, + "peak_period": 6, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 1 + }, + { + "fields": { + "name": "Focalin", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 2, + "peak_period": 5, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 2 + }, + { + "fields": { + "name": "Ritalin", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 2, + "peak_period": 4.5, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 2 + }, + { + "fields": { + "name": "VyVance", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 1, + "peak_period": 6, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 2 + }] diff --git a/neuropy/medication/medication.json b/neuropy/medication/medication.json new file mode 100644 index 0000000..f64f0ef --- /dev/null +++ b/neuropy/medication/medication.json @@ -0,0 +1,64 @@ +[{ + "fields": { + "name": "Adderall", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 1, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 0 + }, + { + "fields": { + "name": "Concerta", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 2, + "peak_period": 6, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 1 + }, + { + "fields": { + "name": "Focalin", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 2, + "peak_period": 5, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 2 + }, + { + "fields": { + "name": "Ritalin", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 2, + "peak_period": 4.5, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 2 + }, + { + "fields": { + "name": "VyVance", + "type": "stimulant", + "half_life": "", + "time_administerd": "", + "ramp_up": 1, + "peak_period": 6, + // "Ease_priority_matrix":, + }, + "model": "medications.medication", + "pk": 2 + }] diff --git a/neuropy/medication/migrations/__init__.py b/neuropy/medication/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/neuropy/medication/models.py b/neuropy/medication/models.py new file mode 100644 index 0000000..70a06bf --- /dev/null +++ b/neuropy/medication/models.py @@ -0,0 +1,23 @@ +from __future__ import unicode_literals + +from django.db import models +from django.utils.encoding import python_2_unicode_compatible + + +@python_2_unicode_compatible +class Medication(models.Model): + """.""" + + name = models.CharField( + max_length=20, + default='CONCERTA') + med_type = models.CharField(default='stimulant') + treating_dis = models.CharField(default='ADD/ADHD') + half_life = models.TimeField() + ramp_up = models.DurationField() + peak_period = models.DurationField() + # Ease_priority_matrix=models.CharField + + def __str__(self): + """.""" + return "name: {}, med_type: {}, treating_dis: {}, half_life: {}, ramp_up: {}, peak_period: {}".format(self.name, self.med_type, self.treating_dis, self.half_life, self.ramp_up, self.peak_period) diff --git a/neuropy/medication/tests.py b/neuropy/medication/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/neuropy/medication/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/neuropy/medication/views.py b/neuropy/medication/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/neuropy/medication/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From f749cdf359ec6d00d145ecaaf7bb380b15ed0925 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 13 Feb 2017 15:46:46 -0800 Subject: [PATCH 2/9] delete extra json file --- neuropy/medication/medication.json | 64 ------------------------------ 1 file changed, 64 deletions(-) delete mode 100644 neuropy/medication/medication.json diff --git a/neuropy/medication/medication.json b/neuropy/medication/medication.json deleted file mode 100644 index f64f0ef..0000000 --- a/neuropy/medication/medication.json +++ /dev/null @@ -1,64 +0,0 @@ -[{ - "fields": { - "name": "Adderall", - "type": "stimulant", - "half_life": "", - "time_administerd": "", - "ramp_up": 1, - // "Ease_priority_matrix":, - }, - "model": "medications.medication", - "pk": 0 - }, - { - "fields": { - "name": "Concerta", - "type": "stimulant", - "half_life": "", - "time_administerd": "", - "ramp_up": 2, - "peak_period": 6, - // "Ease_priority_matrix":, - }, - "model": "medications.medication", - "pk": 1 - }, - { - "fields": { - "name": "Focalin", - "type": "stimulant", - "half_life": "", - "time_administerd": "", - "ramp_up": 2, - "peak_period": 5, - // "Ease_priority_matrix":, - }, - "model": "medications.medication", - "pk": 2 - }, - { - "fields": { - "name": "Ritalin", - "type": "stimulant", - "half_life": "", - "time_administerd": "", - "ramp_up": 2, - "peak_period": 4.5, - // "Ease_priority_matrix":, - }, - "model": "medications.medication", - "pk": 2 - }, - { - "fields": { - "name": "VyVance", - "type": "stimulant", - "half_life": "", - "time_administerd": "", - "ramp_up": 1, - "peak_period": 6, - // "Ease_priority_matrix":, - }, - "model": "medications.medication", - "pk": 2 - }] From 968d89b508603dcdbc06b2102bee8896a43f231b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 13 Feb 2017 15:59:32 -0800 Subject: [PATCH 3/9] .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index a1122b4..2c7cc93 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,10 @@ var/ *.egg neuroEnv/ .DS_Store +bin/ +pip-selfcheck.json +pyvenv.cfg +share/ # PyInstaller # Usually these files are written by a python script from a template From 2cd97918835d15d1c7a507072099769f1c596623 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 13 Feb 2017 16:06:58 -0800 Subject: [PATCH 4/9] installed medications app the installed_apps, added max_length for some fields, initial migration created. --- neuropy/medication/migrations/0001_initial.py | 28 +++++++++++++++++++ neuropy/medication/models.py | 4 +-- neuropy/neuropy/settings.py | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 neuropy/medication/migrations/0001_initial.py diff --git a/neuropy/medication/migrations/0001_initial.py b/neuropy/medication/migrations/0001_initial.py new file mode 100644 index 0000000..f2004c1 --- /dev/null +++ b/neuropy/medication/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-02-14 00:05 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Medication', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(default='CONCERTA', max_length=20)), + ('med_type', models.CharField(default='stimulant', max_length=20)), + ('treating_dis', models.CharField(default='ADD/ADHD', max_length=25)), + ('half_life', models.TimeField()), + ('ramp_up', models.DurationField()), + ('peak_period', models.DurationField()), + ], + ), + ] diff --git a/neuropy/medication/models.py b/neuropy/medication/models.py index 70a06bf..997bcdc 100644 --- a/neuropy/medication/models.py +++ b/neuropy/medication/models.py @@ -11,8 +11,8 @@ class Medication(models.Model): name = models.CharField( max_length=20, default='CONCERTA') - med_type = models.CharField(default='stimulant') - treating_dis = models.CharField(default='ADD/ADHD') + med_type = models.CharField(max_length=20, default='stimulant') + treating_dis = models.CharField(max_length=25, default='ADD/ADHD') half_life = models.TimeField() ramp_up = models.DurationField() peak_period = models.DurationField() diff --git a/neuropy/neuropy/settings.py b/neuropy/neuropy/settings.py index 34b6aac..6bb6d84 100644 --- a/neuropy/neuropy/settings.py +++ b/neuropy/neuropy/settings.py @@ -37,6 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'medication' ] MIDDLEWARE = [ From 346ace7d529dbdfb331e0375c89abc8b12163d4a Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 13 Feb 2017 16:13:18 -0800 Subject: [PATCH 5/9] created empty migration. --- .../migrations/0002_auto_20170213_1612.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 neuropy/medication/migrations/0002_auto_20170213_1612.py diff --git a/neuropy/medication/migrations/0002_auto_20170213_1612.py b/neuropy/medication/migrations/0002_auto_20170213_1612.py new file mode 100644 index 0000000..d8a70cd --- /dev/null +++ b/neuropy/medication/migrations/0002_auto_20170213_1612.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-02-14 00:12 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('medication', '0001_initial'), + ] + + operations = [ + ] From 5fe75a6bbc565aa0602b6217d37474c43ea259ff Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 13 Feb 2017 16:18:47 -0800 Subject: [PATCH 6/9] second migration configured --- .../medication/migrations/0002_auto_20170213_1612.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/neuropy/medication/migrations/0002_auto_20170213_1612.py b/neuropy/medication/migrations/0002_auto_20170213_1612.py index d8a70cd..5af5f74 100644 --- a/neuropy/medication/migrations/0002_auto_20170213_1612.py +++ b/neuropy/medication/migrations/0002_auto_20170213_1612.py @@ -1,3 +1,5 @@ +""".""" + # -*- coding: utf-8 -*- # Generated by Django 1.10.5 on 2017-02-14 00:12 from __future__ import unicode_literals @@ -5,11 +7,19 @@ from django.db import migrations +def load_medications_from_fixture(apps, schema_editor): + """.""" + from django.core.management import call_command + call_command("loaddata", "medication") + + class Migration(migrations.Migration): + """.""" dependencies = [ ('medication', '0001_initial'), ] operations = [ + migrations.RunPython(load_medications_from_fixture), ] From d2a20516de7d9524188a1e9ea9f89c3b81c4058f Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 14 Feb 2017 08:49:52 -0800 Subject: [PATCH 7/9] fixed test error. Added another test. Passing. minor change to model format --- neuropy/medication/models.py | 15 ++++++++++++--- neuropy/medication/tests.py | 22 ++++++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/neuropy/medication/models.py b/neuropy/medication/models.py index bf47d2f..ab06773 100644 --- a/neuropy/medication/models.py +++ b/neuropy/medication/models.py @@ -1,3 +1,5 @@ +"""Medication model- no user relation.""" + from __future__ import unicode_literals from django.db import models @@ -6,7 +8,7 @@ @python_2_unicode_compatible class Medication(models.Model): - """.""" + """Medication instace class.""" name = models.CharField( max_length=20, @@ -19,5 +21,12 @@ class Medication(models.Model): # Ease_priority_matrix=models.CharField def __str__(self): - """.""" - return "name: {}, med_type: {}, treating_dis: {}, half_life: {}, ramp_up: {}, peak_period: {}".format(self.name, self.med_type, self.treating_dis, self.half_life, self.ramp_up, self.peak_period) + """String representation of Medication.""" + return "name: {},med_type: {}, treating_dis: {}, half_life: {}, ramp_up: {}, peak_period: {}".format( + self.name, + self.med_type, + self.treating_dis, + self.half_life, + self.ramp_up, + self.peak_period + ) diff --git a/neuropy/medication/tests.py b/neuropy/medication/tests.py index 840fcc8..15f2b17 100644 --- a/neuropy/medication/tests.py +++ b/neuropy/medication/tests.py @@ -25,7 +25,6 @@ def medication_instance(self): ramp_up=ramp_up, peak_period=peak_period ) - import pdb; pdb.set_trace() objects.save() return objects.id @@ -34,12 +33,19 @@ def test_name(self): """Test that a medication instance has a name.""" #med_id = self.medication_instance() medication = Medication.objects.get(name="CONCERTA") - import pdb; pdb.set_trace() self.assertTrue(medication.name == "CONCERTA") - # def test_med_type(self): - # """Test that medication instanc.""" - # #med_id = self.medication_instance() - # medication = Medication.objects.get(med_type="stimulant") - # import pdb; pdb.set_trace() - # assert medication.med_type == "stimulant" + def test_med_type(self): + """Test medication instance type.""" + #med_id = self.medication_instance() + medications = Medication.objects.filter(med_type="stimulant") + for medication in medications: + assert medication.med_type == "stimulant" + + def test_delete_med(self): + """Test fetching medication after delete throws an exception.""" + #med_id = self.medication_instance() + medication = Medication.objects.get(name="CONCERTA") + medication.delete() + with self.assertRaises(Medication.DoesNotExist): + Medication.objects.get(name="CONCERTA") From 4672f209840b78a8e8d5848289e338d544ba7541 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 14 Feb 2017 10:31:15 -0800 Subject: [PATCH 8/9] committing to change branch. changing tests to use factory. --- neuropy/medication/tests.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/neuropy/medication/tests.py b/neuropy/medication/tests.py index 15f2b17..864b6b7 100644 --- a/neuropy/medication/tests.py +++ b/neuropy/medication/tests.py @@ -10,12 +10,12 @@ class MedicationTestCase(TestCase): def medication_instance(self): """Create An Instance of a Medication and Save to DB.""" - name = 'CONCERTA', - med_type = 'stimulant', - treating_dis = 'ADD/ADHD', - half_life = datetime.timedelta(hours=3, minutes=30), # 03:30:00 - ramp_up = datetime.timedelta(hours=4, minutes=30), # 04:30:00 - peak_period = datetime.timedelta(hours=7), # 07:00:00 + name = 'CONCERTA' + med_type = 'stimulant' + treating_dis = 'ADD/ADHD' + half_life = datetime.timedelta(hours=3, minutes=30) # 03:30:00 + ramp_up = datetime.timedelta(hours=4, minutes=30) # 04:30:00 + peak_period = datetime.timedelta(hours=7) # 07:00:00 objects = Medication.objects.create( name=name, @@ -31,20 +31,20 @@ def medication_instance(self): def test_name(self): """Test that a medication instance has a name.""" - #med_id = self.medication_instance() - medication = Medication.objects.get(name="CONCERTA") + objects = self.medication_instance() + medication = Medication.objects.get(id=objects) self.assertTrue(medication.name == "CONCERTA") def test_med_type(self): """Test medication instance type.""" - #med_id = self.medication_instance() + objects = self.medication_instance() medications = Medication.objects.filter(med_type="stimulant") for medication in medications: assert medication.med_type == "stimulant" def test_delete_med(self): """Test fetching medication after delete throws an exception.""" - #med_id = self.medication_instance() + objects = self.medication_instance() medication = Medication.objects.get(name="CONCERTA") medication.delete() with self.assertRaises(Medication.DoesNotExist): From dec9ec72f6b42e26ef5c70cab3b331dcb0e50cd2 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 14 Feb 2017 11:09:36 -0800 Subject: [PATCH 9/9] added more tests, using factoryboy to save to test db insetad. All passing. --- neuropy/medication/tests.py | 72 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/neuropy/medication/tests.py b/neuropy/medication/tests.py index 864b6b7..11f1bd7 100644 --- a/neuropy/medication/tests.py +++ b/neuropy/medication/tests.py @@ -2,50 +2,64 @@ from django.test import TestCase from medication.models import Medication +import factory import datetime +class MedicationFactory(factory.django.DjangoModelFactory): + """Create test instance of todos.""" + + class Meta: + """Invoke Todo instance using Todo model class.""" + + model = Medication + + name = 'CONCERTA' + med_type = 'stimulant' + treating_dis = 'ADD/ADHD' + half_life = datetime.timedelta(hours=3, minutes=30) # 03:30:00 + ramp_up = datetime.timedelta(hours=4, minutes=30) # 04:30:00 + peak_period = datetime.timedelta(hours=7) # 07:00:00 + + class MedicationTestCase(TestCase): """Test the Medication model.""" - def medication_instance(self): - """Create An Instance of a Medication and Save to DB.""" - name = 'CONCERTA' - med_type = 'stimulant' - treating_dis = 'ADD/ADHD' - half_life = datetime.timedelta(hours=3, minutes=30) # 03:30:00 - ramp_up = datetime.timedelta(hours=4, minutes=30) # 04:30:00 - peak_period = datetime.timedelta(hours=7) # 07:00:00 - - objects = Medication.objects.create( - name=name, - med_type=med_type, - treating_dis=treating_dis, - half_life=half_life, - ramp_up=ramp_up, - peak_period=peak_period - ) - - objects.save() - return objects.id + def setUp(self): + """Setup for medications.""" + self.medications = [MedicationFactory.create() for i in range(10)] def test_name(self): """Test that a medication instance has a name.""" - objects = self.medication_instance() - medication = Medication.objects.get(id=objects) + medication = self.medications[1] + medication = Medication.objects.get(id=medication.id) self.assertTrue(medication.name == "CONCERTA") + def test_treating_disorder(self): + """Test that a medication instance has a name.""" + medication = self.medications[1] + medication = Medication.objects.get(id=medication.id) + self.assertTrue(medication.treating_dis == "ADD/ADHD") + def test_med_type(self): """Test medication instance type.""" - objects = self.medication_instance() - medications = Medication.objects.filter(med_type="stimulant") - for medication in medications: - assert medication.med_type == "stimulant" + medication = self.medications[1] + medications = Medication.objects.get(id=medication.id) + self.assertTrue(medication.med_type == "stimulant") + + def test_change_data(self): + """Test Editing medication data.""" + medication = self.medications[1] + medication = Medication.objects.get(id=medication.id) + medication.peak_period = datetime.timedelta(hours=10) + medication.save() + medication = Medication.objects.get(id=medication.id) + self.assertTrue(medication.peak_period == datetime.timedelta(hours=10)) def test_delete_med(self): """Test fetching medication after delete throws an exception.""" - objects = self.medication_instance() - medication = Medication.objects.get(name="CONCERTA") + medication = self.medications[1] + medication = Medication.objects.get(id=medication.id) medication.delete() with self.assertRaises(Medication.DoesNotExist): - Medication.objects.get(name="CONCERTA") + Medication.objects.get(id=medication.id)