def identity_from_jsonObject(jsonObj):
     n = jsonObj.get('name')
     des = jsonObj.get('description')
     u = jsonObj.get('url')
     lm = RequestBase.dateTimeFromJsonString(jsonObj.get('modified'))
     c = RequestBase.dateTimeFromJsonString(jsonObj.get('created'))
     id = int(jsonObj.get('id'))
     return ExternalSystem(name=n, description=des, url=u, modified=lm, created=c, id=id)
 def identity_from_jsonObject(jsonObj):
     n = jsonObj.get('name')
     des = jsonObj.get('description')
     lm = RequestBase.dateTimeFromJsonString(jsonObj.get('modified'))
     c = RequestBase.dateTimeFromJsonString(jsonObj.get('created'))
     gid = int(jsonObj.get('id'))
     il = jsonObj.get('is_locking', False)
     ek = jsonObj.get('ehb_key')
     ck = None
     return Group(name=n, description=des, is_locking=il, ehb_key=ek,
                  client_key=ck, modified=lm, created=c, id=gid)
 def identity_from_jsonObject(jsonObj):
     fn = jsonObj.get('first_name')
     ln = jsonObj.get('last_name')
     org_id = int(jsonObj.get('organization'))
     org_subj_id = jsonObj.get('organization_subject_id')
     org_id_label = jsonObj.get('organization_id_label')
     dob = RequestBase.dateFromString(jsonObj.get('dob'))
     lm = RequestBase.dateTimeFromJsonString(jsonObj.get('modified'))
     c = RequestBase.dateTimeFromJsonString(jsonObj.get('created'))
     id = int(jsonObj.get('id'))
     sub = Subject(first_name=fn, last_name=ln, organization_id=org_id,
                   organization_subject_id=org_subj_id,
                   organization_id_label=org_id_label, dob=dob,
                   modified=lm, created=c, id=id)
     return sub
 def identity_from_jsonObject(jsonObj):
     es_id = int(jsonObj.get('external_system'))
     s_id = int(jsonObj.get('subject'))
     lm = RequestBase.dateTimeFromJsonString(jsonObj.get('modified'))
     c = RequestBase.dateTimeFromJsonString(jsonObj.get('created'))
     id = int(jsonObj.get('id'))
     rec_id = jsonObj.get('record_id')
     p = jsonObj.get('path')
     lbl = jsonObj.get('label')
     return ExternalRecord(
         record_id=rec_id,
         external_system_id=es_id,
         subject_id=s_id,
         path=p,
         modified=lm,
         created=c,
         id=id,
         label_id=lbl
     )
    def json_from_identity(subject):
        if not hasattr(subject, 'group_name'):
            subject.group_name = ''
        o = {}
        o = {
            'first_name': subject.first_name,
            'last_name': subject.last_name,
            'group_name': subject.group_name,
            'organization_subject_id': subject.organization_subject_id,
            'organization': subject.organization_id,
            'organization_id_label': subject.organization_id_label,
            'dob': RequestBase.stringFromDate(subject.dob),
            'id': subject.id
        }

        if subject.modified:
            o['modified'] = subject.modified.strftime('%Y-%m-%d %H:%M:%S.%f')
        if subject.created:
            o['created'] = subject.created.strftime('%Y-%m-%d %H:%M:%S.%f')

        return json.dumps(o)
 def __init__(self, host, root_path='', secure=False, api_key=None):
     RequestBase.__init__(self, host, '{0}/api/group/'.format(root_path), secure, api_key)
 def onSuccess(g, o):
     g.current_client_key(g.client_key)
     g.modified = RequestBase.dateTimeFromJsonString(o.get('modified'))
 def onSuccess(grp, o):
     grp.id = int(o.get('id'))
     grp.created = RequestBase.dateTimeFromJsonString(o.get('created'))
     grp.modified = RequestBase.dateTimeFromJsonString(o.get('modified'))
     grp.ehb_key = o.get('ehb_key')
 def onSuccess(s, o):
     s.modified = RequestBase.dateTimeFromJsonString(o.get('modified'))
 def onSuccess(s, o):
     s.id = int(o.get('id'))
     s.created = RequestBase.dateTimeFromJsonString(o.get('created'))
     s.modified = RequestBase.dateTimeFromJsonString(o.get('modified'))
Exemple #11
0
def edit_subject(request, protocol_id, subject_ehb_id):
    '''
    renders / processes a subject edit form to update subject phi in ehb system
    '''
    try:
        protocol = Protocol.objects.get(pk=protocol_id)
        # is this user authorized for this protocol? A user could accidently /
        # maliciously manually enter the URL for an unauthorized protocol
        if not protocol.isUserAuthorized(request.user):
            return forbidden(request)
        organizations = protocol.organizations.all()
        s_rh = ServiceClient.get_rh_for(record_type=ServiceClient.SUBJECT)

        msg = None

        try:
            subject = s_rh.get(id=subject_ehb_id)
            '''
            Is this subject on this protocol? A user could accidently /
            maliciously manually enter the URL a protocol they are authorized
            on but for which the subject is not on OR the link could be stale
            because the ehb primary key is used to ask for this subject record.
            this key is NOT stored in this app's DB. Rather it is dynamically
            added to the link in the subject select page. There is the unlikely
            chance that the link becomes stale between the time it is rendered
            and the time it is clicked. Hence, a second check is done to make
            sure this subject is on this protocol. This check done without
            reference to the ehb's primary key values
            '''
            if not protocol.isSubjectOnProtocol(subject):
                raise Http404
        except PageNotFound:
            raise Http404

        if request.method == 'POST':
            # process the form
            form = EditSubjectForm(request.POST)
            if form.is_valid():
                success, subject, errors = form.save(subject=subject,
                                                     protocol=protocol)
                if success:
                    cache.delete('{0}_subjects'.format(protocol.id))
                    return HttpResponseRedirect(
                        '%s/dataentry/protocol/%s/' %
                        (ServiceClient.self_root_path, protocol_id))
                else:
                    msg = []
                    selected_organization = form.selectedOrg()
                    for error in errors:
                        if error == ErrorConstants.ERROR_SUBJECT_ORG_ID_EXISTS:
                            l = Organization.objects.get(
                                pk=int(selected_organization)).subject_id_label
                            msg.append(
                                'A Subject record with this %s is already in the ehb-service system.'
                                % l)
                        else:
                            msg.append(error)
            else:
                selected_organization = form.selectedOrg()
        else:
            # render new form for this subject
            context = {
                'subject_id': str(subject.organization_subject_id),
                'subject_id_verify': str(subject.organization_subject_id),
                'first_name': subject.first_name,
                'last_name': subject.last_name,
                'dob': RequestBase.stringFromDate(subject.dob)
            }
            form = EditSubjectForm(context)
            o_rh = ServiceClient.get_rh_for(
                record_type=ServiceClient.ORGANIZATION)
            selected_organization = '0'
            try:
                org = o_rh.get(id=subject.organization_id)
                for o in organizations:
                    if o.name == org.name:
                        selected_organization = str(o.id)
            except PageNotFound:
                raise Http404

        return render_to_response('subject_edit.html', {
            'errors': msg,
            'form': form,
            'selected_organization': selected_organization,
            'protocol': protocol,
            'organizations': organizations,
            'subject': subject,
            'root_path': ServiceClient.self_root_path,
            'redcap_status': getRedcapStatus()
        },
                                  context_instance=RequestContext(request))

    except Protocol.DoesNotExist:
        raise Http404
 def __init__(self, host, root_path='', secure=False, api_key=None):
     RequestBase.__init__(self, host, '{0}/api/externalrecord/'.format(root_path), secure, api_key)
     self.root_path = root_path
 def onSuccess(er, o):
     er.id = int(o.get('id'))
     er.created = RequestBase.dateTimeFromJsonString(o.get('created'))
     er.modified = RequestBase.dateTimeFromJsonString(o.get('modified'))