Skip to content

Commit

Permalink
Merge pull request #951 from ImageMarkup/improve-mosaic-constraint
Browse files Browse the repository at this point in the history
Fix RCM mosaic check constraint to accept unprocessed images
  • Loading branch information
danlamanna authored Aug 26, 2024
2 parents d13f3a4 + e423044 commit 1d6ad59
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.1 on 2024-08-26 21:05

from django.conf import settings
from django.db import migrations, models
import isic_metadata.fields


class Migration(migrations.Migration):
dependencies = [
("ingest", "0003_accession_accession_is_cog_mosaic"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.RemoveConstraint(
model_name="accession",
name="accession_is_cog_mosaic",
),
migrations.AddConstraint(
model_name="accession",
constraint=models.CheckConstraint(
condition=models.Q(
("is_cog", False),
("image_type__isnull", True),
("image_type", isic_metadata.fields.ImageTypeEnum["rcm_mosaic"]),
_connector="OR",
),
name="accession_is_cog_mosaic",
),
),
]
9 changes: 6 additions & 3 deletions isic/ingest/models/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,14 @@ class Meta(CreationSortedTimeStampedModel.Meta):
fields=["cohort_id", "rcm_case_id"],
condition=Q(image_type=ImageTypeEnum.rcm_macroscopic),
),
# image_type == mosaic implies is_cog is True where image_type is set
# is_cog => mosaic/null image type. it's important that is_cog implies mosaic instead
# of the other way around because an image can have metadata before it's processed
# (and is_cog) is set.
CheckConstraint(
name="accession_is_cog_mosaic",
check=Q(image_type__isnull=True)
| (~Q(image_type=ImageTypeEnum.rcm_mosaic) | Q(is_cog=True)),
check=Q(is_cog=False)
| Q(image_type__isnull=True)
| Q(image_type=ImageTypeEnum.rcm_mosaic),
),
]

Expand Down

0 comments on commit 1d6ad59

Please sign in to comment.