Пример #1
0
def patient_case_xml(request, patient_id):
    """
    Case xml for a single patient.  This is just a debug method, and as such
    ignores the start date flag and always returns the full case xml block
    """
    template = \
"""<cases>%s
</cases>"""
    return HttpResponse(template % "".join([xml.get_case_xml(PhoneCase.from_bhoma_case(case)) \
                                 for case in cases_for_patient(patient_id)]), 
                        mimetype="text/xml")
Пример #2
0
def generate_restore_payload(user, restore_id):
    try:
        last_sync = None
        if restore_id:
            try:
                last_sync = SyncLog.get(restore_id)
            except Exception:
                logging.error("Request for bad sync log %s by %s, ignoring..." % (restore_id, user))
        
        username = user.username
        chw_id = user.get_profile().chw_id
        if not chw_id:
            raise Exception("No linked chw found for %s" % username)
        
        chw = CommunityHealthWorker.get(chw_id)
        last_seq = get_db().info()["update_seq"]
        cases_to_send = get_open_cases_to_send(chw.current_clinic_id, 
                                               chw.current_clinic_zone, 
                                               last_sync)
        case_xml_blocks = [xml.get_case_xml(case, create) for case, create in cases_to_send]
        
        # save the case blocks
        for case, _ in cases_to_send:
            case.save()
        
        saved_case_ids = [case.case_id for case, _ in cases_to_send]
        # create a sync log for this
        last_sync_id = last_sync.get_id if last_sync is not None else None
        
        # change 5/28/2011, always sync reg xml to phone
        reg_xml = xml.get_registration_xml(chw)
        synclog = SyncLog(chw_id=chw_id, last_seq=last_seq,
                          clinic_id=chw.current_clinic_id,
                          date=datetime.utcnow(), 
                          previous_log_id=last_sync_id,
                          cases=saved_case_ids)
        synclog.save()
                                             
        yield xml.RESTOREDATA_TEMPLATE % {"registration": reg_xml, 
                                          "restore_id": synclog.get_id, 
                                          "case_list": "".join(case_xml_blocks)}
    except Exception, e:
        logging.exception("problem restoring: %s" % user.username)
        raise