Selaa lähdekoodia

Merge branch '20201014_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20201014_xt_api_new_branch

csx 4 vuotta sitten
vanhempi
commit
4fceeef6f5
4 muutettua tiedostoa jossa 599 lisäystä ja 399 poistoa
  1. 320 171
      controllers/his_api_controller.go
  2. 33 16
      models/his_models.go
  3. 192 192
      service/gdyb_service.go
  4. 54 20
      service/his_service.go

+ 320 - 171
controllers/his_api_controller.go Näytä tiedosto

@@ -43,15 +43,17 @@ func HisManagerApiRegistRouters() {
43 43
 	beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
44 44
 	beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
45 45
 	beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
46
-	//beego.Router("/api/doctorworkstation/printcasehistory/get", &HisApiController{}, "get:GetPrintHisPatientCaseHistory")
47 46
 
48 47
 	beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
49
-
50 48
 	beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
51 49
 
52 50
 	beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
53 51
 	beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
54 52
 
53
+	beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
54
+
55
+	beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
56
+
55 57
 }
56 58
 
57 59
 func (c *HisApiController) GetHisPatientList() {
@@ -151,7 +153,7 @@ func (c *HisApiController) CreateHisPrescription() {
151 153
 	record_date := c.GetString("record_date")
152 154
 	fmt.Println("record_date", record_date)
153 155
 	patient_id, _ := c.GetInt64("patient_id")
154
-	reg_type, _ := c.GetInt64("reg_type")
156
+	reg_type := c.GetString("reg_type")
155 157
 
156 158
 	diagnose := c.GetString("diagnose")
157 159
 	sick_history := c.GetString("sick_history")
@@ -176,16 +178,17 @@ func (c *HisApiController) CreateHisPrescription() {
176 178
 	adminInfo := c.GetAdminUserInfo()
177 179
 	recordDateTime := theTime.Unix()
178 180
 
179
-	var randNum int
180
-	randNum = rand.Intn(10000) + 1000
181
-	timestamp := time.Now().Unix()
182
-	tempTime := time.Unix(timestamp, 0)
183
-	timeFormat := tempTime.Format("20060102150405")
184
-	number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
185
-
186 181
 	info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
182
+	var hpInfo models.HisPrescriptionInfo
187 183
 	if info.ID == 0 {
188
-		hpInfo := models.HisPrescriptionInfo{
184
+		var randNum int
185
+		randNum = rand.Intn(10000) + 1000
186
+		timestamp := time.Now().Unix()
187
+		tempTime := time.Unix(timestamp, 0)
188
+		timeFormat := tempTime.Format("20060102150405")
189
+		p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
190
+
191
+		hpInfo = models.HisPrescriptionInfo{
189 192
 			UserOrgId:          adminInfo.CurrentOrgId,
190 193
 			RecordDate:         theTime.Unix(),
191 194
 			PatientId:          patient_id,
@@ -198,26 +201,31 @@ func (c *HisApiController) CreateHisPrescription() {
198 201
 			SickHistory:        sick_history,
199 202
 			Departments:        department,
200 203
 			RegisterType:       reg_type,
201
-			PrescriptionNumber: number,
204
+			PrescriptionNumber: p_number,
205
+			PrescriptionStatus: 1,
206
+			Doctor:             doctor,
202 207
 		}
203 208
 		service.SavePatientPrescriptionInfo(hpInfo)
204 209
 
205 210
 	} else {
206
-		hpInfo := models.HisPrescriptionInfo{
207
-			ID:                 info.ID,
208
-			UserOrgId:          adminInfo.CurrentOrgId,
209
-			RecordDate:         info.RecordDate,
210
-			PatientId:          info.PatientId,
211
-			Status:             1,
212
-			Ctime:              info.Ctime,
213
-			Mtime:              time.Now().Unix(),
214
-			Creator:            info.Creator,
215
-			Modifier:           adminInfo.AdminUser.Id,
216
-			Diagnosis:          diagnose,
217
-			SickHistory:        sick_history,
218
-			Departments:        department,
219
-			RegisterType:       reg_type,
211
+		hpInfo = models.HisPrescriptionInfo{
212
+			ID:           info.ID,
213
+			UserOrgId:    adminInfo.CurrentOrgId,
214
+			RecordDate:   info.RecordDate,
215
+			PatientId:    info.PatientId,
216
+			Status:       1,
217
+			Ctime:        info.Ctime,
218
+			Mtime:        time.Now().Unix(),
219
+			Creator:      info.Creator,
220
+			Modifier:     adminInfo.AdminUser.Id,
221
+			Diagnosis:    diagnose,
222
+			SickHistory:  sick_history,
223
+			Departments:  department,
224
+			RegisterType: reg_type,
225
+
220 226
 			PrescriptionNumber: info.PrescriptionNumber,
227
+			Doctor:             doctor,
228
+			PrescriptionStatus: info.PrescriptionStatus,
221 229
 		}
222 230
 		service.SavePatientPrescriptionInfo(hpInfo)
223 231
 	}
@@ -244,20 +252,21 @@ func (c *HisApiController) CreateHisPrescription() {
244 252
 
245 253
 				ctime := time.Now().Unix()
246 254
 				prescription := &models.HisPrescription{
247
-					ID:           id,
248
-					PatientId:    patient_id,
249
-					UserOrgId:    adminInfo.CurrentOrgId,
250
-					RecordDate:   recordDateTime,
251
-					Ctime:        ctime,
252
-					Mtime:        ctime,
253
-					Type:         types,
254
-					Modifier:     adminInfo.AdminUser.Id,
255
-					Creator:      adminInfo.AdminUser.Id,
256
-					Status:       1,
257
-					Doctor:       doctor,
258
-					HisPatientId: his_patient_id,
259
-					IsFinish:     1,
260
-					BatchNumber:  "",
255
+					ID:                 id,
256
+					PatientId:          patient_id,
257
+					UserOrgId:          adminInfo.CurrentOrgId,
258
+					RecordDate:         recordDateTime,
259
+					Ctime:              ctime,
260
+					Mtime:              ctime,
261
+					Type:               types,
262
+					Modifier:           adminInfo.AdminUser.Id,
263
+					Creator:            adminInfo.AdminUser.Id,
264
+					Status:             1,
265
+					Doctor:             doctor,
266
+					HisPatientId:       his_patient_id,
267
+					OrderStatus:        1,
268
+					BatchNumber:        "",
269
+					PrescriptionNumber: hpInfo.PrescriptionNumber,
261 270
 				}
262 271
 				service.SaveHisPrescription(prescription)
263 272
 
@@ -1053,6 +1062,17 @@ type ResultFive struct {
1053 1062
 	Insutype string `json:"insutype"`
1054 1063
 }
1055 1064
 
1065
+type Custom struct {
1066
+	DetItemFeeSumamt string
1067
+	Cut              string
1068
+	FeedetlSn        string
1069
+	Price            string
1070
+	MedListCodg      string
1071
+	Type             int64
1072
+	AdviceId         int64
1073
+	ProjectId        int64
1074
+}
1075
+
1056 1076
 func (c *HisApiController) GetUploadInfo() {
1057 1077
 	id, _ := c.GetInt64("id")
1058 1078
 	record_time := c.GetString("record_time")
@@ -1093,34 +1113,180 @@ func (c *HisApiController) GetUploadInfo() {
1093 1113
 	for _, item := range prescriptions {
1094 1114
 		ids = append(ids, item.ID)
1095 1115
 	}
1116
+	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
1096 1117
 
1097
-	bytesData, _ := json.Marshal(data)
1098
-	req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
1099
-	resp, _ := client.Do(req)
1100
-	defer resp.Body.Close()
1101
-	body, ioErr := ioutil.ReadAll(resp.Body)
1102
-	if ioErr != nil {
1103
-		utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1104
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1105
-		return
1106
-	}
1107
-	var respJSON map[string]interface{}
1108
-	if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
1109
-		utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1110
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1111
-		return
1112
-	}
1118
+	if config.IsOpen == 1 {
1119
+		bytesData, _ := json.Marshal(data)
1120
+		req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
1121
+		resp, _ := client.Do(req)
1122
+		defer resp.Body.Close()
1123
+		body, ioErr := ioutil.ReadAll(resp.Body)
1124
+		if ioErr != nil {
1125
+			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1126
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1127
+			return
1128
+		}
1129
+		var respJSON map[string]interface{}
1130
+		if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
1131
+			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1132
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1133
+			return
1134
+		}
1113 1135
 
1114
-	respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1115
-	userJSONBytes, _ := json.Marshal(respJSON)
1116
-	var res ResultFour
1117
-	if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1118
-		utils.ErrorLog("解析失败:%v", err)
1119
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1120
-		return
1121
-	}
1136
+		respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1137
+		userJSONBytes, _ := json.Marshal(respJSON)
1138
+		var res ResultFour
1139
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1140
+			utils.ErrorLog("解析失败:%v", err)
1141
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1142
+			return
1143
+		}
1144
+
1145
+		if res.Infcode == 0 {
1146
+			order := &models.HisOrder{
1147
+				UserOrgId:          adminUser.CurrentOrgId,
1148
+				HisPatientId:       his.ID,
1149
+				PatientId:          his.PatientId,
1150
+				SettleAccountsDate: recordDateTime,
1151
+				Ctime:              time.Now().Unix(),
1152
+				Mtime:              time.Now().Unix(),
1153
+				Status:             1,
1154
+				Number:             chrg_bchno,
1155
+				Infcode:            res.Infcode,
1156
+				WarnMsg:            res.WarnMsg,
1157
+				Cainfo:             res.Cainfo,
1158
+				ErrMsg:             res.ErrMsg,
1159
+				RespondTime:        res.RefmsgTime,
1160
+				InfRefmsgid:        res.InfRefmsgid,
1161
+				OrderStatus:        1,
1162
+			}
1163
+			err = service.CreateOrder(order)
1164
+			if err != nil {
1165
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
1166
+				return
1167
+			}
1168
+
1169
+			for _, item := range res.Output.Result {
1170
+				temp := strings.Split(item.FeedetlSn, "-")
1171
+				var advice_id int64 = 0
1172
+				var project_id int64 = 0
1173
+				var types int64 = 0
1174
+
1175
+				id, _ := strconv.ParseInt(temp[2], 10, 64)
1176
+				types, _ = strconv.ParseInt(temp[1], 10, 64)
1177
+
1178
+				if temp[1] == "1" {
1179
+					advice_id = id
1180
+					project_id = 0
1181
+				} else if temp[1] == "2" {
1182
+					advice_id = 0
1183
+					project_id = id
1184
+				}
1185
+
1186
+				info := &models.HisOrderInfo{
1187
+					OrderNumber:      order.Number,
1188
+					FeedetlSn:        item.FeedetlSn,
1189
+					UploadDate:       time.Now().Unix(),
1190
+					AdviceId:         advice_id,
1191
+					DetItemFeeSumamt: item.DetItemFeeSumamt,
1192
+					Cnt:              item.Cnt,
1193
+					Pric:             float64(item.Pric),
1194
+					PatientId:        his.PatientId,
1195
+					PricUplmtAmt:     item.PricUplmtAmt,
1196
+					SelfpayProp:      item.SelfpayProp,
1197
+					FulamtOwnpayAmt:  item.FulamtOwnpayAmt,
1198
+					OverlmtAmt:       item.OverlmtAmt,
1199
+					PreselfpayAmt:    item.PreselfpayAmt,
1200
+					BasMednFlag:      item.BasMednFlag,
1201
+					MedChrgitmType:   item.MedChrgitmType,
1202
+					HiNegoDrugFlag:   item.HiNegoDrugFlag,
1203
+					Status:           1,
1204
+					Memo:             item.Memo,
1205
+					Mtime:            time.Now().Unix(),
1206
+					InscpScpAmt:      item.InscpScpAmt,
1207
+					DrtReimFlag:      item.DrtReimFlag,
1208
+					Ctime:            time.Now().Unix(),
1209
+					ListSpItemFlag:   item.ListSpItemFlag,
1210
+					ChldMedcFlag:     item.ChldMedcFlag,
1211
+					LmtUsedFlag:      item.LmtUsedFlag,
1212
+					ChrgitmLv:        item.ChrgitmLv,
1213
+					UserOrgId:        adminUser.CurrentOrgId,
1214
+					HisPatientId:     his.ID,
1215
+					OrderId:          order.ID,
1216
+					ProjectId:        project_id,
1217
+					Type:             types,
1218
+				}
1219
+				service.CreateOrderInfo(info)
1220
+			}
1221
+
1222
+			service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
1223
+			service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
1224
+
1225
+			var total float64
1226
+			for _, item := range prescriptions {
1227
+				if item.Type == 1 { //药品
1228
+					for _, subItem := range item.HisDoctorAdviceInfo {
1229
+						total = total + (subItem.Price * subItem.PrescribingNumber)
1230
+					}
1231
+				}
1232
+				if item.Type == 2 { //项目
1233
+					for _, subItem := range item.HisPrescriptionProject {
1234
+						total = total + (subItem.Price * float64(subItem.Count))
1235
+					}
1236
+				}
1237
+			}
1238
+
1239
+			org, _ := service.GetOrgById(adminUser.CurrentOrgId)
1240
+			patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
1241
+			allTotal := fmt.Sprintf("%.2f", total)
1242
+			if res.Infcode == 0 {
1243
+				var rf []*ResultFive
1244
+				json.Unmarshal([]byte(his.Iinfo), &rf)
1245
+				psn_no := his.PsnNo
1246
+				mdtrt_id := his.Number
1247
+				chrg_bchno := chrg_bchno
1248
+				cert_no := his.Certno
1249
+				insutype := rf[0].Insutype
1250
+				api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
1251
+					insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
1252
+					"&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor
1253
+				resp, requestErr := http.Get(api)
1254
+
1255
+				if requestErr != nil {
1256
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1257
+					return
1258
+				}
1259
+				defer resp.Body.Close()
1260
+				body, ioErr := ioutil.ReadAll(resp.Body)
1261
+				if ioErr != nil {
1262
+					utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1263
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1264
+					return
1265
+				}
1266
+				var respJSON map[string]interface{}
1267
+				if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
1268
+					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1269
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1270
+					return
1271
+				}
1272
+				fmt.Println(respJSON)
1273
+				respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1274
+				userJSONBytes, _ := json.Marshal(respJSON)
1275
+				var res ResultFour
1276
+				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1277
+					utils.ErrorLog("解析失败:%v", err)
1278
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1279
+					return
1280
+				}
1281
+			} else {
1122 1282
 
1123
-	if res.Infcode == 0 {
1283
+			}
1284
+
1285
+		} else {
1286
+
1287
+		}
1288
+
1289
+	} else {
1124 1290
 		order := &models.HisOrder{
1125 1291
 			UserOrgId:          adminUser.CurrentOrgId,
1126 1292
 			HisPatientId:       his.ID,
@@ -1129,66 +1295,81 @@ func (c *HisApiController) GetUploadInfo() {
1129 1295
 			Ctime:              time.Now().Unix(),
1130 1296
 			Mtime:              time.Now().Unix(),
1131 1297
 			Status:             1,
1132
-			Number:             chrg_bchno,
1133
-			Infcode:            res.Infcode,
1134
-			WarnMsg:            res.WarnMsg,
1135
-			Cainfo:             res.Cainfo,
1136
-			ErrMsg:             res.ErrMsg,
1137
-			RespondTime:        res.RefmsgTime,
1138
-			InfRefmsgid:        res.InfRefmsgid,
1139
-			OrderStatus:        1,
1298
+			OrderStatus:        2,
1140 1299
 		}
1141 1300
 
1142 1301
 		err = service.CreateOrder(order)
1302
+
1143 1303
 		if err != nil {
1144 1304
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
1145 1305
 			return
1146 1306
 		}
1147 1307
 
1148
-		for _, item := range res.Output.Result {
1149
-			temp := strings.Split(item.FeedetlSn, "-")
1308
+		var customs []*Custom
1309
+
1310
+		for _, item := range prescriptions {
1311
+			if item.Type == 1 { //药品
1312
+				for _, subItem := range item.HisDoctorAdviceInfo {
1313
+					cus := &Custom{
1314
+						AdviceId:         subItem.ID,
1315
+						ProjectId:        0,
1316
+						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
1317
+						Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
1318
+						FeedetlSn:        subItem.FeedetlSn,
1319
+						Price:            fmt.Sprintf("%.2f", subItem.Price),
1320
+						MedListCodg:      subItem.MedListCodg,
1321
+						Type:             1,
1322
+					}
1323
+					customs = append(customs, cus)
1324
+				}
1325
+			}
1326
+
1327
+			if item.Type == 2 { //项目
1328
+				for _, subItem := range item.HisPrescriptionProject {
1329
+					cus := &Custom{
1330
+						AdviceId:         0,
1331
+						ProjectId:        subItem.ID,
1332
+						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
1333
+						Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
1334
+						FeedetlSn:        subItem.FeedetlSn,
1335
+						Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
1336
+						MedListCodg:      subItem.MedListCodg,
1337
+						Type:             2,
1338
+					}
1339
+
1340
+					customs = append(customs, cus)
1341
+				}
1342
+			}
1343
+		}
1344
+
1345
+		for _, item := range customs {
1150 1346
 			var advice_id int64 = 0
1151 1347
 			var project_id int64 = 0
1152 1348
 			var types int64 = 0
1153 1349
 
1154
-			id, _ := strconv.ParseInt(temp[2], 10, 64)
1155
-			types, _ = strconv.ParseInt(temp[1], 10, 64)
1156
-
1157
-			if temp[1] == "1" {
1158
-				advice_id = id
1350
+			if item.Type == 1 {
1351
+				advice_id = item.AdviceId
1159 1352
 				project_id = 0
1160
-			} else if temp[1] == "2" {
1353
+			} else if item.Type == 2 {
1161 1354
 				advice_id = 0
1162
-				project_id = id
1355
+				project_id = item.ProjectId
1163 1356
 			}
1164 1357
 
1358
+			detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
1359
+			cut, _ := strconv.ParseFloat(item.Cut, 32)
1360
+			pric, _ := strconv.ParseFloat(item.Price, 32)
1361
+
1165 1362
 			info := &models.HisOrderInfo{
1166 1363
 				OrderNumber:      order.Number,
1167
-				FeedetlSn:        item.FeedetlSn,
1168 1364
 				UploadDate:       time.Now().Unix(),
1169 1365
 				AdviceId:         advice_id,
1170
-				DetItemFeeSumamt: item.DetItemFeeSumamt,
1171
-				Cnt:              item.Cnt,
1172
-				Pric:             float64(item.Pric),
1366
+				DetItemFeeSumamt: detItemFeeSumamt,
1367
+				Cnt:              cut,
1368
+				Pric:             pric,
1173 1369
 				PatientId:        his.PatientId,
1174
-				PricUplmtAmt:     item.PricUplmtAmt,
1175
-				SelfpayProp:      item.SelfpayProp,
1176
-				FulamtOwnpayAmt:  item.FulamtOwnpayAmt,
1177
-				OverlmtAmt:       item.OverlmtAmt,
1178
-				PreselfpayAmt:    item.PreselfpayAmt,
1179
-				BasMednFlag:      item.BasMednFlag,
1180
-				MedChrgitmType:   item.MedChrgitmType,
1181
-				HiNegoDrugFlag:   item.HiNegoDrugFlag,
1182 1370
 				Status:           1,
1183
-				Memo:             item.Memo,
1184 1371
 				Mtime:            time.Now().Unix(),
1185
-				InscpScpAmt:      item.InscpScpAmt,
1186
-				DrtReimFlag:      item.DrtReimFlag,
1187 1372
 				Ctime:            time.Now().Unix(),
1188
-				ListSpItemFlag:   item.ListSpItemFlag,
1189
-				ChldMedcFlag:     item.ChldMedcFlag,
1190
-				LmtUsedFlag:      item.LmtUsedFlag,
1191
-				ChrgitmLv:        item.ChrgitmLv,
1192 1373
 				UserOrgId:        adminUser.CurrentOrgId,
1193 1374
 				HisPatientId:     his.ID,
1194 1375
 				OrderId:          order.ID,
@@ -1197,73 +1378,8 @@ func (c *HisApiController) GetUploadInfo() {
1197 1378
 			}
1198 1379
 			service.CreateOrderInfo(info)
1199 1380
 		}
1200
-
1201 1381
 		service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
1202
-
1203
-		var total float64
1204
-		for _, item := range prescriptions {
1205
-			if item.Type == 1 { //药品
1206
-				for _, subItem := range item.HisDoctorAdviceInfo {
1207
-					total = total + (subItem.Price * subItem.PrescribingNumber)
1208
-				}
1209
-			}
1210
-			if item.Type == 2 { //项目
1211
-				for _, subItem := range item.HisPrescriptionProject {
1212
-					total = total + (subItem.Price * float64(subItem.Count))
1213
-				}
1214
-			}
1215
-		}
1216
-
1217
-		org, _ := service.GetOrgById(adminUser.CurrentOrgId)
1218
-		patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
1219
-		allTotal := fmt.Sprintf("%.2f", total)
1220
-		if res.Infcode == 0 {
1221
-			var rf []*ResultFive
1222
-			json.Unmarshal([]byte(his.Iinfo), &rf)
1223
-			psn_no := his.PsnNo
1224
-			mdtrt_id := his.Number
1225
-			chrg_bchno := chrg_bchno
1226
-			cert_no := his.Certno
1227
-			insutype := rf[0].Insutype
1228
-			api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
1229
-				insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
1230
-				"&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor
1231
-			resp, requestErr := http.Get(api)
1232
-
1233
-			if requestErr != nil {
1234
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1235
-				return
1236
-			}
1237
-			defer resp.Body.Close()
1238
-			body, ioErr := ioutil.ReadAll(resp.Body)
1239
-			if ioErr != nil {
1240
-				utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
1241
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1242
-				return
1243
-			}
1244
-			var respJSON map[string]interface{}
1245
-			if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
1246
-				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1247
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1248
-				return
1249
-			}
1250
-			fmt.Println(respJSON)
1251
-			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
1252
-			userJSONBytes, _ := json.Marshal(respJSON)
1253
-			var res ResultFour
1254
-			if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1255
-				utils.ErrorLog("解析失败:%v", err)
1256
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1257
-				return
1258
-			}
1259
-		} else {
1260
-
1261
-		}
1262
-	} else {
1263
-
1264
-		c.ServeSuccessJSON(map[string]interface{}{
1265
-			"msg": res.ErrMsg,
1266
-		})
1382
+		service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
1267 1383
 
1268 1384
 	}
1269 1385
 }
@@ -1318,16 +1434,49 @@ func (c *HisApiController) GetHisPrescriptionList() {
1318 1434
 }
1319 1435
 
1320 1436
 func (c *HisApiController) GetHisPrescriptionInfo() {
1321
-	patient_id, _ := c.GetInt64("patient_id")
1322
-	his_patient_id, _ := c.GetInt64("his_patient_id")
1437
+	id, _ := c.GetInt64("id")
1323 1438
 	adminInfo := c.GetAdminUserInfo()
1324
-	prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(patient_id, his_patient_id, adminInfo.CurrentOrgId)
1439
+	prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
1440
+	prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
1325 1441
 	if err == nil {
1326 1442
 		c.ServeSuccessJSON(map[string]interface{}{
1327
-			"order": prescriptionOrder,
1443
+			"order":        prescriptionOrder,
1444
+			"prescription": prescription,
1328 1445
 		})
1329 1446
 	} else {
1330 1447
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1331 1448
 		return
1332 1449
 	}
1333 1450
 }
1451
+
1452
+func (c *HisApiController) Refund() {
1453
+	order_id, _ := c.GetInt64("order_id")
1454
+	number := c.GetString("number")
1455
+
1456
+	adminUser := c.GetAdminUserInfo()
1457
+	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
1458
+	if config.IsOpen == 1 { //对接了医保,走医保流程
1459
+
1460
+	} else {
1461
+		err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
1462
+		if err == nil {
1463
+			c.ServeSuccessJSON(map[string]interface{}{
1464
+				"msg": "退费成功",
1465
+			})
1466
+		} else {
1467
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1468
+			return
1469
+		}
1470
+
1471
+	}
1472
+
1473
+}
1474
+
1475
+func (c *HisApiController) GetMedicalInsuranceConfig() {
1476
+	adminUser := c.GetAdminUserInfo()
1477
+	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
1478
+	c.ServeSuccessJSON(map[string]interface{}{
1479
+		"config": config,
1480
+	})
1481
+
1482
+}

+ 33 - 16
models/his_models.go Näytä tiedosto

@@ -257,11 +257,13 @@ type HisPrescriptionInfo struct {
257 257
 	Creator            int64  `gorm:"column:creator" json:"creator" form:"creator"`
258 258
 	Modifier           int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
259 259
 	Diagnosis          string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
260
-	RegisterType       int64  `gorm:"column:register_type" json:"register_type" form:"register_type"`
260
+	RegisterType       string `gorm:"column:register_type" json:"register_type" form:"register_type"`
261 261
 	Doctor             string `gorm:"column:doctor" json:"doctor" form:"doctor"`
262 262
 	Departments        string `gorm:"column:departments" json:"departments" form:"departments"`
263 263
 	SickHistory        string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
264 264
 	PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
265
+	PrescriptionStatus int64  `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
266
+	BatchNumber        string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
265 267
 }
266 268
 
267 269
 func (HisPrescriptionInfo) TableName() string {
@@ -269,21 +271,23 @@ func (HisPrescriptionInfo) TableName() string {
269 271
 }
270 272
 
271 273
 type HisPrescription struct {
272
-	ID                     int64                     `gorm:"column:id" json:"id" form:"id"`
273
-	UserOrgId              int64                     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
274
-	RecordDate             int64                     `gorm:"column:record_date" json:"record_date" form:"record_date"`
275
-	PatientId              int64                     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
276
-	HisPatientId           int64                     `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
277
-	Status                 int64                     `gorm:"column:status" json:"status" form:"status"`
278
-	Ctime                  int64                     `gorm:"column:ctime" json:"ctime" form:"ctime"`
279
-	Mtime                  int64                     `gorm:"column:mtime" json:"mtime" form:"mtime"`
280
-	Number                 string                    `gorm:"column:number" json:"number" form:"number"`
281
-	Type                   int64                     `gorm:"column:type" json:"type" form:"type"`
282
-	Doctor                 string                    `gorm:"column:doctor" json:"doctor" form:"doctor"`
283
-	Creator                int64                     `gorm:"column:creator" json:"creator" form:"creator"`
284
-	Modifier               int64                     `gorm:"column:modifier" json:"modifier" form:"modifier"`
285
-	IsFinish               int64                     `gorm:"column:is_finish" json:"is_finish" form:"is_finish"`
286
-	BatchNumber            string                    `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
274
+	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
275
+	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
276
+	RecordDate         int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
277
+	PatientId          int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
278
+	HisPatientId       int64  `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
279
+	Status             int64  `gorm:"column:status" json:"status" form:"status"`
280
+	Ctime              int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
281
+	Mtime              int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
282
+	Number             string `gorm:"column:number" json:"number" form:"number"`
283
+	Type               int64  `gorm:"column:type" json:"type" form:"type"`
284
+	Doctor             string `gorm:"column:doctor" json:"doctor" form:"doctor"`
285
+	Creator            int64  `gorm:"column:creator" json:"creator" form:"creator"`
286
+	Modifier           int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
287
+	OrderStatus        int64  `gorm:"column:order_status" json:"order_status" form:"order_status"`
288
+	BatchNumber        string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
289
+	PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
290
+
287 291
 	HisDoctorAdviceInfo    []*HisDoctorAdviceInfo    `gorm:"ForeignKey:PatientId,RecordDate,PrescriptionId;AssociationForeignKey:PatientId,RecordDate,ID" json:"advices"`
288 292
 	HisPrescriptionProject []*HisPrescriptionProject `gorm:"ForeignKey:PatientId,RecordDate,PrescriptionId;AssociationForeignKey:PatientId,RecordDate,ID" json:"project"`
289 293
 }
@@ -676,3 +680,16 @@ type VMHisPatient struct {
676 680
 func (VMHisPatient) TableName() string {
677 681
 	return "his_patient"
678 682
 }
683
+
684
+type MedicalInsuranceConfig struct {
685
+	ID        int64 `gorm:"column:id" json:"id" form:"id"`
686
+	UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
687
+	Ctime     int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
688
+	Mtime     int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
689
+	Status    int64 `gorm:"column:status" json:"status" form:"status"`
690
+	IsOpen    int64 `gorm:"column:is_open" json:"is_open" form:"is_open"`
691
+}
692
+
693
+func (MedicalInsuranceConfig) TableName() string {
694
+	return "medical_insurance_config"
695
+}

+ 192 - 192
service/gdyb_service.go Näytä tiedosto

@@ -718,198 +718,198 @@ func Gdyb2208(psnNo string, mdtrtId string, setlId string, org_name string, doct
718 718
 }
719 719
 
720 720
 //  门诊结算撤销
721
-func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
722
-	// 生成签名
723
-	nonce := GetRandomString(32)
724
-	timestamp := time.Now().Unix()
725
-	signature := setSignature(timestamp, nonce)
726
-
727
-	// 生成输入报文
728
-	inputMessage := SetInputMessage(nonce, timestamp)
729
-	input := make(map[string]interface{})
730
-	inputData := make(map[string]interface{})
731
-	inputMessage["infno"] = "4101" // 交易编码
732
-
733
-	inputData["mdtrt_id"] = mdtrtId // 就诊 ID  必填(来自2201接口返回)
734
-	inputData["setl_id"] = setlId   // 结算 ID  必填
735
-	inputData["fixmedins_name"] = ""   // 定点医药机构名称  必填
736
-	inputData["fixmedins_code"] = ""   // 定点医药机构编码  必填
737
-	inputData["hi_setl_lv"] = ""   // 医保结算等级
738
-	inputData["hi_no"] = ""   // 医保编号
739
-	inputData["medcasno"] = ""   // 病案号  必填
740
-	inputData["dcla_time"] = ""   // 申报时间  必填
741
-	inputData["psn_name"] = ""   // 人员姓名  必填
742
-	inputData["gend"] = ""   // 性别  必填
743
-	inputData["brdy"] = ""   // 出生日期  必填
744
-	inputData["age"] = ""   // 年龄  必填
745
-	inputData["ntly"] = ""   // 国籍  必填
746
-	inputData["nwb_age"] = ""   // 年龄  必填
747
-	inputData["naty"] = ""   // 民族  必填
748
-	inputData["patn_cert_type"] = ""   // 患者证件类别  必填
749
-	inputData["certno"] = ""   // 证件号码  必填
750
-	inputData["prfs"] = ""   // 职业  必填
751
-	inputData["curr_addr"] = ""   // 现住址  必填
752
-	inputData["emp_name"] = ""   // 单位名称  必填
753
-	inputData["emp_addr"] = ""   // 单位地址  必填
754
-	inputData["emp_tel"] = ""   // 单位电话  必填
755
-	inputData["poscode"] = ""   // 邮编  必填
756
-	inputData["coner_name"] = ""   // 联系人姓名  必填
757
-	inputData["patn_rlts"] = ""   // 与患者关系  必填
758
-	inputData["coner_addr"] = ""   // 联系人地址  必填
759
-	inputData["coner_tel"] = ""   // 联系人电话  必填
760
-	inputData["hi_type"] = ""   // 医保类型  必填
761
-	inputData["insuplc"] = ""   // 参保地  必填
762
-	inputData["sp_psn_type"] = ""   // 特殊人员类型  必填
763
-	inputData["nwb_adm_type"] = ""   // 新生儿入院类型  必填
764
-	inputData["nwb_bir_wt"] = ""   // 新生儿出生体重  必填
765
-	inputData["nwb_adm_wt"] = ""   // 新生儿入院体重  必填
766
-	inputData["opsp_diag_caty"] = ""   // 门诊慢特病诊断  必填
767
-	inputData["opsp_mdtrt_date"] = ""   // 门诊慢特病就诊日期  必填
768
-	inputData["ipt_med_type"] = ""   // 住院医疗类型  必填
769
-	inputData["adm_way"] = ""   // 入院途径  必填
770
-	inputData["trt_type"] = ""   // 治疗类别  必填
771
-	inputData["adm_time"] = ""   // 入院时间  必填
772
-	inputData["adm_caty"] = ""   // 入院科别  必填
773
-	inputData["refldept_dept"] = ""   // 转科科别  必填
774
-	inputData["dscg_time"] = ""   // 出院时间  必填
775
-	inputData["dscg_caty"] = ""   // 出院科别  必填
776
-	inputData["act_ipt_days"] = ""   // 实际住院天数  必填
777
-	inputData["otp_wm_dise"] = ""   // 门(急) 诊西医诊断  必填
778
-	inputData["wm_dise_code"] = ""   // 门(急) 诊中医诊断  必填
779
-	inputData["otp_tcm_dise"] = ""   // 西医诊断疾病代码  必填
780
-	inputData["tcm_dise_code"] = ""   // 中医诊断代码  必填
781
-	inputData["oprn_oprt_code_cnt"] = ""   // 手术操作代码计数  必填
782
-	inputData["vent_used_dura"] = ""   // 呼吸机使用时长  必填
783
-	inputData["pwcry_bfadm_coma_dura"] = ""   // 颅脑损伤患者入院前昏迷时长  必填
784
-	inputData["pwcry_afadm_coma_dura"] = ""   // 颅脑损伤患者入院后昏迷时长  必填
785
-	inputData["bld_cat"] = ""   // 输血品种  必填
786
-	inputData["bld_amt"] = ""   // 输血量  必填
787
-	inputData["bld_unt"] = ""   // 输血计量单位  必填
788
-	inputData["spga_nurscare_days"] = ""   // 特级护理天数  必填
789
-	inputData["lv1_nurscare_days"] = ""   // 一级护理天数  必填
790
-	inputData["scd_nurscare_days"] = ""   // 二级护理天数  必填
791
-	inputData["lv3_nurscare_days"] = ""   // 三级护理天数  必填
792
-	inputData["acp_medins_name"] = ""   // 拟接收机构名称  必填
793
-	inputData["acp_optins_code"] = ""   // 拟接收机构代码  必填
794
-	inputData["bill_code"] = ""   // 票据代码  必填
795
-	inputData["bill_no"] = ""   // 票据号码  必填
796
-	inputData["biz_sn"] = ""   // 业务流水号  必填
797
-	inputData["days_rinp_flag_31"] = ""   // 出院 31 天内再住院计划标志  必填
798
-	inputData["days_rinp_pup_31"] = ""   // 出院 31 天内再住院目的  必填
799
-	inputData["chfpdr_name"] = ""   // 主诊医师姓名  必填
800
-	inputData["chfpdr_code"] = ""   // 主诊医师代码  必填
801
-	inputData["setl_begn_date"] = ""   // 结算开始日期  必填
802
-	inputData["setl_end_date"] = ""   // 结算结束日期  必填
803
-	inputData["psn_selfpay"] = ""   // 个人自付  必填
804
-	inputData["psn_ownpay"] = ""   // 个人自费  必填
805
-	inputData["acct_pay"] = ""   // 个人账户支出  必填
806
-	inputData["hi_paymtd"] = ""   // 医保支付方式  必填
807
-	inputData["hsorg"] = ""   // 医保机构  必填
808
-	inputData["hsorg_opter"] = ""   // 医保机构经办人  必填
809
-	inputData["medins_fill_dept"] = ""   // 医疗机构填报部门  必填
810
-	inputData["medins_fill_psn"] = ""   // 医疗机构填报人  必填
811
-
812
-	payinfo := make([]map[string]interface{},0)  // 基金支付信息
813
-	payinfotemp := make(map[string]interface{})
814
-	payinfotemp["fund_pay_type"] =  "" // 基金支付类型  必填
815
-	payinfotemp["fund_payamt"] = ""    // 基金支付金额
816
-	payinfo = append(payinfo,payinfotemp)
817
-
818
-	opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
819
-	opspdiseinfotemp := make(map[string]interface{})
820
-	opspdiseinfotemp["diag_name"] =  "" // 诊断名称  必填
821
-	opspdiseinfotemp["diag_code"] = ""    // 诊断代码 必填
822
-	opspdiseinfotemp["oprn_oprt_name"] = ""    // 手术操作名称 必填
823
-	opspdiseinfotemp["oprn_oprt_code"] = ""    // 手术操作代码 必填
824
-	opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
825
-
826
-	diseinfo := make([]map[string]interface{},0) // 住院诊断信息
827
-	diseinfotemp := make(map[string]interface{})
828
-	diseinfotemp["diag_type"] =  "" // 诊断类别  必填
829
-	diseinfotemp["diag_code"] = ""    // 诊断代码 必填
830
-	diseinfotemp["diag_name"] = ""    // 诊断名称 必填
831
-	diseinfotemp["adm_cond_type"] = ""    // 入院病情类型 必填
832
-	diseinfo = append(diseinfo,diseinfotemp)
833
-
834
-	iteminfo := make([]map[string]interface{},0) // 住院诊断信息
835
-	iteminfotemp := make(map[string]interface{})
836
-	iteminfotemp["med_chrgitm"] =  "" // 医疗收费项目  必填
837
-	iteminfotemp["amt"] = ""    // 金额 必填
838
-	iteminfotemp["claa_sumfee"] = ""    // 甲类费用合计 必填
839
-	iteminfotemp["clab_amt"] = ""    // 乙类金额 必填
840
-	iteminfotemp["fulamt_ownpay_amt"] = ""    // 全自费金额 必填
841
-	iteminfotemp["oth_amt"] = ""    // 其他金额 必填
842
-	iteminfo = append(iteminfo,iteminfotemp)
843
-
844
-	oprninfo := make([]map[string]interface{},0) // 手术操作信息
845
-	oprninfotemp := make(map[string]interface{})
846
-	oprninfotemp["oprn_oprt_type"] =  "" // 手术操作类别  必填
847
-	oprninfotemp["oprn_oprt_name"] = ""    // 手术操作名称 必填
848
-	oprninfotemp["oprn_oprt_code"] = ""    // 手术操作代码 必填
849
-	oprninfotemp["oprn_oprt_date"] = ""    // 手术操作日期 必填
850
-	oprninfotemp["anst_way"] = ""    // 麻醉方式 必填
851
-	oprninfotemp["oper_dr_name"] = ""    // 术者医师姓名 必填
852
-	oprninfotemp["oper_dr_code"] = ""    // 术者医师代码 必填
853
-	oprninfotemp["anst_dr_name"] = ""    // 麻醉医师姓名 必填
854
-	oprninfotemp["anst_dr_code"] = ""    // 麻醉医师代码 必填
855
-	oprninfo = append(oprninfo,iteminfotemp)
856
-
857
-	icuinfo := make([]map[string]interface{},0) // 重症监护信息
858
-	icuinfotemp := make(map[string]interface{})
859
-	icuinfotemp["scs_cutd_ward_type"] =  "" // 重症监护病房类型  必填
860
-	icuinfotemp["scs_cutd_inpool_time"] = ""    // 重症监护进入时间 必填
861
-	icuinfotemp["scs_cutd_exit_time"] = ""    // 重症监护退出时间 必填
862
-	icuinfotemp["scs_cutd_sum_dura"] = ""    // 重症监护合计时长 必填
863
-	icuinfo = append(icuinfo,iteminfotemp)
864
-
865
-
866
-
867
-
868
-	input["setlinfo"] = inputData
869
-	input["payinfo"] = payinfo
870
-	input["opspdiseinfo"] = opspdiseinfo
871
-	input["diseinfo"] = diseinfo
872
-	input["iteminfo"] = iteminfo
873
-	input["oprninfo"] = oprninfo
874
-	input["icuinfo"] = icuinfo
875
-	inputMessage["input"] = input //交易输入
876
-
877
-	bytesData, err := json.Marshal(inputMessage)
878
-	fmt.Println(string(bytesData))
879
-	if err != nil {
880
-		fmt.Println(err.Error())
881
-		return err.Error()
882
-	}
883
-	reader := bytes.NewReader(bytesData)
884
-
885
-	url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
886
-	request, err := http.NewRequest("POST", url, reader)
887
-	if err != nil {
888
-		fmt.Println(err.Error())
889
-		return err.Error()
890
-	}
891
-
892
-	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
893
-	request.Header.Set("x-tif-paasid", "test_hosp")
894
-	request.Header.Set("x-tif-signature", signature)
895
-	request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
896
-	request.Header.Set("x-tif-nonce", nonce)
897
-
898
-	client := http.Client{}
899
-	resp, err := client.Do(request)
900
-	if err != nil {
901
-		fmt.Println(err.Error())
902
-		return err.Error()
903
-	}
904
-	respBytes, err := ioutil.ReadAll(resp.Body)
905
-	if err != nil {
906
-		fmt.Println(err.Error())
907
-		return err.Error()
908
-	}
909
-	str := string(respBytes)
910
-	fmt.Println(str)
911
-	return str
912
-}
721
+//func Gdyb4101(psnNo string, mdtrtId string, setlId string) string {
722
+//	// 生成签名
723
+//	nonce := GetRandomString(32)
724
+//	timestamp := time.Now().Unix()
725
+//	signature := setSignature(timestamp, nonce)
726
+//
727
+//	// 生成输入报文
728
+//	inputMessage := SetInputMessage(nonce, timestamp)
729
+//	input := make(map[string]interface{})
730
+//	inputData := make(map[string]interface{})
731
+//	inputMessage["infno"] = "4101" // 交易编码
732
+//
733
+//	inputData["mdtrt_id"] = mdtrtId // 就诊 ID  必填(来自2201接口返回)
734
+//	inputData["setl_id"] = setlId   // 结算 ID  必填
735
+//	inputData["fixmedins_name"] = ""   // 定点医药机构名称  必填
736
+//	inputData["fixmedins_code"] = ""   // 定点医药机构编码  必填
737
+//	inputData["hi_setl_lv"] = ""   // 医保结算等级
738
+//	inputData["hi_no"] = ""   // 医保编号
739
+//	inputData["medcasno"] = ""   // 病案号  必填
740
+//	inputData["dcla_time"] = ""   // 申报时间  必填
741
+//	inputData["psn_name"] = ""   // 人员姓名  必填
742
+//	inputData["gend"] = ""   // 性别  必填
743
+//	inputData["brdy"] = ""   // 出生日期  必填
744
+//	inputData["age"] = ""   // 年龄  必填
745
+//	inputData["ntly"] = ""   // 国籍  必填
746
+//	inputData["nwb_age"] = ""   // 年龄  必填
747
+//	inputData["naty"] = ""   // 民族  必填
748
+//	inputData["patn_cert_type"] = ""   // 患者证件类别  必填
749
+//	inputData["certno"] = ""   // 证件号码  必填
750
+//	inputData["prfs"] = ""   // 职业  必填
751
+//	inputData["curr_addr"] = ""   // 现住址  必填
752
+//	inputData["emp_name"] = ""   // 单位名称  必填
753
+//	inputData["emp_addr"] = ""   // 单位地址  必填
754
+//	inputData["emp_tel"] = ""   // 单位电话  必填
755
+//	inputData["poscode"] = ""   // 邮编  必填
756
+//	inputData["coner_name"] = ""   // 联系人姓名  必填
757
+//	inputData["patn_rlts"] = ""   // 与患者关系  必填
758
+//	inputData["coner_addr"] = ""   // 联系人地址  必填
759
+//	inputData["coner_tel"] = ""   // 联系人电话  必填
760
+//	inputData["hi_type"] = ""   // 医保类型  必填
761
+//	inputData["insuplc"] = ""   // 参保地  必填
762
+//	inputData["sp_psn_type"] = ""   // 特殊人员类型  必填
763
+//	inputData["nwb_adm_type"] = ""   // 新生儿入院类型  必填
764
+//	inputData["nwb_bir_wt"] = ""   // 新生儿出生体重  必填
765
+//	inputData["nwb_adm_wt"] = ""   // 新生儿入院体重  必填
766
+//	inputData["opsp_diag_caty"] = ""   // 门诊慢特病诊断  必填
767
+//	inputData["opsp_mdtrt_date"] = ""   // 门诊慢特病就诊日期  必填
768
+//	inputData["ipt_med_type"] = ""   // 住院医疗类型  必填
769
+//	inputData["adm_way"] = ""   // 入院途径  必填
770
+//	inputData["trt_type"] = ""   // 治疗类别  必填
771
+//	inputData["adm_time"] = ""   // 入院时间  必填
772
+//	inputData["adm_caty"] = ""   // 入院科别  必填
773
+//	inputData["refldept_dept"] = ""   // 转科科别  必填
774
+//	inputData["dscg_time"] = ""   // 出院时间  必填
775
+//	inputData["dscg_caty"] = ""   // 出院科别  必填
776
+//	inputData["act_ipt_days"] = ""   // 实际住院天数  必填
777
+//	inputData["otp_wm_dise"] = ""   // 门(急) 诊西医诊断  必填
778
+//	inputData["wm_dise_code"] = ""   // 门(急) 诊中医诊断  必填
779
+//	inputData["otp_tcm_dise"] = ""   // 西医诊断疾病代码  必填
780
+//	inputData["tcm_dise_code"] = ""   // 中医诊断代码  必填
781
+//	inputData["oprn_oprt_code_cnt"] = ""   // 手术操作代码计数  必填
782
+//	inputData["vent_used_dura"] = ""   // 呼吸机使用时长  必填
783
+//	inputData["pwcry_bfadm_coma_dura"] = ""   // 颅脑损伤患者入院前昏迷时长  必填
784
+//	inputData["pwcry_afadm_coma_dura"] = ""   // 颅脑损伤患者入院后昏迷时长  必填
785
+//	inputData["bld_cat"] = ""   // 输血品种  必填
786
+//	inputData["bld_amt"] = ""   // 输血量  必填
787
+//	inputData["bld_unt"] = ""   // 输血计量单位  必填
788
+//	inputData["spga_nurscare_days"] = ""   // 特级护理天数  必填
789
+//	inputData["lv1_nurscare_days"] = ""   // 一级护理天数  必填
790
+//	inputData["scd_nurscare_days"] = ""   // 二级护理天数  必填
791
+//	inputData["lv3_nurscare_days"] = ""   // 三级护理天数  必填
792
+//	inputData["acp_medins_name"] = ""   // 拟接收机构名称  必填
793
+//	inputData["acp_optins_code"] = ""   // 拟接收机构代码  必填
794
+//	inputData["bill_code"] = ""   // 票据代码  必填
795
+//	inputData["bill_no"] = ""   // 票据号码  必填
796
+//	inputData["biz_sn"] = ""   // 业务流水号  必填
797
+//	inputData["days_rinp_flag_31"] = ""   // 出院 31 天内再住院计划标志  必填
798
+//	inputData["days_rinp_pup_31"] = ""   // 出院 31 天内再住院目的  必填
799
+//	inputData["chfpdr_name"] = ""   // 主诊医师姓名  必填
800
+//	inputData["chfpdr_code"] = ""   // 主诊医师代码  必填
801
+//	inputData["setl_begn_date"] = ""   // 结算开始日期  必填
802
+//	inputData["setl_end_date"] = ""   // 结算结束日期  必填
803
+//	inputData["psn_selfpay"] = ""   // 个人自付  必填
804
+//	inputData["psn_ownpay"] = ""   // 个人自费  必填
805
+//	inputData["acct_pay"] = ""   // 个人账户支出  必填
806
+//	inputData["hi_paymtd"] = ""   // 医保支付方式  必填
807
+//	inputData["hsorg"] = ""   // 医保机构  必填
808
+//	inputData["hsorg_opter"] = ""   // 医保机构经办人  必填
809
+//	inputData["medins_fill_dept"] = ""   // 医疗机构填报部门  必填
810
+//	inputData["medins_fill_psn"] = ""   // 医疗机构填报人  必填
811
+//
812
+//	payinfo := make([]map[string]interface{},0)  // 基金支付信息
813
+//	payinfotemp := make(map[string]interface{})
814
+//	payinfotemp["fund_pay_type"] =  "" // 基金支付类型  必填
815
+//	payinfotemp["fund_payamt"] = ""    // 基金支付金额
816
+//	payinfo = append(payinfo,payinfotemp)
817
+//
818
+//	opspdiseinfo := make([]map[string]interface{},0) // 门诊慢特病诊断信息
819
+//	opspdiseinfotemp := make(map[string]interface{})
820
+//	opspdiseinfotemp["diag_name"] =  "" // 诊断名称  必填
821
+//	opspdiseinfotemp["diag_code"] = ""    // 诊断代码 必填
822
+//	opspdiseinfotemp["oprn_oprt_name"] = ""    // 手术操作名称 必填
823
+//	opspdiseinfotemp["oprn_oprt_code"] = ""    // 手术操作代码 必填
824
+//	opspdiseinfo = append(opspdiseinfo,opspdiseinfotemp)
825
+//
826
+//	diseinfo := make([]map[string]interface{},0) // 住院诊断信息
827
+//	diseinfotemp := make(map[string]interface{})
828
+//	diseinfotemp["diag_type"] =  "" // 诊断类别  必填
829
+//	diseinfotemp["diag_code"] = ""    // 诊断代码 必填
830
+//	diseinfotemp["diag_name"] = ""    // 诊断名称 必填
831
+//	diseinfotemp["adm_cond_type"] = ""    // 入院病情类型 必填
832
+//	diseinfo = append(diseinfo,diseinfotemp)
833
+//
834
+//	iteminfo := make([]map[string]interface{},0) // 住院诊断信息
835
+//	iteminfotemp := make(map[string]interface{})
836
+//	iteminfotemp["med_chrgitm"] =  "" // 医疗收费项目  必填
837
+//	iteminfotemp["amt"] = ""    // 金额 必填
838
+//	iteminfotemp["claa_sumfee"] = ""    // 甲类费用合计 必填
839
+//	iteminfotemp["clab_amt"] = ""    // 乙类金额 必填
840
+//	iteminfotemp["fulamt_ownpay_amt"] = ""    // 全自费金额 必填
841
+//	iteminfotemp["oth_amt"] = ""    // 其他金额 必填
842
+//	iteminfo = append(iteminfo,iteminfotemp)
843
+//
844
+//	oprninfo := make([]map[string]interface{},0) // 手术操作信息
845
+//	oprninfotemp := make(map[string]interface{})
846
+//	oprninfotemp["oprn_oprt_type"] =  "" // 手术操作类别  必填
847
+//	oprninfotemp["oprn_oprt_name"] = ""    // 手术操作名称 必填
848
+//	oprninfotemp["oprn_oprt_code"] = ""    // 手术操作代码 必填
849
+//	oprninfotemp["oprn_oprt_date"] = ""    // 手术操作日期 必填
850
+//	oprninfotemp["anst_way"] = ""    // 麻醉方式 必填
851
+//	oprninfotemp["oper_dr_name"] = ""    // 术者医师姓名 必填
852
+//	oprninfotemp["oper_dr_code"] = ""    // 术者医师代码 必填
853
+//	oprninfotemp["anst_dr_name"] = ""    // 麻醉医师姓名 必填
854
+//	oprninfotemp["anst_dr_code"] = ""    // 麻醉医师代码 必填
855
+//	oprninfo = append(oprninfo,iteminfotemp)
856
+//
857
+//	icuinfo := make([]map[string]interface{},0) // 重症监护信息
858
+//	icuinfotemp := make(map[string]interface{})
859
+//	icuinfotemp["scs_cutd_ward_type"] =  "" // 重症监护病房类型  必填
860
+//	icuinfotemp["scs_cutd_inpool_time"] = ""    // 重症监护进入时间 必填
861
+//	icuinfotemp["scs_cutd_exit_time"] = ""    // 重症监护退出时间 必填
862
+//	icuinfotemp["scs_cutd_sum_dura"] = ""    // 重症监护合计时长 必填
863
+//	icuinfo = append(icuinfo,iteminfotemp)
864
+//
865
+//
866
+//
867
+//
868
+//	input["setlinfo"] = inputData
869
+//	input["payinfo"] = payinfo
870
+//	input["opspdiseinfo"] = opspdiseinfo
871
+//	input["diseinfo"] = diseinfo
872
+//	input["iteminfo"] = iteminfo
873
+//	input["oprninfo"] = oprninfo
874
+//	input["icuinfo"] = icuinfo
875
+//	inputMessage["input"] = input //交易输入
876
+//
877
+//	bytesData, err := json.Marshal(inputMessage)
878
+//	fmt.Println(string(bytesData))
879
+//	if err != nil {
880
+//		fmt.Println(err.Error())
881
+//		return err.Error()
882
+//	}
883
+//	reader := bytes.NewReader(bytesData)
884
+//
885
+//	url := "http://igb.hsa.gdgov.cn/ebus/gdyb_inf/poc/hsa/hgs/2208"
886
+//	request, err := http.NewRequest("POST", url, reader)
887
+//	if err != nil {
888
+//		fmt.Println(err.Error())
889
+//		return err.Error()
890
+//	}
891
+//
892
+//	request.Header.Set("Content-Type", "application/json;charset=UTF-8")
893
+//	request.Header.Set("x-tif-paasid", "test_hosp")
894
+//	request.Header.Set("x-tif-signature", signature)
895
+//	request.Header.Set("x-tif-timestamp", strconv.FormatInt(timestamp, 10))
896
+//	request.Header.Set("x-tif-nonce", nonce)
897
+//
898
+//	client := http.Client{}
899
+//	resp, err := client.Do(request)
900
+//	if err != nil {
901
+//		fmt.Println(err.Error())
902
+//		return err.Error()
903
+//	}
904
+//	respBytes, err := ioutil.ReadAll(resp.Body)
905
+//	if err != nil {
906
+//		fmt.Println(err.Error())
907
+//		return err.Error()
908
+//	}
909
+//	str := string(respBytes)
910
+//	fmt.Println(str)
911
+//	return str
912
+//}
913 913
 
914 914
 // 生成签名
915 915
 func setSignature(timestamp int64, nonce string) string {

+ 54 - 20
service/his_service.go Näytä tiedosto

@@ -264,6 +264,12 @@ func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (er
264 264
 	return
265 265
 }
266 266
 
267
+func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
268
+	err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date = ?", user_org_id, id, record_time).Updates(map[string]interface{}{"batch_number": number, "status": 2, "mtime": time.Now().Unix()}).Error
269
+
270
+	return
271
+}
272
+
267 273
 type HisOrder struct {
268 274
 	ID                 int64  `gorm:"column:id" json:"id" form:"id"`
269 275
 	UserOrgId          int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -309,23 +315,26 @@ func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64,
309 315
 }
310 316
 
311 317
 type HisPrescriptionInfo struct {
312
-	ID           int64             `gorm:"column:id" json:"id" form:"id"`
313
-	UserOrgId    int64             `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
314
-	RecordDate   int64             `gorm:"column:record_date" json:"record_date" form:"record_date"`
315
-	PatientId    int64             `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
316
-	HisPatientId int64             `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
317
-	Status       int64             `gorm:"column:status" json:"status" form:"status"`
318
-	Ctime        int64             `gorm:"column:ctime" json:"ctime" form:"ctime"`
319
-	Mtime        int64             `gorm:"column:mtime" json:"mtime" form:"mtime"`
320
-	Creator      int64             `gorm:"column:creator" json:"creator" form:"creator"`
321
-	Modifier     int64             `gorm:"column:modifier" json:"modifier" form:"modifier"`
322
-	Diagnosis    string            `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
323
-	RegisterType int64             `gorm:"column:register_type" json:"register_type" form:"register_type"`
324
-	Doctor       string            `gorm:"column:doctor" json:"doctor" form:"doctor"`
325
-	Departments  string            `gorm:"column:departments" json:"departments" form:"departments"`
326
-	SickHistory  string            `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
327
-	Patients     models.Patients   `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
328
-	HisPatient   models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
318
+	ID                 int64             `gorm:"column:id" json:"id" form:"id"`
319
+	UserOrgId          int64             `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
320
+	RecordDate         int64             `gorm:"column:record_date" json:"record_date" form:"record_date"`
321
+	PatientId          int64             `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
322
+	HisPatientId       int64             `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
323
+	Status             int64             `gorm:"column:status" json:"status" form:"status"`
324
+	Ctime              int64             `gorm:"column:ctime" json:"ctime" form:"ctime"`
325
+	Mtime              int64             `gorm:"column:mtime" json:"mtime" form:"mtime"`
326
+	Creator            int64             `gorm:"column:creator" json:"creator" form:"creator"`
327
+	Modifier           int64             `gorm:"column:modifier" json:"modifier" form:"modifier"`
328
+	Diagnosis          string            `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
329
+	RegisterType       string            `gorm:"column:register_type" json:"register_type" form:"register_type"`
330
+	Doctor             string            `gorm:"column:doctor" json:"doctor" form:"doctor"`
331
+	Departments        string            `gorm:"column:departments" json:"departments" form:"departments"`
332
+	SickHistory        string            `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
333
+	Patients           models.Patients   `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
334
+	HisPatient         models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
335
+	PrescriptionNumber string            `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
336
+	BatchNumber        string            `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
337
+	PrescriptionStatus int64             `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
329 338
 }
330 339
 
331 340
 func (HisPrescriptionInfo) TableName() string {
@@ -340,10 +349,35 @@ func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescrip
340 349
 
341 350
 }
342 351
 
343
-func GetHisPrescriptionOrderInfo(patient_id, his_patient_id, org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
344
-	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
352
+func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
353
+	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
345 354
 		Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
346
-		Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).Error
355
+		Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
356
+	return
357
+
358
+}
359
+
360
+func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
361
+	err = readDb.Model(&models.HisPrescription{}).
362
+		Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
363
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
364
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
365
+		}).
366
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
367
+		Find(&prescription).Error
368
+	return
369
+}
370
+
371
+func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
372
+	err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
373
+	return
374
+
375
+}
376
+
377
+func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
378
+	err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix()}).Error
379
+	err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix()}).Error
380
+	err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
347 381
 	return
348 382
 
349 383
 }