<commit_before>from django.db import models
from django.utils import timezone

from common.models import AbstractBase, Contact, SequenceMixin, Ward
from common.fields import SequenceField
from facilities.models import Facility


class Status(AbstractBase):
    """
    Indicates the of operation of a community health unit.
    e.g  fully-functional, semi-functional, functional
    """
    name = models.CharField(max_length=50)
    description = models.TextField(null=True, blank=True)

    def __unicode__(self):
        return self.name

    class Meta(object):
        verbose_name_plural = 'statuses'


class Approver(AbstractBase):
    """
    These are the bodies or the people that approve a community health unit.
    """
    name = models.CharField(
        max_length=150, help_text='name of the approver', unique=True)
    description = models.TextField(null=True, blank=True)
    abbreviation = models.CharField(
        max_length=50, help_text='A short name for the approver.')

    def __unicode__(self):
        return self.name


class ApprovalStatus(AbstractBase):
    """
    Status of a community health unit indicating whether it has been
    approved or not.
    """
    name = models.CharField(max_length=100)
    description = models.TextField(null=True, blank=True)

    def __unicode__(self):
        return self.name

    class Meta(object):
        verbose_name_plural = 'approval_statuses'


class Community(SequenceMixin, AbstractBase):
    """
    A certain area within a ward.
    """
    name = models.CharField(max_length=100)
    code = SequenceField(unique=True)
    ward = models.ForeignKey(Ward)

    def save(self, *args, **kwargs):
        if not self.code:
            self.code = self.generate_next_code_sequence()
        super(Community, self).save(*args, **kwargs)

    class Meta(object):
        verbose_name_plural = 'communities'


class CommunityHealthUnitContact(AbstractBase):
    """
    The contacts of the health unit may be email, fax mobile etc.
    """
    health_unit = models.ForeignKey('CommunityHealthUnit')
    contact = models.ForeignKey(Contact)

    def __unicode__(self):
        return "{}: {}".format(self.health_unit, self.contact)


class CommunityHealthUnit(SequenceMixin, AbstractBase):
    """
    This is a health service delivery structure within a defined geographical
    area covering a population of approximately 5,000 people.

    Each unit is assigned 2 Community Health Extension Workers (CHEWs) and<commit_msg>Add a unique together contraint to chul community model.<commit_after>from django.db import models
from django.utils import timezone

from common.models import AbstractBase, Contact, SequenceMixin, Ward
from common.fields import SequenceField
from facilities.models import Facility


class Status(AbstractBase):
    """
    Indicates the of operation of a community health unit.
    e.g  fully-functional, semi-functional, functional
    """
    name = models.CharField(max_length=50)
    description = models.TextField(null=True, blank=True)

    def __unicode__(self):
        return self.name

    class Meta(object):
        verbose_name_plural = 'statuses'


class Approver(AbstractBase):
    """
    These are the bodies or the people that approve a community health unit.
    """
    name = models.CharField(
        max_length=150, help_text='name of the approver', unique=True)
    description = models.TextField(null=True, blank=True)
    abbreviation = models.CharField(
        max_length=50, help_text='A short name for the approver.')

    def __unicode__(self):
        return self.name


class ApprovalStatus(AbstractBase):
    """
    Status of a community health unit indicating whether it has been
    approved or not.
    """
    name = models.CharField(max_length=100)
    description = models.TextField(null=True, blank=True)

    def __unicode__(self):
        return self.name

    class Meta(object):
        verbose_name_plural = 'approval_statuses'


class Community(SequenceMixin, AbstractBase):
    """
    A certain area within a ward.
    """
    name = models.CharField(max_length=100)
    code = SequenceField(unique=True)
    ward = models.ForeignKey(Ward)

    def save(self, *args, **kwargs):
        if not self.code:
            self.code = self.generate_next_code_sequence()
        super(Community, self).save(*args, **kwargs)

    class Meta(object):
        verbose_name_plural = 'communities'
        unique_together = ('name', 'ward', )


class CommunityHealthUnitContact(AbstractBase):
    """
    The contacts of the health unit may be email, fax mobile etc.
    """
    health_unit = models.ForeignKey('CommunityHealthUnit')
    contact = models.ForeignKey(Contact)

    def __unicode__(self):
        return "{}: {}".format(self.health_unit, self.contact)


class CommunityHealthUnit(SequenceMixin, AbstractBase):
    """
    This is a health service delivery structure within a defined geographical
    area covering a population of approximately 5,000 people.

    Each unit is assigned 2 Community Health Extension Workers (CHEWs) and
{'fraction_non_alphanumeric': 0.09051554506099961, 'fraction_numerical': 0.0070838252656434475, 'mean_word_length': 3.4784140969162998, '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': '3895641', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1365, 'n_words': 422}