Permalink
Browse files

add individual hi risk reasons to mothers, update tests

  • Loading branch information...
1 parent 56ebd42 commit c541e7f8231e1b533ef3a70e464c2d68fa416078 @czue czue committed Jun 29, 2012
View
8 mwana/apps/smgl/keyword_handlers/pregnancy.py
@@ -57,8 +57,7 @@ def pregnant_registration(session, xform, router):
mother.first_name = get_value_from_form('first_name', xform)
mother.last_name = get_value_from_form('last_name', xform)
- mother.high_risk_history = get_value_from_form('high_risk_factor', xform)
-
+
next_visit, error_msg = make_date(xform, "next_visit_dd", "next_visit_mm", "next_visit_yy")
if error_msg:
send_msg(connection, error_msg, router, **{"date_name": "Next Visit",
@@ -97,6 +96,11 @@ def pregnant_registration(session, xform, router):
send_msg(connection, const.UNKOWN_ZONE, router, zone=zone_name)
return True
+ reasons = xform.xpath("form/high_risk_factor")
+ if reasons:
+ for r in reasons.split(" "):
+ mother.set_risk_reason(r)
+
mother.contact = data_associate
mother.save()
View
289 ...migrations/0017_auto__chg_field_facilityvisit_visit_date__del_field_pregnantmother_hig.py
@@ -0,0 +1,289 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'FacilityVisit.visit_date'
+ db.alter_column('smgl_facilityvisit', 'visit_date', self.gf('django.db.models.fields.DateField')())
+
+ # Deleting field 'PregnantMother.high_risk_history'
+ db.delete_column('smgl_pregnantmother', 'high_risk_history')
+
+ # Adding field 'PregnantMother.risk_reason_csec'
+ db.add_column('smgl_pregnantmother', 'risk_reason_csec', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+ # Adding field 'PregnantMother.risk_reason_cmp'
+ db.add_column('smgl_pregnantmother', 'risk_reason_cmp', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+ # Adding field 'PregnantMother.risk_reason_gd'
+ db.add_column('smgl_pregnantmother', 'risk_reason_gd', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+ # Adding field 'PregnantMother.risk_reason_hbp'
+ db.add_column('smgl_pregnantmother', 'risk_reason_hbp', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+ # Adding field 'PregnantMother.risk_reason_psb'
+ db.add_column('smgl_pregnantmother', 'risk_reason_psb', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+ # Adding field 'PregnantMother.risk_reason_oth'
+ db.add_column('smgl_pregnantmother', 'risk_reason_oth', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+ # Adding field 'PregnantMother.risk_reason_none'
+ db.add_column('smgl_pregnantmother', 'risk_reason_none', self.gf('django.db.models.fields.BooleanField')(default=False), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Changing field 'FacilityVisit.visit_date'
+ db.alter_column('smgl_facilityvisit', 'visit_date', self.gf('django.db.models.fields.DateField')(auto_now_add=True))
+
+ # Adding field 'PregnantMother.high_risk_history'
+ db.add_column('smgl_pregnantmother', 'high_risk_history', self.gf('django.db.models.fields.CharField')(default='', max_length=160), keep_default=False)
+
+ # Deleting field 'PregnantMother.risk_reason_csec'
+ db.delete_column('smgl_pregnantmother', 'risk_reason_csec')
+
+ # Deleting field 'PregnantMother.risk_reason_cmp'
+ db.delete_column('smgl_pregnantmother', 'risk_reason_cmp')
+
+ # Deleting field 'PregnantMother.risk_reason_gd'
+ db.delete_column('smgl_pregnantmother', 'risk_reason_gd')
+
+ # Deleting field 'PregnantMother.risk_reason_hbp'
+ db.delete_column('smgl_pregnantmother', 'risk_reason_hbp')
+
+ # Deleting field 'PregnantMother.risk_reason_psb'
+ db.delete_column('smgl_pregnantmother', 'risk_reason_psb')
+
+ # Deleting field 'PregnantMother.risk_reason_oth'
+ db.delete_column('smgl_pregnantmother', 'risk_reason_oth')
+
+ # Deleting field 'PregnantMother.risk_reason_none'
+ db.delete_column('smgl_pregnantmother', 'risk_reason_none')
+
+
+ models = {
+ 'contactsplus.contacttype': {
+ 'Meta': {'object_name': 'ContactType'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'slug': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+ },
+ 'formplayer.xform': {
+ 'Meta': {'object_name': 'XForm'},
+ 'checksum': ('django.db.models.fields.CharField', [], {'max_length': '40', 'blank': 'True'}),
+ 'created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}),
+ 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'namespace': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'uiversion': ('django.db.models.fields.IntegerField', [], {'null': 'True'}),
+ 'version': ('django.db.models.fields.IntegerField', [], {'null': 'True'})
+ },
+ 'locations.location': {
+ 'Meta': {'object_name': 'Location'},
+ 'has_independent_printer': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Location']", 'null': 'True', 'blank': 'True'}),
+ 'point': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Point']", 'null': 'True', 'blank': 'True'}),
+ 'send_live_results': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'slug': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
+ 'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.LocationType']"})
+ },
+ 'locations.locationtype': {
+ 'Meta': {'object_name': 'LocationType'},
+ 'exists_in': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Location']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'plural': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'singular': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'slug': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'locations.point': {
+ 'Meta': {'object_name': 'Point'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.DecimalField', [], {'max_digits': '13', 'decimal_places': '10'}),
+ 'longitude': ('django.db.models.fields.DecimalField', [], {'max_digits': '13', 'decimal_places': '10'})
+ },
+ 'rapidsms.backend': {
+ 'Meta': {'object_name': 'Backend'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20'})
+ },
+ 'rapidsms.connection': {
+ 'Meta': {'unique_together': "(('backend', 'identity'),)", 'object_name': 'Connection'},
+ 'backend': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Backend']"}),
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Contact']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'identity': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'rapidsms.contact': {
+ 'Meta': {'object_name': 'Contact'},
+ 'alias': ('django.db.models.fields.CharField', [], {'max_length': '100', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_help_admin': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'language': ('django.db.models.fields.CharField', [], {'max_length': '6', 'blank': 'True'}),
+ 'location': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Location']", 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
+ 'pin': ('django.db.models.fields.CharField', [], {'max_length': '4', 'blank': 'True'}),
+ 'types': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'contacts'", 'blank': 'True', 'to': "orm['contactsplus.ContactType']"}),
+ 'unique_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'unique': 'True', 'null': 'True', 'blank': 'True'})
+ },
+ 'smgl.ambulanceoutcome': {
+ 'Meta': {'object_name': 'AmbulanceOutcome'},
+ 'ambulance_request': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smgl.AmbulanceRequest']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mother': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smgl.PregnantMother']", 'null': 'True', 'blank': 'True'}),
+ 'mother_uid': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'outcome': ('django.db.models.fields.CharField', [], {'max_length': '60'}),
+ 'outcome_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
+ },
+ 'smgl.ambulancerequest': {
+ 'Meta': {'object_name': 'AmbulanceRequest'},
+ 'ambulance_driver': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'ambulance_driver'", 'null': 'True', 'to': "orm['rapidsms.Contact']"}),
+ 'connection': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Connection']", 'null': 'True', 'blank': 'True'}),
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'er_iniator'", 'null': 'True', 'to': "orm['rapidsms.Contact']"}),
+ 'danger_sign': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'from_location': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'from_location'", 'null': 'True', 'to': "orm['locations.Location']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mother': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smgl.PregnantMother']", 'null': 'True', 'blank': 'True'}),
+ 'mother_uid': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'other_recipient': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'other_recipient'", 'null': 'True', 'to': "orm['rapidsms.Contact']"}),
+ 'received_response': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'receiving_facility': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'receiving_facility'", 'null': 'True', 'to': "orm['locations.Location']"}),
+ 'receiving_facility_recipient': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'receiving_facility_recipient'", 'null': 'True', 'to': "orm['rapidsms.Contact']"}),
+ 'requested_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'triage_nurse': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'triage_nurse'", 'null': 'True', 'to': "orm['rapidsms.Contact']"})
+ },
+ 'smgl.ambulanceresponse': {
+ 'Meta': {'object_name': 'AmbulanceResponse'},
+ 'ambulance_request': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smgl.AmbulanceRequest']", 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mother': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smgl.PregnantMother']", 'null': 'True', 'blank': 'True'}),
+ 'mother_uid': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'responded_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'responder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Contact']"}),
+ 'response': ('django.db.models.fields.CharField', [], {'max_length': '60'})
+ },
+ 'smgl.birthregistration': {
+ 'Meta': {'object_name': 'BirthRegistration'},
+ 'complications': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'connection': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Connection']"}),
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Contact']", 'null': 'True'}),
+ 'date': ('django.db.models.fields.DateField', [], {}),
+ 'gender': ('django.db.models.fields.CharField', [], {'max_length': '2'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'number': ('django.db.models.fields.IntegerField', [], {'default': '1'}),
+ 'place': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
+ 'unique_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'smgl.deathregistration': {
+ 'Meta': {'object_name': 'DeathRegistration'},
+ 'connection': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Connection']"}),
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Contact']", 'null': 'True'}),
+ 'date': ('django.db.models.fields.DateField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'person': ('django.db.models.fields.CharField', [], {'max_length': '3'}),
+ 'place': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
+ 'unique_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'})
+ },
+ 'smgl.facilityvisit': {
+ 'Meta': {'object_name': 'FacilityVisit'},
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Contact']"}),
+ 'edd': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'location': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Location']"}),
+ 'mother': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'facility_visits'", 'to': "orm['smgl.PregnantMother']"}),
+ 'next_visit': ('django.db.models.fields.DateField', [], {}),
+ 'reason_for_visit': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'visit_date': ('django.db.models.fields.DateField', [], {})
+ },
+ 'smgl.pregnantmother': {
+ 'Meta': {'object_name': 'PregnantMother'},
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Contact']"}),
+ 'edd': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '160'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '160'}),
+ 'lmp': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
+ 'location': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Location']"}),
+ 'next_visit': ('django.db.models.fields.DateField', [], {}),
+ 'reason_for_visit': ('django.db.models.fields.CharField', [], {'max_length': '160'}),
+ 'risk_reason_cmp': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'risk_reason_csec': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'risk_reason_gd': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'risk_reason_hbp': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'risk_reason_none': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'risk_reason_oth': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'risk_reason_psb': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'uid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '160'}),
+ 'zone': ('django.db.models.fields.CharField', [], {'max_length': '160', 'null': 'True', 'blank': 'True'})
+ },
+ 'smgl.preregistration': {
+ 'Meta': {'object_name': 'PreRegistration'},
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['rapidsms.Contact']", 'null': 'True', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'has_confirmed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'language': ('django.db.models.fields.CharField', [], {'default': "'english'", 'max_length': '255'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'location': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Location']"}),
+ 'phone_number': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+ 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'unique_id': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'zone': ('django.db.models.fields.CharField', [], {'max_length': '20', 'null': 'True', 'blank': 'True'})
+ },
+ 'smgl.referral': {
+ 'Meta': {'object_name': 'Referral'},
+ 'facility': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['locations.Location']"}),
+ 'form_id': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'mother': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smgl.PregnantMother']", 'null': 'True', 'blank': 'True'}),
+ 'mother_uid': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'reason_aph': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_cpd': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_ec': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_fd': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_hbp': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_other': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_pec': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_pl': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'reason_pph': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'session': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smsforms.XFormsSession']"}),
+ 'status': ('django.db.models.fields.CharField', [], {'max_length': '3', 'null': 'True', 'blank': 'True'})
+ },
+ 'smgl.xformkeywordhandler': {
+ 'Meta': {'object_name': 'XFormKeywordHandler'},
+ 'function_path': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'keyword': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ 'smsforms.decisiontrigger': {
+ 'Meta': {'object_name': 'DecisionTrigger'},
+ 'final_response': ('django.db.models.fields.CharField', [], {'max_length': '160', 'null': 'True', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'trigger_keyword': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'xform': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['formplayer.XForm']"})
+ },
+ 'smsforms.xformssession': {
+ 'Meta': {'object_name': 'XFormsSession'},
+ 'cancelled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'connection': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'xform_sessions'", 'to': "orm['rapidsms.Connection']"}),
+ 'end_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'ended': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'error_msg': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'has_error': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'modified_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'session_id': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'start_time': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+ 'trigger': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['smsforms.DecisionTrigger']"})
+ }
+ }
+
+ complete_apps = ['smgl']
View
32 mwana/apps/smgl/models.py
@@ -16,22 +16,52 @@ class XFormKeywordHandler(models.Model):
class PregnantMother(models.Model):
+ HI_RISK_REASONS = {
+ "csec": "C-Section",
+ "cmp": "Complications during previous pregnancy",
+ "gd": "Gestational Diabetes",
+ "hbp": "High Blood Pressure",
+ "psb": "Previous still born",
+ "oth": "Other",
+ "none": "None"
+ }
+
contact = models.ForeignKey(Contact, help_text="The contact that registered this mother")
location = models.ForeignKey(Location)
first_name = models.CharField(max_length=160)
last_name = models.CharField(max_length=160)
uid = models.CharField(max_length=160, unique=True, help_text="The Unique Identifier associated with this mother")
lmp = models.DateField(null=True, blank=True, help_text="Last Menstrual Period")
edd = models.DateField(help_text="Estimated Date of Delivery", null=True, blank=True)
- high_risk_history = models.CharField(max_length=160, help_text="The code indicating any high risk issues for this pregnant mother")
next_visit = models.DateField(help_text="Date of next visit")
reason_for_visit = models.CharField(max_length=160, choices=REASON_FOR_VISIT_CHOICES)
zone = models.CharField(max_length=160, null=True, blank=True)
+
+ risk_reason_csec = models.BooleanField(default=False)
+ risk_reason_cmp = models.BooleanField(default=False)
+ risk_reason_gd = models.BooleanField(default=False)
+ risk_reason_hbp = models.BooleanField(default=False)
+ risk_reason_psb = models.BooleanField(default=False)
+ risk_reason_oth = models.BooleanField(default=False)
+ risk_reason_none = models.BooleanField(default=False)
@property
def name(self):
return "%s %s" % (self.first_name, self.last_name)
+ def set_risk_reason(self, code, val=True):
+ assert code in self.HI_RISK_REASONS
+ setattr(self, "risk_reason_%s" % code, val)
+
+ def get_risk_reason(self, code):
+ assert code in self.HI_RISK_REASONS
+ return getattr(self, "risk_reason_%s" % code)
+
+ def get_risk_reasons(self):
+ for c in self.HI_RISK_REASONS:
+ if self.get_risk_reason(c):
+ yield c
+
def __unicode__(self):
return 'Mother: %s %s, UID: %s' % (self.first_name, self.last_name, self.uid)
View
21 mwana/apps/smgl/tests/test_pregnancy.py
@@ -33,6 +33,8 @@ def testRegister(self):
self.assertEqual(date(2012, 2, 12), mom.lmp)
self.assertEqual(date(2012, 11, 18), mom.edd)
self.assertEqual(date(2012, 8, 4), mom.next_visit)
+ self.assertTrue(mom.risk_reason_none)
+ self.assertEqual(["none"], list(mom.get_risk_reasons()))
self.assertEqual("r", mom.reason_for_visit)
self.assertEqual(1, FacilityVisit.objects.count())
@@ -43,7 +45,24 @@ def testRegister(self):
self.assertEqual(date(2012, 11, 18), visit.edd)
self.assertEqual(date(2012, 8, 4), visit.next_visit)
-
+ def testRegisterMultipleReasons(self):
+ resp = const.MOTHER_SUCCESS_REGISTERED % { "name": self.name,
+ "unique_id": "80403000000112" }
+ reasons = "csec,cmp,gd,hbp"
+ script = """
+ %(num)s > REG 80403000000112 Mary Soko %(reasons)s 04 08 2012 R 80402404 12 02 2012 18 11 2012
+ %(num)s < %(resp)s
+ """ % { "num": self.user_number, "resp": resp, "reasons": reasons }
+ self.runScript(script)
+
+ mom = PregnantMother.objects.get(uid='80403000000112')
+ rback = list(mom.get_risk_reasons())
+ self.assertEqual(4, len(rback))
+ for r in reasons.split(","):
+ self.assertTrue(r in rback)
+ self.assertTrue(mom.get_risk_reason(r))
+ self.assertTrue(getattr(mom, "risk_reason_%s" % r))
+
def testRegisterWithBadZone(self):
resp = const.UNKOWN_ZONE % { "zone": "notarealzone" }
script = """

0 comments on commit c541e7f

Please sign in to comment.