Пример #1
0
def search():
    form = set_query_form()
    if form.validate_on_submit():
        keys = tp.extend_option(form)
        #get the keys the doctor selected

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

    return render_template('orientation.html', form=form)
Пример #2
0
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)