Skip to content

Commit

Permalink
Merge pull request #843 from ImageMarkup/isic-161-add-primary-biopsy-…
Browse files Browse the repository at this point in the history
…db-field

Add a database field for primary_biopsy
  • Loading branch information
danlamanna authored Feb 16, 2024
2 parents ba14f6c + f33212f commit e1f8054
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions isic/ingest/migrations/0050_accession_primary_biopsy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.13 on 2024-02-16 19:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("ingest", "0049_alter_accession_blob_size_alter_accession_height_and_more"),
]

operations = [
migrations.AddField(
model_name="accession",
name="primary_biopsy",
field=models.BooleanField(db_index=True, default=False),
),
]
14 changes: 14 additions & 0 deletions isic/ingest/models/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class Meta(CreationSortedTimeStampedModel.Meta):
Patient, on_delete=models.SET_NULL, null=True, blank=True, related_name="accessions"
)

primary_biopsy = models.BooleanField(default=False, db_index=True)

objects = AccessionQuerySet.as_manager()

def __str__(self) -> str:
Expand Down Expand Up @@ -499,3 +501,15 @@ def remove_unstructured_metadata(
self.save()

return modified

def full_clean(self, *args, **kwargs):
if (
self.lesion
and self.primary_biopsy
and self.cohort.accessions.filter(lesion=self.lesion, primary_biopsy=True).exclude(
pk=self.pk
)
):
raise ValidationError("Lesion already has a primary biopsy.")

return super().full_clean(*args, **kwargs)

0 comments on commit e1f8054

Please sign in to comment.