def set_form(patient_id,search_text):
    forward_args = request.args.to_dict(flat=False)
    forward_args['_format'] = 'json'
    forwarded_url =  'Patient' + '/' + patient_id
    #api_url = '/neprivacy/%s?%s'% (forwarded_url, urlencode(forward_args, doseq=True))
    api_url='/%s?%s'% (forwarded_url, urlencode(forward_args, doseq=True))
    api_resp = api_call(api_url)
    json_file = api_resp.json()
    #json_file is the user info we get from the server

    cross_loc = TextFilter(patient_id,search_text)

    # First scan the observation data to locate specific observation result
    cross_loc.get_observation_list()

    #Then to locate the genetic info(i.e. Sequence Resource) in the data base
    #cross_loc.observation_prune()
    cross_loc.get_genetic_info()
    print cross_loc.filtered_Observation
    patient_info_form,patient_info_class,observed,sequence = init_setting(json_file,cross_loc.filtered_Observation, cross_loc.correlated_genetic)
    #with the json file we now get from and class

    if patient_info_form.validate_on_submit():
        print observed
        patient_private,ob_private,seq_private =  pe.get_private_profile(patient_info_form,patient_info_class,observed,sequence,json_file)
        # now we get the private profile
        #print type(private_profile)
        #if 'id' in private_profile:
        #    private_profile['resourceID'] = private_profile['id']
        #    del private_profile['id']


        '''
        resp = requests.put('%s/%s' %(PRIVACY_BASE,patient_private['resourceID']), data=json.dumps(patient_private), headers={'Content-Type': 'application/json'})
        for ob in cross_loc.filtered_Observation:
            ob_private['resourceID']=ob['id']
            resp_ob = requests.put('%s/%s' %(PRIVACY_BASE,ob_private['resourceID']), data=json.dumps(ob_private), headers={'Content-Type': 'application/json'})
            if resp_ob.status_code == 404:
                return STATUS_ERROR
        resp_ob = requests.put('%s/%s' %(PRIVACY_BASE,ob_private['resourceID']), data=json.dumps(ob_private), headers={'Content-Type': 'application/json'})

        for seq in seq_private:
            resp_seq = requests.put('%s/%s' %(PRIVACY_BASE,seq['resourceID']), data=json.dumps(seq), headers={'Content-Type': 'application/json'})
            if resp_seq.status_code ==404:
                return STATUS_ERROR

        if resp.status_code == 404 :
            return STATUS_ERROR
        else:
        '''
        return json.dumps(ob_private,indent=4);
            #return render_template('temp.html',result = {"Patient":resp.json(), "Observation": resp_ob.json(), "Sequence": resp_seq.json()})
            #return redirect('/doctor')
    return render_template('rebuild_set.html',form = patient_info_form,patient_info = patient_info_class,observation=observed,sequences= sequence)
def test(patient_id):
    cross_loc = TextFilter(patient_id,'Lung cancer')

    # First scan the observation data to locate specific observation result
    cross_loc.get_observation_list()

    #Then to locate the genetic info(i.e. Sequence Resource) in the data base
    cross_loc.observation_prune()
    cross_loc.get_genetic_info()
    bundle = {
            'resourceType': 'searchset',
            'entry': [],
            'is_single_resource': False
    }
    for v in cross_loc.filtered_Observation:
        bundle['entry'].append({'resource':v})
    print cross_loc.seq_id
    for v in cross_loc.correlated_genetic:
        bundle['entry'].append({'resource':v})
    #print cross_loc.correlated_genetic


    return json.dumps(bundle,indent =4 )
Exemple #3
0
 def __init__(self, **kwargs):
     self.fast = kwargs.get('fast', self.fast)
     self.re_pattern = re.compile(self.generic_pw_pattern)
     self.filter = TextFilter()
def doctor():
    form = set_query_form()
    if form.validate_on_submit():
        keys = tp.extend_option(form)
        #get the keys the doctor selected

        forward_args = request.args.to_dict(flat=False)
        forward_args['_format'] = 'json'
        forwarded_url =  'Patient' + '/' + form.identifier.data
        api_url = '/%s?%s'% (forwarded_url, urlencode(forward_args, doseq=True))
        api_resp = api_call(api_url)
        #print api_resp._content
        raw_patient_file = json.dumps(api_resp.json())
        resp = requests.get('%s/%s' %(PRIVACY_BASE,form.identifier.data), headers={'Content-Type': 'application/json'})
        private_profile = json.loads(json.dumps(resp.json()))
        try:
            private_policy=[]
            for k,v in private_profile['Resource'].items():
                private_policy.append(v)
        except:
            private_policy=[{"Policy":"Nope","Policy_ResourceType":"NULL"}]


        cross_loc = TextFilter(form.identifier.data, form.disease.data)

        # First scan the observation data to locate specific observation result
        cross_loc.get_observation_list()

        #Then to locate the genetic info(i.e. Sequence Resource) in the data base
        cross_loc.observation_prune()
        cross_loc.get_genetic_info()

        #print raw_patient_file
        #print cross_loc.filtered_Observation
        #print cross_loc.correlated_genetic
        #print private_profile
        #if resp.status_code == 404:
        #    return STATUS_ERROR
        #json_data = pe.retrive_patient_info(keys,private_profile,raw_json_file);
        #print cross_loc.filtered_Observation[0]

        #private_policy = json.dumps(private_policy)
        '''
        try:
            patient, observation, sequence = pe.retrive_patient_info(keys, private_policy, raw_patient_file, cross_loc.filtered_Observation[0] ,cross_loc.correlated_genetic)
        except:
            patient, observation, sequence = pe.retrive_patient_info(keys, private_policy, raw_patient_file, json.dumps({"message": "No result"}), cross_loc.correlated_genetic)
        '''
        #get the masked user info
        #query_dict  = json.loads(json_data)

        #token needed, but now I don't konw how to get it
        #user's id still in form.identifier.data

        '''
        return render_template('query_result.html',
                          token= 'Found',
                          json = json.dumps(query_dict,indent=4))
        '''
        #patient = json.loads(patient)
        #print json.dumps(patient)
        #print json.dumps(observation,indent= 4)
        #print json.dumps(sequence,indent= 4)
        print json.dumps(private_policy, indent= 4)

        if(len(cross_loc.filtered_Observation)>0):
            for observation in cross_loc.filtered_Observation:
                resp = requests.get('%s/%s' %(PRIVACY_BASE,observation['id']), headers={'Content-Type': 'application/json'})
                private_profile = json.loads(json.dumps(resp.json()))
                print private_profile
                try:
                    for k,v in private_profile['Resource'].items():
                        private_policy.append(v)
                except:
                    pass
            for seq in cross_loc.correlated_genetic:
                resp = requests.get('%s/%s' %(PRIVACY_BASE,seq['id']), headers={'Content-Type': 'application/json'})
                private_profile = json.loads(json.dumps(resp.json()))
                try:
                    for k,v in private_profile['Resource'].items():
                        private_policy.append(v)
                except:
                    pass
            patient, observation,sequences = pe.display(keys, private_policy, raw_patient_file, cross_loc.filtered_Observation ,cross_loc.correlated_genetic)

        else:
            patient, observation,sequences =  pe.display(keys, private_policy, raw_patient_file, [], cross_loc.correlated_genetic)


        #patient,observation = pe.display(selected_keys, private_profile, raw_json_patient,raw_ob,raw_seq)
        return render_template('rebuild_show.html',patient_info = patient,observation = observation,sequences = sequences)


        #return redirect('/patient_test/%s' % (form.identifier.data))

    return render_template('submit.html',
                           form=form)