Beispiel #1
0
def fetch_phenotips_pdf_page(request, eid):
    """
    A proxy for phenotips view and edit patient pages
    Notes:
        - Exempting csrf here since phenotips doesn't have this support
        - Each call to this endpoint is atomic, no session information is kept
          between calls. Each call to this is from within a new Frame, hence no
          notion of session is kept. Each is a new login into PhenoTips.
    """
    try:
        current_user = request.user
        project_id = request.GET['project']
        uname, pwd = get_uname_pwd_for_project(project_id, read_only=True)
        patient_id = get_phenotips_internal_id(eid, project_id)
        auth_level = get_auth_level(project_id, request.user)
        if auth_level == 'unauthorized':
            raise PermissionDenied

        url = settings.PHENOPTIPS_BASE_URL + '/bin/export/data/' + patient_id + '?format=pdf&pdfcover=0&pdftoc=0&pdftemplate=PhenoTips.PatientSheetCode'
        response, curr_session = do_authenticated_call_to_phenotips(
            url, uname, pwd)
        http_response = HttpResponse(response.content)
        for header in response.headers.keys():
            if header != 'connection' and header != 'Transfer-Encoding':  # these hop-by-hop headers are not allowed by Django
                http_response[header] = response.headers[header]
        return http_response
    except Exception as e:
        print e
        raise Http404
Beispiel #2
0
def fetch_phenotips_pdf_page(request, eid):
    """
    A proxy for phenotips view and edit patient pages
    Notes:
        - Exempting csrf here since phenotips doesn't have this support
        - Each call to this endpoint is atomic, no session information is kept
          between calls. Each call to this is from within a new Frame, hence no
          notion of session is kept. Each is a new login into PhenoTips.
    """
    try:
        current_user = request.user
        project_id = request.GET['project']
        uname, pwd = get_uname_pwd_for_project(project_id, read_only=True)
        patient_id = get_phenotips_internal_id(eid, project_id)
        auth_level = get_auth_level(project_id, request.user)
        if auth_level == 'unauthorized':
            raise PermissionDenied

        url = settings.PHENOPTIPS_BASE_URL + '/bin/export/data/' + patient_id + '?format=pdf&pdfcover=0&pdftoc=0&pdftemplate=PhenoTips.PatientSheetCode'
        response, curr_session = do_authenticated_call_to_phenotips(url, uname, pwd)
        http_response = HttpResponse(response.content)
        for header in response.headers.keys():
            if header != 'connection' and header != 'Transfer-Encoding':  # these hop-by-hop headers are not allowed by Django
                http_response[header] = response.headers[header]
        return http_response
    except Exception as e:
        print e
        raise Http404
Beispiel #3
0
def fetch_phenotips_edit_page(request, eid):
    """
    A proxy for phenotips view and edit patient pages
    Note: exempting csrf here since phenotips doesn't have this support
    """
    try:
        current_user = request.user
        # if projectID key is found in in GET, it is the first connection call from browser
        if request.GET.has_key('project'):
            # adding project id and patient_id to session for later use in proxying
            project_id = request.GET['project']
            request.session['current_project_id'] = project_id
            patient_id = get_phenotips_internal_id(eid, project_id)
            request.session['current_patient_id'] = patient_id
            auth_level = get_auth_level(project_id, request.user)
            if auth_level == 'unauthorized':
                raise PermissionDenied

            if auth_level == 'admin':
                phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(
                    project_id, read_only=False)
            else:
                phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(
                    project_id, read_only=True)
            url = settings.PHENOPTIPS_BASE_URL + '/bin/' + patient_id
            if auth_level == 'admin':
                url = settings.PHENOPTIPS_BASE_URL + '/bin/edit/data/' + patient_id
            response, curr_session = do_authenticated_call_to_phenotips(
                url, phenotips_uname, phenotips_pwd)
            # save this session with PhenoTips in current seqr session to be used within it to prevent
            # re-authenticating
            request.session['current_phenotips_session'] = pickle.dumps(
                curr_session)
            http_response = HttpResponse(response.content)
            for header in response.headers.keys():
                http_response[header] = response.headers[header]
            return http_response

        # this is a subsequent call made during the opening of the frame by phenotips
        # and will use session info for required variables
        else:
            project_id = request.session['current_project_id']
            patient_id = request.session['current_patient_id']
            auth_level = get_auth_level(request.session['current_project_id'],
                                        request.user)
            if auth_level == 'unauthorized':
                raise PermissionDenied

        if auth_level == 'admin':
            phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(
                project_id, read_only=False)
        else:
            phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(
                project_id, read_only=True)
        url = settings.PHENOPTIPS_BASE_URL + '/bin/' + patient_id
        if auth_level == 'admin':
            url = settings.PHENOPTIPS_BASE_URL + '/bin/edit/data/' + patient_id
        if not request.GET.has_key('project'):
            url += '?'
            counter = 0
            for param, val in request.GET.iteritems():
                url += param + '=' + val
                if counter < len(request.GET) - 1:
                    url += '&'
                counter += 1

        # pedigree editor is special
        if 'sheet' in request.GET.keys():
            url += '#'

        # get back a session and a result
        curr_session = pickle.loads(
            request.session['current_phenotips_session'])
        response, _ = do_authenticated_call_to_phenotips(
            url, phenotips_uname, phenotips_pwd, curr_session)
        http_response = HttpResponse(response.content)
        for header in response.headers.keys():
            http_response[header] = response.headers[header]
        return http_response
    except Exception as e:
        print e
        raise Http404
Beispiel #4
0
def fetch_phenotips_edit_page(request, eid):
    """
    A proxy for phenotips view and edit patient pages
    Note: exempting csrf here since phenotips doesn't have this support
    """
    try:
        current_user = request.user
        # if projectID key is found in in GET, it is the first connection call from browser
        if request.GET.has_key('project'):
            # adding project id and patient_id to session for later use in proxying
            project_id = request.GET['project']
            request.session['current_project_id'] = project_id
            patient_id = get_phenotips_internal_id(eid, project_id)
            request.session['current_patient_id'] = patient_id
            auth_level = get_auth_level(project_id, request.user)
            if auth_level == 'unauthorized':
                raise PermissionDenied

            if auth_level == 'admin':
                phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(project_id, read_only=False)
            else:
                phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(project_id, read_only=True)
            url = settings.PHENOPTIPS_BASE_URL + '/bin/' + patient_id
            if auth_level == 'admin':
                url = settings.PHENOPTIPS_BASE_URL + '/bin/edit/data/' + patient_id
            response, curr_session = do_authenticated_call_to_phenotips(url, phenotips_uname, phenotips_pwd)
            # save this session with PhenoTips in current seqr session to be used within it to prevent
            # re-authenticating
            request.session['current_phenotips_session'] = pickle.dumps(curr_session)
            http_response = HttpResponse(response.content)
            for header in response.headers.keys():
                http_response[header] = response.headers[header]
            return http_response

        # this is a subsequent call made during the opening of the frame by phenotips
        # and will use session info for required variables
        else:
            project_id = request.session['current_project_id']
            patient_id = request.session['current_patient_id']
            auth_level = get_auth_level(request.session['current_project_id'], request.user)
            if auth_level == 'unauthorized':
                raise PermissionDenied

        if auth_level == 'admin':
            phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(project_id, read_only=False)
        else:
            phenotips_uname, phenotips_pwd = get_uname_pwd_for_project(project_id, read_only=True)
        url = settings.PHENOPTIPS_BASE_URL + '/bin/' + patient_id
        if auth_level == 'admin':
            url = settings.PHENOPTIPS_BASE_URL + '/bin/edit/data/' + patient_id
        if not request.GET.has_key('project'):
            url += '?'
            counter = 0
            for param, val in request.GET.iteritems():
                url += param + '=' + val
                if counter < len(request.GET) - 1:
                    url += '&'
                counter += 1

        # pedigree editor is special
        if 'sheet' in request.GET.keys():
            url += '#'

        # get back a session and a result
        curr_session = pickle.loads(request.session['current_phenotips_session'])
        response, _ = do_authenticated_call_to_phenotips(url, phenotips_uname, phenotips_pwd, curr_session)
        http_response = HttpResponse(response.content)
        for header in response.headers.keys():
            http_response[header] = response.headers[header]
        return http_response
    except Exception as e:
        print e
        raise Http404