class CDotWeeklySchedule(OldDocument): """Weekly schedule where each day has a username""" schedule_id = StringProperty(default=make_uuid) sunday = StringProperty() monday = StringProperty() tuesday = StringProperty() wednesday = StringProperty() thursday = StringProperty() friday = StringProperty() saturday = StringProperty() comment = StringProperty() deprecated = BooleanProperty(default=False) started = OldDateTimeProperty(default=datetime.utcnow, required=True) ended = OldDateTimeProperty() created_by = StringProperty() # user id edited_by = StringProperty() # user id @property def is_current(self): now = datetime.utcnow() return self.started <= now and (self.ended is None or self.ended > now) class Meta: app_label = 'pact'
class CObservationAddendum(OldDocument): observed_date = DateProperty() art_observations = SchemaListProperty(CObservation) nonart_observations = SchemaListProperty(CObservation) created_by = StringProperty() created_date = OldDateTimeProperty() notes = StringProperty() # placeholder if need be class Meta: app_label = 'pact'
class CObservation(OldDocument): doc_id = StringProperty() patient = StringProperty() # case id pact_id = StringProperty() # patient pact id provider = StringProperty() encounter_date = OldDateTimeProperty() anchor_date = OldDateTimeProperty() observed_date = OldDateTimeProperty() submitted_date = OldDateTimeProperty() created_date = OldDateTimeProperty() is_art = BooleanProperty() dose_number = IntegerProperty() total_doses = IntegerProperty() adherence = StringProperty() # DOT_OBSERVATION_ types method = StringProperty() is_reconciliation = BooleanProperty(default=False) day_index = IntegerProperty() # if there's something for that particular day, then it'll be here day_note = StringProperty() # new addition, if there's a slot for the day label, then retain it day_slot = IntegerProperty() # this is for the overall note for that submission, # will exist on the anchor date note = StringProperty() @classmethod def wrap(cls, obj): ints = ['dose_number', 'total_doses', 'day_index', 'day_slot'] for prop_name in ints: val = obj.get(prop_name) if val and isinstance(val, six.string_types): obj[prop_name] = int(val) return super(CObservation, cls).wrap(obj) @property def obs_score(self): """Gets the relative score of the observation. """ if self.method == "direct": return 3 if self.method == "pillbox": return 2 if self.method == "self": return 1 @property def adinfo(self): """helper function to concatenate adherence and method to check for conflicts""" return ((self.is_art, self.dose_number, self.total_doses), "%s" % (self.adherence)) class Meta: app_label = 'pact' def __unicode__(self): return "Obs %s [%s] %d/%d" % (json_format_date(self.observed_date), "ART" if self.is_art else "NonART", self.dose_number+1, self.total_doses) def __str__(self): return "Obs %s [%s] %d/%d" % (json_format_date(self.observed_date), "ART" if self.is_art else "NonART", self.dose_number+1, self.total_doses) def __repr__(self): return json.dumps(self.to_json(), indent=4)