app.memos.models
1from django.db import models 2import random 3import string 4 5import uuid 6from django.utils import timezone 7from accounts.models import Role, User, Hospital 8 9class Memo(models.Model): 10 """ 11 Represents a memo record in the system. 12 13 Fields: 14 - memoId: Unique identifier for the memo (UUID string). 15 - hospital: ForeignKey to Hospital where the memo belongs. 16 - is_deleted: Marks if the memo is deleted (soft delete). 17 - is_merged: Marks if the memo is merged with another. 18 - created_at: Timestamp when the memo was created. 19 - modified_at: Timestamp when the memo was last modified. 20 21 Methods: 22 - latest_snapshot(): Returns the latest MemoSnapshot for this memo. 23 - __str__(): String representation of the memo. 24 """ 25 memoId = models.CharField(max_length=36, primary_key=True) 26 hospital = models.ForeignKey('accounts.Hospital', on_delete=models.CASCADE, related_name='memos') 27 is_deleted = models.BooleanField(default=False) 28 is_merged = models.BooleanField(default=False) 29 created_at = models.DateTimeField(auto_now_add=True) 30 modified_at = models.DateTimeField(auto_now=True) 31 32 class Meta: 33 ordering = ['-created_at'] 34 35 def latest_snapshot(self): 36 """ 37 Returns the latest snapshot of the memo. 38 """ 39 return self.snapshots.order_by('-timestamp').first() 40 41 def __str__(self): 42 return f"Memo {self.memoId}" 43 44class MemoEvents(models.Model): 45 """ 46 Represents an event in the lifecycle of a memo. 47 48 Fields: 49 - memo: ForeignKey to Memo. 50 - event_type: Type of event (created, updated, deleted, etc.). 51 - event_timestamp: Timestamp when the event occurred. 52 - event_by: User who triggered the event. 53 - payload: JSON field containing memo details at the time of event. 54 - metadata: JSON field containing additional metadata. 55 """ 56 memo = models.ForeignKey(Memo, on_delete=models.CASCADE, related_name='events') 57 event_type = models.CharField( 58 max_length=50, 59 choices=( 60 ('created', 'Created'), ('updated', 'Updated'), ('deleted', 'Deleted'), 61 ('merged', 'Merged'), ('escalated','Escalated'), ('approved','Approved'), 62 ('rejected','Rejected'), ('incomplete','Incomplete'), ('completed','Completed'), 63 ('tagged','Tagged'), ('attended','Attended') 64 ) 65 ) 66 event_timestamp = models.DateTimeField(auto_now_add=True) 67 event_by = models.ForeignKey('accounts.User', on_delete=models.CASCADE, related_name='events') 68 payload = models.JSONField() # contains the memo details 69 metadata = models.JSONField() # contains the memo metadata like users local storage at the current time.. 70 71class MemoSnapshot(models.Model): 72 """ 73 Represents a snapshot of a memo at a specific point in time. 74 75 Fields: 76 - memo: ForeignKey to Memo. 77 - info: JSON field with contextual information (role, department, complaint, etc.). 78 - hierarchy: JSON field with hierarchical structure of the memo. 79 - approval_history: JSON field with history of approvals. 80 - worker_status: JSON field with current worker allocation/status. 81 - timestamp: Timestamp when the snapshot was created. 82 - attendee_otp: OTP for attendee verification. 83 - completion_otp: OTP for completion verification. 84 85 Methods: 86 - refresh_otp(): Generates new OTPs for attendee and completion. 87 - generate_otp(): Helper to generate a random OTP. 88 - save(): Ensures OTPs are set before saving. 89 - __str__(): String representation of the snapshot. 90 """ 91 memo = models.ForeignKey(Memo, on_delete=models.CASCADE, related_name='snapshots') 92 info = models.JSONField(default=dict) 93 hierarchy = models.JSONField(default=dict) 94 approval_history = models.JSONField(default=list) 95 worker_status = models.JSONField(default=list) 96 timestamp = models.DateTimeField(auto_now_add=True) 97 attendee_otp = models.CharField(max_length=6,default=None) 98 completion_otp = models.CharField(max_length=6,default=None) 99 100 def refresh_otp(self): 101 self.attendee_otp = self.generate_otp() 102 self.completion_otp = self.generate_otp() 103 104 def generate_otp(self): 105 return ''.join(random.choices(string.ascii_uppercase+string.digits, k=6)) 106 107 def save(self, *args, **kwargs): 108 if not self.attendee_otp or not self.completion_otp: 109 self.refresh_otp() 110 super().save(*args, **kwargs) 111 112 class Meta: 113 db_table = 'memo_snapshot' 114 ordering = ['-timestamp'] 115 116 def __str__(self): 117 return f"Memo Snapshot of {self.memo.memoId}" 118 119class AttendeeETA(models.Model): 120 """ 121 Tracks the estimated time of arrival (ETA) for an attendee to a memo. 122 123 Fields: 124 - attendee: ForeignKey to User who is the attendee. 125 - memo: ForeignKey to Memo. 126 - created_at: Timestamp when the ETA was created. 127 - updated_at: Timestamp when the ETA was last updated. 128 - updated_count: Number of times the ETA was updated. 129 - eta: The estimated time of arrival. 130 131 Methods: 132 - save(): Increments updated_count on each save. 133 - __str__(): String representation of the attendee ETA. 134 """ 135 attendee = models.ForeignKey('accounts.User', on_delete=models.CASCADE, related_name='attendee_etas') 136 memo = models.ForeignKey(Memo, on_delete=models.CASCADE, related_name='attendee_eta') 137 created_at = models.DateTimeField(auto_now_add=True) 138 updated_at = models.DateTimeField(auto_now=True) 139 updated_count = models.IntegerField(default=0) 140 eta = models.DateTimeField() 141 attendee = models.ForeignKey('accounts.User', on_delete=models.CASCADE, related_name='attendee_eta') 142 143 def save(self, *args, **kwargs): 144 if not self.updated_count: 145 self.updated_count = 1 146 else: 147 self.updated_count += 1 148 super().save(*args, **kwargs) 149 150 def __str__(self): 151 return f"Attendee ETA for {self.memo.memoId} at {self.eta} for {self.attendee}"
10class Memo(models.Model): 11 """ 12 Represents a memo record in the system. 13 14 Fields: 15 - memoId: Unique identifier for the memo (UUID string). 16 - hospital: ForeignKey to Hospital where the memo belongs. 17 - is_deleted: Marks if the memo is deleted (soft delete). 18 - is_merged: Marks if the memo is merged with another. 19 - created_at: Timestamp when the memo was created. 20 - modified_at: Timestamp when the memo was last modified. 21 22 Methods: 23 - latest_snapshot(): Returns the latest MemoSnapshot for this memo. 24 - __str__(): String representation of the memo. 25 """ 26 memoId = models.CharField(max_length=36, primary_key=True) 27 hospital = models.ForeignKey('accounts.Hospital', on_delete=models.CASCADE, related_name='memos') 28 is_deleted = models.BooleanField(default=False) 29 is_merged = models.BooleanField(default=False) 30 created_at = models.DateTimeField(auto_now_add=True) 31 modified_at = models.DateTimeField(auto_now=True) 32 33 class Meta: 34 ordering = ['-created_at'] 35 36 def latest_snapshot(self): 37 """ 38 Returns the latest snapshot of the memo. 39 """ 40 return self.snapshots.order_by('-timestamp').first() 41 42 def __str__(self): 43 return f"Memo {self.memoId}"
Represents a memo record in the system.
Fields: - memoId: Unique identifier for the memo (UUID string). - hospital: ForeignKey to Hospital where the memo belongs. - is_deleted: Marks if the memo is deleted (soft delete). - is_merged: Marks if the memo is merged with another. - created_at: Timestamp when the memo was created. - modified_at: Timestamp when the memo was last modified.
Methods: - latest_snapshot(): Returns the latest MemoSnapshot for this memo. - __str__(): String representation of the memo.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
36 def latest_snapshot(self): 37 """ 38 Returns the latest snapshot of the memo. 39 """ 40 return self.snapshots.order_by('-timestamp').first()
Returns the latest snapshot of the memo.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
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.
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.
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.
The requested object does not exist
The query returned multiple objects when only one was expected.
45class MemoEvents(models.Model): 46 """ 47 Represents an event in the lifecycle of a memo. 48 49 Fields: 50 - memo: ForeignKey to Memo. 51 - event_type: Type of event (created, updated, deleted, etc.). 52 - event_timestamp: Timestamp when the event occurred. 53 - event_by: User who triggered the event. 54 - payload: JSON field containing memo details at the time of event. 55 - metadata: JSON field containing additional metadata. 56 """ 57 memo = models.ForeignKey(Memo, on_delete=models.CASCADE, related_name='events') 58 event_type = models.CharField( 59 max_length=50, 60 choices=( 61 ('created', 'Created'), ('updated', 'Updated'), ('deleted', 'Deleted'), 62 ('merged', 'Merged'), ('escalated','Escalated'), ('approved','Approved'), 63 ('rejected','Rejected'), ('incomplete','Incomplete'), ('completed','Completed'), 64 ('tagged','Tagged'), ('attended','Attended') 65 ) 66 ) 67 event_timestamp = models.DateTimeField(auto_now_add=True) 68 event_by = models.ForeignKey('accounts.User', on_delete=models.CASCADE, related_name='events') 69 payload = models.JSONField() # contains the memo details 70 metadata = models.JSONField() # contains the memo metadata like users local storage at the current time..
Represents an event in the lifecycle of a memo.
Fields: - memo: ForeignKey to Memo. - event_type: Type of event (created, updated, deleted, etc.). - event_timestamp: Timestamp when the event occurred. - event_by: User who triggered the event. - payload: JSON field containing memo details at the time of event. - metadata: JSON field containing additional metadata.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
The requested object does not exist
The query returned multiple objects when only one was expected.
72class MemoSnapshot(models.Model): 73 """ 74 Represents a snapshot of a memo at a specific point in time. 75 76 Fields: 77 - memo: ForeignKey to Memo. 78 - info: JSON field with contextual information (role, department, complaint, etc.). 79 - hierarchy: JSON field with hierarchical structure of the memo. 80 - approval_history: JSON field with history of approvals. 81 - worker_status: JSON field with current worker allocation/status. 82 - timestamp: Timestamp when the snapshot was created. 83 - attendee_otp: OTP for attendee verification. 84 - completion_otp: OTP for completion verification. 85 86 Methods: 87 - refresh_otp(): Generates new OTPs for attendee and completion. 88 - generate_otp(): Helper to generate a random OTP. 89 - save(): Ensures OTPs are set before saving. 90 - __str__(): String representation of the snapshot. 91 """ 92 memo = models.ForeignKey(Memo, on_delete=models.CASCADE, related_name='snapshots') 93 info = models.JSONField(default=dict) 94 hierarchy = models.JSONField(default=dict) 95 approval_history = models.JSONField(default=list) 96 worker_status = models.JSONField(default=list) 97 timestamp = models.DateTimeField(auto_now_add=True) 98 attendee_otp = models.CharField(max_length=6,default=None) 99 completion_otp = models.CharField(max_length=6,default=None) 100 101 def refresh_otp(self): 102 self.attendee_otp = self.generate_otp() 103 self.completion_otp = self.generate_otp() 104 105 def generate_otp(self): 106 return ''.join(random.choices(string.ascii_uppercase+string.digits, k=6)) 107 108 def save(self, *args, **kwargs): 109 if not self.attendee_otp or not self.completion_otp: 110 self.refresh_otp() 111 super().save(*args, **kwargs) 112 113 class Meta: 114 db_table = 'memo_snapshot' 115 ordering = ['-timestamp'] 116 117 def __str__(self): 118 return f"Memo Snapshot of {self.memo.memoId}"
Represents a snapshot of a memo at a specific point in time.
Fields: - memo: ForeignKey to Memo. - info: JSON field with contextual information (role, department, complaint, etc.). - hierarchy: JSON field with hierarchical structure of the memo. - approval_history: JSON field with history of approvals. - worker_status: JSON field with current worker allocation/status. - timestamp: Timestamp when the snapshot was created. - attendee_otp: OTP for attendee verification. - completion_otp: OTP for completion verification.
Methods: - refresh_otp(): Generates new OTPs for attendee and completion. - generate_otp(): Helper to generate a random OTP. - save(): Ensures OTPs are set before saving. - __str__(): String representation of the snapshot.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
108 def save(self, *args, **kwargs): 109 if not self.attendee_otp or not self.completion_otp: 110 self.refresh_otp() 111 super().save(*args, **kwargs)
Save the current instance. Override this in a subclass if you want to control the saving process.
The 'force_insert' and 'force_update' parameters can be used to insist that the "save" must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
The requested object does not exist
The query returned multiple objects when only one was expected.
120class AttendeeETA(models.Model): 121 """ 122 Tracks the estimated time of arrival (ETA) for an attendee to a memo. 123 124 Fields: 125 - attendee: ForeignKey to User who is the attendee. 126 - memo: ForeignKey to Memo. 127 - created_at: Timestamp when the ETA was created. 128 - updated_at: Timestamp when the ETA was last updated. 129 - updated_count: Number of times the ETA was updated. 130 - eta: The estimated time of arrival. 131 132 Methods: 133 - save(): Increments updated_count on each save. 134 - __str__(): String representation of the attendee ETA. 135 """ 136 attendee = models.ForeignKey('accounts.User', on_delete=models.CASCADE, related_name='attendee_etas') 137 memo = models.ForeignKey(Memo, on_delete=models.CASCADE, related_name='attendee_eta') 138 created_at = models.DateTimeField(auto_now_add=True) 139 updated_at = models.DateTimeField(auto_now=True) 140 updated_count = models.IntegerField(default=0) 141 eta = models.DateTimeField() 142 attendee = models.ForeignKey('accounts.User', on_delete=models.CASCADE, related_name='attendee_eta') 143 144 def save(self, *args, **kwargs): 145 if not self.updated_count: 146 self.updated_count = 1 147 else: 148 self.updated_count += 1 149 super().save(*args, **kwargs) 150 151 def __str__(self): 152 return f"Attendee ETA for {self.memo.memoId} at {self.eta} for {self.attendee}"
Tracks the estimated time of arrival (ETA) for an attendee to a memo.
Fields: - attendee: ForeignKey to User who is the attendee. - memo: ForeignKey to Memo. - created_at: Timestamp when the ETA was created. - updated_at: Timestamp when the ETA was last updated. - updated_count: Number of times the ETA was updated. - eta: The estimated time of arrival.
Methods: - save(): Increments updated_count on each save. - __str__(): String representation of the attendee ETA.
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.
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.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
144 def save(self, *args, **kwargs): 145 if not self.updated_count: 146 self.updated_count = 1 147 else: 148 self.updated_count += 1 149 super().save(*args, **kwargs)
Save the current instance. Override this in a subclass if you want to control the saving process.
The 'force_insert' and 'force_update' parameters can be used to insist that the "save" must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
Method descriptor with partial application of the given arguments and keywords.
Supports wrapping existing descriptors and handles non-descriptor callables as instance methods.
The requested object does not exist
The query returned multiple objects when only one was expected.