csx 4 年之前
父節點
當前提交
a971c7a79a
共有 1 個文件被更改,包括 193 次插入191 次删除
  1. 193 191
      controllers/his_api_controller.go

+ 193 - 191
controllers/his_api_controller.go 查看文件

@@ -149,200 +149,202 @@ func (c *HisApiController) GetHisPatientInfo() {
149 149
 }
150 150
 
151 151
 func (c *HisApiController) Sscard() {
152
-	//id_card_type, _ := c.GetInt64("id_card_type")
153
-	//adminUser := c.GetAdminUserInfo()
154
-	//miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
152
+	id_card_type, _ := c.GetInt64("id_card_type")
153
+	adminUser := c.GetAdminUserInfo()
154
+	miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
155 155
 
156 156
 	r := CardInit()
157 157
 	if r == 0 {
158
-		//switch id_card_type {
159
-		//case 1:
160
-		//	basStr, err := GetBasBaseInfo()
161
-		//
162
-		//	fmt.Println(LoadDllErr)
163
-		//	fmt.Println(FindPErr)
164
-		//	fmt.Println(FindPErr2)
165
-		//	fmt.Println(FindPErr3)
166
-		//
167
-		//	if err != nil {
168
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
169
-		//		return
170
-		//
171
-		//	} else {
172
-		//
173
-		//		bas := strings.Split(basStr, "|")
174
-		//
175
-		//		basNumber := bas[2]
176
-		//		card_sn := bas[3]
177
-		//
178
-		//		appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
179
-		//
180
-		//		api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
181
-		//		resp, requestErr := http.Get(api)
182
-		//		if requestErr != nil {
183
-		//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
184
-		//			return
185
-		//		}
186
-		//		defer resp.Body.Close()
187
-		//		body, ioErr := ioutil.ReadAll(resp.Body)
188
-		//		if ioErr != nil {
189
-		//			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
190
-		//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
191
-		//			return
192
-		//		}
193
-		//		var respJSON map[string]interface{}
194
-		//
195
-		//		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
196
-		//			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
197
-		//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
198
-		//			return
199
-		//		}
200
-		//
201
-		//		userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
202
-		//		userJSONBytes, _ := json.Marshal(userJSON)
203
-		//		var res ResultTwo
204
-		//		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
205
-		//			utils.ErrorLog("解析失败:%v", err)
206
-		//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
207
-		//			return
208
-		//		}
209
-		//		Iinfos, _ := json.Marshal(res.Output.Iinfo)
210
-		//		Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
211
-		//		infoStr := string(Iinfos)
212
-		//		idetinfoStr := string(Idetinfos)
213
-		//
214
-		//		if res.Infcode == 0 {
215
-		//			his := models.VMHisPatient{
216
-		//				Status:      1,
217
-		//				Ctime:       time.Now().Unix(),
218
-		//				Mtime:       time.Now().Unix(),
219
-		//				PsnNo:       res.Output.Baseinfo.PsnNo,
220
-		//				PsnCertType: res.Output.Baseinfo.PsnCertType,
221
-		//				Certno:      res.Output.Baseinfo.Certno,
222
-		//				PsnName:     res.Output.Baseinfo.PsnName,
223
-		//				Gend:        res.Output.Baseinfo.Gend,
224
-		//				Naty:        res.Output.Baseinfo.Naty,
225
-		//				Brdy:        res.Output.Baseinfo.Brdy,
226
-		//				Age:         res.Output.Baseinfo.Age,
227
-		//				Iinfo:       infoStr,
228
-		//				Idetinfo:    idetinfoStr,
229
-		//				UserOrgId:   adminUser.CurrentOrgId,
230
-		//				IsReturn:    1,
231
-		//				IdCardType:  id_card_type,
232
-		//			}
233
-		//
234
-		//			patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
235
-		//			if err == gorm.ErrRecordNotFound {
236
-		//				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
237
-		//				return
238
-		//
239
-		//			} else if err != nil {
240
-		//				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
241
-		//				return
242
-		//
243
-		//			} else {
244
-		//				c.ServeSuccessJSON(map[string]interface{}{
245
-		//					"patient": patient,
246
-		//					"his":     his,
247
-		//					"number":  basNumber,
248
-		//				})
249
-		//			}
250
-		//		} else {
251
-		//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
252
-		//			return
253
-		//		}
254
-		//
255
-		//	}
256
-		//
257
-		//	break
258
-		//case 2:
259
-		//	SFZStr, err := GetSFZBaseInfo()
260
-		//	if err != nil {
261
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
262
-		//		return
263
-		//
264
-		//	} else {
265
-		//
266
-		//		id_card_str := strings.Split(SFZStr, "^")
267
-		//		id_card_number := id_card_str[0]
268
-		//		//appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
269
-		//		//
270
-		//		//api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
271
-		//		//resp, requestErr := http.Get(api)
272
-		//		//if requestErr != nil {
273
-		//		//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
274
-		//		//	return
275
-		//		//}
276
-		//		//defer resp.Body.Close()
277
-		//		//body, ioErr := ioutil.ReadAll(resp.Body)
278
-		//		//if ioErr != nil {
279
-		//		//	utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
280
-		//		//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
281
-		//		//	return
282
-		//		//}
283
-		//		//var respJSON map[string]interface{}
284
-		//		//
285
-		//		//if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
286
-		//		//	utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
287
-		//		//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
288
-		//		//	return
289
-		//		//}
290
-		//		//
291
-		//		//userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
292
-		//		//userJSONBytes, _ := json.Marshal(userJSON)
293
-		//		//var res ResultTwo
294
-		//		//if err := json.Unmarshal(userJSONBytes, &res); err != nil {
295
-		//		//	utils.ErrorLog("解析失败:%v", err)
296
-		//		//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
297
-		//		//	return
298
-		//		//}
299
-		//		//Iinfos, _ := json.Marshal(res.Output.Iinfo)
300
-		//		//Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
301
-		//		//infoStr := string(Iinfos)
302
-		//		//idetinfoStr := string(Idetinfos)
303
-		//		//
304
-		//		//if res.Infcode == 0 {
305
-		//		//	his := models.VMHisPatient{
306
-		//		//		Status:      1,
307
-		//		//		Ctime:       time.Now().Unix(),
308
-		//		//		Mtime:       time.Now().Unix(),
309
-		//		//		PsnNo:       res.Output.Baseinfo.PsnNo,
310
-		//		//		PsnCertType: res.Output.Baseinfo.PsnCertType,
311
-		//		//		Certno:      res.Output.Baseinfo.Certno,
312
-		//		//		PsnName:     res.Output.Baseinfo.PsnName,
313
-		//		//		Gend:        res.Output.Baseinfo.Gend,
314
-		//		//		Naty:        res.Output.Baseinfo.Naty,
315
-		//		//		Brdy:        res.Output.Baseinfo.Brdy,
316
-		//		//		Age:         res.Output.Baseinfo.Age,
317
-		//		//		Iinfo:       infoStr,
318
-		//		//		Idetinfo:    idetinfoStr,
319
-		//		//		UserOrgId:   adminUser.CurrentOrgId,
320
-		//		//		IsReturn:    1,
321
-		//		//		IdCardType:  id_card_type,
322
-		//		//	}
323
-		//
324
-		//		patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
325
-		//		if err == gorm.ErrRecordNotFound {
326
-		//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
327
-		//			return
328
-		//
329
-		//		} else if err != nil {
330
-		//			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
331
-		//			return
332
-		//
333
-		//		} else {
334
-		//			c.ServeSuccessJSON(map[string]interface{}{
335
-		//				"patient": patient,
336
-		//				"number":  id_card_number,
337
-		//			})
338
-		//		}
339
-		//	}
340
-		//	break
341
-		//case 3:
342
-		//
343
-		//	break
344
-		//
345
-		//}
158
+		switch id_card_type {
159
+		case 1:
160
+			basStr, err := GetBasBaseInfo()
161
+			fmt.Println("~~~~~~~~")
162
+			fmt.Println(basStr)
163
+			fmt.Println(LoadDllErr)
164
+			fmt.Println(FindPErr)
165
+			fmt.Println(FindPErr2)
166
+			fmt.Println(FindPErr3)
167
+
168
+			if err != nil {
169
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
170
+				return
171
+
172
+			} else {
173
+				fmt.Println(basStr)
174
+
175
+				bas := strings.Split(basStr, "|")
176
+
177
+				basNumber := bas[2]
178
+				card_sn := bas[3]
179
+
180
+				appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
181
+
182
+				api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
183
+				resp, requestErr := http.Get(api)
184
+				if requestErr != nil {
185
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
186
+					return
187
+				}
188
+				defer resp.Body.Close()
189
+				body, ioErr := ioutil.ReadAll(resp.Body)
190
+				if ioErr != nil {
191
+					utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
192
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
193
+					return
194
+				}
195
+				var respJSON map[string]interface{}
196
+
197
+				if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
198
+					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
199
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
200
+					return
201
+				}
202
+
203
+				userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
204
+				userJSONBytes, _ := json.Marshal(userJSON)
205
+				var res ResultTwo
206
+				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
207
+					utils.ErrorLog("解析失败:%v", err)
208
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
209
+					return
210
+				}
211
+				Iinfos, _ := json.Marshal(res.Output.Iinfo)
212
+				Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
213
+				infoStr := string(Iinfos)
214
+				idetinfoStr := string(Idetinfos)
215
+
216
+				if res.Infcode == 0 {
217
+					his := models.VMHisPatient{
218
+						Status:      1,
219
+						Ctime:       time.Now().Unix(),
220
+						Mtime:       time.Now().Unix(),
221
+						PsnNo:       res.Output.Baseinfo.PsnNo,
222
+						PsnCertType: res.Output.Baseinfo.PsnCertType,
223
+						Certno:      res.Output.Baseinfo.Certno,
224
+						PsnName:     res.Output.Baseinfo.PsnName,
225
+						Gend:        res.Output.Baseinfo.Gend,
226
+						Naty:        res.Output.Baseinfo.Naty,
227
+						Brdy:        res.Output.Baseinfo.Brdy,
228
+						Age:         res.Output.Baseinfo.Age,
229
+						Iinfo:       infoStr,
230
+						Idetinfo:    idetinfoStr,
231
+						UserOrgId:   adminUser.CurrentOrgId,
232
+						IsReturn:    1,
233
+						IdCardType:  id_card_type,
234
+					}
235
+
236
+					patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
237
+					if err == gorm.ErrRecordNotFound {
238
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
239
+						return
240
+
241
+					} else if err != nil {
242
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
243
+						return
244
+
245
+					} else {
246
+						c.ServeSuccessJSON(map[string]interface{}{
247
+							"patient": patient,
248
+							"his":     his,
249
+							"number":  basNumber,
250
+						})
251
+					}
252
+				} else {
253
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
254
+					return
255
+				}
256
+
257
+			}
258
+
259
+			break
260
+		case 2:
261
+			SFZStr, err := GetSFZBaseInfo()
262
+			if err != nil {
263
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
264
+				return
265
+
266
+			} else {
267
+
268
+				id_card_str := strings.Split(SFZStr, "^")
269
+				id_card_number := id_card_str[0]
270
+				//appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
271
+				//
272
+				//api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
273
+				//resp, requestErr := http.Get(api)
274
+				//if requestErr != nil {
275
+				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
276
+				//	return
277
+				//}
278
+				//defer resp.Body.Close()
279
+				//body, ioErr := ioutil.ReadAll(resp.Body)
280
+				//if ioErr != nil {
281
+				//	utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
282
+				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
283
+				//	return
284
+				//}
285
+				//var respJSON map[string]interface{}
286
+				//
287
+				//if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
288
+				//	utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
289
+				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
290
+				//	return
291
+				//}
292
+				//
293
+				//userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
294
+				//userJSONBytes, _ := json.Marshal(userJSON)
295
+				//var res ResultTwo
296
+				//if err := json.Unmarshal(userJSONBytes, &res); err != nil {
297
+				//	utils.ErrorLog("解析失败:%v", err)
298
+				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
299
+				//	return
300
+				//}
301
+				//Iinfos, _ := json.Marshal(res.Output.Iinfo)
302
+				//Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
303
+				//infoStr := string(Iinfos)
304
+				//idetinfoStr := string(Idetinfos)
305
+				//
306
+				//if res.Infcode == 0 {
307
+				//	his := models.VMHisPatient{
308
+				//		Status:      1,
309
+				//		Ctime:       time.Now().Unix(),
310
+				//		Mtime:       time.Now().Unix(),
311
+				//		PsnNo:       res.Output.Baseinfo.PsnNo,
312
+				//		PsnCertType: res.Output.Baseinfo.PsnCertType,
313
+				//		Certno:      res.Output.Baseinfo.Certno,
314
+				//		PsnName:     res.Output.Baseinfo.PsnName,
315
+				//		Gend:        res.Output.Baseinfo.Gend,
316
+				//		Naty:        res.Output.Baseinfo.Naty,
317
+				//		Brdy:        res.Output.Baseinfo.Brdy,
318
+				//		Age:         res.Output.Baseinfo.Age,
319
+				//		Iinfo:       infoStr,
320
+				//		Idetinfo:    idetinfoStr,
321
+				//		UserOrgId:   adminUser.CurrentOrgId,
322
+				//		IsReturn:    1,
323
+				//		IdCardType:  id_card_type,
324
+				//	}
325
+
326
+				patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
327
+				if err == gorm.ErrRecordNotFound {
328
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
329
+					return
330
+
331
+				} else if err != nil {
332
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
333
+					return
334
+
335
+				} else {
336
+					c.ServeSuccessJSON(map[string]interface{}{
337
+						"patient": patient,
338
+						"number":  id_card_number,
339
+					})
340
+				}
341
+			}
342
+			break
343
+		case 3:
344
+
345
+			break
346
+
347
+		}
346 348
 	}
347 349
 }
348 350
 func GetBasBaseInfo() (jsonStr string, err error) {