import pymysql import pymongo import re def getvalue(sp, sa): if len(sa) > 0: for i in range(len(sa)): if sp == sa[i] and i + 1 < len(sa): return sa[i + 1] return "" # 需要注意的是diagnose_info在SQL中难以解析,因此需要代码解析 # {"e": 1, "l": 1, "l_c": 1, "n": "十二指肠球炎"},MongoDB中该字段被拆分为28项 # {"k":1,"k_b":1,"k_c":1,"l":1,"l_c":1,"n":"胃底腺息肉"} # {"k":1,"type_k":"b","k_a":1,"l":1,"l_c":1} # {"a":1,"type_a":"b","a_b":1,"l":1,"l_c":1} # {"k":1,"type_k":"a","k_b":1,"k_d":1,"l":1,"l_c":1,"n":"霉菌性食管炎"} # 食管粘膜上皮内瘤变:a(0,1)=》(a,b),级别:type_a(a,b),部位:a_a(0,1)、a_b(0,1)、a_c(0,1)=》["a","b","c"] # gc-4-4-0,gc-4-4-1,gc-4-4-2 # 早期食管癌:b,部位:b_a,b_b,b_c # gc-4-4-3,gc-4-4-3-1 # 进展期食管癌:c,部位:c_a,c_b,c_c # gc-4-4-4,gc-4-3-2 # Barret食管:d # gc-4-3-3 # 反流性食管炎:e # gc-4-3-4 # 胃粘膜上皮内瘤变:f,级别:type_f,部位:f_a、f_b、f_c、f_d、f_e # gc-4-3-4,gc-4-5-1,gc-4-5-2 # 早期胃癌:g,部位:g_a、g_b、g_c、g_d、g_e # gc-4-3-5-0,gc-4-3-5 # 进展性胃癌:h,部位:h_a、h_b、h_c、h_d、h_e # gc-4-3-6-0,gc-4-3-6 # 萎缩性胃炎:i,部位:i_a、i_b、i_c、i_d、h_e # gc-4-3-7-0,gc-4-3-7 # 胃溃疡:j,部位:j_a、j_b、j_c、j_d、j_e # gc-4-3-8-0,gc-4-3-8 # 胃息肉:k,级别:type_k,部位:k_a、k_b、k_c、k_d、k_e # gc-4-3-9-0,gc-4-6-1,gc-4-6-2 # 非萎缩性胃炎:l,部位:l_a、l_b、l_c # gc-4-3-10-0,gc-4-3-10 # 十二指肠球部溃疡:m # gc-4-3-11 # 其他病变:n:qt # gc-4-3-12,gc-4-3-13 def getsplit(diagnose_info): ##{"k":1,"type_k":"a","k_b":1,"k_d":1,"l":1,"l_c":1,"n":"霉菌性食管炎"} diagnose_info = diagnose_info.replace("1", "a") diagnose_info = diagnose_info.replace("{", "") diagnose_info = diagnose_info.replace("}", "") diagnose_info = diagnose_info.replace("[", "") diagnose_info = diagnose_info.replace("]", "") diagnose_info = diagnose_info.replace("\"", "") splittemp = re.split(',|:', diagnose_info) # split结果['k', 'a', 'type_k', 'a', 'k_b', 'a', 'k_d', 'a', 'l', 'a', 'l_c', 'a', 'n', '霉菌性食管炎'] return splittemp # 第一步,先导入医院 # 第二步,导入用户 # 第三步,导入筛查记录 # 第四步,修改筛查记录中的hospitalbean # 第五步,修改筛查记录中的审核记录 # 第六步,导入筛查记录中实验室检查报告图片 # 第七步,导入筛查记录中内镜检查图片 # 使用cursor()方法获取操作游标 # mysqlcur = mysqldb.cursor() # 需要注意的是diagnose_info在SQL中难以解析,因此需要代码解析 # {"e": 1, "l": 1, "l_c": 1, "n": "十二指肠球炎"},MongoDB中该字段被拆分为28项 # {"k":1,"k_b":1,"k_c":1,"l":1,"l_c":1,"n":"胃底腺息肉"} # 第一种方式,mysql导出json格式文件,然后import到MongoDB # 第二种方式,mysql读取一条记录,MongoDB插入一条记录,然后依次赋值 # 第三种方式,mysql读取一条记录,MongoDB插入转换后的记录 def get_json_str(row, dinfo0, dinfo1, dinfo2): if len(str(row[2])) == 4: sampleId = '00' + str(row[2]) + '-' + str(row[3]) + '-' + str(row[4]) elif len(str(row[2])) == 5: sampleId = '0' + str(row[2]) + '-' + str(row[3]) + '-' + str(row[4]) else: sampleId = str(row[2]) + '-' + str(row[3]) + '-' + str(row[4]) # 这里采用的是第一种方式,json格式导出,关于OID以及SampleID需要额外处理 jsonS = "{\"_class\":\"com.ewell.bean.report.ReportDataBean\"" jsonS = jsonS + ",\"sampleId\":\"" + sampleId + "\"" jsonS = jsonS + ",\"diseaseTypes\":\"gc_yq\"" jsonS = jsonS + ",\"userId\":\"superadmin\"" # 录入人员 jsonS = jsonS + ",\"name\":\"" + row[1] + "\"" # 患者姓名 jsonS = jsonS + ",\"version\":\"1.1\"" jsonS = jsonS + ",\"reportTime\":\"" + str(row[5]) + "\"" if row[ 5] is not None else jsonS + ",\"reportTime\":\"\"" # 录入时间 jsonS = jsonS + ",\"lastUpdateTime\":\"" + str(row[5]) + "\"" if row[ 5] is not None else jsonS + ",\"lastUpdateTime\":\"\"" # 更新时间 jsonS = jsonS + ",\"riskRank\":\"" + str(row[24]) + "\"" if row[ 24] is not None else jsonS + ",\"riskRank\":\"\"" # 风险评估 # 患者筛查病例 # 患者基本信息 jsonS = jsonS + ",\"reportContent\":{\"diseaseType\":\"gc_yq\"" jsonS = jsonS + ",\"data\":{\"sampleId\":\"20191228-2033-267\"" jsonS = jsonS + ",\"sex\":\"" + row[6] + "\"" # 性别 jsonS = jsonS + ",\"birthday\":\"" + str(row[7]) + "\"" if row[ 7] is not None else jsonS + ",\"birthday\":\"\"" # 出生日期 jsonS = jsonS + ",\"age\":\"" + str(row[8]) + "\"" if row[8] is not None else jsonS + ",\"age\":\"\"" # 年龄 jsonS = jsonS + ",\"agree\":\"a\"" # 知情同意 jsonS = jsonS + ",\"gc-1-2-1\":\"b\",\"gc-1-2-1-1\":\"b\",\"gc-1-2-2\":\"b\",\"gc-1-2-3\":\"b\",\"gc-1-2-4\":\"b\",\"gc-1-2-5\":\"b\",\"gc-1-2-6\":\"b\"" # 排除标准 jsonS = jsonS + ",\"name\":\"" + row[4] + "\"" # 姓名 jsonS = jsonS + ",\"sex-1\":\"" + row[6] + "\"" # 患者性别 jsonS = jsonS + ",\"birthday-1\":\"" + str(row[7]) + "\"" if row[ 7] is not None else jsonS + ",\"birthday-1\":\"\"" # 患者出生日期 jsonS = jsonS + ",\"weight\":{\"$NumberDecimal\":\"0\"}" # 患者身高 jsonS = jsonS + ",\"height\":{\"$NumberDecimal\":\"0\"}" # 患者体重 jsonS = jsonS + ",\"IDCard\":\"\"" # 患者身份证号 jsonS = jsonS + ",\"medicalCard\":\"\"" # 患者医保卡号 jsonS = jsonS + ",\"cellPhone\":\"" + row[9] + "\"" # 手机号码 jsonS = jsonS + ",\"telephone\":\"" + row[10] + "\"" if row[ 10] is not None else jsonS + ",\"telephone\":\"\"" # 联系电话 jsonS = jsonS + ",\"address\":\"\"" # 家庭住址 # 调查 jsonS = jsonS + ",\"checkTime\":\"" + str(row[5]) + "\"" # 调查时间 jsonS = jsonS + ",\"relativesGastric\":\"" + row[11] + "\"" # 一级亲属罹患胃癌情况 jsonS = jsonS + ",\"relativesGastricCount\":\"" + row[12] + "\"" # 一级亲属(父母、子女、兄弟姐妹)罹患胃癌数量 jsonS = jsonS + ",\"relativesGastricAge\":{\"$NumberDecimal\":\"" + row[13] + "\"}" if row[ 13] is not None else jsonS + ",\"relativesGastricAge\":\"\"" # 诊断时最小年龄22 jsonS = jsonS + ",\"relativesCancer\":\"" + row[14] + "\"" if row[ 14] is not None else jsonS + ",\"relativesCancer\":\"\"" # 一级亲属罹患其他恶性肿瘤情况 jsonS = jsonS + ",\"relativesCancerCount\":\"" + row[15] + "\"" if row[ 15] is not None else jsonS + ",\"relativesCancerCount\":\"\"" # 一级亲属(父母、子女、兄弟姐妹)罹患其他肿瘤数量 jsonS = jsonS + ",\"relativesCancerAge\":\"" + row[16] + "\"" if row[ 16] is not None else jsonS + ",\"relativesCancerAge\":\"\"" # 一级亲属(父母、子女、兄弟姐妹)罹患其他肿瘤名称 # 实验室检查 jsonS = jsonS + ",\"inspectionsTime\":\"" + str(row[5]) + "\"" if row[ 5] is not None else jsonS + ",\"inspectionsTime\":\"\"" # 实验室检查时间,可以用录入时间替代 jsonS = jsonS + ",\"g17\":{\"$NumberDecimal\":\"" + str(row[19]) + "\"}" if row[ 19] is not None else jsonS + ",\"g17\":\"\"" # 胃泌素-17 jsonS = jsonS + ",\"pgi\":{\"$NumberDecimal\":\"" + str(row[20]) + "\"}" if row[ 20] is not None else jsonS + ",\"pgi\":\"\"" # 胃蛋白酶原I jsonS = jsonS + ",\"pgii\":{\"$NumberDecimal\":\"" + str(row[21]) + "\"}" if row[ 21] is not None else jsonS + ",\"pgii\":\"\"" # 胃蛋白酶原II jsonS = jsonS + ",\"HPScore\":\"" + str(row[22]) + "\"" if row[ 22] is not None else jsonS + ",\"HPScore\":\"\"" # Hp抗体(IgG)检测 jsonS = jsonS + ",\"caga\":\"\"" # CagA抗体 jsonS = jsonS + ",\"vaca\":\"\"" # VacA抗体 jsonS = jsonS + ",\"urea\":\"\"" # 尿素酶A抗体 jsonS = jsonS + ",\"ureb\":\"\"" # 尿素酶B抗体 jsonS = jsonS + ",\"pgr\":{\"$NumberDecimal\":\"" + str(row[21] / row[20]) + "\"}" if row[20] is not None and row[ 21] is not None else jsonS + ",\"gc-3-1-6\":{\"$NumberDecimal\":\"" + str('0') + "\"}" # PepI/PepII,需要计算 jsonS = jsonS + ",\"file\":\"\"" # 实验室检查报告图片的二进制流,应该放在这里,实际上放到了gc-3-3-1 jsonS = jsonS + ",\"labImages\":\"5e074ca5bbc96666667d65b5,5e074cb472c3d50b5f2c64e6,5e074cfcbbc96666667d65b6,5e074d19bbc96666667d65b7,5e0751fc72c3d50b5f2c64e9\"" # 实验室检查报告图片的二进制流 # 风险评估 jsonS = jsonS + ",\"riskScore\":\"" + str(row[24]) + "\"" if row[ 24] is not None else jsonS + ",\"riskScore\":\"\"" # 风险评分 jsonS = jsonS + ",\"riskLevel\":\"" + str(row[25]) + "\"" if row[ 25] is not None else jsonS + ",\"riskLevel\":\"\"" # 风险等级 jsonS = jsonS + ",\"gc-3-4-3\":\"b\"" # 筛查建议 # 内镜检查 jsonS = jsonS + ",\"inspectionsChecked\":\"" + str(row[27]) + "\"" if row[ 27] is not None else jsonS + ",\"inspectionsChecked\":\"\"" # 是否接受胃镜检查 jsonS = jsonS + ",\"gastroscopeTime\":\"" + str(row[28]) + "\"" if row[ 28] is not None else jsonS + ",\"gastroscopeTime\":\"\"" # 胃镜检查时间 jsonS = jsonS + ",\"gastroscopeWay\":\"" + str(row[29]) + "\"" if row[ 29] is not None else jsonS + ",\"gastroscopeWay\":\"\"" # 胃镜检查方式 jsonS = jsonS + ",\"gc-4-2-3\":\"" + row[30] + "\"" if row[ 30] is not None else jsonS + ",\"gc-4-2-3\":\"\"" # 胃镜普通白光检查、普通白光+LCI检查、或磁控胶囊胃镜检查结果 jsonS = jsonS + ",\"finalDiagnose\":" + row[32] if row[ 32] is not None and "" else jsonS + ",\"finalDiagnose\":[]" # 最后诊断(以病理诊断为准;除“未见明显异常外,其他可多选) divalue = getvalue("a", dinfo0) if divalue != "": jsonS = jsonS + ",\"gc-4-4-0\":\"" + divalue + "\"" # 食管粘膜上皮内瘤变a divalue = getvalue("type_a", dinfo0) if divalue != "": jsonS = jsonS + ",\"gc-4-4-1\":\"" + divalue + "\"" # 级别 divalueall = ["", "", "", ] divalue = getvalue("a_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("a_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("a_c", dinfo0) if divalue != "": divalueall[2] = divalue # ["a","b","c",],["","b","c",],["","","c",]["","","",]["a","","",]["a","","c",] divalue = "" for divaluepart in divalueall: divalue = divalue + "\"" + divaluepart + "\"," divalue = divalue.replace("\"\"", "") if divalueall != "": jsonS = jsonS + ",\"gc-4-4-2\":" + str(divalueall).replace('\'', '\"') # 部位["a","b","c"] divalue = getvalue("b", dinfo0) if divalue != "": jsonS = jsonS + ",\"earlyEsophagealCancer\":\"" + divalue + "\"" # 早期食管癌 # 部位 divalueall = ["", "", ""] divalue = getvalue("b_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("b_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("b_c", dinfo0) if divalue != "": divalueall[2] = divalue if divalueall != "": jsonS = jsonS + ",\"earlyEsophagealPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("c", dinfo0) if divalue != "": jsonS = jsonS + ",\"advancedEsophagealCancer\":\"" + divalue + "\"" # 早期食管癌 # 部位 divalueall = ["", "", ""] divalue = getvalue("c_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("c_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("c_c", dinfo0) if divalue != "": divalueall[2] = divalue if divalueall != "": jsonS = jsonS + ",\"advancedEsophagealPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("d", dinfo0) if divalue != "": jsonS = jsonS + ",\"barretEsophageal\":\"a\"" # Barret食管 divalue = getvalue("e", dinfo0) if divalue != "": jsonS = jsonS + ",\"refluxEsophagealCancer\":\"a\"" # 反流性食管炎 divalue = getvalue("f", dinfo0) if divalue != "": jsonS = jsonS + ",\"gastricIntraepithelialNeoplasia\":\"" + divalue + "\"" # 胃粘膜上皮内瘤变 divalue = getvalue("type_f", dinfo0) if divalue != "": jsonS = jsonS + ",\"gastricIntraepithelialNeoplasiaLevel\":\"" + divalue + "\"" # 级别 divalueall = ["", "", "", "", ""] divalue = getvalue("f_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("f_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("f_c", dinfo0) if divalue != "": divalueall[2] = divalue divalue = getvalue("f_d", dinfo0) if divalue != "": divalueall[3] = divalue divalue = getvalue("f_e", dinfo0) if divalue != "": divalueall[4] = divalue if divalueall != "": jsonS = jsonS + ",\"gastricIntraepithelialNeoplasiaPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("g", dinfo0) if divalue != "": jsonS = jsonS + ",\"earlyGastricCancer\":\"" + divalue + "\"" # 早期胃癌 # 部位 divalueall = ["", "", "", "", ""] divalue = getvalue("g_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("g_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("g_c", dinfo0) if divalue != "": divalueall[2] = divalue divalue = getvalue("g_d", dinfo0) if divalue != "": divalueall[3] = divalue divalue = getvalue("g_e", dinfo0) if divalue != "": divalueall[4] = divalue if divalueall != "": jsonS = jsonS + ",\"earlyGastricCancerPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("h", dinfo0) if divalue != "": jsonS = jsonS + ",\"advancedGastricCancer\":\"" + divalue + "\"" # 进展性胃癌 # 部位 divalueall = ["", "", "", "", ""] divalue = getvalue("h_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("h_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("h_c", dinfo0) if divalue != "": divalueall[2] = divalue divalue = getvalue("h_d", dinfo0) if divalue != "": divalueall[3] = divalue divalue = getvalue("h_e", dinfo0) if divalue != "": divalueall[4] = divalue if divalueall != "": jsonS = jsonS + ",\"advancedGastricCancerPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("i", dinfo0) if divalue != "": jsonS = jsonS + ",\"atrophicGastritis\":\"" + divalue + "\"" # 萎缩性胃炎 # 部位 divalueall = ["", "", "", "", ""] divalue = getvalue("i_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("i_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("i_c", dinfo0) if divalue != "": divalueall[2] = divalue divalue = getvalue("i_d", dinfo0) if divalue != "": divalueall[3] = divalue divalue = getvalue("i_e", dinfo0) if divalue != "": divalueall[4] = divalue if divalueall != "": jsonS = jsonS + ",\"atrophicGastritisPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("j", dinfo0) if divalue != "": jsonS = jsonS + ",\"gastricUlcer\":\"" + divalue + "\"" # 胃溃疡 # 部位 divalueall = ["", "", "", "", ""] divalue = getvalue("j_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("j_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("j_c", dinfo0) if divalue != "": divalueall[2] = divalue divalue = getvalue("j_d", dinfo0) if divalue != "": divalueall[3] = divalue divalue = getvalue("j_e", dinfo0) if divalue != "": divalueall[4] = divalue if divalueall != "": jsonS = jsonS + ",\"gastricUlcerPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("k", dinfo0) if divalue != "": jsonS = jsonS + ",\"gastricPolyps\":\"" + divalue + "\"" # 胃息肉 divalue = getvalue("type_k", dinfo0) if divalue != "": jsonS = jsonS + ",\"gastricPolypsType\":\"" + divalue + "\"" # 类型 divalueall = ["", "", "", "", ""] divalue = getvalue("k_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("k_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("k_c", dinfo0) if divalue != "": divalueall[2] = divalue divalue = getvalue("k_d", dinfo0) if divalue != "": divalueall[3] = divalue divalue = getvalue("k_e", dinfo0) if divalue != "": divalueall[4] = divalue if divalueall != "": jsonS = jsonS + ",\"gastricPolypsPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("l", dinfo0) if divalue != "": jsonS = jsonS + ",\"nonatrophicGastritis\":\"" + divalue + "\"" # 非萎缩性胃炎 # 部位 divalueall = ["", "", "", "", ""] divalue = getvalue("l_a", dinfo0) if divalue != "": divalueall[0] = divalue divalue = getvalue("l_b", dinfo0) if divalue != "": divalueall[1] = divalue divalue = getvalue("l_c", dinfo0) if divalue != "": divalueall[2] = divalue divalue = getvalue("l_d", dinfo0) if divalue != "": divalueall[3] = divalue divalue = getvalue("l_e", dinfo0) if divalue != "": divalueall[4] = divalue if divalueall != "": jsonS = jsonS + ",\"nonatrophicGastritisPart\":" + str(divalueall).replace('\'', '\"') # 部位 divalue = getvalue("m", dinfo0) if divalue != "": jsonS = jsonS + ",\"duodenalBulbarUlcer\":\"" + divalue + "\"" # 十二指肠球部溃疡 divalue = getvalue("n", dinfo0) if divalue != "": jsonS = jsonS + ",\"otherLesions\":\"" + divalue + "\"" # 其他病变 jsonS = jsonS + ",\"otherDiseases\":\"" + dinfo0[len(dinfo0) - 1] + "\"" # 其他病变内容 jsonS = jsonS + ",\"gc-4-3-14\":\"5e074f4772c3d50b5f2c64e7,5e0751e472c3d50b5f2c64e8\"" # 内镜报告二进制流 jsonS = jsonS + ",\"gc-5-1-1\":\"" + str(row[55]) + "\"" if row[ 55] is not None else jsonS + ",\"gc-5-1-1\":\"\"" # 是否继续随访 jsonS = jsonS + ",\"gc-5-2-1\":\"a\"" # jsonS = jsonS + ",\"followUpPlanDate\":\"" + str(row[56]) + "\"" if row[ 56] is not None else jsonS + ",\"followUpPlanDate\":\"\"" # 具体时间 jsonS = jsonS + ",\"followUpContent\":[\"" + str(row[57]) + "\"]}}}" if row[ 57] is not None else jsonS + ",\"followUpContent\":[\"\"]}}}" # 计划随访内容 return jsonS # # #随访 # jsonS = jsonS + \""followReportContent":[{" #随访开始,需要判断随访次数后循环处理 # jsonS = jsonS + \""gc-6-1-1\":\"2019-06-01\"" #随访时间 # jsonS = jsonS + ",\"gc-6-1-2\":\"a\"" #存活情况 # jsonS = jsonS + ",\"gc-3-1-1\":\"a\"" #是否实验室检查 # jsonS = jsonS + ",\"gc-3-2-1\":\"2019-06-01\"" # # jsonS = jsonS + ",\"gc-3-2-1\":\"2017-05-01\"" #实验室检查时间,可以用录入时间替代 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-2\":{\"$NumberDecimal\":\"12\"}" #胃泌素-17 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-3\":{\"$NumberDecimal\":\"12\"}" #胃蛋白酶原I # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-4\":{\"$NumberDecimal\":\"12\"}" #胃蛋白酶原II # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-11\":\"b\"" #Hp抗体(IgG)检测 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-7\":\"b\"" #CagA抗体 # jsonS = jsonS + ",\"gc-3-2-8\":\"b\"" #VacA抗体 # jsonS = jsonS + ",\"gc-3-2-9\":\"b\"" #尿素酶A抗体 # jsonS = jsonS + ",\"gc-3-2-10\":\"b\"" #尿素酶B抗体 # jsonS = jsonS + ",\"gc-3-1-6\":{\"$NumberDecimal\":\"1\"}" #PepI/PepII,需要计算 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"file\":\\""" #实验室检查报告图片的二进制流,应该放在这里,实际上放到了gc-3-3-1 # jsonS = jsonS + ",\"gc-3-3-1\":\"5e074ca5bbc96666667d65b5,5e074cb472c3d50b5f2c64e6,5e074cfcbbc96666667d65b6,5e074d19bbc96666667d65b7,5e0751fc72c3d50b5f2c64e9\"" #实验室检查报告图片的二进制流 # #风险评估 # jsonS = jsonS + ",\"gc-3-4-1\":\"13.00\"" #风险评分 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-4-2\":\"b\"" #风险等级 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-4-3\":\"b\"" #筛查建议 # jsonS = jsonS.replace("xxx","") # #内镜检查 # jsonS = jsonS + ",\"gc-4-1-1\":\"a\"" #是否接受胃镜检查 # jsonS = jsonS + ",\"gc-4-2-1\":\"2018-01-01\"" #胃镜检查时间 # # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-2\":\"b\"" #胃镜检查方式 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-3\":\"b\"" #胃镜普通白光检查、普通白光+LCI检查、或磁控胶囊胃镜检查结果 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-4\":\"2018-01-01\"" #胃镜检查时间 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-5\":[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\"]" #胃镜精查方式 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-3-1\":\"b\"" #最后诊断(以病理诊断为准;除“未见明显异常外,其他可多选) # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-4-0\":\"a\"" #食管粘膜上皮内瘤变 # jsonS = jsonS + ",\"gc-4-4-1\":\"a\"" #级别 # jsonS = jsonS + ",\"gc-4-4-2\":[\"a\",\"b\",\"c\"]" #部位 # jsonS = jsonS + \""gc-4-4-3\":\"a\"" #早期食管癌 # jsonS = jsonS + ",\"gc-4-4-3-1\":[\"a\",\"b\",\"c\"]" #部位 # jsonS = jsonS + ",\"gc-4-4-4\":\"a\"" #进展期食管癌 # jsonS = jsonS + ",\"gc-4-3-2\":[\"a\",\"b\",\"c\"]" #部位 # jsonS = jsonS + ",\"gc-4-3-3\":\"a\"" #Barret食管 # jsonS = jsonS + \""gc-4-3-4\":\"a\"" #反流性食管炎 # jsonS = jsonS + ",\"gc-4-3-4-1\":\"a\"" #胃粘膜上皮内瘤变 # jsonS = jsonS + ",\"gc-4-5-1\":\"a\"" #级别 # jsonS = jsonS + ",\"gc-4-5-2\":[\"a\",\"b\",\"c\",\"d\",\"e\"]" #部位 # jsonS = jsonS + ",\"gc-4-3-5-0\":\"a\"" #早期胃癌 # jsonS = jsonS + ",\"gc-4-3-5\":[\"a\",\"b\",\"c\",\"d\",\"e\"]" #部位 # jsonS = jsonS + ",\"gc-4-3-6-0\":\"a\"" #进展性胃癌 # jsonS = jsonS + ",\"gc-4-3-6\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-7-0\":\"a\"" #萎缩性胃炎 # jsonS = jsonS + ",\"gc-4-3-7\":["c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-8-0\":\"a\"" #胃溃疡 # jsonS = jsonS + ",\"gc-4-3-8\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-9-0\":\"a\"" #胃息肉 # jsonS = jsonS + \""gc-4-6-1\":\"a\"" #类型 # jsonS = jsonS + ",\"gc-4-6-2\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-10-0\":\"a\"" #非萎缩性胃炎 # jsonS = jsonS + ",\"gc-4-3-10\":["c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-11\":\"a\"" #十二指肠球部溃疡 # jsonS = jsonS + ",\"gc-4-3-12\":\"a\"" #其他病变 # jsonS = jsonS + ",\"gc-4-3-13\":\"认证\"" #其他病变内容 # jsonS = jsonS + ",\"gc-4-3-14\":\"5e074f4772c3d50b5f2c64e7,5e0751e472c3d50b5f2c64e8\"" #内镜报告二进制流 # jsonS = jsonS + ",\"gc-5-1-1\":\"b\"" #是否继续随访 # jsonS = jsonS + ",\"gc-5-2-1\":\"a\"" # # jsonS = jsonS + ",\"gc-5-2-2\":\"2019-01-01\"" #具体时间 # jsonS = jsonS + ",\"gc-5-2-3\":["a","b"]}" #计划随访内容,如果只有一次随访,则最后应该加上],标识随访结束,否则没有] # # #第二次随访 # jsonS = jsonS + \""gc-6-1-1\":\"2019-06-01\"" #随访时间 # jsonS = jsonS + ",\"gc-6-1-2\":\"a\"" #存活情况 # jsonS = jsonS + ",\"gc-3-1-1\":\"a\"" #是否实验室检查 # jsonS = jsonS + ",\"gc-3-2-1\":\"2019-06-01\"" # # jsonS = jsonS + ",\"gc-3-2-1\":\"2017-05-01\"" #实验室检查时间,可以用录入时间替代 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-2\":{"$NumberDecimal\":\"12"\}" #胃泌素-17 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-3\":{"$NumberDecimal\":\"12\"}" #胃蛋白酶原I # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-4\":{"$NumberDecimal\":\"12\"}" #胃蛋白酶原II # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-11\":\"b\"" #Hp抗体(IgG)检测 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-2-7\":\"b\"" #CagA抗体 # jsonS = jsonS + ",\"gc-3-2-8\":\"b\"" #VacA抗体 # jsonS = jsonS + ",\"gc-3-2-9\":\"b\"" #尿素酶A抗体 # jsonS = jsonS + ",\"gc-3-2-10\":\"b\"" #尿素酶B抗体 # jsonS = jsonS + ",\"gc-3-1-6\":{\"$NumberDecimal\":\"1\"}" #PepI/PepII,需要计算 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"file\":\\""" #实验室检查报告图片的二进制流,应该放在这里,实际上放到了gc-3-3-1 # jsonS = jsonS + ",\"gc-3-3-1\":\"5e074ca5bbc96666667d65b5,5e074cb472c3d50b5f2c64e6,5e074cfcbbc96666667d65b6,5e074d19bbc96666667d65b7,5e0751fc72c3d50b5f2c64e9\"" #实验室检查报告图片的二进制流 # #风险评估 # jsonS = jsonS + ",\"gc-3-4-1\":\"13.00\"" #风险评分 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-4-2\":\"b\"" #风险等级 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-3-4-3\":\"b\"" #筛查建议 # jsonS = jsonS.replace("xxx","") # #内镜检查 # jsonS = jsonS + ",\"gc-4-1-1\":\"a\"" #是否接受胃镜检查 # jsonS = jsonS + ",\"gc-4-2-1\":\"2018-01-01\"" #胃镜检查时间 # # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-2\":\"b\"" #胃镜检查方式 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-3\":\"b\"" #胃镜普通白光检查、普通白光+LCI检查、或磁控胶囊胃镜检查结果 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-4\":\"2018-01-01\"" #胃镜检查时间 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-2-5\":["a","b","c","d","e","f","g"]" #胃镜精查方式 # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-3-1\":\"b\"" #最后诊断(以病理诊断为准;除“未见明显异常外,其他可多选) # jsonS = jsonS.replace("xxx","") # jsonS = jsonS + ",\"gc-4-4-0\":\"a\"" #食管粘膜上皮内瘤变 # jsonS = jsonS + ",\"gc-4-4-1\":\"a\"" #级别 # jsonS = jsonS + ",\"gc-4-4-2":["a","b","c"]" #部位 # jsonS = jsonS + \""gc-4-4-3\":\"a\"" #早期食管癌 # jsonS = jsonS + ",\"gc-4-4-3-1":["a","b","c"]" #部位 # jsonS = jsonS + ",\"gc-4-4-4\":\"a\"" #进展期食管癌 # jsonS = jsonS + ",\"gc-4-3-2":["a","b","c"]" #部位 # jsonS = jsonS + ",\"gc-4-3-3\":\"a\"" #Barret食管 # jsonS = jsonS + \""gc-4-3-4\":\"a\"" #反流性食管炎 # jsonS = jsonS + ",\"gc-4-3-4-1\":\"a\"" #胃粘膜上皮内瘤变 # jsonS = jsonS + ",\"gc-4-5-1\":\"a\"" #级别 # jsonS = jsonS + ",\"gc-4-5-2\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-5-0\":\"a\"" #早期胃癌 # jsonS = jsonS + ",\"gc-4-3-5\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-6-0\":\"a\"" #进展性胃癌 # jsonS = jsonS + ",\"gc-4-3-6\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-7-0\":\"a\"" #萎缩性胃炎 # jsonS = jsonS + ",\"gc-4-3-7\":["c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-8-0\":\"a\"" #胃溃疡 # jsonS = jsonS + ",\"gc-4-3-8\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-9-0\":\"a\"" #胃息肉 # jsonS = jsonS + \""gc-4-6-1\":\"a\"" #类型 # jsonS = jsonS + ",\"gc-4-6-2\":["a","b","c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-10-0\":\"a\"" #非萎缩性胃炎 # jsonS = jsonS + ",\"gc-4-3-10\":["c","d","e"]" #部位 # jsonS = jsonS + ",\"gc-4-3-11\":\"a\"" #十二指肠球部溃疡 # jsonS = jsonS + ",\"gc-4-3-12\":\"a\"" #其他病变 # jsonS = jsonS + ",\"gc-4-3-13\":\"认证\"" #其他病变内容 # jsonS = jsonS + ",\"gc-4-3-14\":\"5e074f4772c3d50b5f2c64e7,5e0751e472c3d50b5f2c64e8\"" #内镜报告二进制流 # jsonS = jsonS + ",\"gc-5-1-1\":\"b\"" #是否继续随访 # jsonS = jsonS + ",\"gc-5-2-1\":\"a\"" # # jsonS = jsonS + ",\"gc-5-2-2\":\"2019-01-01\"" #具体时间 # jsonS = jsonS + ",\"gc-5-2-3\":["a","b"]}]" #计划随访内容 # # #其他内容 # jsonS = jsonS + \""progressStatus":{"$NumberDecimal\":\"2"}" #患者表中的step # jsonS = jsonS + ",\"auditStatus":{"$NumberDecimal\":\"2"}" # # #,"auditRecords":[{"create_time\":\"2019-12-28 20:41:56","status":{"$NumberDecimal\":\"1"},"auditUserId\":\"why-sys-1577324928240","auditUserName\":\"why-sys"},{"create_time\":\"2019-12-28 21:03:01","status":{"$NumberDecimal\":\"1"},"auditUserId\":\"why-nj-1577325106640","auditUserName\":\"why-nj"},{"create_time\":\"2019-12-28 21:07:34","status":{"$NumberDecimal\":\"1"},"auditUserId\":\"why-sys-1577324928240","auditUserName\":\"why-sys"},{"create_time\":\"2019-12-28 21:11:15","status":{"$NumberDecimal\":\"1"},"auditUserId\":\"why-nj-1577325106640","auditUserName\":\"why-nj"},{"create_time\":\"2019-12-28 21:17:36","status":{"$NumberDecimal\":\"1"},"auditUserId\":\"why-sys-1577324928240","auditUserName\":\"why-sys"}] # #auditRecords建议在其他数据倒完后再导入。 # #需要建立两边的用户映射和转换后导入 # #jsonS = jsonS + ",\"auditRecords":[{" # # jsonS = jsonS + ",\"noticeFlag":{"$NumberDecimal\":\"0"}}" # # # # # # # # # # #例子 # #1.查询操作 # # 编写sql 查询语句 user 对应我的表名 # sql = "select * from tb_hosp" # try: # cur.execute(sql) #执行sql语句 # # results = cur.fetchall() #获取查询的所有记录 # print("id","number","name") # #遍历结果 # for row in results : # id = row[0] # number = row[1] # name = row[2] # print(id,number,name) # except Exception as e: # raise e # finally: # db.close() #关闭连接 # # # # # 创建mongodb数据库连接 # connection = pymongo.MongoClient(host='localhost', port=27017) # # 获取数据库 # mongodb = connection.cancer3 #或者db=client.pp,相当于数据库中的use pp; # hospital = mongodb.gastric_cancer_hospital