Skip to content

Commit

Permalink
black format
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 29, 2019
1 parent 9e02903 commit 6d2285d
Show file tree
Hide file tree
Showing 28 changed files with 1,135 additions and 567 deletions.
32 changes: 21 additions & 11 deletions ambition_screening/admin/modeladmin_mixins.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
from django_revision.modeladmin_mixin import ModelAdminRevisionMixin
from edc_base.sites import ModelAdminSiteMixin
from edc_model_admin import (
ModelAdminNextUrlRedirectMixin, ModelAdminFormInstructionsMixin,
ModelAdminFormAutoNumberMixin, ModelAdminAuditFieldsMixin,
ModelAdminReadOnlyMixin, ModelAdminInstitutionMixin,
ModelAdminRedirectOnDeleteMixin)
ModelAdminNextUrlRedirectMixin,
ModelAdminFormInstructionsMixin,
ModelAdminFormAutoNumberMixin,
ModelAdminAuditFieldsMixin,
ModelAdminReadOnlyMixin,
ModelAdminInstitutionMixin,
ModelAdminRedirectOnDeleteMixin,
)
from edc_metadata import NextFormGetter


class ModelAdminMixin(ModelAdminNextUrlRedirectMixin, ModelAdminFormInstructionsMixin,
ModelAdminFormAutoNumberMixin, ModelAdminRevisionMixin,
ModelAdminAuditFieldsMixin, ModelAdminReadOnlyMixin,
ModelAdminInstitutionMixin, ModelAdminRedirectOnDeleteMixin,
ModelAdminSiteMixin):
class ModelAdminMixin(
ModelAdminNextUrlRedirectMixin,
ModelAdminFormInstructionsMixin,
ModelAdminFormAutoNumberMixin,
ModelAdminRevisionMixin,
ModelAdminAuditFieldsMixin,
ModelAdminReadOnlyMixin,
ModelAdminInstitutionMixin,
ModelAdminRedirectOnDeleteMixin,
ModelAdminSiteMixin,
):

list_per_page = 10
date_hierarchy = 'modified'
empty_value_display = '-'
date_hierarchy = "modified"
empty_value_display = "-"
next_form_getter_cls = NextFormGetter
77 changes: 39 additions & 38 deletions ambition_screening/admin/subject_screening_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,47 @@ class SubjectScreeningAdmin(ModelAdminMixin, SimpleHistoryAdmin, admin.ModelAdmi
form = SubjectScreeningForm

post_url_on_delete_name = settings.DASHBOARD_URL_NAMES.get(
'screening_dashboard_url')
"screening_dashboard_url"
)

radio_fields = {
'gender': admin.VERTICAL,
'meningitis_dx': admin.VERTICAL,
'will_hiv_test': admin.VERTICAL,
'mental_status': admin.VERTICAL,
'consent_ability': admin.VERTICAL,
'pregnancy': admin.VERTICAL,
'breast_feeding': admin.VERTICAL,
'previous_drug_reaction': admin.VERTICAL,
'contraindicated_meds': admin.VERTICAL,
'received_amphotericin': admin.VERTICAL,
'received_fluconazole': admin.VERTICAL,
'unsuitable_for_study': admin.VERTICAL}
"gender": admin.VERTICAL,
"meningitis_dx": admin.VERTICAL,
"will_hiv_test": admin.VERTICAL,
"mental_status": admin.VERTICAL,
"consent_ability": admin.VERTICAL,
"pregnancy": admin.VERTICAL,
"breast_feeding": admin.VERTICAL,
"previous_drug_reaction": admin.VERTICAL,
"contraindicated_meds": admin.VERTICAL,
"received_amphotericin": admin.VERTICAL,
"received_fluconazole": admin.VERTICAL,
"unsuitable_for_study": admin.VERTICAL,
}

fieldsets = (
(None, {
'fields': (
'report_datetime',
'gender',
'age_in_years',
'meningitis_dx',
'will_hiv_test',
'mental_status',
'consent_ability',
'pregnancy',
'preg_test_date',
'breast_feeding',
'previous_drug_reaction',
'contraindicated_meds',
'received_amphotericin',
'received_fluconazole',
'unsuitable_for_study',
'reasons_unsuitable')
}),
('Blood Results', {
'fields': (
'alt',
'neutrophil',
'platelets')
}),
(
None,
{
"fields": (
"report_datetime",
"gender",
"age_in_years",
"meningitis_dx",
"will_hiv_test",
"mental_status",
"consent_ability",
"pregnancy",
"preg_test_date",
"breast_feeding",
"previous_drug_reaction",
"contraindicated_meds",
"received_amphotericin",
"received_fluconazole",
"unsuitable_for_study",
"reasons_unsuitable",
)
},
),
("Blood Results", {"fields": ("alt", "neutrophil", "platelets")}),
)
12 changes: 4 additions & 8 deletions ambition_screening/admin_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

class AdminSite(DjangoAdminSite):

site_url = '/administration/'
site_url = "/administration/"

def each_context(self, request):
context = super().each_context(request)
context.update(global_site=get_current_site(request))
label = f'Ambition {get_current_site(request).name.title()}: Screening'
context.update(
site_title=label,
site_header=label,
index_title=label,
)
label = f"Ambition {get_current_site(request).name.title()}: Screening"
context.update(site_title=label, site_header=label, index_title=label)
return context


ambition_screening_admin = AdminSite(name='ambition_screening_admin')
ambition_screening_admin = AdminSite(name="ambition_screening_admin")
20 changes: 12 additions & 8 deletions ambition_screening/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@


class AppConfig(DjangoApponfig):
name = 'ambition_screening'
verbose_name = 'Ambition Subject Screening'
name = "ambition_screening"
verbose_name = "Ambition Subject Screening"
screening_age_adult_upper = 99
screening_age_adult_lower = 18
include_in_administration_section = True
has_exportable_data = True


if settings.APP_NAME == 'ambition_screening':
if settings.APP_NAME == "ambition_screening":

from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU

class EdcFacilityAppConfig(BaseEdcFacilityAppConfig):
country = 'botswana'
country = "botswana"
definitions = {
'7-day clinic': dict(days=[MO, TU, WE, TH, FR, SA, SU],
slots=[100, 100, 100, 100, 100, 100, 100]),
'5-day clinic': dict(days=[MO, TU, WE, TH, FR],
slots=[100, 100, 100, 100, 100])}
"7-day clinic": dict(
days=[MO, TU, WE, TH, FR, SA, SU],
slots=[100, 100, 100, 100, 100, 100, 100],
),
"5-day clinic": dict(
days=[MO, TU, WE, TH, FR], slots=[100, 100, 100, 100, 100]
),
}
6 changes: 3 additions & 3 deletions ambition_screening/choices.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from edc_constants.constants import YES, NO, NOT_APPLICABLE

PREG_YES_NO_NA = (
(YES, 'Yes'),
(NO, 'No'),
(NOT_APPLICABLE, 'Not Applicable: e.g. male, post-menopausal'),
(YES, "Yes"),
(NO, "No"),
(NOT_APPLICABLE, "Not Applicable: e.g. male, post-menopausal"),
)
57 changes: 37 additions & 20 deletions ambition_screening/early_withdrawal_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ class EarlyWithdrawalEvaluator:
Used by `Eligibility`.
"""

subject_screening_model = 'ambition_screening.subjectscreening'
blood_result_model = 'ambition_subject.bloodresult'
subject_screening_model = "ambition_screening.subjectscreening"
blood_result_model = "ambition_subject.bloodresult"

def __init__(self, subject_identifier=None, screening_identifier=None,
subject_screening=None, alt=None, neutrophil=None,
platelets=None, allow_none=None, request=None):
def __init__(
self,
subject_identifier=None,
screening_identifier=None,
subject_screening=None,
alt=None,
neutrophil=None,
platelets=None,
allow_none=None,
request=None,
):
self._day_one_blood_results = None
self._subject_screening = subject_screening
self.allow_none = allow_none
Expand All @@ -33,7 +41,8 @@ def __init__(self, subject_identifier=None, screening_identifier=None,
self.subject_identifier = subject_identifier

self.blood_results = OrderedDict(
alt=alt, neutrophil=neutrophil, platelets=platelets)
alt=alt, neutrophil=neutrophil, platelets=platelets
)
self.update_blood_results(self.subject_screening)
self.update_blood_results(self.day_one_blood_results)
self.evaluate()
Expand All @@ -43,30 +52,36 @@ def evaluate(self):
flag (T/F) and updates the `reasons_ineligible` dictionary.
"""
alt, neutrophil, platelets = [v for v in self.blood_results.values()]
if (not alt and not neutrophil and not platelets and self.allow_none):
if not alt and not neutrophil and not platelets and self.allow_none:
self.eligible = True
if self.request:
messages.warning(
self.request, 'Screening blood results are required.')
messages.warning(self.request, "Screening blood results are required.")
elif not alt and not neutrophil and not platelets and not self.allow_none:
self.eligible = False
else:
if alt and not alt_ref.in_bounds(value=float(alt), units=IU_LITER):
self.reasons_ineligible.update(
alt=f'High ALT: {alt}. Ref: {alt_ref.description()}.')
alt=f"High ALT: {alt}. Ref: {alt_ref.description()}."
)
if neutrophil and not neutrophil_ref.in_bounds(
float(neutrophil), units=TEN_X_9_PER_LITER):
float(neutrophil), units=TEN_X_9_PER_LITER
):
self.reasons_ineligible.update(
neutrophil=(
f'Low neutrophil: {neutrophil}. Ref: '
f'{neutrophil_ref.description()}.'))
f"Low neutrophil: {neutrophil}. Ref: "
f"{neutrophil_ref.description()}."
)
)
if platelets and not platelets_ref.in_bounds(
float(platelets), units=TEN_X_9_PER_LITER):
float(platelets), units=TEN_X_9_PER_LITER
):
self.reasons_ineligible.update(
platelets=(f'Low platelets: {platelets}. '
f'Ref: {platelets_ref.description()}.'))
self.eligible = (
True if len(self.reasons_ineligible) == 0 else False)
platelets=(
f"Low platelets: {platelets}. "
f"Ref: {platelets_ref.description()}."
)
)
self.eligible = True if len(self.reasons_ineligible) == 0 else False
return None

@property
Expand All @@ -78,7 +93,8 @@ def subject_screening(self):
model_cls = django_apps.get_model(self.subject_screening_model)
try:
self._subject_screening = model_cls.objects.get(
screening_identifier=self.screening_identifier)
screening_identifier=self.screening_identifier
)
except ObjectDoesNotExist:
pass
return self._subject_screening
Expand All @@ -94,7 +110,8 @@ def day_one_blood_results(self):
self._day_one_blood_results = model_cls.objects.get(
subject_visit__subject_identifier=self.subject_identifier,
subject_visit__visit_code=DAY1,
subject_visit__visit_code_sequence=0)
subject_visit__visit_code_sequence=0,
)
except ObjectDoesNotExist:
pass
return self._day_one_blood_results
Expand Down

0 comments on commit 6d2285d

Please sign in to comment.