Пример #1
0
def cover_protected_data(data_list, resource, patient_id, status='full'):
    '''
    data_list : sometimes we don't wanna display all part of this resource, this list will tell us which to display,a list
        resource : json data that wanna to display, the format is dict
    patient_id : extract identifier of policy_list
    '''
    privacy_policy = db.select_policy(patient_id)

    if (privacy_policy == -2):
        #No record in the database
        return resource

    policy_data = jd.json2list(privacy_policy, RESERVED_WORD)

    if type(data_list) is dict:
        jd.json_reduce_structure(data_list)
        data_list = jd.json2list(data_list, RESERVED_WORD)

    if isinstance(resource['resourceType'], unicode):
        s = resource['resourceType']
    else:
        s = unicode(resource['resourceType'], "utf-8")

    jd.json_reduce_structure(resource)
    resource_data = jd.json2list(resource, RESERVED_WORD)

    for i in range(len(resource_data)):
        resource_data[i].insert(0, s)

    data = data_list

    for i in range(len(data)):
        data[i].insert(0, s)

    #If the query is only part of data,then do the intersection
    for i in range(len(data)):
        if data[i][1] == 'text' or data[i][1] == 'resourceType':
            continue

        tmp = retrieve(data[i], resource_data)
        if tmp[0] == 'Not_Found':
            data[i][-1] = 'Not in the online record'
        else:
            data[i][-1] = tmp[1]

    for i in range(len(data)):
        if data[i][1] == 'text' or data[i][1] == 'resourceType':
            continue
        tmp = retrieve(data[i], policy_data)
        # Not found or unmasked means we should not change the value
        if tmp[0] == 'Mask':
            # Here we need to filter the policy
            data[i][-1] = 'Protected data due to privacy policy'

    for i in range(len(data)):
        del data[i][0]

    result = jd.list2json(data, RESERVED_WORD)
    return result
Пример #2
0
def cover_protected_data(data_list, resource, patient_id, status='full'):
    '''
    data_list : sometimes we don't wanna display all part of this resource, this list will tell us which to display,a list
        resource : json data that wanna to display, the format is dict
    patient_id : extract identifier of policy_list
    '''
    privacy_policy = db.select_policy(patient_id)

    if (privacy_policy == -2):
        #No record in the database
        return resource

    policy_data = jd.json2list(privacy_policy,RESERVED_WORD)

    if type(data_list) is dict:
        jd.json_reduce_structure(data_list)
        data_list = jd.json2list(data_list, RESERVED_WORD)

    if isinstance(resource['resourceType'], unicode):
        s=resource['resourceType']
    else:
        s=unicode(resource['resourceType'],"utf-8")

    jd.json_reduce_structure(resource)
    resource_data = jd.json2list(resource,RESERVED_WORD)

    for i in range(len(resource_data)):
        resource_data[i].insert(0,s)

    data = data_list

    for i in range(len(data)):
        data[i].insert(0,s)
    
    #If the query is only part of data,then do the intersection
    for i in range(len(data)):
        if data[i][1] == 'text' or data[i][1] == 'resourceType':
            continue

        tmp = retrieve(data[i],resource_data)
        if tmp[0] == 'Not_Found':
            data[i][-1] = 'Not in the online record'
        else:
            data[i][-1] = tmp[1]

    for i in range(len(data)):
        if data[i][1]=='text' or data[i][1]=='resourceType':
            continue
        tmp = retrieve(data[i],policy_data)
        # Not found or unmasked means we should not change the value
        if tmp[0] == 'Mask':
            # Here we need to filter the policy
            data[i][-1] = 'Protected data due to privacy policy'

    for i in range(len(data)):
        del data[i][0]

    result = jd.list2json(data,RESERVED_WORD)
    return result
Пример #3
0
def get_list_and_class(json_file, reserved_word):
    li = jd.json2list(json_file,reserved_word)
    output = get_struct(li,reserved_word)

    if output.value:
        map(lambda x:x.init_type(reserved_word),output.value)

    map(lambda x:x.set_level(0),output.value)

    num = 0
    for item in output.value:
        num = item.dfs(num)


    templist = []
    for item in output.value:
        item.set_list(templist)

    class_list = []
    for item in output.value:
        class_list.append(item)
        item.append_to_list(class_list,False)



    return li,class_list
Пример #4
0
def strcture_json(json_file,reserved_word,fieldname):
    li = jd.json2list(json_file,reserved_word)
    output = get_struct(li,reserved_word)

    if output.value:
        map(lambda x:x.init_type(reserved_word),output.value)
        map(lambda x:x.init_attr(),output.value)

    map(lambda x:x.set_level(0),output.value)


    num = 0
    for item in output.value:
        num = item.dfs(num)



    class_list = []
    for item in output.value:
        class_list.append(item)
        item.append_to_list(class_list)

    dict_temp = []
    for item in class_list:
        dict_temp.append([item.get_key(),item])


    class_dict = dict((key,value) for key, value in dict_temp)


    class_list[len(class_list)-1].set_succ(-1)
    for i in range(0,len(class_list)-1):
        class_list[i].set_succ(class_list[i+1].get_level())


    class_list[0].set_pred(-1)
    for i in range(1,len(class_list)):
        class_list[i].set_pred(class_list[i-1].get_level())



    for i in range(len(class_list)):
        fieldkey=  fieldname+str(class_list[i].get_seq())
        setattr(private_Form,fieldkey,BooleanField(fieldkey,default=False))



    form = private_Form()

   # for item in class_list:
   #    print '\t'*item.get_level()+item.get_key()

   # for item in class_list:
   #     print str(item.get_level())+'\t'+str(item.get_pred())




    return class_list,class_dict,form
Пример #5
0
def list_extension (json_data):
    #Extend resource type into json_list module
    data = jd.json2list(json_data,RESERVED_WORD)
    if isinstance(json_data['resourceType'], unicode):
        s=json_data['resourceType']
    else:
        s=unicode(json_data['resourceType'],"utf-8")
    for i in range(len(data)):
        data[i].insert(0,s)
    return json.dumps(jd.list2json(json_data,RESERVED_WORD),separators=(',',':'))
Пример #6
0
def list_extension(json_data):
    #Extend resource type into json_list module
    data = jd.json2list(json_data, RESERVED_WORD)
    if isinstance(json_data['resourceType'], unicode):
        s = json_data['resourceType']
    else:
        s = unicode(json_data['resourceType'], "utf-8")
    for i in range(len(data)):
        data[i].insert(0, s)
    return json.dumps(jd.list2json(json_data, RESERVED_WORD),
                      separators=(',', ':'))
Пример #7
0
def query_info(data_list, patient_id):
    '''
    data_list is a json_list(need to be extended)
    Now we only support single type data
        This is the query port to ask for specific sequence from remote server
     And , add filter policy
    '''
    # Now time to ask for patient's data
    resource = search_request_patient(patient_id)

    if resource == 'Http_403_error':
        return 'Not_Found', {}

    data_list = jd.form2list(data_list, jd.formtable,
                             jd.json2list(resource, RESERVED_WORD))
    #print json.dumps(jd.list2json(data_list,RESERVED_WORD),indent=4)
    #data_list = jd.list2json(data_list, RESERVED_WORD)
    #if data_list is None or data_list['resourceType'] is None:
    #Catch_dataError()
    #return 'Not_Found',data_list
    return 'Found', cover_protected_data(data_list, resource, patient_id,
                                         'cap')
Пример #8
0
def query_info (data_list, patient_id):
    '''
    data_list is a json_list(need to be extended)
    Now we only support single type data
        This is the query port to ask for specific sequence from remote server
     And , add filter policy
    '''
    # Now time to ask for patient's data
    resource = search_request_patient(patient_id)

    if resource == 'Http_403_error' :
        return 'Not_Found',{}

    data_list = jd.form2list(data_list, jd.formtable, jd.json2list(resource, RESERVED_WORD))
    #print json.dumps(jd.list2json(data_list,RESERVED_WORD),indent=4)
    #data_list = jd.list2json(data_list, RESERVED_WORD)
    #if data_list is None or data_list['resourceType'] is None:
    #Catch_dataError()
    #return 'Not_Found',data_list
    return 'Found',cover_protected_data(
            data_list,
            resource,
            patient_id,
            'cap')
Пример #9
0
    def get_observation_list(self):

        self.filtered_Observation=[]
        self.seq_id=[]
        for x in range(0,901,50):
            resource_type = 'Observation'
            forward_args = request.args.to_dict(flat=False)
            forward_args['_format'] = 'json'
            forward_args['_offset'] = str(x)
            forwarded_url =  resource_type
            api_url = '/%s?%s'% (forwarded_url, urlencode(forward_args, doseq=True))
            print api_url
            resp = api_call(api_url)
            bundle =resp.json();
            if ('type' in bundle and bundle['type'] != 'searchset') or ('resourceType' in bundle and bundle['resourceType']!='Bundle'):
                resource = bundle
                bundle = {
                'resourceType': resource['resourceType'],
                'entry': [{
                    'resource': resource,
                    'id': forwarded_url
                }],
                'is_single_resource': True,
            }
            elif len(bundle.get('entry', [])) > 0:
                bundle['resourceType'] = bundle['entry'][0]['resource']['resourceType']


            k=1;

            for i in range(len(bundle['entry'])):
                resource = bundle['entry'][i]['resource']
                #print resource
                try:
                    resource_subject = resource['subject']['reference'].split('/')[-1]
                except:
                    resource_subject = "Not want to be seen"
                #print resource['id'],resource_subject
                #print json.dumps(resource , indent= 2)
                #print resource_subject
                if resource_subject == self.patient_id:
                    if(self.search_text=='*'):
                        self.filtered_Observation.append(resource)
                        #print self.filtered_Observation
                        self.add_locale_info(resource)
                        k+=1
                    else:
                        list_resource = json2list(resource,'FindText')
                        #print list_resource
                        flag= False;
                        for list in list_resource:
                            try:
                                #print list
                                if((list[-3]=='text' or list[-2]=='text') and (list[-1]==self.search_text or self.search_text in list[-1])):
                                    flag= True;
                                    break;
                            except:
                                pass
                        if(flag):
                            #print type(resource)
                            #print "here\n\n\n"
                            self.filtered_Observation.append(resource)
                            self.add_locale_info(resource)
                            k+=1
Пример #10
0
    def get_observation_list(self):

        self.filtered_Observation = []
        self.seq_id = []
        for x in range(0, 901, 50):
            resource_type = 'Observation'
            forward_args = request.args.to_dict(flat=False)
            forward_args['_format'] = 'json'
            forward_args['_offset'] = str(x)
            forwarded_url = resource_type
            api_url = '/%s?%s' % (forwarded_url,
                                  urlencode(forward_args, doseq=True))
            print api_url
            resp = api_call(api_url)
            bundle = resp.json()
            if ('type' in bundle and bundle['type'] != 'searchset') or (
                    'resourceType' in bundle
                    and bundle['resourceType'] != 'Bundle'):
                resource = bundle
                bundle = {
                    'resourceType': resource['resourceType'],
                    'entry': [{
                        'resource': resource,
                        'id': forwarded_url
                    }],
                    'is_single_resource': True,
                }
            elif len(bundle.get('entry', [])) > 0:
                bundle['resourceType'] = bundle['entry'][0]['resource'][
                    'resourceType']

            k = 1

            for i in range(len(bundle['entry'])):
                resource = bundle['entry'][i]['resource']
                #print resource
                try:
                    resource_subject = resource['subject']['reference'].split(
                        '/')[-1]
                except:
                    resource_subject = "Not want to be seen"
                #print resource['id'],resource_subject
                #print json.dumps(resource , indent= 2)
                #print resource_subject
                if resource_subject == self.patient_id:
                    if (self.search_text == '*'):
                        self.filtered_Observation.append(resource)
                        #print self.filtered_Observation
                        self.add_locale_info(resource)
                        k += 1
                    else:
                        list_resource = json2list(resource, 'FindText')
                        #print list_resource
                        flag = False
                        for list in list_resource:
                            try:
                                #print list
                                if ((list[-3] == 'text' or list[-2] == 'text')
                                        and (list[-1] == self.search_text
                                             or self.search_text in list[-1])):
                                    flag = True
                                    break
                            except:
                                pass
                        if (flag):
                            #print type(resource)
                            #print "here\n\n\n"
                            self.filtered_Observation.append(resource)
                            self.add_locale_info(resource)
                            k += 1
Пример #11
0
    masked_part = jd.list2json(masked_list,reserved_word)
    print masked_part


    final_file = package(json_file,masked_part)

    print json.dumps(masked_part,indent=4)



reserved_word = 'test'

if __name__ == '__main__':

    e = jp.s
    li = jd.json2list(e,reserved_word)
    output = get_struct(li,reserved_word)
    if output.value:
        map(lambda x:x.init_type(reserved_word),output.value)

    map(lambda x:x.dump(0),output.value)

    map(lambda x:x.set_level(0),output.value)

    num = 0
    for item in output.value:
        num = item.dfs(num)

    #map(lambda x:x.dump_level(), output.value)

    class_list = []