Skip to content

Commit

Permalink
Merge branch 'release/0.3.39' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Dec 5, 2023
2 parents 15cf282 + 36a0e67 commit a75d4a2
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 20 deletions.
440 changes: 440 additions & 0 deletions edc_export/migrations/0017_alter_datarequest_options_and_more.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.7 on 2023-12-04 02:32

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("edc_export", "0017_alter_datarequest_options_and_more"),
]

operations = [
migrations.RemoveIndex(
model_name="objecthistory",
name="edc_export__modifie_36e5ad_idx",
),
migrations.RemoveIndex(
model_name="plan",
name="edc_export__modifie_db36ec_idx",
),
migrations.AddIndex(
model_name="objecthistory",
index=models.Index(
fields=["modified", "created"], name="edc_export__modifie_808a80_idx"
),
),
migrations.AddIndex(
model_name="plan",
index=models.Index(
fields=["modified", "created"], name="edc_export__modifie_25ba96_idx"
),
),
]
3 changes: 2 additions & 1 deletion edc_export/model_mixins/notification_model_mixin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.db.models import Index


class NotificationMixin(models.Model):
Expand Down Expand Up @@ -26,4 +27,4 @@ class NotificationMixin(models.Model):

class Meta:
abstract = True
ordering = ("notification_datetime",)
indexes = [Index(fields=["notification_datetime"])]
3 changes: 2 additions & 1 deletion edc_export/models/data_request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.apps import apps as django_apps
from django.db import models
from django.db.models import Index
from edc_model.models import BaseUuidModel, HistoricalRecords
from edc_sites.model_mixins import SiteModelMixin

Expand Down Expand Up @@ -39,4 +40,4 @@ def models_as_list(self):
return [ModelOptions(x) for x in models_as_list]

class Meta:
ordering = ("name",)
indexes = [Index(fields=["name"])]
3 changes: 2 additions & 1 deletion edc_export/models/data_request_history.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.db.models import Index
from django.db.models.deletion import PROTECT
from edc_model.models import BaseUuidModel
from edc_sites.model_mixins import SiteModelMixin
Expand All @@ -21,6 +22,6 @@ class DataRequestHistory(SiteModelMixin, BaseUuidModel):
exported_datetime = models.DateTimeField(default=get_utcnow)

class Meta:
ordering = ("-exported_datetime",)
verbose_name = "Data Request History"
verbose_name_plural = "Data Request History"
indexes = [Index(fields=["-exported_datetime"])]
5 changes: 3 additions & 2 deletions edc_export/models/export_receipt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.db.models import Index
from edc_model.models import BaseUuidModel, HistoricalRecords


Expand Down Expand Up @@ -30,5 +31,5 @@ def __str__(self):
def natural_key(self):
return (self.export_uuid,)

class Meta:
ordering = ("-timestamp",)
class Meta(BaseUuidModel.Meta):
indexes = [Index(fields=["-timestamp"])]
5 changes: 3 additions & 2 deletions edc_export/models/file_history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from uuid import uuid4

from django.db import models
from django.db.models import Index
from django.utils import timezone
from edc_model.models import BaseUuidModel, HistoricalRecords

Expand Down Expand Up @@ -75,5 +76,5 @@ def save(self, *args, **kwargs):
def natural_key(self):
return (self.history_uuid,)

class Meta:
ordering = ("-sent_datetime",)
class Meta(BaseUuidModel.Meta):
indexes = [Index(fields=["-sent_datetime"])]
5 changes: 3 additions & 2 deletions edc_export/models/object_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ def render(self):

render.allow_tags = True

class Meta:
ordering = ("-timestamp",)
class Meta(BaseUuidModel.Meta):
verbose_name = "Object History"
verbose_name_plural = "Object Histories"
5 changes: 3 additions & 2 deletions edc_export/models/upload_export_receipt_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime

from django.db import models
from django.db.models import Index
from edc_constants.constants import UUID_PATTERN
from edc_model.models import BaseUuidModel

Expand Down Expand Up @@ -71,5 +72,5 @@ def update_file_history(self):
self.accepted += 1
self.errors = "; ".join(error_list)

class Meta:
ordering = ("-created",)
class Meta(BaseUuidModel.Meta):
indexes = [Index(fields=["-created"])]
12 changes: 9 additions & 3 deletions edc_export/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ def add_unscheduled_appointment(appointment=None):
return creator.appointment

def create_crfs(self, i):
for appointment in Appointment.objects.all().order_by("visit_code"):
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("visit_code")[j]
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}",
Expand All @@ -87,7 +91,9 @@ def create_crfs(self, i):
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("visit_code")):
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)

Expand Down
6 changes: 4 additions & 2 deletions edc_export/tests/tests/test_export_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
class TestExportModel(TestCase):
def setUp(self):
self.helper = Helper()
for appointment in Appointment.objects.all().order_by("visit_code"):
for appointment in Appointment.objects.all().order_by(
"timepoint", "visit_code_sequence"
):
SubjectVisit.objects.create(
appointment=appointment,
subject_identifier=appointment.subject_identifier,
Expand Down Expand Up @@ -167,7 +169,7 @@ def test_values_row(self):
csv_reader = csv.reader(f)
rows = [row for row in enumerate(csv_reader)]
values_row = rows[1][1][0]
self.assertEqual(len(values_row.split("|")), 28)
self.assertEqual(len(values_row.split("|")), 30)

def test_lookup(self):
queryset = Crf.objects.all()
Expand Down
10 changes: 7 additions & 3 deletions edc_export/tests/tests/test_model_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ def test_records_as_qs(self):
def test_columns(self):
model = "edc_export.crf"
m = ModelToDataframe(model=model, drop_sys_columns=False)
self.assertEqual(len(list(m.dataframe.columns)), 26)
self.assertEqual(len(list(m.dataframe.columns)), 28)

def test_values(self):
model = "edc_export.crf"
m = ModelToDataframe(model=model)
df = m.dataframe
df.sort_values(by=["subject_identifier", "visit_code"], inplace=True)
for i, appointment in enumerate(
Appointment.objects.all().order_by("subject_identifier", "visit_code")
Appointment.objects.all().order_by(
"subject_identifier", "timepoint", "visit_code_sequence"
)
):
self.assertEqual(df.subject_identifier.iloc[i], appointment.subject_identifier)
self.assertEqual(df.visit_code.iloc[i], appointment.visit_code)
Expand Down Expand Up @@ -107,7 +109,9 @@ def test_records_to_csv_from_model(self):
rows = [row for row in enumerate(csv_reader)]
self.assertEqual(len(rows), 4)
for i, appointment in enumerate(
Appointment.objects.all().order_by("subject_identifier", "visit_code")
Appointment.objects.all().order_by(
"subject_identifier", "timepoint", "visit_code_sequence"
)
):
self.assertEqual(
rows[i][1].get("subject_identifier"), appointment.subject_identifier
Expand Down
4 changes: 3 additions & 1 deletion edc_export/tests/tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
class TestPlan(TestCase):
def setUp(self):
self.helper = Helper()
for appointment in Appointment.objects.all().order_by("visit_code"):
for appointment in Appointment.objects.all().order_by(
"timepoint", "visit_code_sequence"
):
SubjectVisit.objects.create(
appointment=appointment,
subject_identifier=appointment.subject_identifier,
Expand Down

0 comments on commit a75d4a2

Please sign in to comment.