Pārlūkot izejas kodu

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

csx 4 gadus atpakaļ
vecāks
revīzija
ceeeb46796

+ 65 - 199
controllers/his_api_controller.go Parādīt failu

@@ -116,6 +116,11 @@ func (c *HisApiController) GetHisPrescriptionConfig() {
116 116
 	advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
117 117
 	//获取所有基础药
118 118
 	drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
119
+
120
+	//drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
121
+	//drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
122
+	drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
123
+	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
119 124
 	//获取所有项目
120 125
 	projects, _ := service.GetAllProjectList(adminInfo.CurrentOrgId)
121 126
 	//获取所有项目组套
@@ -124,73 +129,17 @@ func (c *HisApiController) GetHisPrescriptionConfig() {
124 129
 		"drugs":            drugs,
125 130
 		"advices_template": advices,
126 131
 		"projects":         projects,
132
+		"drugways":         drugways,
133
+		"efs":              efs,
127 134
 	})
128 135
 }
129 136
 func (c *HisApiController) CreateHisPrescription() {
130 137
 	record_date := c.GetString("record_date")
131 138
 	patient_id, _ := c.GetInt64("patient_id")
132
-	his_patient_id, _ := c.GetInt64("his_patient_id")
133
-	types, _ := c.GetInt64("type")
134
-	doctor := c.GetAdminUserInfo().AdminUser.Id
135
-
136
-	timeLayout := "2006-01-02"
137
-	loc, _ := time.LoadLocation("Local")
138
-
139
-	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
140
-	if err != nil {
141
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
142
-		return
143
-	}
144
-	recordDateTime := theTime.Unix()
145
-
146
-	prescription := &models.HisPrescription{
147
-		UserOrgId:    c.GetAdminUserInfo().CurrentOrgId,
148
-		RecordDate:   recordDateTime,
149
-		PatientId:    patient_id,
150
-		HisPatientId: his_patient_id,
151
-		Status:       1,
152
-		Ctime:        time.Now().Unix(),
153
-		Mtime:        time.Now().Unix(),
154
-		Type:         types,
155
-		Doctor:       doctor,
156
-		Creator:      doctor,
157
-		Modifier:     doctor,
158
-	}
159
-
160
-	err = service.SaveHisPrescription(prescription)
161
-	if err == nil {
162
-		c.ServeSuccessJSON(map[string]interface{}{
163
-			"msg": "保存成功",
164
-		})
165
-		return
166
-
167
-	} else {
168
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
169
-		return
170
-	}
171
-}
172
-func (c *HisApiController) CreateHisDoctorAdvice() {
173
-	patient_id, _ := c.GetInt64("patient_id")
174
-	his_patient_id, _ := c.GetInt64("his_patient_id")
175
-	prescription_id, _ := c.GetInt64("prescription_id")
176
-
177
-	//patient, _ := c.GetInt64("id", 0)
178
-	//if patient <= 0 {
179
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
180
-	//	return
181
-	//}
182
-	adminUserInfo := c.GetAdminUserInfo()
183
-
184
-	//patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
185
-	//if patientInfo.ID == 0 {
186
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
187
-	//	return
188
-	//}
139
+	doctor, _ := c.GetInt64("doctor")
189 140
 
190
-	group_no, _ := c.GetInt64("group_no")
191
-	if group_no <= 0 {
192
-		group_no = 0
193
-	}
141
+	diagnose := c.GetString("diagnose")
142
+	special_sick_history := c.GetString("special_sick_history")
194 143
 
195 144
 	dataBody := make(map[string]interface{}, 0)
196 145
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -202,155 +151,76 @@ func (c *HisApiController) CreateHisDoctorAdvice() {
202 151
 
203 152
 	timeLayout := "2006-01-02"
204 153
 	loc, _ := time.LoadLocation("Local")
205
-
206
-	if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
207
-		utils.ErrorLog("advice_type")
208
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
209
-		return
210
-	}
211
-	adviceType := int64(dataBody["advice_type"].(float64))
212
-	if adviceType != 1 && adviceType != 2 {
213
-		utils.ErrorLog("advice_type != 1&&2")
214
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
215
-		return
216
-	}
217
-
218
-	if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
219
-		utils.ErrorLog("start_time")
220
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
221
-		return
222
-	}
223
-
224
-	startTime2, _ := dataBody["start_time"].(string)
225
-	time_arr := strings.Split(startTime2, " ")
226
-	if len(time_arr) > 0 {
227
-		startTime2 = time_arr[0]
228
-	}
229
-	if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
230
-		utils.ErrorLog("advice_date")
231
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
232
-		return
233
-	}
234
-	adviceDate := startTime2
235
-	if len(adviceDate) == 0 {
236
-		utils.ErrorLog("len(adviceDate) == 0")
237
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
238
-		return
239
-	}
240
-	theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
154
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
241 155
 	if err != nil {
242
-		utils.ErrorLog(err.Error())
243 156
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
244 157
 		return
245 158
 	}
246
-	AdviceDate := theTime.Unix()
247
-	RecordDate := theTime.Unix()
159
+	adminInfo := c.GetAdminUserInfo()
160
+	recordDateTime := theTime.Unix()
248 161
 
249
-	if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
250
-		utils.ErrorLog("start_time")
251
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
252
-		return
253
-	}
254
-	startTime, _ := dataBody["start_time"].(string)
255
-	if len(startTime) == 0 {
256
-		utils.ErrorLog("len(start_time) == 0")
257
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
258
-		return
259
-	}
260
-	theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
261
-	if err != nil {
262
-		utils.ErrorLog(err.Error())
263
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
264
-		return
265
-	}
266
-	StartTime := theTime.Unix()
162
+	//types, _ := c.GetInt64("type")
163
+	var prescriptions []*models.HisPrescription
267 164
 
268
-	Remark := ""
269
-	if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
270
-		remark, _ := dataBody["remark"].(string)
271
-		Remark = remark
272
-	}
165
+	if dataBody["prescription"] != nil && reflect.TypeOf(dataBody["prescription"]).String() == "[]interface {}" {
166
+		prescriptions, _ := dataBody["prescription"].([]interface{})
167
+		if len(prescriptions) > 0 {
168
+			for _, item := range prescriptions {
169
+				items := item.(map[string]interface{})
273 170
 
274
-	var advices []*models.HisGroupAdvice
275
-	// utils.TraceLog("%+v", dataBody["adviceNames"])
276
-	if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
277
-		utils.ErrorLog("adviceNames")
278
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
279
-		return
280
-	}
281
-	adviceNames := dataBody["adviceNames"].([]interface{})
282
-	for _, adviceNameMap := range adviceNames {
283
-		adviceNameM := adviceNameMap.(map[string]interface{})
284
-		var advice models.HisGroupAdvice
285
-		advice.Remark = Remark
286
-		advice.AdviceType = adviceType
287
-		advice.StartTime = StartTime
288
-		advice.AdviceDate = AdviceDate
289
-		advice.RecordDate = RecordDate
290
-		advice.Status = 1
291
-		advice.CreatedTime = time.Now().Unix()
292
-		advice.UpdatedTime = time.Now().Unix()
293
-		advice.StopState = 2
294
-		advice.ExecutionState = 2
295
-		advice.UserOrgId = adminUserInfo.CurrentOrgId
296
-		advice.PatientId = patient_id
297
-		advice.HisPatientId = his_patient_id
298
-		advice.AdviceDoctor = adminUserInfo.AdminUser.Id
299
-		advice.PrescriptionId = prescription_id
300
-
301
-		//入口
302
-		errcode := c.setAdviceWithJSON(&advice, adviceNameM)
303
-		if errcode > 0 {
304
-			c.ServeFailJSONWithSGJErrorCode(errcode)
305
-			return
306
-		}
171
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
172
+					utils.ErrorLog("type")
173
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
174
+					return
175
+				}
176
+				types := int64(items["type"].(float64))
307 177
 
308
-		if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
309
-			subdrugs := adviceNameM["subdrugs"].([]interface{})
310
-			if len(subdrugs) > 0 {
311
-				for _, subdrug := range subdrugs {
312
-					var s models.HisGroupAdvice
313
-					s.Remark = Remark
314
-					s.AdviceType = adviceType
315
-					s.StartTime = StartTime
316
-					s.AdviceDate = AdviceDate
317
-					s.RecordDate = RecordDate
318
-					s.Status = 1
319
-					s.CreatedTime = time.Now().Unix()
320
-					s.UpdatedTime = time.Now().Unix()
321
-					s.StopState = 2
322
-					s.ExecutionState = 2
323
-					s.HisPatientId = his_patient_id
324
-					s.UserOrgId = adminUserInfo.CurrentOrgId
325
-					s.PatientId = patient_id
326
-					s.AdviceDoctor = adminUserInfo.AdminUser.Id
327
-
328
-					errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
329
-					if errcode > 0 {
330
-						c.ServeFailJSONWithSGJErrorCode(errcode)
331
-						return
178
+				ctime := time.Now().Unix()
179
+				prescription := &models.HisPrescription{
180
+					PatientId:  patient_id,
181
+					UserOrgId:  adminInfo.CurrentOrgId,
182
+					RecordDate: recordDateTime,
183
+					Ctime:      ctime,
184
+					Mtime:      ctime,
185
+					Type:       types,
186
+					Modifier:   adminInfo.AdminUser.Id,
187
+					Creator:    adminInfo.AdminUser.Id,
188
+					Status:     1,
189
+					Doctor:     doctor,
190
+				}
191
+				//prescriptions = append(prescriptions, prescription)
192
+				service.SaveHisPrescription(prescription)
193
+
194
+				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
195
+					advices := items["advices"].([]interface{})
196
+					if len(advices) > 0 {
197
+						for _, advice := range advices {
198
+							var s models.HisDoctorAdviceInfo
199
+
200
+							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
201
+							if errcode > 0 {
202
+								c.ServeFailJSONWithSGJErrorCode(errcode)
203
+								return
204
+							}
205
+							advice.Children = append(advice.Children, &s)
206
+						}
332 207
 					}
333
-
334
-					advice.Children = append(advice.Children, &s)
335 208
 				}
209
+
336 210
 			}
337 211
 		}
338
-
339
-		advices = append(advices, &advice)
340 212
 	}
341 213
 
342
-	newAdvices, createErr := service.CreateHisGroupAdvice(adminUserInfo.CurrentOrgId, advices, group_no)
343
-	if createErr != nil {
344
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
214
+	if err == nil {
215
+		c.ServeSuccessJSON(map[string]interface{}{
216
+			"msg": "保存成功",
217
+		})
218
+		return
219
+
220
+	} else {
221
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
345 222
 		return
346 223
 	}
347
-
348
-	c.ServeSuccessJSON(map[string]interface{}{
349
-		"msg":     "ok",
350
-		"advices": newAdvices,
351
-	})
352
-	return
353
-
354 224
 }
355 225
 
356 226
 func (c *HisApiController) CreateHisAdditionalCharge() {
@@ -584,7 +454,7 @@ func (c *HisApiController) GetCaseHistoryTemplate() {
584 454
 func (c *HisApiController) GetPrintHisPatientCaseHistory() {
585 455
 
586 456
 }
587
-func (c *HisApiController) setAdviceWithJSON(advice *models.HisGroupAdvice, json map[string]interface{}) int {
457
+func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
588 458
 
589 459
 	if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
590 460
 		utils.ErrorLog("advice_name")
@@ -610,10 +480,6 @@ func (c *HisApiController) setAdviceWithJSON(advice *models.HisGroupAdvice, json
610 480
 		advice.Remark = remark
611 481
 	}
612 482
 
613
-	//if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
614
-	//	src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
615
-	//	advice.Way = src_type
616
-	//}
617 483
 	if json["way"] == nil {
618 484
 		advice.Way = 0
619 485
 

+ 1 - 1
controllers/his_project_api_controller.go Parādīt failu

@@ -5,7 +5,7 @@ import (
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8
-	"encoding/json"
8
+	//"encoding/json"
9 9
 	"fmt"
10 10
 	"github.com/astaxie/beego"
11 11
 	"github.com/jinzhu/gorm"