예제 #1
0
def dumpToJson( ):
  bigJson = ""
  try:
      conn = mydb.getConn()
      cur = conn.cursor( cursorclass=MySQLdb.cursors.DictCursor )
      cur.execute('SELECT id,medicine_name,short_name,price FROM t_medicine ORDER BY short_name')
      rs = cur.fetchall()
      bigJson = json.dumps(rs, ensure_ascii=False,indent=2)
      cur.close()
      conn.close()
   
  except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])
예제 #2
0
def dumpToJson():
    bigJson = ""
    try:
        conn = mydb.getConn()
        cur = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
        cur.execute(
            "SELECT id,patient_no,patient_name,concat('****', right(mobile, 4)) as mobile,sex,age,remark FROM t_customer "
        )
        rs = cur.fetchall()
        bigJson = json.dumps(rs, ensure_ascii=False, indent=2)
        cur.close()
        conn.close()

    except MySQLdb.Error, e:
        print "Mysql Error %d: %s" % (e.args[0], e.args[1])
예제 #3
0
파일: fromdb.py 프로젝트: today/FRT_Master
def getRecipe( p_no, doctor_name ):
  bigJson = ""
  try:
      p_json = mydb.getPatientJson( p_no )

      conn = mydb.getConn()
      cur = conn.cursor()
      
      """ 取出病历信息的 Json_id  """
      sql2 = "select json_id from t_recipe where  patient_no='"+ p_no + \
        "' and doctor_name='"+ doctor_name +"'  order by id desc LIMIT 3"
      #print sql2
      cur.execute(sql2)
      allResult=cur.fetchall()
      """ 循环取出每一份病历的json串  """
      c_json_list = []
      for result in allResult:
        temp_c_json_id = result[0]
        #print temp_c_json_id

        sql4 = "select json_string from t_json where  id='"+ str(temp_c_json_id) + "' "
        cur.execute(sql4)
        ajson = cur.fetchone()
        c_json_list.append(ajson[0])
        #print c_json

      """ 所有的Json都取出来了,现在需要拼接字符串了。 """
      full_p_json = '"patients":' + p_json 
      all_c_json = '  '
      for temp_str in c_json_list :
        all_c_json += temp_str + ','
      bigJson = '{ '+ full_p_json + ',' + '"cases":[' + all_c_json[0:-1] + ']' +' }'
      
        
      conn.commit()
      cur.close()
      conn.close()

      #print bigJson 
   
  except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])
예제 #4
0
def saveCustom( customs ):
  optVals = ['mobile','sex','age','remark']

  try:
      conn = mydb.getConn()
      cur = conn.cursor()

      for custom in customs :
        if not custom.has_key("patient_name") :
          print "import: " + unicode(custom["patient_no"]) + " Patient name lost, ingore."
          continue

        checkOptionValue(custom, optVals )
        print "import: " + unicode(custom["patient_no"]) + " " #+ unicode(custom["patient_name"])

        p_no = str( custom['patient_no'] )
        strSql1 = "SELECT * FROM t_customer WHERE patient_no='" + p_no + "' "
        #print strSql1
        cur.execute(strSql1)
        if cur.fetchone() :
          # 存在,则执行update
          values = getVals(custom, [ 'patient_name', 'mobile','sex','age','remark','patient_no'])
          strSql2 = "UPDATE t_customer SET  "  \
            + "`patient_name`=%s, `mobile`=%s, `sex`=%s, `age`=%s, `remark`=%s "  \
            + "  WHERE patient_no=%s" 
          #print strSql2
          #cur.execute( strSql2, values )
          #conn.commit()
        else :
          # 不存在,执行insert
          values = getVals(custom, ['patient_no', 'patient_name', 'mobile','sex','age','remark'])
          strSql3 = "INSERT INTO t_customer ( `patient_no`, `patient_name`, `mobile`, `sex`, `age`, `remark`) " \
            + " VALUES (%s,%s,%s,%s,%s,%s) "
          #print strSql3
          cur.execute( strSql3, values )
          conn.commit()
      
      cur.close()
      conn.close()
   
  except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])