Ejemplo n.º 1
0
def add_history_note(request, problem_id):
    resp = {'success': False}
    try:
        problem = Problem.objects.get(id=problem_id)
    except Problem.DoesNotExist:
        return ajax_response(resp)

    # Get params
    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)
    note = request.POST.get('note')
    physician = request.user
    patient = problem.patient

    # Save note
    new_note = ProblemNote.objects.create_history_note(actor, problem, note)

    # Save problem log
    activity = "Added History Note  <b>{}</b>".format(note)
    add_problem_activity(problem, request.user, activity, 'input')

    # Save system log
    op_add_event(physician, patient, activity, problem)

    # https://trello.com/c/hkdbHZjw
    auto_generate_note_todo(actor_profile, patient, problem, request, resp)

    # Build response
    resp['success'] = True
    resp['note'] = ProblemNoteSerializer(new_note).data

    return ajax_response(resp)
Ejemplo n.º 2
0
def add_value(request, component_id):
    resp = {}
    actor_profile = UserProfile.objects.get(user=request.user)
    component = ObservationComponent.objects.get(id=component_id)
    effective_date = datetime.strptime(request.POST.get('date'),
                                       '%Y-%m-%d').date()

    value = ObservationValue.objects.create(component=component,
                                            value_quantity=request.POST.get(
                                                "value", None),
                                            effective_datetime=effective_date,
                                            author=request.user)

    a1c = component.observation.observation_aonecs
    a1c.patient_refused_A1C = False
    a1c.todo_past_six_months = False
    a1c.save()

    resp['value'] = ObservationValueSerializer(value).data
    resp['success'] = True

    # set problem authentication
    set_problem_authentication_false(actor_profile, a1c.problem)

    summary = """
        Added new a1c value <u>A1C</u> : <b>%s</b> ,
        <u>problem</u> <b>%s</b>
        """ % (value.value_quantity, a1c.problem.problem_name)

    add_problem_activity(a1c.problem, request.user, summary)

    summary = "An A1C value of <b>%s</b> was entered" % (value.value_quantity)
    op_add_event(request.user, a1c.problem.patient, summary, a1c.problem)
    return ajax_response(resp)
Ejemplo n.º 3
0
def add_problem_goal(request, problem_id):
    resp = {'success': False}

    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)
    problem = Problem.objects.get(id=problem_id)
    patient = problem.patient

    goal = request.POST.get('name')

    new_goal = Goal(patient=patient, problem=problem, goal=goal)
    new_goal.save()

    physician = request.user

    summary = '''Added <u> goal </u> : <b>%s</b> to <u>problem</u> : <b>%s</b>''' % (
        goal, problem.problem_name)
    op_add_event(physician, patient, summary, problem)

    activity = summary
    add_problem_activity(problem, request.user, activity, 'output')

    resp['success'] = True
    resp['goal'] = GoalSerializer(new_goal).data
    return ajax_response(resp)
Ejemplo n.º 4
0
def relate_problem(request):
    resp = {'success': False}

    actor_profile = UserProfile.objects.get(user=request.user)
    relationship = request.POST.get('relationship') == 'true'
    source_id = request.POST.get('source_id', None)
    target_id = request.POST.get('target_id', None)

    source = Problem.objects.get(id=source_id)
    target = Problem.objects.get(id=target_id)
    activity = None

    if relationship:
        try:
            problem_relationship = ProblemRelationship.objects.get(
                source=source, target=target)
        except ProblemRelationship.DoesNotExist:
            problem_relationship = ProblemRelationship.objects.create(
                source=source, target=target)
            activity = '''Created Problem Relationship: <b>%s</b> effects <b>%s</b>''' % (
                source.problem_name, target.problem_name)
    else:
        ProblemRelationship.objects.get(source=source, target=target).delete()
        activity = '''Removed Problem Relationship: <b>%s</b> effects <b>%s</b>''' % (
            source.problem_name, target.problem_name)

    if activity:
        add_problem_activity(source, request.user, activity)
        add_problem_activity(target, request.user, activity)
        op_add_event(request.user, source.patient, activity)

    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 5
0
def upload_problem_image(request, problem_id):
    resp = {'success': False}
    actor_profile = UserProfile.objects.get(user=request.user)
    problem = Problem.objects.get(id=problem_id)
    problem.authenticated = actor_profile.role in ['physician', 'admin']
    problem.save()

    patient = problem.patient
    images = request.FILES
    image_holder = []
    for dict in images:
        image = request.FILES[dict]
        patient_image = PatientImage(patient=patient,
                                     problem=problem,
                                     image=image)
        patient_image.save()

        activity = summary = '''
        Physician added <u>image</u> to <u>problem</u> <b>%s</b> <br/><a href="/media/%s">
        <img src="/media/%s" class="thumbnail thumbnail-custom" /></a>
        ''' % (problem.problem_name, patient_image.image, patient_image.image)

        op_add_event(request.user, patient, summary, problem)
        add_problem_activity(problem, request.user, activity, 'input')

        image_holder.append(patient_image)

    resp['images'] = PatientImageSerializer(image_holder, many=True).data
    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 6
0
def update_problem_status(request, problem_id):
    resp = {'success': False}

    # Different permissions for different cases
    # Modify this view

    actor_profile = UserProfile.objects.get(user=request.user)

    is_controlled = request.POST.get('is_controlled') == 'true'
    is_active = request.POST.get('is_active') == 'true'
    authenticated = request.POST.get('authenticated') == 'true'

    problem = Problem.objects.select_related("patient").get(id=problem_id)
    problem.is_controlled = is_controlled
    problem.is_active = is_active
    problem.authenticated = authenticated
    problem.save()

    status_labels = {
        'problem_name': problem.problem_name,
        'is_controlled': "controlled" if is_controlled else "not controlled",
        "is_active": "active" if is_active else "not_active",
        "authenticated":
        "authenticated" if authenticated else "not_authenticated",
    }

    physician = request.user

    summary = """Changed <u>problem</u>: <b>%(problem_name)s</b> status to : <b>%(is_controlled)s</b> ,<b>%(is_active)s</b> ,<b>%(authenticated)s</b>""" % status_labels
    op_add_event(physician, problem.patient, summary, problem)
    activity = summary
    add_problem_activity(problem, request.user, activity)

    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 7
0
def update_goal_status(request, patient_id, goal_id):
    resp = {}
    patient = User.objects.get(id=patient_id)
    goal = Goal.objects.get(id=goal_id, patient=patient)

    is_controlled = request.POST.get('is_controlled') == 'true'
    accomplished = request.POST.get('accomplished') == 'true'
    goal.is_controlled = is_controlled
    goal.accomplished = accomplished
    goal.save()

    status_labels = {
        "goal": goal.goal,
        "is_controlled":
        "controlled" if goal.is_controlled else "not controlled",
        "accomplished":
        "accomplished" if goal.accomplished else "not accomplished",
        "problem": goal.problem.problem_name if goal.problem else "",
    }

    physician = request.user
    summary = "Change <u>goal</u>: <b>%(goal)s</b> <u>status</u>"
    summary += " to <b>%(is_controlled)s</b> <b>%(accomplished)s</b>"
    summary += " for <u>problem</u> <b>%(problem)s</b> "
    summary = summary % status_labels

    op_add_event(physician, patient, summary, goal.problem)

    if goal.problem:
        actor_profile = UserProfile.objects.get(user=request.user)
        add_problem_activity(goal.problem, request.user, summary, 'output')

    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 8
0
def add_goal_note(request, patient_id, goal_id):
    resp = {}

    actor_profile = UserProfile.objects.get(user=request.user)
    goal = Goal.objects.get(id=goal_id, patient_id=patient_id)

    note = request.POST.get('new_note')
    new_note = TextNote.objects.create(note=note, by=actor_profile.role)
    goal.notes.add(new_note)

    problem_name = goal.problem.problem_name if goal.problem else "",
    summary = """
        Added <u>note</u> <b>%s</b> for <u>goal</u>:
        <b>%s</b> ,
        <u> problem </u>: <b>%s</b>
    """ % (note, goal.goal, problem_name)

    physician = request.user
    patient = goal.patient
    op_add_event(physician, patient, summary, goal.problem)

    if goal.problem:
        add_problem_activity(goal.problem, request.user, summary, 'output')

    resp['success'] = True
    resp['note'] = TextNoteSerializer(new_note).data
    return ajax_response(resp)
Ejemplo n.º 9
0
def add_patient_common_problem(request, patient_id):
    resp = {'success': False}

    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)
    cproblem = request.POST.get('cproblem')
    problem_type = request.POST.get('type')

    problem = CommonProblem.objects.get(id=cproblem)

    if Problem.objects.filter(problem_name=problem.problem_name,
                              concept_id=problem.concept_id,
                              patient__id=patient_id).exists():
        return ajax_response({"msg": "Problem already added"})

    new_problem = Problem.objects.create_new_problem(patient_id,
                                                     problem.problem_name,
                                                     problem.concept_id,
                                                     actor_profile)
    physician = request.user

    summary = 'Added <u>problem</u> <b>%s</b>' % problem.problem_name
    op_add_event(physician, new_problem.patient, summary, new_problem)
    activity = "Added <u>problem</u>: <b>%s</b>" % problem.problem_name
    add_problem_activity(new_problem, request.user, activity)

    resp['success'] = True
    resp['problem'] = ProblemSerializer(new_problem).data
    return ajax_response(resp)
Ejemplo n.º 10
0
def save_text_component_entry(request, patient_id, component_id):
    resp = {}
    resp['success'] = False
    if permissions_accessed(request.user, int(patient_id)):
        component = MyStoryTextComponent.objects.get(id=int(component_id))
        patient = User.objects.get(id=patient_id)

        entry = MyStoryTextComponentEntry()
        entry.component = component
        entry.text = request.POST.get("text", None)
        entry.patient = patient
        entry.author = request.user
        entry.save()

        resp['entry'] = MyStoryTextComponentEntrySerializer(entry).data

        actor = request.user

        summary = "<b>%s</b> note was updated to %s" % (component.name,
                                                        entry.text)
        op_add_event(actor, patient, summary)

        resp['success'] = True

    return ajax_response(resp)
Ejemplo n.º 11
0
def problem_relationship_auto_pinning_for_3_times_matched():
    """
    https://trello.com/c/TWI2l0UU
    If any two SNOMED CT CONCEPT_IDs are set as relationship more than 3 times
    then set this as a relationship for all patients who have those two problems.
    :return:
    """
    print(
        'Starting cron problem_relationship_auto_pinning_for_3_times_matched...'
    )
    # Default actor for cron job
    actor = User.objects.filter(profile__role='admin').first()

    # Find all paired problem have same SNOMED CT id
    relationships = ProblemRelationship.objects.filter(source__concept_id__isnull=False,
                                                       target__concept_id__isnull=False) \
        .values('source__concept_id', 'target__concept_id').annotate(total=Count('source__concept_id')).filter(
        total__gte=3)

    # find_all_problem_relationship_more_than_3_time()
    print('Find all paired problem have same SNOMED CT...')
    print(relationships)
    print('')

    for relation in relationships:
        print("Processing problem relationship source: {}- target {}".format(
            relation['source__concept_id'], relation['target__concept_id']))
        for p in User.objects.filter(profile__role='patient').all():
            problem_pairs = Problem.objects.filter(patient_id=p.id).filter(
                concept_id__in=[
                    relation['source__concept_id'],
                    relation['target__concept_id']
                ])
            print("Processing patient:({}) {}".format(p.id, p))
            print("Number of problems in pair: {}".format(
                problem_pairs.count()))
            if problem_pairs.exists() and problem_pairs.count() == 2:
                source = Problem.objects.get(
                    patient_id=p.id, concept_id=relation['source__concept_id'])
                target = Problem.objects.get(
                    patient_id=p.id, concept_id=relation['target__concept_id'])

                if not ProblemRelationship.objects.filter(
                        source=source, target=target).exists():
                    ProblemRelationship.objects.create(source=source,
                                                       target=target)
                    activity = "Created Problem Relationship(automation pinning): <b>{0}</b> effects <b>{1}</b>".format(
                        source.problem_name, target.problem_name)
                    # Add log
                    add_problem_activity(source, actor, activity)
                    add_problem_activity(target, actor, activity)
                    op_add_event(actor, source.patient, activity)
                    print("Activity log: {}".format(activity))
            print('')
    print(
        'Finished cron problem_relationship_auto_pinning_for_3_times_matched...'
    )
    print('')
Ejemplo n.º 12
0
def track_a1c_click(request, a1c_id):
    actor = request.user
    a1c_info = AOneC.objects.get(id=a1c_id)
    patient = a1c_info.problem.patient

    summary = "<b>%s</b> visited <u>a1c</u> module" % (actor.username)
    op_add_event(actor, patient, summary, a1c_info.problem)

    resp = {}
    return ajax_response(resp)
Ejemplo n.º 13
0
def track_colon_click(request, colon_id):
    resp = {'success': False}
    colon_info = ColonCancerScreening.objects.get(id=colon_id)
    if permissions_accessed(request.user, colon_info.patient.id):
        actor = request.user
        patient = colon_info.problem.patient

        summary = "<b>%s</b> accessed colorectal cancer screening" % (actor.username)
        op_add_event(actor, patient, summary, colon_info.problem)
        resp['success'] = True

    return ajax_response(resp)
Ejemplo n.º 14
0
def add_patient_goal(request, patient_id):
    resp = {}
    goal_name = request.POST.get('name')
    new_goal = Goal.objects.create(patient_id=patient_id, goal=goal_name)

    physician = request.user
    patient = User.objects.get(id=patient_id)
    summary = 'Added <u>goal</u> <b>%s</b>' % goal_name
    op_add_event(physician, patient, summary)

    resp['success'] = True
    resp['goal'] = GoalSerializer(new_goal).data
    return ajax_response(resp)
Ejemplo n.º 15
0
def track_tab_click(request):
    resp = {'success': False}
    if request.POST.get("tab_id", None):
        tab_info = MyStoryTab.objects.get(id=request.POST.get("tab_id", None))
        if permissions_accessed(request.user, tab_info.patient.id):
            actor = request.user
            patient = tab_info.patient

            summary = "<b>%s</b> accessed %s" % (actor.username, tab_info.name)
            op_add_event(actor, patient, summary)
            resp['success'] = True

    return ajax_response(resp)
Ejemplo n.º 16
0
def update_problem_list_note(request, list_id):
    resp = {'success': False}
    problem_list = LabeledProblemList.objects.get(id=list_id)
    problem_list.note = request.POST.get('note')
    problem_list.save()

    activity = '"%s" was added to the folder "%s"' % (problem_list.note,
                                                      problem_list.name)
    physician = request.user
    patient = problem_list.patient
    op_add_event(physician, patient, activity)

    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 17
0
def change_name(request, problem_id):
    resp = {'success': False}

    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)
    term = request.POST.get('term')
    concept_id = request.POST.get('code', None)

    problem = Problem.objects.get(id=problem_id)
    if Problem.objects.filter(problem_name=term,
                              patient=problem.patient).exists():
        return ajax_response({"msg": "Problem already added"})

    old_problem_concept_id = problem.concept_id
    old_problem_name = problem.problem_name
    if datetime.now() > datetime.strptime(
            problem.start_date.strftime('%d/%m/%Y') + ' ' +
            problem.start_time.strftime('%H:%M:%S'),
            "%d/%m/%Y %H:%M:%S") + timedelta(hours=24):
        problem.old_problem_name = old_problem_name

    problem.problem_name = term
    problem.concept_id = concept_id
    problem.save()

    physician = request.user

    if old_problem_concept_id and problem.concept_id:
        summary = '<b>%s (%s)</b> was changed to <b>%s (%s)</b>' % (
            old_problem_name, old_problem_concept_id, problem.problem_name,
            problem.concept_id)
    elif old_problem_concept_id:
        summary = '<b>%s (%s)</b> was changed to <b>%s</b>' % (
            old_problem_name, old_problem_concept_id, problem.problem_name)
    elif problem.concept_id:
        summary = '<b>%s</b> was changed to <b>%s (%s)</b>' % (
            old_problem_name, problem.problem_name, problem.concept_id)
    else:
        summary = '<b>%s</b> was changed to <b>%s</b>' % (old_problem_name,
                                                          problem.problem_name)

    op_add_event(physician, problem.patient, summary, problem)
    add_problem_activity(problem, request.user, summary)

    resp['success'] = True
    resp['problem'] = ProblemSerializer(problem).data

    return ajax_response(resp)
Ejemplo n.º 18
0
def track_problem_click(request, problem_id):
    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)

    if actor_profile.role in ['physician', 'admin']:
        problem = Problem.objects.get(id=problem_id)
        patient = problem.patient

        summary = "Clicked <u>problem</u>: <b>%s</b>" % problem.problem_name
        op_add_event(actor, patient, summary)

        activity = "Visited <u>problem</u>: <b>%s</b>" % problem.problem_name
        add_problem_activity(problem, request.user, activity)

    resp = {}
    return ajax_response(resp)
Ejemplo n.º 19
0
def delete_problem_image(request, problem_id, image_id):
    resp = {'success': False}

    actor_profile = UserProfile.objects.get(user=request.user)
    PatientImage.objects.get(id=image_id).delete()

    problem = Problem.objects.select_related("patient").get(id=problem_id)
    patient = problem.patient
    physician = request.user
    summary = '''Deleted <u>image</u> from <u>problem</u> : <b>%s</b>''' % problem.problem_name
    op_add_event(physician, patient, summary, problem)
    activity = summary
    add_problem_activity(problem, request.user, activity, 'input')

    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 20
0
def todo_access_encounter(request, todo_id):
    resp = {}
    todo = ToDo.objects.get(id=todo_id)
    physician = request.user
    patient = todo.patient

    if todo.problem:
        summary = '''<a href="#/todo/%s"><b>%s</b></a> for <b>%s</b> was visited.''' % (
            todo.id, todo.todo, todo.problem.problem_name)
    else:
        summary = '''<a href="#/todo/%s"><b>%s</b></a> was visited.''' % (todo.id, todo.todo)

    op_add_todo_event(physician, patient, summary, todo)
    if todo.problem:
        op_add_event(physician, patient, summary, todo.problem, True)

    return ajax_response(resp)
Ejemplo n.º 21
0
def delete_problem(request, problem_id):
    resp = {'success': False}

    physician = request.user
    patient_id = request.POST.get('patient_id', None)
    latest_encounter = Encounter.objects.filter(
        physician=physician,
        patient_id=patient_id).order_by('-starttime').first()

    if latest_encounter and latest_encounter.stoptime is None:
        resp['success'] = True

        problem = Problem.objects.get(id=problem_id)
        summary = "Deleted <u>problem</u>: <b>%s</b>" % problem.problem_name
        op_add_event(physician, problem.patient, summary)
        problem.delete()

    return ajax_response(resp)
Ejemplo n.º 22
0
def track_observation_click(request):
    resp = {'success': False}

    actor = request.user
    if request.POST.get("patient_id", None):
        patient = User.objects.get(id=request.POST.get("patient_id", None))

        if request.POST.get("observation_id", None):
            observation = Observation.objects.get(
                id=request.POST.get("observation_id", None))
            summary = "<b>%s</b> accessed %s" % (actor.username,
                                                 observation.name)
        else:
            summary = "<b>%s</b> accessed data" % (actor.username)
        op_add_event(actor, patient, summary)
        resp['success'] = True

    return ajax_response(resp)
Ejemplo n.º 23
0
def update_todo_status(request, todo_id):
    resp = {'success': False}

    accomplished = request.POST.get('accomplished') == 'true'
    physician = request.user
    # patient = todo.patient

    todo = ToDo.objects.get(id=todo_id)
    todo.accomplished = accomplished
    todo.save(update_fields=["accomplished"])
    # set problem authentication
    set_problem_authentication_false(request, todo)

    problem_name = todo.problem.problem_name if todo.problem else ""
    accomplished_label = 'accomplished' if accomplished else "not accomplished"

    summary = """
    Updated status of <u>todo</u> : <a href="#/todo/{}"><b>{}</b></a> ,
    <u>problem</u> <b>{}</b> to <b>{}</b>
    """.format(todo.id, todo.todo, problem_name, accomplished_label)

    op_add_todo_event(physician, todo.patient, summary, todo)

    actor_profile = UserProfile.objects.get(user=request.user)
    if todo.problem:
        add_problem_activity(todo.problem, request.user, summary, 'output')
        if accomplished:
            op_add_event(physician, todo.patient, summary, todo.problem, True)

    # todo activity
    activity = "Updated status of this todo to <b>{}</b>.".format(accomplished_label)
    add_todo_activity(todo, request.user, activity)

    # todos = ToDo.objects.filter(patient=patient)
    # accomplished_todos = [todo for todo in todos if todo.accomplished]
    # pending_todos = [todo for todo in todos if not todo.accomplished]

    resp['success'] = True
    resp['todo'] = TodoSerializer(todo).data
    # resp['accomplished_todos'] = TodoSerializer(accomplished_todos, many=True).data
    # resp['pending_todos'] = TodoSerializer(pending_todos, many=True).data
    return ajax_response(resp)
Ejemplo n.º 24
0
def update_start_date(request, problem_id):
    resp = {'success': False}

    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)
    start_date = request.POST.get('start_date')
    problem = Problem.objects.get(id=problem_id)
    problem.start_date = get_new_date(start_date)
    problem.save()

    physician = request.user
    patient = problem.patient
    summary = '''Changed <u>problem</u> : <b>%s</b> start date to <b>%s</b>''' % (
        problem.problem_name, problem.start_date)
    op_add_event(physician, patient, summary, problem)
    activity = summary
    add_problem_activity(problem, request.user, activity)

    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 25
0
def update_by_ptw(request):
    resp = {'success': False}
    actor_profile = UserProfile.objects.get(user=request.user)

    timeline_data = json.loads(request.body)['timeline_data']
    for problem_json in timeline_data['problems']:
        problem = ProblemService.update_from_timeline_data(problem_json)
        patient = problem.patient
        problem.authenticated = actor_profile.role in ['physician', 'admin']
        problem.save()

        physician = request.user
        summary = '''Changed <u>problem</u> :<b>%s</b> start date to <b>%s</b>''' % (
            problem.problem_name, problem.start_date)
        op_add_event(physician, patient, summary, problem)
        activity = summary
        add_problem_activity(problem, request.user, activity)

        resp['success'] = True

    return ajax_response(resp)
Ejemplo n.º 26
0
def add_wiki_note(request, problem_id):
    """
    @depre
    :param request:
    :param problem_id:
    :return:
    """
    resp = {'success': False}

    try:
        problem = Problem.objects.get(id=problem_id)
        author_profile = UserProfile.objects.get(user=request.user)
    except (Problem.DoesNotExist, UserProfile.DoesNotExist) as e:
        return ajax_response(resp)

    # Check if user is able to view patient
    # Todo
    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)
    note = request.POST.get('note')
    physician = request.user
    patient = problem.patient

    new_note = ProblemNote.objects.create_wiki_note(request.user, problem,
                                                    note)

    activity = 'Added wiki note: <b>%s</b>' % note
    add_problem_activity(problem, request.user, activity, 'input')

    op_add_event(physician, patient, activity, problem)

    # https://trello.com/c/hkdbHZjw
    auto_generate_note_todo(actor_profile, patient, problem, request, resp)

    resp['note'] = ProblemNoteSerializer(new_note).data
    resp['success'] = True

    return ajax_response(resp)
Ejemplo n.º 27
0
def change_name(request, patient_id, goal_id):
    resp = {}
    patient = User.objects.get(id=patient_id)
    new_goal = request.POST.get("goal")

    goal = Goal.objects.get(id=goal_id, patient=patient)
    goal.goal = new_goal
    goal.save()

    status_labels = {'goal': goal.goal, 'new_goal': new_goal}

    physician = request.user
    summary = 'Change <u>goal</u>: <b>%(goal)s</b> <u>name</u> to <b>%(new_goal)s</b>'
    summary = summary % status_labels

    op_add_event(physician, patient, summary, goal.problem)

    if goal.problem:
        add_problem_activity(goal.problem, request.user, summary, 'output')

    resp['goal'] = GoalSerializer(goal).data
    resp['success'] = True
    return ajax_response(resp)
Ejemplo n.º 28
0
def add_patient_problem(request, patient_id):
    resp = {'success': False}
    actor = request.user
    actor_profile = UserProfile.objects.get(user=actor)
    term = request.POST.get('term')
    concept_id = request.POST.get('code', None)
    physician = request.user
    patient = User.objects.get(id=int(patient_id))

    if Problem.objects.filter(problem_name=term,
                              patient__id=patient_id).exists():
        resp["msg"] = "Problem already being added"
        return ajax_response(resp)

    new_problem = Problem.objects.create_new_problem(patient_id, term,
                                                     concept_id, actor_profile)

    # https://trello.com/c/0OlwGwCB
    # Only add if problem is diabetes and patient have not
    if "44054006" == concept_id:
        if not ObservationComponent.objects.filter(
                component_code="2345-7",
                observation__subject=patient).exists():
            # Add data(observation) Glucose type
            observation = Observation.objects.create(subject=patient,
                                                     author=request.user,
                                                     name="Glucose",
                                                     code="2345-7",
                                                     color="#FFD2D2")
            observation.save()

            #  Add data unit
            observation_unit = ObservationUnit.objects.create(
                observation=observation, value_unit="mg/dL")
            observation_unit.is_used = True  # will be changed in future when having conversion
            observation_unit.save()

            #  Add data component
            observation_component = ObservationComponent()
            observation_component.observation = observation
            observation_component.component_code = "2345-7"
            observation_component.name = "Glucose"
            observation_component.save()
        else:
            observation = ObservationComponent.objects.get(
                component_code="2345-7", observation__subject=patient)
        # Pin to problem
        ObservationPinToProblem.objects.create(author_id=request.user.id,
                                               observation=observation,
                                               problem=new_problem)

    # Event
    summary = "Added <u>problem</u> <b>{}</b>".format(term)
    op_add_event(physician, new_problem.patient, summary, new_problem)

    # Activity
    activity = "Added <u>problem</u>: <b>{}</b>".format(term)
    add_problem_activity(new_problem, request.user, activity)

    resp['success'] = True
    resp['problem'] = ProblemSerializer(new_problem).data
    return ajax_response(resp)
Ejemplo n.º 29
0
def add_problem_todo(request, problem_id):
    resp = {'success': False}

    problem = Problem.objects.get(id=problem_id)
    actor_profile = UserProfile.objects.get(user=request.user)
    problem.authenticated = actor_profile.role in ['physician', 'admin']
    problem.save()

    patient = problem.patient

    todo = request.POST.get('name')
    due_date = request.POST.get('due_date', None)
    if due_date:
        due_date = parser.parse(due_date, dayfirst=False).date()
        # due_date = datetime.strptime(due_date, '%m/%d/%Y').date()

    new_todo = ToDo(patient=patient,
                    problem=problem,
                    todo=todo,
                    due_date=due_date)

    a1c_id = request.POST.get('a1c_id', None)
    if a1c_id:
        a1c = AOneC.objects.get(id=int(a1c_id))
        new_todo.a1c = a1c

    order = ToDo.objects.all().aggregate(Max('order'))
    if not order['order__max']:
        order = 1
    else:
        order = order['order__max'] + 1
    new_todo.order = order
    new_todo.save()

    colon_cancer_id = request.POST.get('colon_cancer_id', None)
    if colon_cancer_id:
        colon = ColonCancerScreening.objects.get(id=int(colon_cancer_id))
        if not Label.objects.filter(name="screening",
                                    css_class="todo-label-yellow",
                                    is_all=True).exists():
            label = Label(name="screening",
                          css_class="todo-label-yellow",
                          is_all=True)
            label.save()
        else:
            label = Label.objects.get(name="screening",
                                      css_class="todo-label-yellow",
                                      is_all=True)
        new_todo.colon_cancer = colon
        new_todo.save()
        new_todo.labels.add(label)

    physician = request.user

    summary = '''Added <u>todo</u> : <a href="#/todo/%s"><b>%s</b></a> to <u>problem</u> : <b>%s</b>''' % (
        new_todo.id, todo, problem.problem_name)
    op_add_event(physician, patient, summary, problem)

    activity = summary
    add_problem_activity(problem, request.user, activity, 'output')

    summary = '''Added <u>todo</u> <a href="#/todo/%s"><b>%s</b></a> for <u>problem</u> <b>%s</b>''' % (
        new_todo.id, new_todo.todo, problem.problem_name)
    op_add_todo_event(physician, patient, summary, new_todo, True)
    # todo activity
    activity = '''
        Added this todo.
    '''
    add_todo_activity(new_todo, request.user, activity)

    resp['success'] = True
    resp['todo'] = TodoSerializer(new_todo).data
    return ajax_response(resp)
Ejemplo n.º 30
0
def add_new_data(request, patient_id, component_id):
    resp = {'success': False}

    patient = User.objects.filter(
        id=int(patient_id)).get()  # Patient user instance
    effective_datetime = request.POST.get(
        "datetime",
        datetime.now().strftime('%m/%d/%Y %H:%M'))  # Get user submit data

    value_quantity = request.POST.get("value", 0)
    value_quantity = value_quantity if value_quantity != '' else 0  # Passed empty value

    # Validate user input
    if permissions_accessed(
            request.user, int(patient_id)) and validate_effective_datetime(
                effective_datetime) and validate_number(
                    value_quantity) and validate_value_quantity(
                        component_id, value_quantity):

        # DB stuff
        effective_datetime = datetime.strptime(effective_datetime,
                                               '%m/%d/%Y %H:%M')
        value = ObservationValue(author=request.user,
                                 component_id=component_id,
                                 effective_datetime=effective_datetime,
                                 value_quantity=float(value_quantity))
        value.save()

        # Auto add bmi data if observation component is weight or height
        # TODO: Need to improve this block of code - https://trello.com/c/PaSdgs3k
        bmiComponent = ObservationComponent.objects.filter(
            component_code='39156-5').filter(
                observation__subject=patient).first()
        #  TODO: Later when finished refactor model relationship and patient
        if value.component.name == 'weight':
            # Calculation
            heightComponent = ObservationComponent.objects.filter(
                component_code='8302-2').filter(
                    observation__subject_id=int(patient_id)).get()
            height = get_observation_most_common_value(heightComponent,
                                                       effective_datetime)
            bmiValue = round(
                float(value.value_quantity) * 703 / pow(height, 2), 2)

            # DB stuff transaction
            ObservationValue(author=request.user,
                             component=bmiComponent,
                             effective_datetime=effective_datetime,
                             value_quantity=bmiValue).save()
            # Save log
            summary = "A value of <b>{0}</b> was added for <b>{1}</b>".format(
                bmiValue, bmiComponent.observation.name)
            op_add_event(request.user, value.component.observation.subject,
                         summary)

        if value.component.name == 'height':
            # Calculation
            weightComponent = ObservationComponent.objects.filter(
                component_code='3141-9').filter(
                    observation__subject_id=int(patient_id)).get()
            weight = get_observation_most_common_value(weightComponent,
                                                       effective_datetime)
            bmiValue = round(
                weight * 703 / pow(float(value.value_quantity), 2), 2)

            # DB stuff transaction
            ObservationValue(author=request.user,
                             component=bmiComponent,
                             effective_datetime=effective_datetime,
                             value_quantity=bmiValue).save()
            # Save log
            summary = "A value of <b>{0}</b> was added for <b>{1}</b>".format(
                bmiValue, bmiComponent.observation.name)
            op_add_event(request.user, value.component.observation.subject,
                         summary)

        # Save log
        summary = "A value of <b>{0}</b> was added for <b>{1}</b>".format(
            value.value_quantity, value.component.observation.name)
        op_add_event(request.user, value.component.observation.subject,
                     summary)

        resp['value'] = ObservationValueSerializer(value).data
        resp['success'] = True

    return ajax_response(resp)