예제 #1
0
def get_matchdvsform(request, dvs_id):
    """
    Returns the form elements string of FHDataElementForm
    given a data value set id
    """
    context = RequestContext(request)
    form = FHDataElementForm(request.GET)
    form.set_data_elements_choices(dvs_id)
    dvs = DataValueSet.objects.get(pk=dvs_id)
    form.set_fh_fields(dvs.service)
    context.form = form
    return  render_to_response("dvs-to-elements-form.html", context_instance=context)
예제 #2
0
def match_datavalueset_to_data_elements(request):
    context = RequestContext(request)
    form = FHDataElementForm()
    context.fde_list = None
    if request.method == 'POST':
        form = FHDataElementForm(request.POST)
        dvs = DataValueSet.objects.get(pk=int(request.POST['dvs']))
        form.set_fh_fields(dvs.service)
        if form.is_valid():
            # form.save()
            de = DataElement.objects.get(pk=form.cleaned_data['data_elements'])
            try:
                fde = FormDataElement()
                fde.data_value_set = dvs
                fde.form_field = form.cleaned_data['fh_fields']
                fde.data_element = de
                fde.save()
            except IntegrityError:
                context.success = False
                context.msg = _(u"Match already saved.")
            else:
                context.success = True
                context.msg = _(u"Successfully saved.")
        else:
            context.success = False
            context.msg = _(u"Failed to save.")
        context.fde_list = list(FormDataElement.objects\
                        .filter(data_value_set=dvs)\
                        .values('data_value_set', 
                                'data_element__name', 'form_field'))
        if request.is_ajax():
            response = {'success': context.success, 'msg': context.msg,
                        'fde_list': context.fde_list}
            return HttpResponse(json.dumps(response))
    context.form = form
    return render_to_response("dvs-to-elements.html", context_instance=context)