diff --git a/体质检测管理.ipynb b/体质检测管理.ipynb index 20cc579..b903880 100644 --- a/体质检测管理.ipynb +++ b/体质检测管理.ipynb @@ -228,6 +228,70 @@ "print('ok!')" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "422270f4-5658-4869-8cc6-cf674ad95abf", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import pymongo\n", + "from bson.objectid import ObjectId\n", + "\n", + "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", + "mydb = myclient[\"tice\"]\n", + "mycol = mydb[\"person1\"]\n", + "\n", + "db = pymysql.connect(\"localhost\",\"root\",\"songyi\",\"ydyb\" )\n", + "cursor = db.cursor()\n", + "\n", + "place_id = 120\n", + "exam_person = []\n", + "sql = f'SELECT distinct a.avatar_id FROM places_result AS a WHERE a.place_id={place_id} and a.avatar_id < 4999 ORDER BY a.avatar_id '\n", + "cursor.execute(sql)\n", + "results = cursor.fetchall()\n", + "cursor.close\n", + "for result in results:\n", + " exam_person.append(str(result[0]).rjust(5,'0'))\n", + "\n", + "filename = '安庆炼化人员名单.json'\n", + "\n", + "list1 = []\n", + "list2 = []\n", + "with open(filename,'r') as fl:\n", + " all_person = json.load(fl)\n", + "with open('result.json','r') as fl1:\n", + " res = json.load(fl1)\n", + "for k,v in all_person.items():\n", + " if k in exam_person:\n", + " dict2 = {}\n", + " dict3 = {}\n", + " dict2['name'] = v['name']\n", + " if v['sex'] == '男':\n", + " dict2['sex'] = 'M'\n", + " else:\n", + " dict2['sex'] = 'F'\n", + " if 'birth' in v:\n", + " s = str(v['birth'])\n", + " dict2['birth'] = f'{s[:4]}-{s[4:6]}-{s[6:8]}'\n", + " if 'id_num' in v:\n", + " s = v['id_num']\n", + " dict2['id_num'] = s\n", + " dict2['birth'] = f'{s[6:10]}-{s[10:12]}-{s[12:14]}'\n", + " dict2.setdefault('exam',[])\n", + " dict3['code'] = 120\n", + " dict3['sn'] = k\n", + " dict3['result'] = res[k]\n", + " dict2['exam'].append(dict3)\n", + " list1.append(dict2)\n", + "x = mycol.insert_many(list1)\n", + "mycol1 = mydb[\"event\"]\n", + "myquery = {'code':120}\n", + "mycol1.update_one(myquery,{'$push':{'persons':x.inserted_ids}})\n", + "print('ok!')" + ] + }, { "cell_type": "markdown", "id": "95ad1920-1393-4830-a48a-540070b51a09", @@ -491,7 +555,7 @@ "id": "c47e9547-d896-4fe2-8f70-8635c92fa792", "metadata": {}, "source": [ - "## 压缩体检报告" + "## 压缩体测报告" ] }, { @@ -538,10 +602,198 @@ "#print(old)\n" ] }, + { + "cell_type": "markdown", + "id": "9f572c02-4a9b-42c1-b6c5-e37f41bbeca1", + "metadata": {}, + "source": [ + "## 上传体测报告" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "5af86665-8abc-493d-a47f-fd9c53b8caea", + "id": "809fa112-1bf8-4509-a5a6-cfad88f9cbf5", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import glob\n", + "import os,sys\n", + "import pymongo\n", + "from gridfs import GridFS\n", + "from bson.objectid import ObjectId\n", + "\n", + "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", + "mydb = myclient[\"tice\"]\n", + "mycol = mydb[\"event\"]\n", + "\n", + "UploadCache = \"uploadcache\"\n", + "dbURL = \"mongodb://localhost:27017\"\n", + "\n", + "#上传文件\n", + "def upLoadFile(file_coll,file_name,data_link):\n", + " \n", + " filter_condition = {\"filename\": os.path.basename(file_name), \"url\": data_link}\n", + " gridfs_col = GridFS(mydb, collection=file_coll)\n", + " file_ = \"0\"\n", + " query = {\"filename\":\"\"}\n", + " query[\"filename\"] = file_name\n", + "\n", + " if gridfs_col.exists(query):\n", + " print('已经存在该文件')\n", + " else:\n", + "\n", + " with open(file_name, 'rb') as file_r:\n", + " file_data = file_r.read()\n", + " file_ = gridfs_col.put(data=file_data, **filter_condition) # 上传到gridfs\n", + "\n", + " print(file_)\n", + "\n", + "\n", + " return file_ \n", + "\n", + "\n", + "dict1 = {}\n", + "list1 = []\n", + "#mycol.update_one(myquery,{'$push':{'persons':list1}})\n", + "fl_path = 'file/new'\n", + "fl=glob.glob(f'{fl_path}/*.pdf')\n", + "fl.sort()\n", + "for fi in fl:\n", + " s = os.path.basename(fi).split('.')[0]\n", + " #print(s) \n", + " dict1[s] = upLoadFile(\"report\",fi,\"\")\n", + " \n", + " print(s)\n", + "myquery = {'code':120}\n", + "mycol.update_one(myquery,{'$set':{'report':dict1}})\n", + " \n" + ] + }, + { + "cell_type": "markdown", + "id": "8af1a4bc-2aee-46bd-9f8c-b7f26093541b", + "metadata": {}, + "source": [ + "## 查询体测报告" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c802046-3931-444a-8a66-75a853ac2467", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import glob\n", + "import os,sys\n", + "import pymongo\n", + "from gridfs import GridFS\n", + "from bson.objectid import ObjectId\n", + "\n", + "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", + "mydb = myclient[\"tice\"]\n", + "mycol = mydb[\"event\"]\n", + "sn = '00005'\n", + "s = f'report.{sn}'\n", + "myquery = {s:{'$exists':True},'code':120}\n", + "x = mycol.find_one(myquery,{s:1})\n", + "if x:\n", + " print(x['report'][sn])\n", + " \n", + "else:\n", + " print('no record!')\n", + "#print(type(x))" + ] + }, + { + "cell_type": "markdown", + "id": "c67fc14e-ccf8-41c5-a0f8-0c3a664eb484", + "metadata": {}, + "source": [ + "## 脊椎代码表导入" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d98a8d7-c888-4630-abec-de85851e4342", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + " \n", + "wb = openpyxl.load_workbook('file/脊柱症状自我诊断表代码表.xlsx')\n", + "sheet = wb.active\n", + "#sheets = wb.sheetnames\n", + "dict1 = {}\n", + "for n in range(1,sheet.max_row+1):\n", + " dict1[sheet.cell(n,1).value] = sheet.cell(n,2).value \n", + "filename = '脊柱症状自我诊断表代码表.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl,ensure_ascii=False) \n", + "print(dict1)\n" + ] + }, + { + "cell_type": "markdown", + "id": "36717021-5c0e-40d6-8988-dfe8ec309275", + "metadata": {}, + "source": [ + "## 脊椎症状自我诊断表导入" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9e33d1bc-1b71-47f7-928a-16ec435449d6", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "import openpyxl\n", + "import json\n", + "\n", + "with open('脊柱症状自我诊断表代码表.json','r') as fl:\n", + " dm = json.load(fl)\n", + "wb = openpyxl.load_workbook('file/脊柱症状自我诊断表统计.xlsx')\n", + "sheet = wb.active\n", + "#sheets = wb.sheetnames\n", + "dict1 = {}\n", + "for n in range(1,sheet.max_row+1):\n", + " mdm = sheet.cell(n,1).value\n", + " dict1.setdefault(mdm,{})\n", + " dict2 = {}\n", + " list1 = []\n", + " for i in range(2,36):\n", + " if sheet.cell(n,i).value is None:\n", + " break\n", + " else:\n", + " s = str(sheet.cell(n,i).value)\n", + " if s.isnumeric(): \n", + " list1.append(dm[s])\n", + " else:\n", + " dict2['备注'] = s\n", + " dict2['症状'] = list1\n", + " dict1[mdm] = dict2\n", + "filename = '脊柱症状自我诊断表统计.json'\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl,ensure_ascii=False) \n", + "print('ok')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "607638c1-9cfe-442a-9823-3b506ce04db6", "metadata": {}, "outputs": [], "source": []