Ejemplo n.º 1
0
 def add_form_to_patient(line):
     
     change = Change(line)
     
     # check the global max seq in this process to avoid repeating ourselves.
     if change.seq < max_seq:
         return log_and_abort(logging.DEBUG, "ignoring item %s because it's seq is old")
     update_max_seq(change)
         
     form_id = change.id
     # don't bother with deleted or old documents
     if change.deleted or not change.is_current(db): return 
         
     formdoc = CXFormInstance.get(form_id)
     pat_id = get_patient_id_from_form(formdoc)
     if pat_id is not None and get_classification(formdoc.namespace) == "clinic":
         try:
             # this is so we don't get conflicting updates.  
             # resolve conflicts and bump version numbers before adding forms  
             pat_data = get_db().get(pat_id, conflicts=True)
             if "_conflicts" in pat_data:
                 return log_and_abort(logging.INFO, "ignoring patient %s because there are still conflicts that need to be resolved" % pat_id)
             else:
                 pat = CPatient.wrap(pat_data)
                 if pat.requires_upgrade():
                     return log_and_abort(logging.INFO, "ignoring patient %s, form %s because it is not yet upgraded to the latest version" % (pat_id, form_id))
             found_ids = [enc.xform_id for enc in pat.encounters]
             if form_id in found_ids and not formdoc.requires_upgrade():
                 return log_and_abort(logging.DEBUG, "Already found appropriate version of form %s in patient %s, no need to do anything" % (form_id, pat_id))
             else:
                 print "Form %s not found in patient %s or was old.  Rebuilding the patient now" % (form_id, pat_id)
                 reprocess(pat_id)
         except ResourceNotFound, e:
             return log_and_abort(logging.WARNING, "tried to check form %s in patient %s but patient has been deleted.  Ignoring" % (form_id, pat_id))
Ejemplo n.º 2
0
        def upgrade_patient(line):
            change = Change(line)
            # don't bother with deleted or old documents
            if change.deleted or not change.is_current(db): return 
            patient_id = change.id
            try:
                if patient_id in problem_patients:
                    return log_and_abort(logging.DEBUG, "skipping problem patient: %s" % patient_id)
                
                pat_data = get_db().get(patient_id, conflicts=True)
                # this is so we don't get conflicting updates.  resolve conflicts before bumping version numbers.  
                if "_conflicts" in pat_data:
                    return log_and_abort(logging.INFO, "ignoring patient %s because there are still conflicts that need to be resolved" % patient_id)
                else:
                    pat = CPatient.wrap(pat_data)
                    if pat.requires_upgrade():
                        print "upgrading patient: %s" % patient_id
                        logging.debug("upgrading patient: %s" % patient_id)
                        if not reprocess(pat.get_id):
                            log_and_abort(logging.ERROR, "problem upgrading patient %s!" % patient_id)
                            problem_patients.append(patient_id)

            except Exception, e:
                logging.exception("problem upgrading patient (id: %s)" % patient_id)
                problem_patients.append(patient_id)
Ejemplo n.º 3
0
 def resolve_conflict(line):
     try:
         change = Change(line)
         # don't bother with deleted or old documents
         if change.deleted or not change.is_current(db): 
             return log_and_abort(logging.DEBUG, "ignoring %s because it's been deleted or is old" % change)
         if conflicts.resolve_conflicts(change.id):
             logging.debug("resolved conflict for %s" % change.id)
         else:
             logging.info("no conflict found when expected in patient: %s" % change.id)
     except Exception, e:
         logging.exception("problem resolving conflict for line: %s" % line)
Ejemplo n.º 4
0
 def update_from_form(line):
     try:
         change = Change(line)
         # don't bother with deleted or old documents
         if change.deleted or not change.is_current(db):
             return 
         
         form = XFormInstance.get(change.id)
         get_formdata_class().create_or_update_from_xforminstance(form)
         
         # update the checkpoint, somewhat arbitrarily
         global sofabed_counter
         sofabed_counter = sofabed_counter + 1
         if sofabed_counter % CHECKPOINT_FREQUENCY == 0:
             Checkpoint.set_checkpoint(CHECKPOINT_ID, change.seq)
     
     except InvalidDataException, e:
         # this is a less severe class of errors
         logging.info("bad update in form listener for line: %s\n%s" % (line, e))
Ejemplo n.º 5
0
 def sync_if_necessary(line):
     try:
         change = Change(line)
         # don't bother with deleted or old documents
         if change.deleted or not change.is_current(db):
             return 
         
         # get doc
         doc = get_db().get(change.id)
         
         # check if transforms, and if so, save to new domain/db
         transforms = global_config.get_transforms(doc)
         for transform in transforms:
             global_config.save(transform)
         
         # update the checkpoint, somewhat arbitrarily
         global domainsync_counter
         domainsync_counter = domainsync_counter + 1
         if domainsync_counter % CHECKPOINT_FREQUENCY == 0:
             Checkpoint.set_checkpoint(CHECKPOINT_ID, change.seq)
     
     except Exception, e:
         logging.exception("problem in domain sync for line: %s\n%s" % (line, e))
Ejemplo n.º 6
0
        def sync_if_necessary(line):
            try:
                change = Change(line)
                # don't bother with deleted or old documents
                if change.deleted or not change.is_current(db):
                    return

                # get doc
                doc = get_db().get(change.id)

                # check if transforms, and if so, save to new domain/db
                transforms = global_config.get_transforms(doc)
                for transform in transforms:
                    global_config.save(transform)

                # update the checkpoint, somewhat arbitrarily
                global domainsync_counter
                domainsync_counter = domainsync_counter + 1
                if domainsync_counter % CHECKPOINT_FREQUENCY == 0:
                    Checkpoint.set_checkpoint(CHECKPOINT_ID, change.seq)

            except Exception, e:
                logging.exception("problem in domain sync for line: %s\n%s" %
                                  (line, e))