<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User


MONTHS = (
    ('enero', 1), ('febrero', 2), ('marzo', 3), ('abril', 4), ('mayo', 5),
    ('junio', 6), ('julio', 7), ('agosto', 8), ('septiembre', 9),
    ('octubre', 10), ('noviembre', 11), ('diciembre', 12)
)
class Odontogram(models.Model):
    TEETH_NUMBERS = tuple([(x, x) for x in range(33)])
    teeth_number = models.SmallIntegerField(choices=TEETH_NUMBERS, null=True, blank=True)
    observations = models.TextField(null=True, blank=True)
    month = models.CharField(choices=MONTHS, max_length=15, null=True, blank=True)
    year = models.PositiveIntegerField(null=True, blank=True)

    def __unicode__(self):
        return "%s" % str(self.id)

    def get_teeth(self):
        return Tooth.objects.filter(odontogram=self)

    def period(self):
        if self.month is not None and self.year is not None:
            result = str(self.month) + ' - ' + str(self.year)
        else:
            result = '-'
        return result

    def teeth_count(self):
        return 52 - Tooth.objects.filter(odontogram=self, work_type=1, color=1).count()


class Clinic_history(models.Model):
    place = models.CharField(max_length=250)
    date = models.DateField()
    notes = models.CharField(max_length=250)


class SocialWork(models.Model):
    name = models.CharField(max_length=250, null=True, blank=True)
    initial = models.CharField(max_length=250)

    def __unicode__(self):
        return "%s" % (self.initial)


class Dentist(models.Model):
    user = models.ForeignKey(User)
    circle = models.CharField('Círculo', max_length=15, null=True, blank=True)
    register_number = models.CharField('Registro', max_length=25, null=True, blank=True)
    carrying_home = models.CharField('Domicilio', max_length=250, null=True, blank=True)

    class Meta:
        verbose_name = "Odontologo"
        verbose_name_plural = "Odontologos"

    def __unicode__(self):
        return "%s" % (self.user.get_full_name())


GENDER = (
    (1, 'M'),(2, 'F')
)
class Patient(models.Model):
    dentist = models.ForeignKey(Dentist, null=True, blank=True) #sacar el null
    clinic_history = models.OneToOneField(Clinic_history, null=True, blank=True)
    first_name = models.CharField(max_length=250)
    last_name = models.CharField(max_length=250)
    subsidiary_number = models.CharField(
        "numero de afiliado", max_length=25, null=True, blank=True
    )
    date_created = models.DateField(auto_now_add=True)
    social_work = models.ForeignKey(SocialWork, null=True, blank=True)
    plan = models.CharField(max_length=25, null=True, blank=True)
    odontogram = models.ForeignKey(Odontogram, null=True, blank=True)
    active = models.BooleanField(default=True)

    #-- extra info
    incumbent = models.CharField(max_length=250, null=True, blank=True)
    family_group = models.CharField(max_length=250, null=True, blank=True)
    relationship = models.CharField(max_length=250, null=True, blank=True)
    birth_date = models.DateField(null=True, blank=True)
    street = models.CharField(max_length=250, null=True, blank=True)
    number = models.PositiveIntegerField(null=True, blank=True)
    floor = models.CharField(max_length=5, null=True, blank=True)
    apartment = models.CharField(max_length=5, null=True, blank=True)
    neighborhood = models.CharField(max_length=250, null=True, blank=True)
    suburb = models.CharField(max_length=250, null=True, blank=True)
    locality = models.CharField(max_length=250, null=True, blank=True)
    tel = models.CharField(max_length=250, null=True, blank=True)
    cel_phone = models.CharField(max_length=250, null=True, blank=True)
    Workplace_holder = models.CharField(max_length=250, null=True, blank=True)
    hierarchy = models.CharField(max_length=250, null=True, blank=True)
    email = models.EmailField(null=True, blank=True)
    gender = models.IntegerField(choices=GENDER, null=True, blank=True)
    derivation = models.CharField(max_length=250, null=True, blank=True)

    class Meta:
        verbose_name = "Paciente"
        verbose_name_plural = "Pacientes"

    def __unicode__(self):
        return "%s %s" % (self.first_name, self.last_name)

    @property
    def domicile(self):
        result = ''
        if self.street not in [None, '']:
            result += self.street
        if self.number not in [None, '']:
            result += ' ' + str(self.number)
        if self.floor not in [None, '']:
            result += ', dpto ' + self.floor
        if self.apartment not in [None, '']:
            result += ' ' + self.apartment
        if self.neighborhood not in [None, '']:
            result += '. Barrio ' + self.neighborhood
        return result

    @property
    def full_locality(self):
        if self.suburb not in [None, '']:
            if self.locality not in [None, '']:
                result = self.suburb + ', ' + self.locality
            else:
                result = self.suburb
        else:
            result = None
        return result

    @property
    def code(self):
        return "P%04d" % (self.id)

    def get_full_name(self):
        return "%s %s" % (self.last_name, self.first_name)

    def get_benefits(self):
        from register.models import Apross, Benefit
        if self.social_work and self.social_work.initial == 'APROSS':
            benefit = Apross.objects.filter(patient=self).order_by('-real_date')
        else:
            benefit = Benefit.objects.filter(patient=self).order_by('-real_date')
        return benefit

    def get_records(self):
        from register.models import Record
        return Record.objects.filter(patient=self).order_by('date')

COLORS = ((1, 'red'), (2, 'blue'))
WORK_TYPES = (<commit_msg>record orden decreciente<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User


MONTHS = (
    ('enero', 1), ('febrero', 2), ('marzo', 3), ('abril', 4), ('mayo', 5),
    ('junio', 6), ('julio', 7), ('agosto', 8), ('septiembre', 9),
    ('octubre', 10), ('noviembre', 11), ('diciembre', 12)
)
class Odontogram(models.Model):
    TEETH_NUMBERS = tuple([(x, x) for x in range(33)])
    teeth_number = models.SmallIntegerField(choices=TEETH_NUMBERS, null=True, blank=True)
    observations = models.TextField(null=True, blank=True)
    month = models.CharField(choices=MONTHS, max_length=15, null=True, blank=True)
    year = models.PositiveIntegerField(null=True, blank=True)

    def __unicode__(self):
        return "%s" % str(self.id)

    def get_teeth(self):
        return Tooth.objects.filter(odontogram=self)

    def period(self):
        if self.month is not None and self.year is not None:
            result = str(self.month) + ' - ' + str(self.year)
        else:
            result = '-'
        return result

    def teeth_count(self):
        return 52 - Tooth.objects.filter(odontogram=self, work_type=1, color=1).count()


class Clinic_history(models.Model):
    place = models.CharField(max_length=250)
    date = models.DateField()
    notes = models.CharField(max_length=250)


class SocialWork(models.Model):
    name = models.CharField(max_length=250, null=True, blank=True)
    initial = models.CharField(max_length=250)

    def __unicode__(self):
        return "%s" % (self.initial)


class Dentist(models.Model):
    user = models.ForeignKey(User)
    circle = models.CharField('Círculo', max_length=15, null=True, blank=True)
    register_number = models.CharField('Registro', max_length=25, null=True, blank=True)
    carrying_home = models.CharField('Domicilio', max_length=250, null=True, blank=True)

    class Meta:
        verbose_name = "Odontologo"
        verbose_name_plural = "Odontologos"

    def __unicode__(self):
        return "%s" % (self.user.get_full_name())


GENDER = (
    (1, 'M'),(2, 'F')
)
class Patient(models.Model):
    dentist = models.ForeignKey(Dentist, null=True, blank=True) #sacar el null
    clinic_history = models.OneToOneField(Clinic_history, null=True, blank=True)
    first_name = models.CharField(max_length=250)
    last_name = models.CharField(max_length=250)
    subsidiary_number = models.CharField(
        "numero de afiliado", max_length=25, null=True, blank=True
    )
    date_created = models.DateField(auto_now_add=True)
    social_work = models.ForeignKey(SocialWork, null=True, blank=True)
    plan = models.CharField(max_length=25, null=True, blank=True)
    odontogram = models.ForeignKey(Odontogram, null=True, blank=True)
    active = models.BooleanField(default=True)

    #-- extra info
    incumbent = models.CharField(max_length=250, null=True, blank=True)
    family_group = models.CharField(max_length=250, null=True, blank=True)
    relationship = models.CharField(max_length=250, null=True, blank=True)
    birth_date = models.DateField(null=True, blank=True)
    street = models.CharField(max_length=250, null=True, blank=True)
    number = models.PositiveIntegerField(null=True, blank=True)
    floor = models.CharField(max_length=5, null=True, blank=True)
    apartment = models.CharField(max_length=5, null=True, blank=True)
    neighborhood = models.CharField(max_length=250, null=True, blank=True)
    suburb = models.CharField(max_length=250, null=True, blank=True)
    locality = models.CharField(max_length=250, null=True, blank=True)
    tel = models.CharField(max_length=250, null=True, blank=True)
    cel_phone = models.CharField(max_length=250, null=True, blank=True)
    Workplace_holder = models.CharField(max_length=250, null=True, blank=True)
    hierarchy = models.CharField(max_length=250, null=True, blank=True)
    email = models.EmailField(null=True, blank=True)
    gender = models.IntegerField(choices=GENDER, null=True, blank=True)
    derivation = models.CharField(max_length=250, null=True, blank=True)

    class Meta:
        verbose_name = "Paciente"
        verbose_name_plural = "Pacientes"

    def __unicode__(self):
        return "%s %s" % (self.first_name, self.last_name)

    @property
    def domicile(self):
        result = ''
        if self.street not in [None, '']:
            result += self.street
        if self.number not in [None, '']:
            result += ' ' + str(self.number)
        if self.floor not in [None, '']:
            result += ', dpto ' + self.floor
        if self.apartment not in [None, '']:
            result += ' ' + self.apartment
        if self.neighborhood not in [None, '']:
            result += '. Barrio ' + self.neighborhood
        return result

    @property
    def full_locality(self):
        if self.suburb not in [None, '']:
            if self.locality not in [None, '']:
                result = self.suburb + ', ' + self.locality
            else:
                result = self.suburb
        else:
            result = None
        return result

    @property
    def code(self):
        return "P%04d" % (self.id)

    def get_full_name(self):
        return "%s %s" % (self.last_name, self.first_name)

    def get_benefits(self):
        from register.models import Apross, Benefit
        if self.social_work and self.social_work.initial == 'APROSS':
            benefit = Apross.objects.filter(patient=self).order_by('-real_date')
        else:
            benefit = Benefit.objects.filter(patient=self).order_by('-real_date')
        return benefit

    def get_records(self):
        from register.models import Record
        return Record.objects.filter(patient=self).order_by('-date')

COLORS = ((1, 'red'), (2, 'blue'))
WORK_TYPES = (
{'fraction_non_alphanumeric': 0.13286056049213943, 'fraction_numerical': 0.01657552973342447, 'mean_word_length': 3.3577810871183917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6251932', 'n_tokens_mistral': 4018, 'n_tokens_neox': 3793, 'n_words': 788}