-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
502 additions
and
2,495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.