updated models structure

This commit is contained in:
Alexander-D-Karpov 2022-11-05 22:14:19 +03:00
parent d5731ad8af
commit 23db12cf8a
3 changed files with 60 additions and 10 deletions

View File

@ -1,3 +1,3 @@
# flake8: noqa
from .base import Dicom, Project
from .base import Dicom, Layer, Project
from .shapes import BaseShape, Circle, Coordinate, FreeHand, Roi, Ruler

View File

@ -7,6 +7,51 @@ User = get_user_model()
class Project(models.Model):
class PathologyType(models.IntegerChoices):
no_pathology = 0, "Без патологий"
covid_pathology_all = 1, "COVID-19; все доли; многочисленные; размер любой"
covid_pathology_lung = (
2,
"COVID-19; Нижняя доля правого лёгкого, Нижняя доля левого лёгкого",
)
few = 3, "Немногочисленные; 10-20 мм"
lung_cancer_lower_right = (
4,
"Рак лёгкого; Нижняя доля правого лёгкого, Единичное; 10-20 мм",
)
lung_cancer_middle_right = (
5,
"Рак лёгкого; Средняя доля правого лёгкого, Единичное; >20 мм",
)
lung_cancer_lower_left = (
6,
"Рак лёгкого; Нижняя доля левого лёгкого, Единичное; 10-20 мм",
)
lung_cancer_upper_right = (
7,
"Рак лёгкого; Верхняя доля правого лёгкого, Единичное; 5-10 мм",
)
lung_cancer_upper_left = (
8,
"Рак лёгкого; Верхняя доля левого лёгкого, Единичное; 5-10 мм",
)
lung_cancer_all_many_small = (
9,
"Метастатическое поражение лёгких; Все доли; Многочисленные; 5-10 мм",
)
lung_cancer_all_many_big = (
10,
"Метастатическое поражение лёгких; Все доли; Многочисленные; 10-20 мм",
)
lung_cancer_all_few_small = (
11,
"Метастатическое поражение лёгких; Все доли; Немногочисленные; 5-10 мм",
)
name = models.CharField(max_length=200)
pathology_type = models.IntegerField(choices=PathologyType.choices, default=0)
user = models.ForeignKey(User, related_name="projects", on_delete=models.CASCADE)
slug = models.SlugField(max_length=10)
stl = models.FileField(blank=True)
@ -18,17 +63,11 @@ class Project(models.Model):
class Dicom(models.Model):
class PathologyType(models.IntegerChoices):
no_pathology = 0, "Без патологий"
covid_pathology = 1, "Covid"
user = models.ForeignKey(User, related_name="files", on_delete=models.CASCADE)
slug = models.SlugField()
file = models.FileField(upload_to=media_upload_path)
uploaded = models.DateTimeField(auto_now_add=True)
pathology_type = models.IntegerField(choices=PathologyType.choices, default=0)
project = models.ForeignKey(
Project, related_name="files", null=True, on_delete=models.SET_NULL
)
@ -38,3 +77,15 @@ class Dicom(models.Model):
def get_absolute_url(self):
return reverse("get_update_delete_dicom", kwargs={"slug": self.slug})
class Layer(models.Model):
parent = models.ForeignKey(
"self", related_name="children", blank=True, null=True, on_delete=models.CASCADE
)
dicom = models.ForeignKey(Dicom, related_name="layers", on_delete=models.CASCADE)
name = models.CharField(max_length=200)
slug = models.SlugField(max_length=8)
def __str__(self):
return f"layer on {self.dicom}"

View File

@ -1,4 +1,4 @@
from dicom.models import Dicom
from dicom.models import Layer
from django.db import models
from polymorphic.models import PolymorphicModel
@ -7,8 +7,7 @@ class BaseShape(PolymorphicModel):
TYPE = "no_type"
min_coordinates = None
max_coordinates = None
dicom = models.ForeignKey(Dicom, related_name="shapes", on_delete=models.CASCADE)
image_number = models.IntegerField()
layer = models.ForeignKey(Layer, related_name="shapes", on_delete=models.CASCADE)
def serialize_self(self):
return {