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)
Exemple #2
0
class PWID(object):
    """
    Finds passwords that are characters and digits, and are at least 8 characters long.
    Basic regex also includes special characters except spaces.
    """

    PW_MIN_LENGTH = 8
    PW_MAX_LENGTH = 48

    filter = None
    fast = False

    generic_pw_pattern = '(\w+\d+[\w\d\S]+)|(\d+\w+[\w\d\S]+)'

    # generic_pw_pattern = '([\w\d\S\$]{0,32})'

    def __init__(self, **kwargs):
        self.fast = kwargs.get('fast', self.fast)
        self.re_pattern = re.compile(self.generic_pw_pattern)
        self.filter = TextFilter()

    def identify_passwords(self, str_input):
        matches = self.re_pattern.findall(str_input)

        prepared_matches = []

        for match in matches:
            for item in match:

                passed_filtering = self.filter.apply_filter(item)
                valid_length = self.PW_MIN_LENGTH <= len(
                    item) <= self.PW_MAX_LENGTH

                if item and valid_length and passed_filtering:
                    prepared_matches.append(item)

        logging.info("Filter Score: {}".format(self.filter.aggregate_score))

        score_length_ratio = float(
            self.filter.aggregate_score) / len(str_input)
        logging.info("Score-Length Ratio: {}".format(score_length_ratio))

        self.filter.aggregate_score = 0

        return prepared_matches
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})
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 #5
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)
Exemple #7
0
class PWID(object):
    """
    Finds passwords that are characters and digits, and are at least 8 characters long.
    Basic regex also includes special characters except spaces.
    """

    PW_MIN_LENGTH = 8
    PW_MAX_LENGTH = 48

    MAX_STR_LEN = 1024

    filter = None
    fast = False
    ultra_verbose = True

    MAX_VERBOSE_ANALYSIS = 512

    generic_pw_pattern = '((?=[A-Za-z0-9\@\#\$\%\^\&\+\=\-\!]*?\d)(?=[A-Za-z0-9\@\#\$\%\^\&\+\=\-\!]*?[A-Z])(?=[A-Za-z0-9\@\#\$\%\^\&\+\=\-\!]*?[a-z])[A-Za-z0-9\@\#\$\%\^\&\+\=\-\!]{8,32})([ \n\|:]|$)'

    def __init__(self, **kwargs):
        self.fast = kwargs.get('fast', self.fast)
        self.ultra_verbose = kwargs.get('ultra_verbose', self.ultra_verbose)
        self.re_pattern = re.compile(self.generic_pw_pattern)
        self.filter = TextFilter()

    def identify_passwords(self, str_input):

        self.filter.aggregate_score = 0

        log.debug("Finding matches...")
        matches = self.re_pattern.findall(str_input)
        log.debug("Done")

        prepared_matches = []

        log.debug("Searching Total: %s possible matches..." % len(matches))

        # for match in matches:
        for item, tail in matches:

            passed_filtering = self.filter.apply_filter(item)
            valid_length = self.PW_MIN_LENGTH <= len(
                item) <= self.PW_MAX_LENGTH

            if item and valid_length and passed_filtering:
                prepared_matches.append(item)

        logging.info("Filter Score: {}".format(self.filter.aggregate_score))

        score_length_ratio = float(
            self.filter.aggregate_score) / len(str_input)
        logging.info("Score-Length Ratio: {}".format(score_length_ratio))

        # If ultra-verbose, apply filters to ENTIRE text if something that looks like a password is found
        if self.ultra_verbose and len(prepared_matches) > 0:
            log.info(
                'Using ultra verbose filter on entire text. This will affect aggregate score...'
            )
            self.filter.apply_filter(str_input[:self.MAX_VERBOSE_ANALYSIS])

        return prepared_matches, self.filter.aggregate_score