Skip to content

Commit

Permalink
initial push
Browse files Browse the repository at this point in the history
  • Loading branch information
ckgathi committed Apr 8, 2017
1 parent c7f7475 commit 43788dd
Show file tree
Hide file tree
Showing 56 changed files with 502 additions and 2,495 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include AUTHORS CHANGES README.md LICENCE
recursive-include bcpp_clinic/templates *
Binary file modified bcpp_clinic/.DS_Store
Binary file not shown.
1,685 changes: 0 additions & 1,685 deletions bcpp_clinic/migrations/0001_initial.py

This file was deleted.

Empty file removed bcpp_clinic/migrations/__init__.py
Empty file.
11 changes: 5 additions & 6 deletions bcpp_clinic/models/base_clinic_registered_subject_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from django.db import models

from edc_base.model.validators import datetime_not_before_study_start, datetime_not_future
from edc_base.model.models import BaseUuidModel
from edc_sync.models import SyncModelMixin
# from edc.subject.registration.managers import RegisteredSubjectManager
from registration.models import RegisteredSubject
from edc.device.sync.models import BaseSyncUuidModel
from edc.subject.registration.managers import RegisteredSubjectManager
from edc.subject.registration.models import RegisteredSubject


class BaseClinicRegisteredSubjectModel(SyncModelMixin, BaseUuidModel):
class BaseClinicRegisteredSubjectModel(BaseSyncUuidModel):

registration_datetime = models.DateTimeField(
verbose_name="Registration date/time",
Expand All @@ -20,7 +19,7 @@ class BaseClinicRegisteredSubjectModel(SyncModelMixin, BaseUuidModel):
# This is updated by a post save signal
registered_subject = models.ForeignKey(RegisteredSubject, editable=False, null=True,)

# objects = RegisteredSubjectManager()
objects = RegisteredSubjectManager()

def __unicode__(self):
return unicode(self.registered_subject)
Expand Down
8 changes: 5 additions & 3 deletions bcpp_clinic/models/base_clinic_visit_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from django.db import models

from simple_history.models import HistoricalRecords as AuditTrail
from edc_base.model.models import HistoricalRecords


from edc_base.model.validators import datetime_not_before_study_start, datetime_not_future
from edc_sync.model_mixins import SyncModelMixin
from edc_base.model.models import BaseUuidModel
from edc_sync.models import SyncModelMixin
from edc_consent.models import RequiresConsentMixin

from .clinic_off_study_mixin import ClinicOffStudyMixin
Expand All @@ -14,7 +16,7 @@
from ..managers import ClinicModelManager


class BaseClinicVisitModel(SyncModelMixin, ClinicOffStudyMixin, RequiresConsentMixin, BaseUuidModel):
class BaseClinicVisitModel(ClinicOffStudyMixin, RequiresConsentMixin, SyncModelMixin, BaseUuidModel):

""" Base model for all clinic scheduled models (adds key to :class:`ClinicVisit`). """

Expand Down
30 changes: 25 additions & 5 deletions bcpp_clinic/models/base_household_member_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@

from django.db import models

from edc_identifier.exceptions import IdentifierError
from edc_appointment.models import AppointmentMixin
from registration.models import RegisteredSubject
from edc.core.bhp_variables.models import StudySite
from edc.core.identifier.exceptions import IdentifierError
from edc_map.site_mappers import site_mappers
from edc.subject.appointment_helper.models import BaseAppointmentMixin
from edc.subject.registration.models import RegisteredSubject
from edc_consent.models import BaseConsent
from edc_constants.choices import YES_NO

from ..choices import COMMUNITIES
from bhp066.apps.bcpp.choices import COMMUNITIES
from bhp066.apps.bcpp_household_member.models import HouseholdMember
from bhp066.apps.bcpp_survey.models import Survey


class BaseClinicConsent(AppointmentMixin, BaseConsent):
class BaseHouseholdMemberConsent(BaseAppointmentMixin, BaseConsent):

household_member = models.ForeignKey(HouseholdMember, help_text='')

registered_subject = models.ForeignKey(
RegisteredSubject,
editable=False,
null=True,
help_text='one registered subject will be related to one household member for each survey')

study_site = models.ForeignKey(
StudySite,
verbose_name='Site',
null=True,
help_text="This refers to the site or 'clinic area' where the subject is being consented."
)

is_minor = models.CharField(
verbose_name=("Is subject a minor?"),
max_length=10,
Expand All @@ -31,6 +44,8 @@ class BaseClinicConsent(AppointmentMixin, BaseConsent):

is_signed = models.BooleanField(default=False)

survey = models.ForeignKey(Survey, editable=False, null=True)

community = models.CharField(max_length=25, choices=COMMUNITIES, null=True, editable=False)

def __unicode__(self):
Expand All @@ -39,9 +54,14 @@ def __unicode__(self):
def get_registration_datetime(self):
return self.consent_datetime

def get_site_code(self):
return site_mappers.get_mapper(site_mappers.current_community).map_code

def save(self, *args, **kwargs):
if not self.id:
self.registered_subject = RegisteredSubject.objects.get(identity=self.identity)
self.household_member = HouseholdMember.objects.get(registered_subject=self.registered_subject)
self.survey = self.household_member.household_structure.survey
super(BaseHouseholdMemberConsent, self).save(*args, **kwargs)

def _check_if_duplicate_subject_identifier(self, using):
Expand Down
154 changes: 114 additions & 40 deletions bcpp_clinic/models/clinic_consent.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,132 @@
import re
import uuid

from django.db import models

from simple_history.models import HistoricalRecords as AuditTrail
from registration.models import RegisteredSubject
from edc_consent.models.fields import (
ReviewFieldsMixin, SampleCollectionFieldsMixin, PersonalFieldsMixin,
CitizenFieldsMixin, VulnerabilityFieldsMixin)
from edc_consent.models.fields.bw import IdentityFieldsMixin
from edc_base.model_mixins import BaseUuidModel
from edc_base.model_managers import HistoricalRecords
from edc_consent.field_mixins.bw import IdentityFieldsMixin
from edc_consent.field_mixins import (
ReviewFieldsMixin, PersonalFieldsMixin, VulnerabilityFieldsMixin,
SampleCollectionFieldsMixin, CitizenFieldsMixin)
from edc_consent.managers import ConsentManager
from edc_consent.model_mixins import ConsentModelMixin
from edc_constants.choices import YES_NO
from edc_constants.constants import YES, NO
from edc_dashboard.model_mixins import SearchSlugManager
from edc_identifier.model_mixins import NonUniqueSubjectIdentifierModelMixin
from edc_map.site_mappers import site_mappers
from edc_registration.exceptions import RegisteredSubjectError
from edc_registration.model_mixins import (
UpdatesOrCreatesRegistrationModelMixin
as BaseUpdatesOrCreatesRegistrationModelMixin)

from edc_consent.models import BaseConsent
from member.models import HouseholdMember
from survey.model_mixins import SurveyScheduleModelMixin

from .clinic_off_study_mixin import ClinicOffStudyMixin
from bcpp_subject.managers import SubjectConsentManager
from bcpp_subject.patterns import subject_identifier
from bcpp_subject.models.model_mixins import SearchSlugModelMixin
from bcpp_subject.utils import is_minor


class ClinicConsent(PersonalFieldsMixin, VulnerabilityFieldsMixin, SampleCollectionFieldsMixin,
ReviewFieldsMixin, IdentityFieldsMixin, CitizenFieldsMixin, ClinicOffStudyMixin,
BaseConsent):
"""A model completed by the user to capture the ICF."""
class Manager(SubjectConsentManager, SearchSlugManager):
pass

registered_subject = models.ForeignKey(RegisteredSubject, null=True)

lab_identifier = models.CharField(
verbose_name=("lab allocated identifier"),
max_length=50,
null=True,
blank=True,
help_text="if known."
)
class UpdatesOrCreatesRegistrationModelMixin(BaseUpdatesOrCreatesRegistrationModelMixin):

htc_identifier = models.CharField(
verbose_name=("HTC Identifier"),
max_length=50,
null=True,
blank=True,
help_text="if known."
)
@property
def registration_options(self):
"""Insert internal_identifier to be updated on
RegisteredSubject.
"""
registration_options = super().registration_options
registration_options.update(
registration_identifier=self.household_member.internal_identifier.hex)
return registration_options

def registration_raise_on_illegal_value_change(self, registered_subject):
"""Raises an exception if a value changes between
updates.
"""
if registered_subject.identity != self.identity:
raise RegisteredSubjectError(
'Identity may not be changed. Expected {}. Got {}'.format(
registered_subject.identity,
self.identity))
if (registered_subject.registration_identifier
and uuid.UUID(registered_subject.registration_identifier) !=
self.household_member.internal_identifier):
raise RegisteredSubjectError(
'Internal Identifier may not be changed. Expected {}. '
'Got {}'.format(
registered_subject.registration_identifier,
self.household_member.internal_identifier))
if registered_subject.dob != self.dob:
raise RegisteredSubjectError(
'DoB may not be changed. Expected {}. Got {}'.format(
registered_subject.dob,
self.dob))

class Meta:
abstract = True


class ClinicConsent(
ConsentModelMixin, UpdatesOrCreatesRegistrationModelMixin,
NonUniqueSubjectIdentifierModelMixin, SurveyScheduleModelMixin,
IdentityFieldsMixin, ReviewFieldsMixin, PersonalFieldsMixin,
SampleCollectionFieldsMixin, CitizenFieldsMixin,
VulnerabilityFieldsMixin, SearchSlugModelMixin, BaseUuidModel):
""" A model completed by the user that captures the ICF.
"""

pims_identifier = models.CharField(
verbose_name=("PIMS identifier"),
max_length=50,
household_member = models.ForeignKey(
HouseholdMember, on_delete=models.PROTECT)

is_minor = models.CharField(
verbose_name=("Is subject a minor?"),
max_length=10,
choices=YES_NO,
null=True,
blank=True,
help_text="if known."
)
blank=False,
help_text=('Subject is a minor if aged 16-17. A guardian must '
'be present for consent. HIV status may NOT be '
'revealed in the household.'),
editable=False)

history = AuditTrail()
is_signed = models.BooleanField(
default=False,
editable=False)

def save(self, *args, **kwargs):
# self.clinic_subject_identifier()
super(ClinicConsent, self).save(*args, **kwargs)
objects = Manager()

def is_dispatchable_model(self):
return False
consent = ConsentManager()

class Meta:
history = HistoricalRecords()

def __str__(self):
return '{0} ({1}) V{2}'.format(
self.subject_identifier,
self.survey_schedule_object.name,
self.version)

def save(self, *args, **kwargs):
if not self.id:
self.survey_schedule = self.household_member.survey_schedule_object.field_value
if re.match(subject_identifier, self.household_member.subject_identifier):
self.subject_identifier = self.household_member.subject_identifier
self.study_site = site_mappers.current_map_code
self.is_minor = YES if is_minor(
self.dob, self.consent_datetime) else NO
super().save(*args, **kwargs)

class Meta(ConsentModelMixin.Meta):
app_label = 'bcpp_clinic'
verbose_name = 'Clinic Consent RBD'
verbose_name_plural = 'Clinic Consent RBD'
get_latest_by = 'consent_datetime'
unique_together = (('subject_identifier', 'version'),
('first_name', 'dob', 'initials', 'version'))
ordering = ('-created', )
8 changes: 6 additions & 2 deletions bcpp_clinic/models/clinic_consent_history.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from django.db import models

from bhp066.apps.bcpp_household_member.models import HouseholdMember
from bhp066.apps.bcpp_survey.models import Survey

from ..managers import ConsentHistoryManager
from .clinic_visit import ClinicVisit


class ClinicConsentHistory(models.Model):

clinic_visit = models.ForeignKey(ClinicVisit)
survey = models.ForeignKey(Survey)

household_member = models.ForeignKey(HouseholdMember)

objects = ConsentHistoryManager()

Expand Down
Loading

0 comments on commit 43788dd

Please sign in to comment.