Skip to content

Commit

Permalink
Merge branch 'release/0.3.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 24, 2024
2 parents 255298c + e385827 commit 35c68a0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
16 changes: 16 additions & 0 deletions edc_pharmacy/tests/consents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from edc_consent.consent_definition import ConsentDefinition
from edc_consent.site_consents import site_consents
from edc_constants.constants import FEMALE, MALE
from edc_protocol import Protocol

consent_v1 = ConsentDefinition(
"edc_pharmacy.subjectconsent",
version="1",
start=Protocol().study_open_datetime,
end=Protocol().study_close_datetime,
age_min=18,
age_is_adult=18,
age_max=64,
gender=[MALE, FEMALE],
)
site_consents.register(consent_v1)
31 changes: 23 additions & 8 deletions edc_pharmacy/tests/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from datetime import date

from django.db import models
from edc_crf.model_mixins import CrfModelMixin
from edc_identifier.managers import SubjectIdentifierManager
from edc_identifier.model_mixins import NonUniqueSubjectIdentifierFieldMixin
from edc_model.models import BaseUuidModel
from edc_registration.model_mixins import UpdatesOrCreatesRegistrationModelMixin
from edc_screening.model_mixins import ScreeningModelMixin
from edc_sites.model_mixins import SiteModelMixin
from edc_utils import get_utcnow
Expand All @@ -10,20 +14,31 @@

from edc_pharmacy.model_mixins import StudyMedicationCrfModelMixin

from .consents import consent_v1

class SubjectScreening(ScreeningModelMixin, BaseUuidModel):
objects = SubjectIdentifierManager()

class SubjectConsent(
SiteModelMixin,
NonUniqueSubjectIdentifierFieldMixin,
UpdatesOrCreatesRegistrationModelMixin,
BaseUuidModel,
):
report_datetime = models.DateTimeField(default=get_utcnow)

consent_datetime = models.DateTimeField(default=get_utcnow)

class SubjectConsent(SiteModelMixin, BaseUuidModel):
subject_identifier = models.CharField(max_length=25)
version = models.CharField(max_length=25, default="1")

consent_datetime = models.DateTimeField()
identity = models.CharField(max_length=25)

dob = models.DateTimeField(null=True)
confirm_identity = models.CharField(max_length=25)

class Meta:
pass
dob = models.DateField(default=date(1995, 1, 1))


class SubjectScreening(ScreeningModelMixin, BaseUuidModel):
consent_definition = consent_v1
objects = SubjectIdentifierManager()


class SubjectVisit(SiteModelMixin, VisitModelMixin, BaseUuidModel):
Expand Down
16 changes: 4 additions & 12 deletions edc_pharmacy/tests/tests/test_study_medication_crf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
from zoneinfo import ZoneInfo

from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.contrib.sites.models import Site
from django.db.models.signals import pre_save
from django.test import TestCase, override_settings
from edc_appointment.constants import INCOMPLETE_APPT
from edc_appointment.creators import UnscheduledAppointmentCreator
from edc_appointment.models import Appointment
from edc_appointment.tests.helper import Helper
from edc_appointment.utils import get_next_appointment
from edc_consent.site_consents import (
AlreadyRegistered as ConsentDefinitionAlreadyRegistered,
)
from edc_consent.tests.consent_test_utils import consent_definition_factory
from edc_constants.constants import YES
from edc_facility import import_holidays
from edc_protocol import Protocol
Expand Down Expand Up @@ -51,14 +49,7 @@ def setUpTestData(cls):
def setUp(self) -> None:
site_visit_schedules._registry = {}
site_visit_schedules.loaded = False

site_visit_schedules.register(visit_schedule)
for schedule in visit_schedule.schedules.values():
try:
consent_definition_factory(model=schedule.consent_model)
except ConsentDefinitionAlreadyRegistered:
pass

self.subject_identifier = "12345"
self.registration_datetime = get_utcnow() - relativedelta(years=5)
RegisteredSubject.objects.create(
Expand All @@ -71,7 +62,6 @@ def setUp(self) -> None:
now=get_utcnow() - relativedelta(years=5),
)
self.helper.consent_and_put_on_schedule(
subject_identifier=self.subject_identifier,
visit_schedule_name="visit_schedule",
schedule_name="schedule",
)
Expand Down Expand Up @@ -430,6 +420,7 @@ def test_study_medication_form_baseline(self):
formulation=self.formulation,
refill_to_next_visit=YES,
roundup_divisible_by=32,
site=Site.objects.get(id=settings.SITE_ID),
)

form = StudyMedicationForm(data=data)
Expand Down Expand Up @@ -504,6 +495,7 @@ def test_inserts_refill(self):
refill_end_datetime=None,
dosage_guideline=self.dosage_guideline_200,
formulation=self.formulation,
site=Site.objects.get(id=settings.SITE_ID),
)
self.assertRaises(NextStudyMedicationError, StudyMedication.objects.create, **opts)
appointment.appt_status = INCOMPLETE_APPT
Expand Down
9 changes: 5 additions & 4 deletions edc_pharmacy/tests/visit_schedule.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from dateutil.relativedelta import relativedelta
from edc_consent.utils import get_consent_model_name
from edc_visit_schedule.schedule import Schedule
from edc_visit_schedule.visit import Crf, FormsCollection, Visit
from edc_visit_schedule.visit import Crf, CrfCollection, Visit
from edc_visit_schedule.visit_schedule import VisitSchedule

from edc_pharmacy.tests.consents import consent_v1

app_label = "edc_pharmacy"

crfs = FormsCollection(
crfs = CrfCollection(
Crf(show_order=1, model=f"{app_label}.studymedication", required=True),
)

Expand Down Expand Up @@ -49,7 +50,7 @@
name="schedule",
onschedule_model="edc_pharmacy.onschedule",
offschedule_model="edc_pharmacy.offschedule",
consent_model=get_consent_model_name(),
consent_definitions=[consent_v1],
appointment_model="edc_appointment.appointment",
)

Expand Down

0 comments on commit 35c68a0

Please sign in to comment.