コード例 #1
0
ファイル: vitals.py プロジェクト: elliotcohen/indivo_server
def _vitals_list(request, limit, offset, status, category=None, order_by='-created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  # change underscores to spaces in the category, to make it easier without URL encoding
  if category:
    category = category.replace("_"," ")

  processed_order_by = report_orderby_update(order_by)

  if category:
    vitals = carenet_filter(carenet,
              Vitals.objects.select_related().filter(
                record=record, 
                name=category, 
                document__status=status).order_by(processed_order_by))
  else:
    vitals = carenet_filter(carenet,
                Vitals.objects.select_related().filter(
                  record=record, 
                  document__status=status).order_by(processed_order_by))
  return render_template('reports/vitals', 
                          { 'vitals' : vitals[offset:offset+limit],
                            'trc' : len(vitals),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by
                          }, type='xml')
コード例 #2
0
ファイル: ccr.py プロジェクト: elliotcohen/indivo_server
def report_ccr(request, record=None, carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    # FIXME: fix these carenet filters to be smarter

    active_status = StatusName.objects.get(name='active')

    medications = carenet_filter(
        carenet,
        Medication.objects.select_related().filter(
            record=record, document__status=active_status))
    immunizations = carenet_filter(
        carenet,
        Immunization.objects.select_related().filter(
            record=record, document__status=active_status))

    vitalsigns = carenet_filter(
        carenet,
        Vitals.objects.select_related().filter(record=record,
                                               document__status=active_status))

    return render_template('reports/ccr', {
        'record': record,
        'now': datetime.datetime.utcnow(),
        'medications': medications,
        'immunizations': immunizations,
        'vitalsigns': vitalsigns
    },
                           type="xml")
コード例 #3
0
ファイル: ccr.py プロジェクト: cviedmai/indivo_server
def report_ccr(request, record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  # FIXME: fix these carenet filters to be smarter

  active_status = StatusName.objects.get(name='active')

  medications = carenet_filter(carenet,
                               Medication.objects.select_related().filter(record=record, 
                                                                          document__status=active_status))
  immunizations = carenet_filter(carenet, 
                                 Immunization.objects.select_related().filter(record=record, 
                                                                              document__status=active_status))

  vitalsigns = carenet_filter(carenet,
                              Vitals.objects.select_related().filter(record=record, 
                                                                     document__status=active_status))


  return render_template('reports/ccr', 
                         {'record': record, 'now': datetime.datetime.utcnow(),
                          'medications': medications,
                          'immunizations' : immunizations,
                          'vitalsigns' : vitalsigns},
                         type="xml")
コード例 #4
0
def _medicationscheduleitem_list(request, limit, offset, status, order_by="created_at", record=None, carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    type_obj = DocumentSchema.objects.get(type="http://indivo.org/vocab/xml/documents#MedicationScheduleItem")
    medicationscheduleitems = carenet_filter(
        carenet,
        Document.objects.filter(type=type_obj, replaced_by=None, record=record, status=status).order_by(
            processed_order_by
        ),
    )

    return render_template(
        "reports/medicationscheduleitems",
        {
            "medicationscheduleitems": medicationscheduleitems[offset : offset + limit],
            "trc": len(medicationscheduleitems),
            "limit": limit,
            "offset": offset,
            "order_by": order_by,
        },
        type="xml",
    )
コード例 #5
0
def _medication_list(request, limit, offset, status, order_by='created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  processed_order_by = report_orderby_update(order_by)

  medications = carenet_filter(carenet,
                  Medication.objects.select_related().filter(
                    record=record, 
                    document__status=status).order_by(processed_order_by))
  """  
  medications = []
  relationship =  DocumentSchema.objects.get(type=DocumentSchema.expand_rel('ScheduledAction'))
  for med in medication_objs:
    rels = Document.objects.filter(record=record, status=status, rels_as_doc_0__document_1__original=med.document.original_id, rels_as_doc_0__relationship=relationship)
    medications += [med, rels]
  """
  return render_template('reports/medications', 
                          { 'medications' : medications[offset:offset+limit],
                            'trc' : len(medications),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by
                          }, 
                          type="xml")
コード例 #6
0
def _measurement_list(request,
                      limit,
                      offset,
                      status,
                      order_by,
                      lab_code,
                      record=None,
                      carenet=None):
    """
  Func for listing measurements
  """

    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    measurements = carenet_filter(
        carenet,
        Measurement.objects.select_related().filter(
            record=record,
            document__status=status).order_by(processed_order_by))
    return render_template('reports/measurements', {
        'measurements': measurements[offset:offset + limit],
        'record': record,
        'trc': len(measurements),
        'limit': limit,
        'offset': offset,
        'order_by': order_by
    },
                           type="xml")
コード例 #7
0
def simple_clinical_notes_list(request,
                               limit,
                               offset,
                               status,
                               order_by='created_at',
                               record=None,
                               carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    simple_clinical_notes = carenet_filter(
        carenet,
        SimpleClinicalNote.objects.select_related().filter(
            record=record,
            document__status=status).order_by(processed_order_by))
    return render_template('reports/simple_clinical_notes', {
        'scns': simple_clinical_notes[offset:offset + limit],
        'trc': len(simple_clinical_notes),
        'limit': limit,
        'offset': offset,
        'order_by': order_by
    },
                           type='xml')
コード例 #8
0
def _adherenceitem_list(request,
                        limit,
                        offset,
                        status,
                        order_by='created_at',
                        record=None,
                        carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    type_obj = DocumentSchema.objects.get(
        type='http://indivo.org/vocab/xml/documents#AdherenceItem')
    adherenceitems = carenet_filter(
        carenet,
        Document.objects.filter(type=type_obj,
                                replaced_by=None,
                                record=record,
                                status=status).order_by(processed_order_by))

    return render_template(
        'reports/adherenceitems', {
            'adherenceitems': adherenceitems[offset:offset + limit],
            'trc': len(adherenceitems),
            'limit': limit,
            'offset': offset,
            'order_by': order_by
        },
        type="xml")
コード例 #9
0
def _videomessage_list(request,
                       limit,
                       offset,
                       status,
                       order_by='created_at',
                       record=None,
                       carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    type_obj = DocumentSchema.objects.get(
        type='http://indivo.org/vocab/xml/documents#VideoMessage')
    videomessages = carenet_filter(
        carenet,
        Document.objects.filter(type=type_obj,
                                replaced_by=None,
                                record=record,
                                status=status).order_by(processed_order_by))
    print "Number of Video Messages: " + str(len(videomessages))

    return render_template(
        'reports/videomessages', {
            'videomessages': videomessages[offset:offset + limit],
            'trc': len(videomessages),
            'limit': limit,
            'offset': offset,
            'order_by': order_by
        },
        type="xml")
コード例 #10
0
def _medication_list(request,
                     limit,
                     offset,
                     status,
                     order_by='created_at',
                     record=None,
                     carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    medications = carenet_filter(
        carenet,
        Medication.objects.select_related().filter(
            record=record,
            document__status=status).order_by(processed_order_by))
    """  
  medications = []
  relationship =  DocumentSchema.objects.get(type=DocumentSchema.expand_rel('ScheduledAction'))
  for med in medication_objs:
    rels = Document.objects.filter(record=record, status=status, rels_as_doc_0__document_1__original=med.document.original_id, rels_as_doc_0__relationship=relationship)
    medications += [med, rels]
  """
    return render_template('reports/medications', {
        'medications': medications[offset:offset + limit],
        'trc': len(medications),
        'limit': limit,
        'offset': offset,
        'order_by': order_by
    },
                           type="xml")
コード例 #11
0
def _equipment_list(request,
                    limit,
                    offset,
                    status,
                    order_by='created_at',
                    record=None,
                    carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    equipment = carenet_filter(
        carenet,
        Equipment.objects.select_related().filter(
            record=record,
            document__status=status).order_by(processed_order_by))
    return render_template('reports/equipment', {
        'equipment': equipment[offset:offset + limit],
        'trc': len(equipment),
        'limit': limit,
        'offset': offset,
        'order_by': order_by
    },
                           type="xml")
コード例 #12
0
def _problem_list(request,
                  limit,
                  offset,
                  status,
                  order_by='created_at',
                  record=None,
                  carenet=None):
    if carenet:
        record = carenet.record
    if not record:
        return HttpResponseBadRequest()

    processed_order_by = report_orderby_update(order_by)

    problems = carenet_filter(
        carenet,
        Problem.objects.select_related().filter(
            record=record,
            document__status=status).order_by(processed_order_by))
    return render_template('reports/problems', {
        'problems': problems[offset:offset + limit],
        'trc': len(problems),
        'limit': limit,
        'offset': offset,
        'order_by': order_by
    },
                           type='xml')
コード例 #13
0
def _immunization_list(request, limit, offset, status, order_by='created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  processed_order_by = report_orderby_update(order_by)

  immunizations = carenet_filter(carenet, 
                    Immunization.objects.select_related().filter(
                      record=record, 
                      document__status=status).order_by(processed_order_by))
  return render_template('reports/immunizations', 
                          { 'immunizations' : immunizations[offset:offset+limit], 
                            'trc' : len(immunizations),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by}, 
                            type="xml")
コード例 #14
0
def _schedulegroup_list(request, limit, offset, status, order_by='created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  processed_order_by = report_orderby_update(order_by)

  type_obj = DocumentSchema.objects.get(type='http://indivo.org/vocab/xml/documents#ScheduleGroup')
  schedulegroups = carenet_filter(carenet, Document.objects.filter(type=type_obj, replaced_by=None, record=record, status=status).order_by(processed_order_by)) 

  return render_template('reports/schedulegroups', 
                          { 'schedulegroups' : schedulegroups[offset:offset+limit],
                            'trc' : len(schedulegroups),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by
                          }, 
                          type="xml")
コード例 #15
0
ファイル: problem.py プロジェクト: cviedmai/indivo_server
def problem_list(request, limit, offset, status, order_by='created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  processed_order_by = report_orderby_update(order_by)

  problems = carenet_filter(carenet,
              Problem.objects.select_related().filter(
                record=record, 
                document__status=status).order_by(processed_order_by))
  return render_template('reports/problems', 
                         { 'problems' : problems[offset:offset+limit], 
                           'trc' : len(problems),
                           'limit' : limit,
                           'offset' : offset,
                           'order_by' : order_by}, 
                         type='xml')
コード例 #16
0
def simple_clinical_notes_list(request, limit, offset, status, order_by='created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  processed_order_by = report_orderby_update(order_by)

  simple_clinical_notes = carenet_filter(carenet,
                SimpleClinicalNote.objects.select_related().filter(
                  record=record, 
                  document__status=status).order_by(processed_order_by))
  return render_template('reports/simple_clinical_notes', 
                          { 'scns' : simple_clinical_notes[offset:offset+limit],
                            'trc' : len(simple_clinical_notes),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by
                          }, 
                          type='xml')
コード例 #17
0
def _videomessage_list(request, limit, offset, status, order_by='created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  processed_order_by = report_orderby_update(order_by)

  type_obj = DocumentSchema.objects.get(type='http://indivo.org/vocab/xml/documents#VideoMessage')
  videomessages = carenet_filter(carenet, Document.objects.filter(type=type_obj, replaced_by=None, record=record, status=status).order_by(processed_order_by))
  print "Number of Video Messages: " + str(len(videomessages))

  return render_template('reports/videomessages', 
                          { 'videomessages' : videomessages[offset:offset+limit],
                            'trc' : len(videomessages),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by
                          }, 
                          type="xml")
コード例 #18
0
def _measurement_list(request, limit, offset, status, order_by, lab_code, record=None, carenet=None):
  """
  Func for listing measurements
  """

  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  processed_order_by = report_orderby_update(order_by)

  measurements = carenet_filter(carenet,
                  Measurement.objects.select_related().filter(
                    record=record, 
                    document__status=status).order_by(processed_order_by))
  return render_template('reports/measurements', 
                          { 'measurements': measurements[offset:offset+limit],
                            'record': record,
                            'trc' : len(measurements),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by}, 
                          type="xml")
コード例 #19
0
ファイル: vitals.py プロジェクト: cviedmai/indivo_server
def vitals_list(request, limit, offset, status, category=None, order_by='-created_at', record=None, carenet=None):
  if carenet:
    record = carenet.record
  if not record:
    return HttpResponseBadRequest()

  occurred_min = request.GET.get('occurred-min', None)
  occurred_max = request.GET.get('occurred-max', None)
  aggregation  = request.GET.get('aggregation', None)
  segmentation = request.GET.get('segmentation', None)

  processed_order_by = report_orderby_update(order_by)

  vitals = Vitals.objects.select_related().filter(record=record, document__status=status)
  
  #Apply all the different filters
  if category:
    # change underscores to spaces in the category, to make it easier without URL encoding
    category = category.replace("_"," ")
    vitals = vitals.filter(name=category)
  
  if occurred_min:
    occurred_min = datetime.datetime.strptime(occurred_min, "%Y-%m-%dT%H:%M:%SZ")
    vitals = vitals.filter(date_measured__gte = occurred_min)
  
  if occurred_max:
    occurred_max = datetime.datetime.strptime(occurred_max, "%Y-%m-%dT%H:%M:%SZ")
    #If there is no date_measured_end then it should be date_measured (start)
    vitals = vitals.filter(date_measured_end__lte = occurred_max)

  #Create the segments
  
  #These functions are methods in the class of vitals
  segmentation_functions = {
    "weekday"    : lambda v: v.weekday(),
    "hourofday"  : lambda v: v.hour_of_day(),
    "hour"       : lambda v: v.hour(),
    "day"        : lambda v: v.day(),
    "week"       : lambda v: v.week(),
    "weekofyear" : lambda v: v.week_of_year(),
    "month"      : lambda v: v.month(),
    "year"       : lambda v: v.year()
  }

  if segmentation:
    if segmentation in segmentation_functions.keys():
      temp = {}
      for key, group in groupby(vitals, segmentation_functions[segmentation]):
        temp[key] = [vital for vital in group]
    vitals = temp 
    # at this point we have a dictionary where Keys are the 
    #segment identifiers and the values are lists of vitals

  #Aggregation functions
 
  sum_vitals = lambda l: reduce(lambda x,y: x + y.value, l, 0)
    
  aggregation_functions = {
    "sum" : lambda l: sum_vitals(l),
    "avg" : lambda l: sum_vitals(l) / float(len(l)),
    "min" : lambda l: min(l, key=lambda x: x.value).value,
    "max" : lambda l: max(l, key=lambda x: x.value).value
  }
  
  #Apply the aggregation functions
  if aggregation:
    #Apply the aggregation if we know how to do
    if aggregation in aggregation_functions.keys():
      temp = []
      for key in vitals.keys():
        #res.append(vitals[k].aggregate(functions[aggregation]('value')))
        #value = reduce(lambda x,y: x + y.value, vitals[k], 0)
        value = aggregation_functions[aggregation](vitals[key])
        vital = Vitals(value = value, 
                       name = "Step Count", 
                       unit = "steps")
        vital.index = key
        temp.append(vital)
    vitals = temp
 
  #Apply carenet_filter and order the results
  #vitals = carenet_filter(carenet, vitals.order_by(processed_order_by))
  vitals = carenet_filter(carenet, vitals)
  #FIX: The ordering data does not work on a normal list. Only in querysets
 
  #Select the template depending if is aggregated vitals or not
  if aggregation:
    template = "reports/vitals_aggregation"
  else:
    template = "reports/vitals" 

  return render_template(template, 
                          { 'vitals' : vitals[offset:offset+limit],
                            'trc' : len(vitals),
                            'limit' : limit,
                            'offset' : offset,
                            'order_by' : order_by
                          }, type='xml')