Can't handle with Django Model related objects for Analysis-tracking App

I'm trying to make a web app that allows to add patients and add then track their medical analyses. Example Trying to make models for it... Could you advise me: what is the strategy if my next purpose is to make form that allows to fill in all lines from analysis group. Should I move in this way? (So next will be problems with orm queries)

I tried to deal with next solution but maybe u will take a professional look at this? Really appreciate


class PatientGender(models.Model):
    gender = models.CharField(max_length=16)

    def __str__(self):
        return f"{self.gender}"

# Create your models here.
class Patient(models.Model):
    hist_number = models.IntegerField(unique=True, verbose_name='Номер истории болезни')
    last_name = models.CharField(max_length=32, verbose_name='Фамилия')
    first_name = models.CharField(max_length=32, verbose_name='Имя')
    second_name = models.CharField(max_length=32, verbose_name='Отчество')
    birth_date = models.DateField(verbose_name='Дата рождения')
    date_time = models.DateField(auto_now_add=True, verbose_name='Время поступления в ОРиТ')
    sex = models.ForeignKey(PatientGender, verbose_name='Пол', on_delete=models.CASCADE, default=1)
    seat = models.PositiveSmallIntegerField(verbose_name='Палата', blank=True, null=True)
    description = models.TextField(blank=True, verbose_name='Палата')
    is_Active = models.BooleanField(verbose_name='Находится на лечении', default=True)

    def __str__(self):
        return f"{self.hist_number}: {self.last_name} {self.first_name} {self.second_name}"


class AnalyzesGroup(models.Model):
    name = models.CharField(max_length=256, verbose_name='Группа исследований')
    description = models.TextField(blank=True, verbose_name='Примечание')

    class Meta:
        verbose_name = 'Группа анализов'
        verbose_name_plural = 'Группы анализов'

    def __str__(self):
        return f"{}"

class AnalysisType(models.Model):
    name = models.CharField(max_length=256, verbose_name='Исследование')
    measurement = models.CharField(max_length=10, verbose_name='Единицы измерения')
    ref_min = models.FloatField(verbose_name='Мин. реф. значения')
    ref_max = models.FloatField(verbose_name='Макс. реф. значения')
    description = models.TextField(blank=True, verbose_name='Примечание')
    analyzes_group = models.ForeignKey(AnalyzesGroup, on_delete=models.CASCADE)

    class Meta:
        verbose_name = 'Лабораторный показатель'
        verbose_name_plural = 'Лабораторные показатели'

    def __str__(self):
        return f"{}"

class PatientAnalysis(models.Model):
    an_number = models.IntegerField(verbose_name='Номер анализа')
    date = models.DateField(verbose_name='Дата анализа')
    time = models.TimeField(verbose_name='Время')
    patient = models.ForeignKey('patient.Patient', verbose_name='Анализ пациента', on_delete=models.CASCADE)
    analysis = models.ForeignKey(AnalysisType, on_delete=models.CASCADE)
    value = models.FloatField(verbose_name='Значение')
    description = models.TextField(blank=True, verbose_name='Примечание')

    class Meta:
        verbose_name = 'Анализ'
        verbose_name_plural = 'Анализы пациентов'
        ordering = ['-date', '-time']

    def __str__(self):
        return f"{self.an_number} {self.patient} {self.analysis} {self.value} {self.analysis.measurement}"

Back to Top