def update_participant(p, logs): try: np, plogs = Participant.from_json(p) logs.extend(plogs) logs.append(dict(info="Restored participant %s" % np.name)) except Exception, e: logs.append(dict(warn="Could not fully restore participant (%s): %s" % (str(e), str(p))))
def test_participant_serialization(self): for p in Participant.objects.all(): d = p.to_json() p2, logs = Participant.from_json(d) for l in logs: self.assertEquals("info" in l, True) self.assertEquals(logs[0], {"info": "participant created"}) self.assertEquals(p.name, p2.name) self.assertEquals(p.display_name(), p2.display_name())
is_superuser = fields['is_superuser'], is_staff = fields['is_staff'], last_login = fields['last_login'], email = fields['email'], date_joined = fields['date_joined'], ) logs.append(dict(info="Counselor %s restored" % u.username)) except Exception, e: logs.append(dict(warn="Could not restore counselor (%s): %s" % (str(e), str(counselor_data)))) # delete existing participant data Participant.objects.all().delete() logs.append(dict(info="existing participant data cleared")) # update participants for p in json['participants']: try: np,plogs = Participant.from_json(p) logs.extend(plogs) logs.append(dict(info="Restored participant %s" % np.name)) except Exception, e: logs.append(dict(warn="Could not fully restore participant (%s): %s" % (str(e), str(p)))) return dict(logs=logs) @render_to("intervention/upload_participants.html") @login_required def upload_participant_data(request): logs = [] if Deployment.objects.count() > 0: deployment = Deployment.objects.all()[0] if not deployment.is_online(): logs.append(dict(error="you should only use this feature on the CCNMTL deployment"))
def setUp(self): self.i = Intervention.objects.create( name="test intervention", intervention_id="1", general_instructions="this is for testing") self.cs = ClientSession.objects.create( intervention=self.i, short_title="Session 1", long_title="Session 1: Getting Started", introductory_copy="Introductory Copy Here", defaulter=False) self.activity = Activity.objects.create( clientsession=self.cs, short_title="Activity 1", long_title="Activity 1 Long Title", objective_copy="Objective Copy for Activity 1 Here", collect_notes=False, collect_buddy_name=False, collect_referral_info=False, collect_reasons_for_returning=False) self.p1, logs = Participant.from_json( { 'name': 'Test Participant 1', 'patient_id': 'test_patient_1', 'id_number': '1', 'status': False, 'gender': 'F', 'buddy_name': '', 'clinical_notes': 'Hello World!', 'initial_referral_notes': 'Sample notes.', 'initial_referral_alcohol': 0, 'initial_referral_drug_use': 0, 'initial_referral_mental_health': 0, 'initial_referral_other': 0, 'defaulter': True, 'defaulter_referral_notes': 'Defaulter referral notes', 'defaulter_referral_alcohol': 0, 'defaulter_referral_drugs': 0, 'defaulter_referral_mental_health': 0, 'defaulter_referral_other': 0, 'reasons_for_returning': 'Reasons for returning notes', 'counselor_notes': [], 'session_progress': [], 'activity_progress': [], 'game_vars': [], u'session_visits': [ {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 12:58:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 12:59:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:00:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:01:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:02:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:03:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:04:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:05:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:06:54.064000'}], u'activity_visits': [ {u'activity': u'Session 1: Activity 1: Session Objectives', u'timestamp': u'2013-02-12 12:58:26.466000'}] }) self.p2, log = Participant.from_json({ 'name': 'Test Participant 2', 'patient_id': 'test_patient_2', 'id_number': '2', 'status': False, 'gender': 'F', 'buddy_name': '', 'clinical_notes': 'Hello World!', 'initial_referral_notes': 'Sample notes.', 'initial_referral_alcohol': 0, 'initial_referral_drug_use': 0, 'initial_referral_mental_health': 0, 'initial_referral_other': 0, 'defaulter': True, 'defaulter_referral_notes': 'Defaulter referral notes', 'defaulter_referral_alcohol': 0, 'defaulter_referral_drugs': 0, 'defaulter_referral_mental_health': 0, 'defaulter_referral_other': 0, 'reasons_for_returning': 'Reasons for returning notes', 'counselor_notes': [], 'session_progress': [], 'activity_progress': [], u'session_visits': [ {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 12:58:17.340000'}, {u'session': u'Session 1: Session 1: Getting Started', u'timestamp': u'2013-02-12 13:06:54.064000'}], u'activity_visits': [ {u'activity': u'Session 1: Activity 1: Session Objectives', u'timestamp': u'2013-02-12 12:58:26.466000'}], u'game_vars': [ {u'pill_game': u'{"regular": {"pills": [{"color": "#FF0000", \ "id": "pill_8913", "name": "Efaverinez EFV"}, \ {"color": "#0000FF", "id": "pill_2044", \ "name": "Tenofivir TNV"}, {"color": "#00FF00", \ "id": "pill_9305", "name": "Lamudivine 3TC"}], \ "day": {"selected": "06:00", "id": "day", \ "views": [{"top": "105px", "pillId": "pill_8913", \ "left": "116px"}, {"top": "105px", "pillId": "pill_2044", \ "left": "62px"}, {"top": "135px", "pillId": "pill_9305", \ "left": "62px"}]}, "night": {"selected": "na", \ "id": "night", "views": []}}}'}, {u'assessmentquiz': u'{"defaulter": {"audit": {"total": 7}, \ "drugaudit": {"total": 0}, "kten": {"total": 27}}, \ "regular": {"audit": {}, "kten": {"total": 18}}}'}, {u'ssnmtree': u'{"defaulter": {"middle1-fruit": \ {"disclosure": true, "support": true, "name": "person1"}, \ "bottom1-fruit": {"disclosure": false, "support": false, \ "name": "person2"}, "bottom2-fruit": {"disclosure": true, \ "support": true, "name": "person3"}, "top2-fruit": \ {"disclosure": false, "support": false, "name": "person4"}, \ "middle4-fruit": {"disclosure": false, "support": true, \ "name": "person5"}, "middle3-fruit": {"disclosure": true, \ "support": true, "name": "person6"}}, "regular": \ {"middle1-fruit": {"disclosure": true, "support": true, \ "name": "person7"}, "bottom1-fruit": {"disclosure": false, \ "support": false, "name": "person8"}, "bottom2-fruit": \ {"disclosure": true, "support": false, "name": "person9"}, \ "top2-fruit": {"disclosure": false, "support": false, "name": \ "person10"}, "middle4-fruit": {"disclosure": false, \ "support": true, "name": "person11"}, "middle3-fruit": \ {"disclosure": true, "support": true, "name": ""}}}'}, {u'lifegoals': u'{"regular": {"step4": "educate my self", \ "step3": "see my kids grow", "step2": "get healtheir", \ "goal": "buy a car"}}'}, {u'problemsolving': u'{"defaulter": {"peopletellmenotto": \ {"customtext": ""}, "forgetful": {"barriers": \ "tirednesss.confusion", "finalPlan": "setphone as a \ reminder.speak to dr", "proposals": "get a relative to \ help you to remember.\\n\\ntreatment buddy,speaking to dr \ \\n\\n", "archive": [{"barriers": "wheniam drunk \ iforget to drink my arv`s", "finalPlan": "Before i go to \ drink i will ask my daughter to remind me my meds when i \ come backor wake me up if i fall asleep before my next \ dose.", "proposals": "get a relative to help you to \ remember."}], "customtext": ""}, "cantgettoclinic": \ {"customtext": ""}, "angrynurse": {"customtext": ""}, \ "nonsense": {"customtext": ""}, \ "confused": {"customtext": ""}, \ "otherpatients": {"customtext": ""}, \ "other": {"customtext": ""}, "hopeless": {"customtext": ""}, \ "notenoughfood": {"customtext": ""}, \ "feelingill": {"customtext": ""}, \ "alone": {"barriers": "", "finalPlan": "", "proposals": "", \ "customtext": ""}, "treatment_fatigue": {"customtext": ""}, \ "dontwantto": {"customtext": ""}, \ "happy": {"customtext": ""}}}'}], })