management.models

 1from django.db import models
 2from accounts.models import User,Hospital
 3from django.core.exceptions import ValidationError
 4
 5class Blocks(models.Model):
 6    """
 7    Represents a hospital block.
 8
 9    Fields:
10        - name: Name of the block.
11        - no_of_floors: Number of floors in the block.
12        - hospital: ForeignKey to Hospital.
13        - created_by: User who created the block.
14        - created_at: Timestamp when block was created.
15        - updated_at: Timestamp when block was last updated.
16
17    Meta:
18        - db_table: Table name in DB.
19        - unique_together: Block name must be unique within a hospital.
20
21    Methods:
22        - __str__(): String representation of block.
23    """
24    name = models.CharField(max_length=100)
25    no_of_floors = models.IntegerField()
26    hospital = models.ForeignKey('accounts.Hospital', on_delete=models.CASCADE)
27    created_by = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
28    created_at = models.DateTimeField(auto_now_add=True)
29    updated_at = models.DateTimeField(auto_now=True)
30    
31    class Meta:
32        db_table = 'blocks'
33        unique_together = ('name', 'hospital')
34    def __str__(self):
35        return f"{self.name} - {self.hospital.name}"
36
37class Ward(models.Model):
38    """
39    Represents a ward within a block.
40
41    Fields:
42        - ward_name: Name of the ward.
43        - block: ForeignKey to Blocks.
44        - floor: Floor number within the block.
45        - deleted: Soft delete flag.
46        - created_at: Timestamp when ward was created.
47        - created_by: User who created the ward.
48        - updated_at: Timestamp when ward was last updated.
49
50    Methods:
51        - clean(): Validates that floor is within block's floor range.
52    """
53    def clean(self):
54        super().clean()
55        if self.block and self.floor:
56            if self.floor < 1 or self.floor > self.block.no_of_floors:
57                raise ValidationError({'floor': f"Floor must be between 1 and {self.block.no_of_floors} for the selected block."})
58            
59    ward_name = models.CharField(max_length=100,null=False,blank=False)
60    block = models.ForeignKey('management.Blocks', on_delete=models.CASCADE, help_text="ward associated with the block")
61    floor = models.IntegerField()
62    deleted = models.BooleanField(default=False)
63    created_at = models.DateTimeField(auto_now_add=True)
64    created_by = models.ForeignKey('accounts.user',related_name='user',on_delete=models.CASCADE,null=True)
65    updated_at = models.DateTimeField(auto_now=True)
66
67class Shift(models.Model):
68    """
69    Represents a work shift for a hospital.
70
71    Fields:
72        - name: Name of the shift.
73        - start_time: Shift start time.
74        - end_time: Shift end time.
75        - hospital: ForeignKey to Hospital.
76        - created_by: User who created the shift.
77        - created_at: Timestamp when shift was created.
78        - updated_at: Timestamp when shift was last updated.
79
80    Meta:
81        - db_table: Table name in DB.
82        - unique_together: Shift name must be unique within a hospital.
83
84    Methods:
85        - __str__(): String representation of shift.
86    """
87    name = models.CharField(max_length=100)
88    start_time = models.TimeField()
89    end_time = models.TimeField()
90    hospital = models.ForeignKey('accounts.Hospital', on_delete=models.CASCADE)
91    created_by = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
92    created_at = models.DateTimeField(auto_now_add=True)
93    updated_at = models.DateTimeField(auto_now=True)
94    
95    class Meta:
96        db_table = 'shifts'
97        unique_together = ('name', 'hospital')
98    def __str__(self):
99        return f"{self.start_time.strftime('%I:%M %p')} - {self.end_time.strftime('%I:%M %p')}"
class Blocks(django.db.models.base.Model):
 6class Blocks(models.Model):
 7    """
 8    Represents a hospital block.
 9
10    Fields:
11        - name: Name of the block.
12        - no_of_floors: Number of floors in the block.
13        - hospital: ForeignKey to Hospital.
14        - created_by: User who created the block.
15        - created_at: Timestamp when block was created.
16        - updated_at: Timestamp when block was last updated.
17
18    Meta:
19        - db_table: Table name in DB.
20        - unique_together: Block name must be unique within a hospital.
21
22    Methods:
23        - __str__(): String representation of block.
24    """
25    name = models.CharField(max_length=100)
26    no_of_floors = models.IntegerField()
27    hospital = models.ForeignKey('accounts.Hospital', on_delete=models.CASCADE)
28    created_by = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
29    created_at = models.DateTimeField(auto_now_add=True)
30    updated_at = models.DateTimeField(auto_now=True)
31    
32    class Meta:
33        db_table = 'blocks'
34        unique_together = ('name', 'hospital')
35    def __str__(self):
36        return f"{self.name} - {self.hospital.name}"

Represents a hospital block.

Fields: - name: Name of the block. - no_of_floors: Number of floors in the block. - hospital: ForeignKey to Hospital. - created_by: User who created the block. - created_at: Timestamp when block was created. - updated_at: Timestamp when block was last updated.

Meta: - db_table: Table name in DB. - unique_together: Block name must be unique within a hospital.

Methods: - __str__(): String representation of block.

def name(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def no_of_floors(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

hospital

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def created_at(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def updated_at(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

hospital_id
created_by_id
def get_next_by_created_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_previous_by_created_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_next_by_updated_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_previous_by_updated_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def objects(unknown):
user_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

ward_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

blockchange_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

to_block

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class Blocks.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class Blocks.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

class Ward(django.db.models.base.Model):
38class Ward(models.Model):
39    """
40    Represents a ward within a block.
41
42    Fields:
43        - ward_name: Name of the ward.
44        - block: ForeignKey to Blocks.
45        - floor: Floor number within the block.
46        - deleted: Soft delete flag.
47        - created_at: Timestamp when ward was created.
48        - created_by: User who created the ward.
49        - updated_at: Timestamp when ward was last updated.
50
51    Methods:
52        - clean(): Validates that floor is within block's floor range.
53    """
54    def clean(self):
55        super().clean()
56        if self.block and self.floor:
57            if self.floor < 1 or self.floor > self.block.no_of_floors:
58                raise ValidationError({'floor': f"Floor must be between 1 and {self.block.no_of_floors} for the selected block."})
59            
60    ward_name = models.CharField(max_length=100,null=False,blank=False)
61    block = models.ForeignKey('management.Blocks', on_delete=models.CASCADE, help_text="ward associated with the block")
62    floor = models.IntegerField()
63    deleted = models.BooleanField(default=False)
64    created_at = models.DateTimeField(auto_now_add=True)
65    created_by = models.ForeignKey('accounts.user',related_name='user',on_delete=models.CASCADE,null=True)
66    updated_at = models.DateTimeField(auto_now=True)

Represents a ward within a block.

Fields: - ward_name: Name of the ward. - block: ForeignKey to Blocks. - floor: Floor number within the block. - deleted: Soft delete flag. - created_at: Timestamp when ward was created. - created_by: User who created the ward. - updated_at: Timestamp when ward was last updated.

Methods: - clean(): Validates that floor is within block's floor range.

def clean(self):
54    def clean(self):
55        super().clean()
56        if self.block and self.floor:
57            if self.floor < 1 or self.floor > self.block.no_of_floors:
58                raise ValidationError({'floor': f"Floor must be between 1 and {self.block.no_of_floors} for the selected block."})

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

def ward_name(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

block

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def floor(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def deleted(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def created_at(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def updated_at(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

block_id
def get_next_by_created_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_previous_by_created_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

created_by_id
def get_next_by_updated_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_previous_by_updated_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def objects(unknown):
user_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

wardchange_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

to_ward

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class Ward.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class Ward.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.

class Shift(django.db.models.base.Model):
 68class Shift(models.Model):
 69    """
 70    Represents a work shift for a hospital.
 71
 72    Fields:
 73        - name: Name of the shift.
 74        - start_time: Shift start time.
 75        - end_time: Shift end time.
 76        - hospital: ForeignKey to Hospital.
 77        - created_by: User who created the shift.
 78        - created_at: Timestamp when shift was created.
 79        - updated_at: Timestamp when shift was last updated.
 80
 81    Meta:
 82        - db_table: Table name in DB.
 83        - unique_together: Shift name must be unique within a hospital.
 84
 85    Methods:
 86        - __str__(): String representation of shift.
 87    """
 88    name = models.CharField(max_length=100)
 89    start_time = models.TimeField()
 90    end_time = models.TimeField()
 91    hospital = models.ForeignKey('accounts.Hospital', on_delete=models.CASCADE)
 92    created_by = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
 93    created_at = models.DateTimeField(auto_now_add=True)
 94    updated_at = models.DateTimeField(auto_now=True)
 95    
 96    class Meta:
 97        db_table = 'shifts'
 98        unique_together = ('name', 'hospital')
 99    def __str__(self):
100        return f"{self.start_time.strftime('%I:%M %p')} - {self.end_time.strftime('%I:%M %p')}"

Represents a work shift for a hospital.

Fields: - name: Name of the shift. - start_time: Shift start time. - end_time: Shift end time. - hospital: ForeignKey to Hospital. - created_by: User who created the shift. - created_at: Timestamp when shift was created. - updated_at: Timestamp when shift was last updated.

Meta: - db_table: Table name in DB. - unique_together: Shift name must be unique within a hospital.

Methods: - __str__(): String representation of shift.

def name(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def start_time(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def end_time(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

hospital

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

created_by

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example::

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

def created_at(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def updated_at(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

hospital_id
created_by_id
def get_next_by_created_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_previous_by_created_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_next_by_updated_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def get_previous_by_updated_at(unknown):

Method descriptor with partial application of the given arguments and keywords.

Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.

def id(unknown):

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

def objects(unknown):
class Shift.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

class Shift.MultipleObjectsReturned(django.core.exceptions.MultipleObjectsReturned):

The query returned multiple objects when only one was expected.