示例#1
0
def generate_table():
	sql = ('CREATE TABLE `' + db.validate(data[0]) + '` (\n' + 
	'`id` INT NOT NULL AUTO_INCREMENT,\n' +
  	'`patient_id` VARCHAR(12) NULL ,\n')

	for test in data[1:]:
		tmp = test.split(';')
		test_name = db.validate(tmp[0])
		value = get_table_field(tmp[1][0])
		sql = sql + '`' + test_name + '` ' + value + ' NULL , \n'

	sql = sql + ('PRIMARY KEY (`id`))')

	db.execute_sql(sql)
	print '\'' + data[0] + '\' table created'
示例#2
0
def register():
    email = request.form['uname']
    fName = request.form['fname']
    lName = request.form['lname']
    password = request.form['psw']
    passwordConfirm = request.form['psw2']
    # print("request.form['psw']")
    image = request.files['img']

    imageB64 = base64.b64encode(image.read())

    print(imageB64)

    # print("request.files['img']")
    # image.save(secure_filename(image.filename))
    # print("f.save(secure_filename(f.filename))")
    _, code = db.validate(email)
    print(code)
    if code == 200:
        # username conflict
        return jsonify(message="username already registered", code=404)
    elif password != passwordConfirm:
        # password not matching
        return jsonify(message="password do not match", code=201)
    else:
        data = {'password': password, 'fName': fName, 'lName': lName, 'img': imageB64}
        _, chkCode = db.create(email, data)

        if chkCode == 200:

            return jsonify(message="Account created", code=200)
        else:

            return jsonify(message='Database insert error', code=404)
示例#3
0
def push():
    ''' API receives product data, the app processes data and return the mean of that product

        Example to run pushing data on localhost:
            curl -X POST \
          http://localhost:5000/api/push \
          -H 'content-type: application/json' \
          -d '{  "UUID": "a2-b3", "score": 5  }'

        Returns:
            Json : The return value. new mean value of product if success,
                    error json message otherwise
    '''
    req = request.get_json()
    product_id = req['UUID']
    score = req['score']
    validated = db.validate(product_id, score)
    if not validated:
        return ERROR_VALIDATE

    data = db.update_and_get_stat(product_id, score)

    if not data:
        return ERROR_GET_DATA

    res = {'UUID': data[0], 'mean': data[1]}
    return res
示例#4
0
def log_submit():

    print("in submit function")
    obj = json.loads(request.data.decode('utf-8'))
    userName = obj['userName']
    pswd = obj['password']
    print(pswd)
    userCred, code = db.validate(userName)
    # print(userCred)
    userCred = json.loads(userCred)
    print(type(userCred))
    print("print after dp response json " + userCred["password"])
    # print(userCred['password'])
    if 'user' in session:
        print('user already logged in')
        return jsonify(message="user already logged in", code=203)

    if code == 404:
        # data = "{'message': 'not registered', 'code': 404}"
        # json_data = json.dumps(data)
        # print(json_data)
        return jsonify(message='Not a registered user', code=404)
    elif code == 200:
        if userCred["password"] == pswd:
            session['user'] = userName
            # return jsonify(message='/home', code=200)
            print("before /home"+session['user'])
            # add imagestring here in session
            return jsonify(message="/home", code=200)
        else:
            return jsonify(message="Invalid password", code=201)
    else:
        return jsonify(message="Error", code=202)
示例#5
0
	def done(self, button):
		global values
		global index
		global data_entered

		fields = test_field.get_gui_field_list()
		
		values['`id`'] = '0' # auto increment value
		values['`patient_id`'] = "'" + str(patient_id) + "'"

		for field in fields:
			obj =  builder.get_object(field)

			key = '`' + field + '`'			

			if obj == None:
				# calculation field
				values[key] = "'" + str(get_calculation_result(field)) + "'" # result of the calculation 
				continue

			object_type = obj.get_name()
			
			if object_type == 'GtkEntry':
				values[key] = "'" + get_gtkEntry_value(obj) + "'"
			elif object_type == 'GtkTextView':
				values[key] = "'" + get_gtkTextView_value(obj) + "'"
			elif object_type == 'GtkComboBoxText':
				values[key] = "'" + get_gtkComboBoxText_value(obj) + "'"

		# if there are preiously entered data do an update, else do an insert
		if data_entered is None:
			db.feed_test_data(db.validate(builder.get_object('title').get_text()), values)
		else:
			db.update_test_data(db.validate(builder.get_object('title').get_text()), values, data_entered['id'])

		# update the data entered field of main table
		db.update_data_entered(index)

		# close the window
		self.window.destroy()
示例#6
0
def gen_report(patient_id, test_definition_files):

	rep = report.Report()

	rep.set_main_data_list(db.get_main_report_list(patient_id))
	rep.generate_main()

	for test_definition_file in test_definition_files:
		temp = test_fields.TestField(test_definition_file)
		test_name = db.validate(temp.get_test_name())
		data = db.retrive_test_data(test_name, patient_id)
		rep.set_test_info(test_definition_file, data)
		rep.generate_report()

	rep.write_xml()
示例#7
0
def get_calculation_result(field):
	global test_field
	global values

	cal = test_field.get_calculation(field)
	
	# split by '(' and ')' and arthmetic operators, +, -, / and
	pattern = re.compile(r"[+-/*()]")
	temp = pattern.split(cal)
	
	# replace fields in the calculation with values
	for t in temp:
		tem = "`" + db.validate(t.strip()) + "`"
		if tem in values.keys():
			val = float(values[tem].strip().replace("'","")) # convert to float for possible decimal calculations
			cal = cal.replace(t, str(val))

	return eval(cal)
示例#8
0
	def generate_report(self):
		temp_from_definition = self.test_field.get_test_name_and_fields() # fields read from the test definition file (no test result values)
		
		# replace field type with values and prepare fields list
		for t in temp_from_definition[1:]:
			tem = t.split(';')
			tem[1] = str(self.data[db.validate(tem[0])])
			self.fields_list.append(';'.join(tem))

		self.increase_frame_height(24 * len(self.fields_list))

		# go to next page if vertical space left is not sufficient for the frame
		if (self.CURRENT_Y_AXIS - (self.BOTTOM_MARGIN + self.SPACE_BETWEEN_TESTS)) < self.FRAME_HEIGHT: # not sufficient space left
			self.output.append('<nextPage />')
			self.reset_current_y_axis()
			self.get_main_dimensions()
			self.output.append(self.get_main()) # append patient information at the start of the new page
			self.CURRENT_Y_AXIS -= self.SPACE_BETWEEN_TESTS

		# start of keepInFrame
		self.output.append('''<keepInFrame frame="F''' + str(self.FRAME_ID) + '''">''')

		if len(self.fields_list) > 1:
			self.output.append(self.get_title(temp_from_definition[0]))
	
		self.output.append(self.get_fields(self.fields_list))
		
		# end of keepInFrame
		self.output.append('</keepInFrame>')


		self.CURRENT_Y_AXIS = self.CURRENT_Y_AXIS - self.FRAME_HEIGHT
#		self.write_xml()

		# add fields list to tests_dict
		self.tests_dict['data' + str(self.FRAME_ID)] = self.fields_list
		
		# add frame
		self.frames.append('''<frame id="F''' + str(self.FRAME_ID) + '''" x1="0.5in" y1="''' + str(self.CURRENT_Y_AXIS)  + '''" width="''' + str(self.FRAME_WIDTH) + '''" height="''' + str(self.FRAME_HEIGHT) + '''" showBoundary="1"/>''')

		self.FRAME_HEIGHT = 0
		self.CURRENT_Y_AXIS -= self.SPACE_BETWEEN_TESTS
示例#9
0
def check_for_table():
	sql = 'SELECT COUNT(*) AS exist FROM information_schema.tables WHERE table_schema="' + db.get_database() + '" AND table_name="' + db.validate(data[0]) + '";'
	cur = db.execute_sql(sql)
	tmp = cur.fetchone()['exist']
	if tmp > 0:
		print 'table \'' + data[0] + '\' already exists'
		return True;
	return False
示例#10
0
def generate_gui():
	global data
	f = open(os.path.join(GUI_DIR, db.validate(data[0])+ '.glade'), 'w')
	f.write(gui.get_glade(data, test_definition_file))
	f.flush()
	f.close()
示例#11
0
文件: gui.py 项目: callkalpa/FreeLab
def get_row_xml(fields):
	global random_id
	global test_definition_file

	temp = ''
	i = 0

	for row in fields:
		t = row.split(';')
		id = db.validate(t[0])
		name = t[0]
		test_type = t[1]
		unit = t[2]
		reference_range = t[3]
	

		# input field
		items = ''
		if test_type == 'A': # text area
			object_class = 'GtkTextView'
		elif test_type[0] == 'T' and len(test_type)>1 and test_type[1] == '[': # combo box
			object_class = 'GtkComboBoxText'
			items = """
            <property name="entry_text_column">0</property>
            <property name="id_column">1</property>
            <items>"""
			its = test_type[2:-1].split(',') # get items to be inserted to the combo box
			for item in its:
				items = items + """
              <item translatable="yes">""" + item.strip() + """</item>"""

			items = items + """
            </items>"""
		elif len(test_type)>1 and test_type[1] == '(': # calculation field, just ignore it
			continue
		else: # text field
			object_class = 'GtkEntry'


		temp = temp + """
	<child>
	  <object class=\"""" + object_class + """\" id=\"""" + id + """\">
	    <property name="visible">True</property>
            <property name="can_focus">True</property>
		""" + items + """
          </object>
          <packing>
            <property name="left_attach">1</property>
            <property name="top_attach">""" + str(i) + """</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>"""
		
		# test name
		# label was moved here so that calculation field labels are not added
		temp = temp + get_label(name, i, 0)		
		
		# unit
		if unit != '':
			temp = temp + get_label(unit, i, 2)

		# reference range
		if reference_range != '':
			temp = temp + get_label(reference_range, i, 3)

		i = i + 1

	# done button
	temp = temp + """
	<child>
          <object class="GtkButton" id="button""" + str(random_id) + """\">
            <property name="label" translatable="yes">Done</property>
            <property name="use_action_appearance">False</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <property name="use_action_appearance">False</property>
	    <signal name="clicked" handler="done" swapped="no"/>
          </object>
          <packing>
            <property name="left_attach">3</property>
            <property name="top_attach">""" + str(i) + """</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>"""

	# label to hold the name of the test definition file
	temp = temp + """<child>
              <object class="GtkLabel" id="test_filename">
                <property name="can_focus">False</property>
		<property name="visible">False</property>
		<property name="no_show_all">True</property>
                <property name="label" translatable="yes">""" + test_definition_file + """</property>
              </object>
              <packing>
                <property name="left_attach">0</property>
                <property name="top_attach">""" + str(i) + """</property>
                <property name="width">1</property>
                <property name="height">1</property>
              </packing>
            </child>
	"""

	random_id = random_id + 1


	return str(temp)
示例#12
0
def validate():
    id_ = request.args.get('id_')
    return db.validate(id_)
示例#13
0
	def get_calculation(self, field):
		for f in self.output:
			if db.validate(f.split(';')[0]) == field:
				return f.split(';')[1][2:-1] # return without the paranthesis and field type
示例#14
0
	def get_gui_field_list(self):
		temp = []
		for field in self.output[1:]:
			temp.append(db.validate(field.split(';')[0]))
		
		return temp