forked from botswana-harvard/edc-export
-
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.
Merge branch 'release/0.3.43' into main
- Loading branch information
Showing
15 changed files
with
259 additions
and
211 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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import uuid | ||
|
||
from edc_appointment.models import Appointment | ||
from edc_utils import get_utcnow | ||
|
||
from export_app.models import Crf, CrfOne, CrfThree, CrfTwo, ListModel, SubjectVisit | ||
|
||
from .create_crfs_with_inlines import create_crf_with_inlines | ||
|
||
|
||
def create_crfs(i) -> None: | ||
j = 0 | ||
for appointment in Appointment.objects.all().order_by("timepoint", "visit_code_sequence"): | ||
j += 1 | ||
if j == i: | ||
break | ||
SubjectVisit.objects.create( | ||
appointment=appointment, | ||
subject_identifier=appointment.subject_identifier, | ||
report_datetime=get_utcnow(), | ||
) | ||
j = 0 | ||
for subject_visit in SubjectVisit.objects.all().order_by( | ||
"appointment__subject_identifier", | ||
"appointment__timepoint", | ||
"appointment__visit_code_sequence", | ||
): | ||
j += 1 | ||
ListModel.objects.create( | ||
display_name=( | ||
f"thing_one_{subject_visit.subject_identifier}" | ||
f"{subject_visit.appointment.visit_code}" | ||
), | ||
name=( | ||
f"thing_one_{subject_visit.subject_identifier}" | ||
f"{subject_visit.appointment.visit_code}" | ||
), | ||
) | ||
ListModel.objects.create( | ||
display_name=( | ||
f"thing_two_{subject_visit.appointment.subject_identifier}" | ||
f"{subject_visit.appointment.visit_code}" | ||
), | ||
name=( | ||
f"thing_two_{subject_visit.appointment.subject_identifier}" | ||
f"{subject_visit.appointment.visit_code}" | ||
), | ||
) | ||
Crf.objects.create( | ||
subject_visit=subject_visit, | ||
char1=f"char{subject_visit.appointment.visit_code}", | ||
date1=get_utcnow(), | ||
int1=j, | ||
uuid1=uuid.uuid4(), | ||
) | ||
CrfOne.objects.create(subject_visit=subject_visit, dte=get_utcnow()) | ||
CrfTwo.objects.create(subject_visit=subject_visit, dte=get_utcnow()) | ||
CrfThree.objects.create(subject_visit=subject_visit, UPPERCASE=get_utcnow()) | ||
|
||
for subject_visit in SubjectVisit.objects.all(): | ||
create_crf_with_inlines(subject_visit) |
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,20 @@ | ||
from edc_utils import get_utcnow | ||
|
||
from export_app.models import CrfWithInline, ListOne, ListTwo | ||
|
||
|
||
def create_crf_with_inlines(subject_visit): | ||
list_one = ListOne.objects.create( | ||
display_name=f"list_one{subject_visit.subject_identifier}{subject_visit.visit_code}", | ||
name=f"list_one{subject_visit.subject_identifier}{subject_visit.visit_code}", | ||
) | ||
list_two = ListTwo.objects.create( | ||
display_name=f"list_two{subject_visit.subject_identifier}{subject_visit.visit_code}", | ||
name=f"list_two{subject_visit.subject_identifier}{subject_visit.visit_code}", | ||
) | ||
CrfWithInline.objects.create( | ||
subject_visit=subject_visit, | ||
list_one=list_one, | ||
list_two=list_two, | ||
dte=get_utcnow(), | ||
) |
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,128 +1,19 @@ | ||
import uuid | ||
from __future__ import annotations | ||
|
||
from edc_appointment.creators import UnscheduledAppointmentCreator | ||
from edc_appointment.models import Appointment | ||
from edc_consent.site_consents import AlreadyRegistered | ||
from edc_consent.tests.consent_test_utils import consent_definition_factory | ||
from edc_registration.models import RegisteredSubject | ||
from edc_utils import get_utcnow | ||
from edc_visit_schedule.site_visit_schedules import site_visit_schedules | ||
from typing import TYPE_CHECKING | ||
|
||
from .models import ( | ||
Crf, | ||
CrfOne, | ||
CrfThree, | ||
CrfTwo, | ||
CrfWithInline, | ||
ListModel, | ||
ListOne, | ||
ListTwo, | ||
SubjectConsent, | ||
SubjectVisit, | ||
) | ||
from .visit_schedule import visit_schedule1 | ||
from edc_appointment.tests.helper import Helper as BaseHelper | ||
|
||
from export_app.models import SubjectScreening | ||
|
||
class Helper: | ||
def __init__(self, now=None, subject_identifier=None): | ||
site_visit_schedules._registry = {} | ||
site_visit_schedules.register(visit_schedule1) | ||
for schedule in visit_schedule1.schedules.values(): | ||
try: | ||
consent_definition_factory(model=schedule.consent_model) | ||
except AlreadyRegistered: | ||
pass | ||
if TYPE_CHECKING: | ||
from edc_appointment.models import Appointment | ||
|
||
self.now = now or get_utcnow() | ||
self.subject_identifier = subject_identifier or uuid.uuid4().hex | ||
self.consent_and_put_on_schedule() | ||
self.subject_visit = None | ||
self.thing_one = None | ||
self.thing_two = None | ||
|
||
def consent_and_put_on_schedule(self, subject_identifier=None): | ||
subject_identifier = subject_identifier or self.subject_identifier | ||
RegisteredSubject.objects.create(subject_identifier=self.subject_identifier) | ||
subject_consent = SubjectConsent.objects.create( | ||
subject_identifier=subject_identifier, consent_datetime=self.now | ||
) | ||
visit_schedule = site_visit_schedules.get_visit_schedule("visit_schedule1") | ||
schedule = visit_schedule.schedules.get("schedule1") | ||
schedule.put_on_schedule( | ||
subject_identifier=subject_consent.subject_identifier, | ||
onschedule_datetime=subject_consent.consent_datetime, | ||
) | ||
return subject_consent | ||
class Helper(BaseHelper): | ||
@property | ||
def screening_model_cls(self): | ||
return SubjectScreening | ||
|
||
@staticmethod | ||
def add_unscheduled_appointment(appointment=None): | ||
creator = UnscheduledAppointmentCreator( | ||
subject_identifier=appointment.subject_identifier, | ||
visit_schedule_name=appointment.visit_schedule_name, | ||
schedule_name=appointment.schedule_name, | ||
visit_code=appointment.visit_code, | ||
facility=appointment.facility, | ||
suggested_visit_code_sequence=appointment.visit_code_sequence + 1, | ||
) | ||
return creator.appointment | ||
|
||
def create_crfs(self, i): | ||
for appointment in Appointment.objects.all().order_by( | ||
"timepoint", "visit_code_sequence" | ||
): | ||
SubjectVisit.objects.create( | ||
appointment=appointment, | ||
subject_identifier=appointment.subject_identifier, | ||
report_datetime=get_utcnow(), | ||
) | ||
for j in range(0, i - 1): | ||
appointment = Appointment.objects.all().order_by( | ||
"timepoint", "visit_code_sequence" | ||
)[j] | ||
self.subject_visit = SubjectVisit.objects.get(appointment=appointment) | ||
self.thing_one = ListModel.objects.create( | ||
display_name=f"thing_one_{appointment.visit_code}", | ||
name=f"thing_one_{appointment.visit_code}", | ||
) | ||
self.thing_two = ListModel.objects.create( | ||
display_name=f"thing_two_{appointment.visit_code}", | ||
name=f"thing_two_{appointment.visit_code}", | ||
) | ||
Crf.objects.create( | ||
subject_visit=self.subject_visit, | ||
char1=f"char{appointment.visit_code}", | ||
date1=get_utcnow(), | ||
int1=j, | ||
uuid1=uuid.uuid4(), | ||
) | ||
CrfOne.objects.create(subject_visit=self.subject_visit, dte=get_utcnow()) | ||
CrfTwo.objects.create(subject_visit=self.subject_visit, dte=get_utcnow()) | ||
CrfThree.objects.create(subject_visit=self.subject_visit, UPPERCASE=get_utcnow()) | ||
|
||
for i, appointment in enumerate( | ||
Appointment.objects.all().order_by("timepoint", "visit_code_sequence") | ||
): | ||
if appointment != self.subject_visit.appointment: | ||
self.create_crf_with_inlines(appointment) | ||
|
||
@staticmethod | ||
def create_crf_with_inlines(appointment): | ||
# subject_visit = SubjectVisit.objects.create( | ||
# appointment=appointment, | ||
# subject_identifier=appointment.subject_identifier, | ||
# report_datetime=get_utcnow(), | ||
# ) | ||
list_one = ListOne.objects.create( | ||
display_name=f"list_one{appointment.visit_code}", | ||
name=f"list_one{appointment.visit_code}", | ||
) | ||
list_two = ListTwo.objects.create( | ||
display_name=f"list_two{appointment.visit_code}", | ||
name=f"list_two{appointment.visit_code}", | ||
) | ||
CrfWithInline.objects.create( | ||
subject_visit=appointment.subjectvisit, | ||
list_one=list_one, | ||
list_two=list_two, | ||
dte=get_utcnow(), | ||
) | ||
def create_unscheduled(self, appointment: Appointment): | ||
return self.add_unscheduled_appointment(appointment) |
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
Oops, something went wrong.