Ejemplo n.º 1
0
def rpc_load_matched_patient_data(request, patient_id,
                                  questionnaire_response_id):
    """
    Try to return any existing data for a patient corresponding the filled in values
    of a questionnaire filled out by on the questionnaire interface
    NB. The curator is responsible for matching an existing patient to the incoming
    questionnaire data.
    See RDR-1229 for a description of the use case.

    The existing data returned is the existing questionnaire values for this matched patient ( not the data
    provided in the questionnaire response itself - which potentially may overwrite the matched data if
    the curator indicates in the approval GUI.
    """
    from registry.patients.models import Patient
    from rdrf.models.definition.models import QuestionnaireResponse
    from rdrf.workflows.questionnaires.questionnaires import Questionnaire

    questionnaire_response_model = QuestionnaireResponse.objects.get(
        pk=questionnaire_response_id)
    patient_model = Patient.objects.get(pk=patient_id)
    registry_model = questionnaire_response_model.registry
    questionnaire = Questionnaire(registry_model, questionnaire_response_model)
    existing_data = questionnaire.existing_data(patient_model)

    return {
        "link": existing_data.link,
        "name": existing_data.name,
        "questions": existing_data.questions
    }
Ejemplo n.º 2
0
def rpc_update_selected_cdes_from_questionnaire(request, patient_id,
                                                questionnaire_response_id,
                                                questionnaire_checked_ids):
    from registry.patients.models import Patient
    from rdrf.models.definition.models import QuestionnaireResponse
    from rdrf.workflows.questionnaires.questionnaires import Questionnaire
    from django.db import transaction

    questionnaire_response_model = QuestionnaireResponse.objects.get(
        pk=questionnaire_response_id)
    patient_model = Patient.objects.get(pk=patient_id)
    registry_model = questionnaire_response_model.registry
    questionnaire = Questionnaire(registry_model, questionnaire_response_model)
    data_to_update = [
        question for question in questionnaire.questions
        if question.src_id in questionnaire_checked_ids
    ]

    try:
        with transaction.atomic():
            errors = questionnaire.update_patient(patient_model,
                                                  data_to_update)
            if len(errors) > 0:
                raise Exception("Errors occurred during update: %s" %
                                ",".join(errors))
    except Exception as ex:
        logger.error("Update patient failed: rolled back: %s" % ex)
        return {"status": "fail", "message": ",".join(errors)}
    else:
        questionnaire_response_model.processed = True
        questionnaire_response_model.patient_id = patient_model.pk
        questionnaire_response_model.save()
        return {"status": "success", "message": "Patient updated successfully"}
Ejemplo n.º 3
0
def rpc_load_matched_patient_data(request, patient_id,
                                  questionnaire_response_id):
    """
    Try to return any existing data for a patient corresponding the filled in values
    of a questionnaire filled out by on the questionnaire interface
    NB. The curator is responsible for matching an existing patient to the incoming
    questionnaire data.
    See RDR-1229 for a description of the use case.

    The existing data returned is the existing questionnaire values for this matched patient ( not the data
    provided in the questionnaire response itself - which potentially may overwrite the matched data if
    the curator indicates in the approval GUI.
    """
    from registry.patients.models import Patient
    from rdrf.models.definition.models import QuestionnaireResponse
    from rdrf.workflows.questionnaires.questionnaires import Questionnaire
    from django.utils.translation import ugettext as _

    patient_model = Patient.objects.get(pk=patient_id)
    try:
        security_check_user_patient(request.user, patient_model)
    except PermissionDenied:
        return {
            "status": "fail",
            "message": _("Permission error. Data cannot be loaded !")
        }

    questionnaire_response_model = QuestionnaireResponse.objects.get(
        pk=questionnaire_response_id)
    patient_model = Patient.objects.get(pk=patient_id)
    registry_model = questionnaire_response_model.registry
    questionnaire = Questionnaire(registry_model, questionnaire_response_model)
    existing_data = questionnaire.existing_data(patient_model)

    return {
        "link": existing_data.link,
        "name": existing_data.name,
        "questions": existing_data.questions
    }