app.infrastructure.models

 1from django.db import models
 2from accounts.models import Role
 3
 4class ApproverHierarchy(models.Model):
 5    """
 6    Represents an approval hierarchy for a hospital.
 7    - created_at: Timestamp when the hierarchy was created.
 8    - is_active: Whether the hierarchy is currently active.
 9    """
10    created_at = models.DateTimeField(auto_now_add=True)
11    is_active = models.BooleanField(default=True)
12
13class ApproverLevel(models.Model):
14    """
15    Represents a level in an approval hierarchy.
16    - hierarchy: Reference to ApproverHierarchy.
17    - role: Role assigned to this level.
18    - priority: Priority of the level (lower means higher priority).
19    """
20    hierarchy = models.ForeignKey(ApproverHierarchy, related_name='levels', on_delete=models.CASCADE)
21    role = models.ForeignKey(Role, on_delete=models.CASCADE)
22    priority = models.PositiveIntegerField(help_text="Lower means higher priority")
23
24    class Meta:
25        ordering = ['priority']
26
27class BlockChange(models.Model):
28    """
29    Tracks changes of a user's block assignment.
30    - user: The user who changed blocks.
31    - from_block: The previous block (nullable).
32    - to_block: The new block.
33    - changed_at: Timestamp of the change.
34    """
35    user = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
36    from_block = models.ForeignKey('management.Blocks', on_delete=models.CASCADE, null=True, blank=True)
37    to_block = models.ForeignKey('management.Blocks', on_delete=models.CASCADE, related_name='to_block')
38    changed_at = models.DateTimeField(auto_now_add=True)
39    
40    class Meta:
41        ordering = ['-changed_at']
42        db_table = 'block_change'
43        
44    def __str__(self):
45        return f"{self.user.username} changed block from {self.from_block.name} to {self.to_block.name} on {self.changed_at}"
46
47class WardChange(models.Model):
48    """
49    Tracks changes of a user's ward assignment.
50    - user: The user who changed wards.
51    - from_ward: The previous ward (nullable).
52    - to_ward: The new ward.
53    - changed_at: Timestamp of the change.
54    """
55    user = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
56    from_ward = models.ForeignKey('management.Ward', on_delete=models.CASCADE, null=True, blank=True)
57    to_ward = models.ForeignKey('management.Ward', on_delete=models.CASCADE, related_name='to_ward')
58    changed_at = models.DateTimeField(auto_now_add=True)
59    
60    class Meta:
61        ordering = ['-changed_at']
62        db_table = 'ward_change'
63        
64    def __str__(self):
65        return f"{self.user.institution_id} changed ward from {self.from_ward.ward_name} to {self.to_ward.ward_name} on {self.changed_at}"
class ApproverHierarchy(django.db.models.base.Model):
 5class ApproverHierarchy(models.Model):
 6    """
 7    Represents an approval hierarchy for a hospital.
 8    - created_at: Timestamp when the hierarchy was created.
 9    - is_active: Whether the hierarchy is currently active.
10    """
11    created_at = models.DateTimeField(auto_now_add=True)
12    is_active = models.BooleanField(default=True)

Represents an approval hierarchy for a hospital.

  • created_at: Timestamp when the hierarchy was created.
  • is_active: Whether the hierarchy is currently active.
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 is_active(unknown):

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

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 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):
levels

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 ApproverHierarchy.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

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

The query returned multiple objects when only one was expected.

class ApproverLevel(django.db.models.base.Model):
14class ApproverLevel(models.Model):
15    """
16    Represents a level in an approval hierarchy.
17    - hierarchy: Reference to ApproverHierarchy.
18    - role: Role assigned to this level.
19    - priority: Priority of the level (lower means higher priority).
20    """
21    hierarchy = models.ForeignKey(ApproverHierarchy, related_name='levels', on_delete=models.CASCADE)
22    role = models.ForeignKey(Role, on_delete=models.CASCADE)
23    priority = models.PositiveIntegerField(help_text="Lower means higher priority")
24
25    class Meta:
26        ordering = ['priority']

Represents a level in an approval hierarchy.

  • hierarchy: Reference to ApproverHierarchy.
  • role: Role assigned to this level.
  • priority: Priority of the level (lower means higher priority).
hierarchy

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.

role

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 priority(unknown):

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

hierarchy_id
role_id
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 ApproverLevel.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

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

The query returned multiple objects when only one was expected.

class BlockChange(django.db.models.base.Model):
28class BlockChange(models.Model):
29    """
30    Tracks changes of a user's block assignment.
31    - user: The user who changed blocks.
32    - from_block: The previous block (nullable).
33    - to_block: The new block.
34    - changed_at: Timestamp of the change.
35    """
36    user = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
37    from_block = models.ForeignKey('management.Blocks', on_delete=models.CASCADE, null=True, blank=True)
38    to_block = models.ForeignKey('management.Blocks', on_delete=models.CASCADE, related_name='to_block')
39    changed_at = models.DateTimeField(auto_now_add=True)
40    
41    class Meta:
42        ordering = ['-changed_at']
43        db_table = 'block_change'
44        
45    def __str__(self):
46        return f"{self.user.username} changed block from {self.from_block.name} to {self.to_block.name} on {self.changed_at}"

Tracks changes of a user's block assignment.

  • user: The user who changed blocks.
  • from_block: The previous block (nullable).
  • to_block: The new block.
  • changed_at: Timestamp of the change.
user

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.

from_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.

to_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 changed_at(unknown):

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

user_id
from_block_id
to_block_id
def get_next_by_changed_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_changed_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 BlockChange.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

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

The query returned multiple objects when only one was expected.

class WardChange(django.db.models.base.Model):
48class WardChange(models.Model):
49    """
50    Tracks changes of a user's ward assignment.
51    - user: The user who changed wards.
52    - from_ward: The previous ward (nullable).
53    - to_ward: The new ward.
54    - changed_at: Timestamp of the change.
55    """
56    user = models.ForeignKey('accounts.User', on_delete=models.CASCADE)
57    from_ward = models.ForeignKey('management.Ward', on_delete=models.CASCADE, null=True, blank=True)
58    to_ward = models.ForeignKey('management.Ward', on_delete=models.CASCADE, related_name='to_ward')
59    changed_at = models.DateTimeField(auto_now_add=True)
60    
61    class Meta:
62        ordering = ['-changed_at']
63        db_table = 'ward_change'
64        
65    def __str__(self):
66        return f"{self.user.institution_id} changed ward from {self.from_ward.ward_name} to {self.to_ward.ward_name} on {self.changed_at}"

Tracks changes of a user's ward assignment.

  • user: The user who changed wards.
  • from_ward: The previous ward (nullable).
  • to_ward: The new ward.
  • changed_at: Timestamp of the change.
user

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.

from_ward

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.

to_ward

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 changed_at(unknown):

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

user_id
from_ward_id
to_ward_id
def get_next_by_changed_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_changed_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 WardChange.DoesNotExist(django.core.exceptions.ObjectDoesNotExist):

The requested object does not exist

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

The query returned multiple objects when only one was expected.