Skip to content

Commit

Permalink
Merge branch 'release/0.1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Sep 3, 2018
2 parents 2cd3079 + 3a83b32 commit 00c5268
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.6
0.1.7
32 changes: 18 additions & 14 deletions ambition_prn/form_validators/validate_death_report_mixin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import arrow

from dateutil import tz
from django import forms
from django.apps import apps as django_apps
from django.conf import settings
Expand All @@ -18,6 +21,8 @@ def validate_death_report_if_deceased(self):
"""Validates death report exists of termination_reason
is "DEAD.
Death "date" is the naive date of the settings.TIME_ZONE datetime.
Note: uses __date field lookup. If using mysql don't forget
to load timezone info.
"""
Expand All @@ -33,17 +38,16 @@ def validate_death_report_if_deceased(self):
'termination_reason':
'Patient is deceased, please complete death report form first.'})
else:
if self.cleaned_data.get('death_date'):
try:
self.death_report_model_cls.objects.get(
subject_identifier=subject_identifier,
death_datetime__date=self.cleaned_data.get('death_date'))
except ObjectDoesNotExist:
expected = death_report.death_datetime.strftime(
convert_php_dateformat(settings.SHORT_DATE_FORMAT))
got = self.cleaned_data.get('death_date').strftime(
convert_php_dateformat(settings.SHORT_DATE_FORMAT))
raise forms.ValidationError({
'death_date':
'Date does not match Death Report. '
f'Expected {expected}. Got {got}.'})
local_death_datetime = arrow.get(
death_report.death_datetime, tz.gettz(settings.TIME_ZONE))
if (self.cleaned_data.get('death_date')
and (local_death_datetime.date() != self.cleaned_data.get(
'death_date'))):
expected = local_death_datetime.date().strftime(
convert_php_dateformat(settings.SHORT_DATE_FORMAT))
got = self.cleaned_data.get('death_date').strftime(
convert_php_dateformat(settings.SHORT_DATE_FORMAT))
raise forms.ValidationError({
'death_date':
'Date does not match Death Report. '
f'Expected {expected}. Got {got}.'})
3 changes: 3 additions & 0 deletions ambition_prn/templates/ambition_prn/bootstrap3/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends edc_base_template %}

{% load static %}
3 changes: 0 additions & 3 deletions ambition_prn/templates/ambition_prn/home.html

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import arrow

from ambition_rando.tests import AmbitionTestCaseMixin
from datetime import date
from django import forms
from django.core.exceptions import ValidationError
from django.test import TestCase, tag
from django.test.utils import override_settings
from edc_base.utils import get_utcnow
from edc_constants.constants import YES, NO, OTHER, NOT_APPLICABLE, DEAD
from edc_list_data import site_list_data
Expand Down Expand Up @@ -127,16 +130,21 @@ def test_died_death_date_mismatch(self):
self.assertRaises(ValidationError, form_validator.validate)
self.assertIn('death_date', form_validator._errors)

@override_settings(TIME_ZONE='Africa/Kampala')
def test_died_death_date_ok(self):
dte = get_utcnow()
from dateutil import tz
from datetime import datetime
dte1 = arrow.get(datetime(2018, 8, 12, 0, 0, 0),
tz.tzutc())
dte2 = date(2018, 8, 12)
DeathReport.objects.create(
subject_identifier=self.subject_identifier,
death_datetime=get_utcnow(),
death_datetime=dte1.datetime,
study_day=1)

cleaned_data = {'subject_identifier': self.subject_identifier,
'termination_reason': DEAD,
'death_date': dte.date()}
'death_date': dte2}
form_validator = StudyTerminationConclusionFormValidator(
cleaned_data=cleaned_data)
try:
Expand Down
2 changes: 1 addition & 1 deletion ambition_prn/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

urlpatterns = [
path('admin/', ambition_prn_admin.urls),
path('', RedirectView.as_view(url='admin/'), name='home_url'),
path('', RedirectView.as_view(url='/ambition_prn/admin/'), name='home_url'),
]


Expand Down

0 comments on commit 00c5268

Please sign in to comment.