Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
svituz committed May 10, 2017
2 parents 575f1cc + b26194f commit 60e9c1e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'sphinx.ext.coverage',
'sphinx.ext.pngmath',
'sphinx.ext.viewcode',
'sphinx_http_domain',
'sphinxcontrib.httpdomain'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
30 changes: 18 additions & 12 deletions src/most/web/demographics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
# Dual licensed under the MIT or GPL Version 2 licenses.
# See license-GPLv2.txt or license-MIT.txt

import string
from datetime import date, datetime

from django.db import models
from django.utils.translation import ugettext_lazy as _
from datetime import date, datetime

from utils import make_new_uid
import string


class Identifier(models.Model):
Expand Down Expand Up @@ -73,7 +75,8 @@ class City(models.Model):
MANDATORY_FIELDS = ('name', 'state')

name = models.CharField(_('Name'), max_length=255)
province = models.CharField(_('Province'), max_length=2, null=True, blank=True, help_text=_('Use 2 letters format')) # No control on existence of the province
province = models.CharField(_('Province'), max_length=2, null=True, blank=True,
help_text=_('Use 2 letters format')) # No control on existence of the province
state = models.CharField(_('State'), max_length=50, help_text=_('Mandatory'))
code = models.CharField(_('Code'), max_length=5, null=True, blank=True, help_text=_('e.g. C.A.P., ZIP, etc.'))

Expand Down Expand Up @@ -156,17 +159,20 @@ class Patient(models.Model):
MANDATORY_FIELDS = ('first_name', 'last_name', 'gender', 'birth_date', 'birth_place')

uid = models.CharField(max_length=40, unique=True, default=make_new_uid)
account_number = models.CharField(_('National Tax Code'), max_length=16, null=True, blank=True, help_text=_('e.g. SSN'))
account_number = models.CharField(_('National Tax Code'), max_length=16, null=True, blank=True,
help_text=_('e.g. SSN'))
first_name = models.CharField(_('First name'), max_length=50)
last_name = models.CharField(_('Last name'), max_length=50)
other_ids = models.ManyToManyField('Identifier', related_name='patient_related', null=True, blank=True, verbose_name=_('Other IDs'))
other_ids = models.ManyToManyField('Identifier', related_name='patient_related', null=True, blank=True,
verbose_name=_('Other IDs'))
gender = models.CharField(_('Gender'), max_length=1, choices=GENDER_CHOICES)
birth_date = models.DateField(_('Birth date'))
birth_place = models.ForeignKey('City', related_name='born_patient_related', verbose_name=_('Birth place'))
address = models.CharField(_('Address'), null=True, blank=True, max_length=255)
city = models.ForeignKey('City', related_name='addressed_patient_related', null=True, blank=True, verbose_name='City')
phone = models.CharField(_('Phone'), max_length=20, null=True, blank=True) # TODO: validation rules
mobile = models.CharField(_('Mobile phone'), max_length=20, null=True, blank=True) # TODO: validation rules
city = models.ForeignKey('City', related_name='addressed_patient_related', null=True, blank=True,
verbose_name='City')
phone = models.CharField(_('Phone'), max_length=20, null=True, blank=True) # TODO: validation rules
mobile = models.CharField(_('Mobile phone'), max_length=20, null=True, blank=True) # TODO: validation rules
email = models.EmailField(_('Email'), null=True, blank=True)
certified_email = models.EmailField(_('Certified email'), null=True, blank=True)
creation_timestamp = models.DateTimeField(auto_now_add=True)
Expand Down Expand Up @@ -216,13 +222,13 @@ def get_age(self, at_date=None):
compare_date = date.today()
birthday = self.birth_date.replace(year=compare_date.year)
if birthday > compare_date:
years = compare_date.year - self.birth_date.year -1
years = compare_date.year - self.birth_date.year - 1
delta = compare_date - birthday
weeks = int((365.25 + delta.days) / 7)
else:
years = compare_date.year - self.birth_date.year
delta = compare_date - birthday
weeks = int(delta.days/7)
weeks = int(delta.days / 7)
return years, weeks

def to_dictionary(self):
Expand All @@ -246,9 +252,9 @@ def to_dictionary(self):
'other_ids': [],
'gender': u'%s' % self.gender, # self.get_gender_display(),
'birth_date': birth_date,
#'birth_date': u'%s' % self.birth_date if self.birth_date else None,
# 'birth_date': u'%s' % self.birth_date if self.birth_date else None,
'birth_place': self.birth_place.to_dictionary() if self.birth_place else None,
#'birth_place': u'%s' % self.birth_place if self.birth_place else None,
# 'birth_place': u'%s' % self.birth_place if self.birth_place else None,
'address': self.address if self.address else None,
'city': self.city.to_dictionary() if self.city else None,
'phone': u'%s' % self.phone if self.phone else None,
Expand Down
68 changes: 33 additions & 35 deletions src/most/web/demographics/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,47 @@
from most.web.demographics.views import patient, city, identifier

from django.contrib import admin
admin.autodiscover()

admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'most.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
#url(r'^admin/', include(admin.site.urls)),
)
urlpatterns = patterns('')

# Patient API related urls
urlpatterns += patterns('',
(r'^patient/new/$', patient.new),
(r'^patient/get/$', patient.get), # TODO add a "real" get api to get single patient
(r'^patient/filter/$', patient.filter), # TODO add a "real" get api to get single patient
(r'^patient/(?P<patient_id>\d+)/edit/$', patient.edit),
(r'^patient/(?P<patient_id>\d+)/deactivate/$', patient.deactivate),
(r'^patient/(?P<patient_id>\d+)/activate/$', patient.activate),
(r'^patient/(?P<patient_id>\d+)/add_id/$', patient.add_identifier),
(r'^patient/(?P<patient_id>\d+)/remove_id/$', patient.remove_identifier),
(r'^patient/(?P<patient_id>\d+)/set_birth_place/$', patient.set_birth_place),
(r'^patient/(?P<patient_id>\d+)/set_city/$', patient.set_city),
#(r"^patient/delete/$", patient.delete),
#(r'^patient/get/all/$', 'get_all_patients'),
#(r'^patient/get/active/$', 'get_active_patients'),
#(r'^patient/get/oauth/$', 'get_active_patients_oauth'),
#(r'^patient/add_task_group/$', 'add_task_group_to_patient'),
#(r'^patient/get_task_groups/$', 'get_task_groups'),
#(r'^patient/(?P<patient_id>\d+)/get_medicalrecords/$', 'get_medicalrecords'),
#(r'^api/patient/get_contacts/$', 'get_contacts'),
urlpatterns += patterns(
'',
(r'patient/new/$', patient.new),
(r'patient/get/$', patient.get), # TODO add a "real" get api to get single patient
(r'patient/filter/$', patient.filter), # TODO add a "real" get api to get single patient
(r'patient/(?P<patient_id>\d+)/edit/$', patient.edit),
(r'patient/(?P<patient_id>\d+)/deactivate/$', patient.deactivate),
(r'patient/(?P<patient_id>\d+)/activate/$', patient.activate),
(r'patient/(?P<patient_id>\d+)/add_id/$', patient.add_identifier),
(r'patient/(?P<patient_id>\d+)/remove_id/$', patient.remove_identifier),
(r'patient/(?P<patient_id>\d+)/set_birth_place/$', patient.set_birth_place),
(r'patient/(?P<patient_id>\d+)/set_city/$', patient.set_city),
# (r"patient/delete/$", patient.delete),
# (r'patient/get/all/$', 'get_all_patients'),
# (r'patient/get/active/$', 'get_active_patients'),
# (r'patient/get/oauth/$', 'get_active_patients_oauth'),
# (r'patient/add_task_group/$', 'add_task_group_to_patient'),
# (r'patient/get_task_groups/$', 'get_task_groups'),
# (r'patient/(?P<patient_id>\d+)/get_medicalrecords/$', 'get_medicalrecords'),
# (r'api/patient/get_contacts/$', 'get_contacts'),
)

# City API related urls
urlpatterns += patterns('',
(r'^city/new/$', city.new),
(r'^city/get/$', city.filter),
(r'^city/(?P<city_id>\d+)/edit/$', city.edit),
urlpatterns += patterns(
'',
(r'city/new/$', city.new),
(r'city/get/$', city.filter),
(r'city/(?P<city_id>\d+)/edit/$', city.edit),
)

# Identifier API related urls
urlpatterns += patterns('',
(r'^identifier/new/$', identifier.new),
(r'^identifier/get/$', identifier.filter),
(r'^identifier/(?P<identifier_id>\d+)/edit/$', identifier.edit),
(r'^identifier/(?P<identifier_id>\d+)/get_patient/$', identifier.get_patient),
urlpatterns += patterns(
'',
(r'identifier/new/$', identifier.new),
(r'identifier/get/$', identifier.filter),
(r'identifier/(?P<identifier_id>\d+)/edit/$', identifier.edit),
(r'identifier/(?P<identifier_id>\d+)/get_patient/$', identifier.get_patient),
)
1 change: 1 addition & 0 deletions src/most/web/demographics/views/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def deactivate(request, patient_id):
result[SUCCESS_KEY] = False
return HttpResponse(json.dumps(result), content_type='application/json; charset=utf8')


@csrf_exempt
@require_POST
def set_birth_place(request, patient_id):
Expand Down

0 comments on commit 60e9c1e

Please sign in to comment.