class ForwardMessage(TimeStampedModel): """ A ForwardMessage is a message *instance* for incoming messages forwarded to a different instance of mWACH """ STATUS_CHOICES = (('success', 'Success'), ('failed', 'Failed'), ('none', 'No Forward In Transport')) #Set Custom Manager objects = BaseQuerySet.as_manager() class Meta: ordering = ('-created', ) app_label = 'transports' identity = models.CharField(max_length=25) text = models.TextField(help_text='Text of the SMS message') transport = models.CharField(max_length=25, help_text='Transport name') fwrd_status = models.CharField(max_length=25, choices=STATUS_CHOICES, help_text='Forward Status') url = models.CharField(max_length=250, help_text='Forward URL') #Africa's Talking Data Only for outgoing messages external_id = models.CharField(max_length=50, blank=True) external_data = JSONField(blank=True)
class EventLog(TimeStampedModel): class Meta: app_label = 'contacts' objects = BaseQuerySet.as_manager() user = models.ForeignKey(User) event = models.CharField(max_length=25, help_text="Event Name") data = JSONField()
class Connection(models.Model): class Meta: app_label = 'contacts' objects = BaseQuerySet.as_manager() identity = models.CharField(max_length=25, primary_key=True) contact = models.ForeignKey(settings.MESSAGING_CONTACT, blank=True, null=True) description = models.CharField( max_length=30, blank=True, null=True, help_text='Description of phone numbers relationship to contact') is_primary = models.BooleanField(default=False, verbose_name='Primary') def __unicode__(self): return "{} ({})".format(self.contact.study_id if self.contact else '', self.identity) def send_custom(self, text, translated_text='', languages='', **kwargs): return self.send_message(text, translation_status='cust', translated_text=translated_text, languages=languages, is_system=False, **kwargs) def send_message(self, text, **kwargs): # Send message over system transport try: msg_id, msg_success, external_data = transports.send( self.identity, text) except transports.TransportError as e: msg_id = "" msg_success = False external_data = {"error": str(e)} # Create new message new_message = self.message_set.create( text=text, connection=self, external_id=msg_id, external_success=msg_success, external_status="Sent" if msg_success else external_data.get( "status", "Failed"), external_data=external_data, **kwargs) return new_message
class Note(TimeStampedModel): class Meta: ordering = ('-created', ) app_label = 'contacts' objects = BaseQuerySet.as_manager() participant = models.ForeignKey(settings.MESSAGING_CONTACT) admin = models.ForeignKey(settings.MESSAGING_ADMIN, blank=True, null=True) comment = models.TextField(blank=True) def is_pregnant(self): return self.participant.was_pregnant(today=self.created.date())
class StatusChange(TimeStampedModel): objects = BaseQuerySet.as_manager() class Meta: app_label = 'contacts' contact = models.ForeignKey(settings.MESSAGING_CONTACT) old = models.CharField(max_length=20) new = models.CharField(max_length=20) type = models.CharField(max_length=10, default='status') comment = models.TextField(blank=True)
class Connection(models.Model): class Meta: app_label = 'contacts' objects = BaseQuerySet.as_manager() identity = models.CharField(max_length=25,primary_key=True) contact = models.ForeignKey(settings.MESSAGING_CONTACT,blank=True,null=True) description = models.CharField(max_length=30,blank=True,null=True,help_text='Description of phone numbers relationship to contact') is_primary = models.BooleanField(default=False,verbose_name='Primary') def __unicode__(self): return "{} ({})".format(self.contact.study_id if self.contact else '',self.identity)
class EventLog(TimeStampedModel): """ The basic idea behind this model is to keep track of which staff accounts take which actions. These are currently created in the "visit seen" and "attended DRF" end points, however there is not currently any logic that accesses / uses the data anywhere in the codebase. """ class Meta: app_label = 'contacts' objects = BaseQuerySet.as_manager() user = models.ForeignKey(User) event = models.CharField(max_length=25,help_text="Event Name") data = JSONField()
class Practitioner(models.Model): ''' User profile for nurse practitioners to link a User profile to a Facility ''' class Meta: app_label = 'contacts' objects = BaseQuerySet.as_manager() user = models.OneToOneField(User) facility = models.CharField(max_length=15, choices=settings.FACILITY_CHOICES) password_changed = models.BooleanField(default=False) @property def username(self): return self.user.username def __str__(self): return '{0}'.format(self.user.username) def __repr__(self): return '<{0!s}> <{1}>'.format(self.facility, self.user.username)