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

XMLWAN 4 gadus atpakaļ
vecāks
revīzija
625ab88034

+ 329 - 461
controllers/his_api_controller.go Parādīt failu

@@ -5,14 +5,11 @@ import (
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7 7
 	"XT_New/utils"
8
-	"bytes"
9 8
 	"encoding/json"
10 9
 	"fmt"
11 10
 	"github.com/astaxie/beego"
12 11
 	"github.com/jinzhu/gorm"
13
-	"io/ioutil"
14 12
 	"math/rand"
15
-	"net/http"
16 13
 	"reflect"
17 14
 	"strconv"
18 15
 	"strings"
@@ -74,9 +71,12 @@ func HisManagerApiRegistRouters() {
74 71
 	beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
75 72
 
76 73
 	beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
74
+	beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
77 75
 
78 76
 	beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
79 77
 
78
+	beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
79
+
80 80
 }
81 81
 
82 82
 func (c *HisApiController) Sscard() {
@@ -132,6 +132,7 @@ func (c *HisApiController) GetHisPatientList() {
132 132
 	record_date := c.GetString("record_date")
133 133
 	timeLayout := "2006-01-02"
134 134
 	loc, _ := time.LoadLocation("Local")
135
+
135 136
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
136 137
 	if err != nil {
137 138
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -241,7 +242,7 @@ func (c *HisApiController) GetHisPatientInfo() {
241 242
 	his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
242 243
 	xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
243 244
 	prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
244
-	monthPrescriptions, _ := service.GetMonthHisPrescription(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
245
+	monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
245 246
 	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
246 247
 	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
247 248
 	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
@@ -1659,6 +1660,13 @@ func (c *HisApiController) GetHisOrderList() {
1659 1660
 	adminUser := c.GetAdminUserInfo()
1660 1661
 	org_id := adminUser.CurrentOrgId
1661 1662
 	order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords)
1663
+
1664
+	for _, item := range order {
1665
+		info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
1666
+		item.DoctorName = info.Doctor
1667
+		item.DepartmentName = info.XtHisDepartment.Name
1668
+	}
1669
+
1662 1670
 	if err == nil {
1663 1671
 		c.ServeSuccessJSON(map[string]interface{}{
1664 1672
 			"order": order,
@@ -1675,7 +1683,7 @@ func (c *HisApiController) GetHisOrder() {
1675 1683
 	number := c.GetString("number")
1676 1684
 	adminInfo := c.GetAdminUserInfo()
1677 1685
 	order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
1678
-	prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
1686
+	prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
1679 1687
 
1680 1688
 	if err == nil {
1681 1689
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -2023,7 +2031,7 @@ func (c *HisApiController) GetRegisterInfo() {
2023 2031
 	medical_care, _ := c.GetInt64("medical_care")
2024 2032
 	birthday := c.GetString("birthday")
2025 2033
 	age, _ := c.GetInt64("age")
2026
-	id_card := c.GetString("idCard")
2034
+	id_card := c.GetString("id_card")
2027 2035
 	register_type, _ := c.GetInt64("register")
2028 2036
 	doctor, _ := c.GetInt64("doctor")
2029 2037
 	department, _ := c.GetInt64("department")
@@ -2033,6 +2041,10 @@ func (c *HisApiController) GetRegisterInfo() {
2033 2041
 	medical_expenses, _ := c.GetFloat("medical_expenses")
2034 2042
 	social_type, _ := c.GetInt64("social_type")
2035 2043
 
2044
+	diagnosis_id, _ := c.GetInt64("diagnosis")
2045
+	sick_type, _ := c.GetInt64("sick_type")
2046
+	reg_type := c.GetString("p_type")
2047
+
2036 2048
 	timeLayout := "2006-01-02"
2037 2049
 	loc, _ := time.LoadLocation("Local")
2038 2050
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
@@ -2046,9 +2058,12 @@ func (c *HisApiController) GetRegisterInfo() {
2046 2058
 	recordDateTime := theTime.Unix()
2047 2059
 
2048 2060
 	adminInfo := c.GetAdminUserInfo()
2049
-
2061
+	tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
2062
+	if tempPatient.ID == 0 {
2063
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
2064
+		return
2065
+	}
2050 2066
 	var patient service.Patients
2051
-
2052 2067
 	if id == 0 {
2053 2068
 		patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
2054 2069
 
@@ -2066,62 +2081,59 @@ func (c *HisApiController) GetRegisterInfo() {
2066 2081
 		return
2067 2082
 	}
2068 2083
 
2069
-	config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
2070
-
2071
-	if config.IsOpen == 1 {
2072
-
2073
-	} else {
2074
-		timeStr := time.Now().Format("2006-01-02")
2075
-		timeArr := strings.Split(timeStr, "-")
2076
-		var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
2077
-
2078
-		his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
2079
-		var hisPatient models.XtHisPatient
2080
-		if err == gorm.ErrRecordNotFound || his.ID == 0 {
2081
-			hisPatient = models.XtHisPatient{
2082
-				Name:                   name,
2083
-				Age:                    age,
2084
-				Gender:                 gender,
2085
-				Birthday:               birthUnix,
2086
-				Phone:                  phone,
2087
-				MedicalTreatmentType:   medical_care,
2088
-				IdType:                 certificates,
2089
-				IdCardNo:               id_card,
2090
-				BalanceAccountsType:    settlementValue,
2091
-				SocialType:             social_type,
2092
-				MedicalInsuranceNumber: medical_insurance_card,
2093
-				RegisterType:           register_type,
2094
-				RegisterCost:           registration_fee,
2095
-				TreatmentCost:          medical_expenses,
2096
-				AdminUserId:            adminInfo.AdminUser.Id,
2097
-				UserOrgId:              adminInfo.CurrentOrgId,
2098
-				Status:                 1,
2099
-				RecordDate:             recordDateTime,
2100
-				IsReturn:               1,
2101
-				PatientId:              patient.ID,
2102
-				Ctime:                  time.Now().Unix(),
2103
-				Mtime:                  time.Now().Unix(),
2104
-				Number:                 str,
2105
-				IdCardType:             id_card_type,
2106
-				Departments:            department,
2107
-				Doctor:                 doctor,
2108
-			}
2109
-			service.CreateHisPatient(&hisPatient)
2110
-
2084
+	timeStr := time.Now().Format("2006-01-02")
2085
+	timeArr := strings.Split(timeStr, "-")
2086
+	var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
2087
+
2088
+	his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
2089
+
2090
+	var hisPatient models.XtHisPatient
2091
+	if err == gorm.ErrRecordNotFound || his.ID == 0 {
2092
+		hisPatient = models.XtHisPatient{
2093
+			Name:                   name,
2094
+			Age:                    age,
2095
+			Gender:                 gender,
2096
+			Birthday:               birthUnix,
2097
+			Phone:                  phone,
2098
+			MedicalTreatmentType:   medical_care,
2099
+			IdType:                 certificates,
2100
+			IdCardNo:               id_card,
2101
+			BalanceAccountsType:    settlementValue,
2102
+			SocialType:             social_type,
2103
+			MedicalInsuranceNumber: medical_insurance_card,
2104
+			RegisterType:           register_type,
2105
+			RegisterCost:           registration_fee,
2106
+			TreatmentCost:          medical_expenses,
2107
+			AdminUserId:            adminInfo.AdminUser.Id,
2108
+			UserOrgId:              adminInfo.CurrentOrgId,
2109
+			Status:                 1,
2110
+			RecordDate:             recordDateTime,
2111
+			IsReturn:               1,
2112
+			PatientId:              patient.ID,
2113
+			Ctime:                  time.Now().Unix(),
2114
+			Mtime:                  time.Now().Unix(),
2115
+			Number:                 str,
2116
+			IdCardType:             id_card_type,
2117
+			Departments:            department,
2118
+			Doctor:                 doctor,
2119
+			PType:                  reg_type,
2120
+			Diagnosis:              diagnosis_id,
2121
+			SickType:               sick_type,
2111 2122
 		}
2123
+		service.CreateHisPatient(&hisPatient)
2112 2124
 		c.ServeSuccessJSON(map[string]interface{}{
2113 2125
 			"his_info": hisPatient,
2114 2126
 		})
2115
-
2127
+	} else {
2128
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
2129
+		return
2116 2130
 	}
2117
-
2118 2131
 }
2119 2132
 
2120 2133
 //上传明细----结算
2121 2134
 func (c *HisApiController) GetUploadInfo() {
2122 2135
 	id, _ := c.GetInt64("id")
2123 2136
 	record_time := c.GetString("record_time")
2124
-
2125 2137
 	pay_way, _ := c.GetInt64("pay_way")
2126 2138
 	pay_price, _ := c.GetFloat("pay_price")
2127 2139
 	pay_card_no := c.GetString("pay_card_no")
@@ -2131,9 +2143,9 @@ func (c *HisApiController) GetUploadInfo() {
2131 2143
 	found_price, _ := c.GetFloat("found_price")
2132 2144
 	medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
2133 2145
 	private_price, _ := c.GetFloat("private_price")
2134
-
2135 2146
 	timeLayout := "2006-01-02"
2136 2147
 	loc, _ := time.LoadLocation("Local")
2148
+	settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
2137 2149
 
2138 2150
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
2139 2151
 	if err != nil {
@@ -2142,449 +2154,208 @@ func (c *HisApiController) GetUploadInfo() {
2142 2154
 	}
2143 2155
 	recordDateTime := theTime.Unix()
2144 2156
 	adminUser := c.GetAdminUserInfo()
2145
-	prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
2157
+	var prescriptions []*models.HisPrescription
2158
+	var start_time int64
2159
+	var end_time int64
2146 2160
 
2147
-	his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
2161
+	if settle_accounts_type == 1 { //日结
2162
+
2163
+		prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
2148 2164
 
2165
+	} else { //月结
2166
+		start_time_str := c.GetString("start_time")
2167
+		end_time_str := c.GetString("end_time")
2168
+		timeLayout := "2006-01-02"
2169
+		loc, _ := time.LoadLocation("Local")
2170
+		theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
2171
+		if err != nil {
2172
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2173
+			return
2174
+		}
2175
+		recordStartTime := theStartTime.Unix()
2176
+		start_time = recordStartTime
2177
+		theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
2178
+		if err != nil {
2179
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2180
+			return
2181
+		}
2182
+		recordEndTime := theEndTime.Unix()
2183
+		end_time = recordEndTime
2184
+		prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
2185
+	}
2186
+
2187
+	his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
2149 2188
 	timestamp := time.Now().Unix()
2150 2189
 	tempTime := time.Unix(timestamp, 0)
2151 2190
 	timeFormat := tempTime.Format("20060102150405")
2152 2191
 	chrgBchno := rand.Intn(100000) + 10000
2153 2192
 	chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
2154
-	miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
2155
-
2156
-	//org, _ := service.GetOrgById(adminUser.CurrentOrgId)
2157
-	patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
2158
-	department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
2159
-
2160 2193
 	strconv.FormatInt(his.PatientId, 10)
2161
-	client := &http.Client{}
2162
-	data := make(map[string]interface{})
2163
-	data["psn_no"] = his.PsnNo
2164
-	data["mdtrt_id"] = his.Number
2165
-	data["pre"] = prescriptions
2166
-	data["chrg_bchno"] = chrg_bchno
2167
-	data["org_name"] = miConfig.OrgName
2168
-	data["doctor"] = patientPrescription.Doctor
2169
-	data["dept"] = patientPrescription.Departments
2170
-
2171
-	data["fixmedins_code"] = miConfig.Code
2172
-	data["dept_code"] = department.Number
2173
-	data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
2174
-	data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
2175
-	data["secret_key"] = miConfig.SecretKey
2176 2194
 
2177 2195
 	var ids []int64
2178
-	//var idsTwo []int64
2179
-	//
2196
+
2180 2197
 	for _, item := range prescriptions {
2181 2198
 		ids = append(ids, item.ID)
2182 2199
 	}
2183 2200
 
2184
-	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
2185
-
2186
-	if config.IsOpen == 1 { //对接了医保,走医保流程
2187
-		bytesData, _ := json.Marshal(data)
2188
-		req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
2189
-		resp, _ := client.Do(req)
2190
-		defer resp.Body.Close()
2191
-		body, ioErr := ioutil.ReadAll(resp.Body)
2192
-		if ioErr != nil {
2193
-			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2194
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2195
-			return
2201
+	var total float64
2202
+	for _, item := range prescriptions {
2203
+		if item.Type == 1 { //药品
2204
+			for _, subItem := range item.HisDoctorAdviceInfo {
2205
+				total = total + (subItem.Price * subItem.PrescribingNumber)
2206
+			}
2196 2207
 		}
2197
-		var respJSON map[string]interface{}
2198
-		if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
2199
-			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2200
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2201
-			return
2208
+		if item.Type == 2 { //项目
2209
+			for _, subItem := range item.HisPrescriptionProject {
2210
+				total = total + (subItem.Price * float64(subItem.Count))
2211
+			}
2202 2212
 		}
2203 2213
 
2204
-		respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2205
-		userJSONBytes, _ := json.Marshal(respJSON)
2206
-		var res ResultFour
2207
-		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2208
-			utils.ErrorLog("解析失败:%v", err)
2209
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2210
-			return
2214
+		for _, subItem := range item.HisAdditionalCharge {
2215
+			total = total + (subItem.Price * float64(subItem.Count))
2211 2216
 		}
2217
+	}
2212 2218
 
2213
-		if res.Infcode == 0 {
2214
-			order := &models.HisOrder{
2215
-				UserOrgId:             adminUser.CurrentOrgId,
2216
-				HisPatientId:          his.ID,
2217
-				PatientId:             his.PatientId,
2218
-				SettleAccountsDate:    recordDateTime,
2219
-				Ctime:                 time.Now().Unix(),
2220
-				Mtime:                 time.Now().Unix(),
2221
-				Status:                1,
2222
-				Number:                chrg_bchno,
2223
-				Infcode:               res.Infcode,
2224
-				WarnMsg:               res.WarnMsg,
2225
-				Cainfo:                res.Cainfo,
2226
-				ErrMsg:                res.ErrMsg,
2227
-				RespondTime:           res.RefmsgTime,
2228
-				InfRefmsgid:           res.InfRefmsgid,
2229
-				OrderStatus:           1,
2230
-				PayWay:                pay_way,
2231
-				PayPrice:              pay_price,
2232
-				PayCardNo:             pay_card_no,
2233
-				DiscountPrice:         discount_price,
2234
-				PreferentialPrice:     preferential_price,
2235
-				RealityPrice:          reality_price,
2236
-				FoundPrice:            found_price,
2237
-				MedicalInsurancePrice: medical_insurance_price,
2238
-				PrivatePrice:          private_price,
2239
-			}
2240
-			err = service.CreateOrder(order)
2241
-			if err != nil {
2242
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
2243
-				return
2244
-			}
2219
+	allTotal := fmt.Sprintf("%.2f", total)
2220
+	totals, _ := strconv.ParseFloat(allTotal, 64)
2221
+	order := &models.HisOrder{
2222
+		UserOrgId:             adminUser.CurrentOrgId,
2223
+		HisPatientId:          his.ID,
2224
+		PatientId:             id,
2225
+		SettleAccountsDate:    recordDateTime,
2226
+		Ctime:                 time.Now().Unix(),
2227
+		Mtime:                 time.Now().Unix(),
2228
+		Status:                1,
2229
+		OrderStatus:           2,
2230
+		Number:                chrg_bchno,
2231
+		MedfeeSumamt:          totals,
2232
+		PayWay:                pay_way,
2233
+		PayPrice:              pay_price,
2234
+		PayCardNo:             pay_card_no,
2235
+		DiscountPrice:         discount_price,
2236
+		PreferentialPrice:     preferential_price,
2237
+		RealityPrice:          reality_price,
2238
+		FoundPrice:            found_price,
2239
+		MedicalInsurancePrice: medical_insurance_price,
2240
+		PrivatePrice:          private_price,
2241
+		SettleEndTime:         end_time,
2242
+		SettleStartTime:       start_time,
2243
+		SettleType:            settle_accounts_type,
2244
+	}
2245
+	err = service.CreateOrder(order)
2246
+	if err != nil {
2247
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
2248
+		return
2249
+	}
2245 2250
 
2246
-			for _, item := range res.Output.Result {
2247
-				temp := strings.Split(item.FeedetlSn, "-")
2248
-				var advice_id int64 = 0
2249
-				var project_id int64 = 0
2250
-				var types int64 = 0
2251
-
2252
-				id, _ := strconv.ParseInt(temp[2], 10, 64)
2253
-				types, _ = strconv.ParseInt(temp[1], 10, 64)
2254
-
2255
-				if temp[1] == "1" {
2256
-					advice_id = id
2257
-					project_id = 0
2258
-				} else if temp[1] == "2" {
2259
-					advice_id = 0
2260
-					project_id = id
2261
-				}
2251
+	var customs []*Custom
2252
+	for _, item := range prescriptions {
2262 2253
 
2263
-				info := &models.HisOrderInfo{
2264
-					OrderNumber:      order.Number,
2265
-					FeedetlSn:        item.FeedetlSn,
2266
-					UploadDate:       time.Now().Unix(),
2267
-					AdviceId:         advice_id,
2268
-					DetItemFeeSumamt: item.DetItemFeeSumamt,
2269
-					Cnt:              item.Cnt,
2270
-					Pric:             float64(item.Pric),
2271
-					PatientId:        his.PatientId,
2272
-					PricUplmtAmt:     item.PricUplmtAmt,
2273
-					SelfpayProp:      item.SelfpayProp,
2274
-					FulamtOwnpayAmt:  item.FulamtOwnpayAmt,
2275
-					OverlmtAmt:       item.OverlmtAmt,
2276
-					PreselfpayAmt:    item.PreselfpayAmt,
2277
-					BasMednFlag:      item.BasMednFlag,
2278
-					MedChrgitmType:   item.MedChrgitmType,
2279
-					HiNegoDrugFlag:   item.HiNegoDrugFlag,
2280
-					Status:           1,
2281
-					Memo:             item.Memo,
2282
-					Mtime:            time.Now().Unix(),
2283
-					InscpScpAmt:      item.InscpScpAmt,
2284
-					DrtReimFlag:      item.DrtReimFlag,
2285
-					Ctime:            time.Now().Unix(),
2286
-					ListSpItemFlag:   item.ListSpItemFlag,
2287
-					ChldMedcFlag:     item.ChldMedcFlag,
2288
-					LmtUsedFlag:      item.LmtUsedFlag,
2289
-					ChrgitmLv:        item.ChrgitmLv,
2290
-					UserOrgId:        adminUser.CurrentOrgId,
2291
-					HisPatientId:     his.ID,
2292
-					OrderId:          order.ID,
2293
-					ProjectId:        project_id,
2294
-					Type:             types,
2295
-				}
2296
-				service.CreateOrderInfo(info)
2297
-			}
2298
-			service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
2299
-			service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
2300
-			var total float64
2301
-			for _, item := range prescriptions {
2302
-				if item.Type == 1 { //药品
2303
-					for _, subItem := range item.HisDoctorAdviceInfo {
2304
-						total = total + (subItem.Price * subItem.PrescribingNumber)
2305
-					}
2306
-				}
2307
-				if item.Type == 2 { //项目
2308
-					for _, subItem := range item.HisPrescriptionProject {
2309
-						total = total + (subItem.Price * float64(subItem.Count))
2310
-					}
2254
+		if item.Type == 1 { //药品
2255
+			for _, subItem := range item.HisDoctorAdviceInfo {
2256
+				cus := &Custom{
2257
+					AdviceId:         subItem.ID,
2258
+					ProjectId:        0,
2259
+					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
2260
+					Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
2261
+					FeedetlSn:        subItem.FeedetlSn,
2262
+					Price:            fmt.Sprintf("%.2f", subItem.Price),
2263
+					MedListCodg:      subItem.MedListCodg,
2264
+					Type:             1,
2311 2265
 				}
2266
+				customs = append(customs, cus)
2312 2267
 			}
2313
-			org, _ := service.GetOrgById(adminUser.CurrentOrgId)
2314
-			patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
2315
-			allTotal := fmt.Sprintf("%.2f", total)
2316
-			if res.Infcode == 0 {
2317
-				var rf []*ResultFive
2318
-				json.Unmarshal([]byte(his.Iinfo), &rf)
2319
-				psn_no := his.PsnNo
2320
-				mdtrt_id := his.Number
2321
-				chrg_bchno := chrg_bchno
2322
-				cert_no := his.Certno
2323
-				insutype := rf[0].Insutype
2324
-				api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
2325
-					insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
2326
-					"&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
2327
-				resp, requestErr := http.Get(api)
2328
-
2329
-				if requestErr != nil {
2330
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2331
-					return
2332
-				}
2333
-				defer resp.Body.Close()
2334
-				body, ioErr := ioutil.ReadAll(resp.Body)
2335
-				if ioErr != nil {
2336
-					utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2337
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2338
-					return
2339
-				}
2340
-				var respJSON map[string]interface{}
2341
-				if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
2342
-					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2343
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2344
-					return
2345
-				}
2346
-				fmt.Println(respJSON)
2347
-				respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2348
-				userJSONBytes, _ := json.Marshal(respJSON)
2349
-				var res ResultSeven
2350
-				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2351
-					utils.ErrorLog("解析失败:%v", err)
2352
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2353
-					return
2354
-				}
2355
-				if res.Infcode == -1 {
2356
-					errlog := &models.HisOrderError{
2357
-						UserOrgId:  adminUser.CurrentOrgId,
2358
-						Ctime:      time.Now().Unix(),
2359
-						Mtime:      time.Now().Unix(),
2360
-						Number:     chrg_bchno,
2361
-						ErrMsg:     res.ErrMsg,
2362
-						Status:     1,
2363
-						PatientId:  id,
2364
-						RecordTime: recordDateTime,
2365
-						Stage:      7,
2366
-					}
2268
+		}
2367 2269
 
2368
-					service.CreateErrMsgLog(errlog)
2369
-
2370
-				} else {
2371
-					order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
2372
-					order.OrderStatus = 2
2373
-					order.MdtrtId = res.Output.Setlinfo.MdtrtID
2374
-					order.SetlId = res.Output.Setlinfo.SetlID
2375
-					order.PsnNo = res.Output.Setlinfo.PsnNo
2376
-					order.PsnName = res.Output.Setlinfo.PsnName
2377
-					order.PsnCertType = res.Output.Setlinfo.PsnCertType
2378
-					order.Certno = res.Output.Setlinfo.Certno
2379
-					order.Gend = res.Output.Setlinfo.Gend
2380
-					order.Naty = res.Output.Setlinfo.Naty
2381
-					order.Age = res.Output.Setlinfo.Age
2382
-					order.Insutype = res.Output.Setlinfo.Insutype
2383
-					order.PsnType = res.Output.Setlinfo.PsnType
2384
-					order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
2385
-					order.SetlTime = res.Output.Setlinfo.SetlTime
2386
-					order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
2387
-					order.MedType = res.Output.Setlinfo.MedType
2388
-					order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
2389
-					order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
2390
-					order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
2391
-					order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
2392
-					order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
2393
-					order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
2394
-					order.HifpPay = res.Output.Setlinfo.HifpPay
2395
-					order.CvlservPay = res.Output.Setlinfo.CvlservPay
2396
-					order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
2397
-					order.HifesPay = res.Output.Setlinfo.HifesPay
2398
-					order.HifobPay = res.Output.Setlinfo.HifobPay
2399
-					order.MafPay = res.Output.Setlinfo.MafPay
2400
-					order.OthPay = res.Output.Setlinfo.OthPay
2401
-					order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
2402
-					order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
2403
-					order.AcctPay = res.Output.Setlinfo.AcctPay
2404
-					order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
2405
-					order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
2406
-					order.Balc = res.Output.Setlinfo.Balc
2407
-					order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
2408
-					order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
2409
-					order.ClrOptins = res.Output.Setlinfo.ClrOptins
2410
-					order.ClrWay = res.Output.Setlinfo.ClrWay
2411
-					setlDetail, _ := json.Marshal(res.Output.Setldetail)
2412
-					detailStr := string(setlDetail)
2413
-					order.SetlDetail = detailStr
2414
-					err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
2415
-					err = service.UpDateOrder(order)
2416
-					if err == nil {
2417
-						c.ServeSuccessJSON(map[string]interface{}{
2418
-							"msg": "结算成功",
2419
-						})
2420
-					}
2270
+		if item.Type == 2 { //项目
2271
+			for _, subItem := range item.HisPrescriptionProject {
2272
+
2273
+				cus := &Custom{
2274
+					AdviceId:         0,
2275
+					ProjectId:        subItem.ID,
2276
+					DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
2277
+					Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
2278
+					FeedetlSn:        subItem.FeedetlSn,
2279
+					Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
2280
+					MedListCodg:      subItem.MedListCodg,
2281
+					Type:             2,
2421 2282
 				}
2422
-			} else {
2423 2283
 
2284
+				customs = append(customs, cus)
2424 2285
 			}
2425
-
2426
-		} else {
2427
-
2428 2286
 		}
2429 2287
 
2430
-	} else {
2431
-		var total float64
2432
-		for _, item := range prescriptions {
2433
-			if item.Type == 1 { //药品
2434
-				for _, subItem := range item.HisDoctorAdviceInfo {
2435
-					total = total + (subItem.Price * subItem.PrescribingNumber)
2436
-				}
2437
-			}
2438
-			if item.Type == 2 { //项目
2439
-				for _, subItem := range item.HisPrescriptionProject {
2440
-					total = total + (subItem.Price * float64(subItem.Count))
2441
-				}
2442
-			}
2443
-
2444
-			for _, subItem := range item.HisAdditionalCharge {
2445
-				total = total + (subItem.Price * float64(subItem.Count))
2288
+		for _, item := range item.HisAdditionalCharge {
2289
+			cus := &Custom{
2290
+				ItemId:           item.ID,
2291
+				AdviceId:         0,
2292
+				ProjectId:        0,
2293
+				DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
2294
+				Cut:              fmt.Sprintf("%.2f", float64(item.Count)),
2295
+				FeedetlSn:        item.FeedetlSn,
2296
+				Price:            fmt.Sprintf("%.2f", float64(item.Price)),
2297
+				MedListCodg:      item.XtHisAddtionConfig.Code,
2298
+				Type:             3,
2446 2299
 			}
2447
-		}
2448 2300
 
2449
-		allTotal := fmt.Sprintf("%.2f", total)
2450
-		totals, _ := strconv.ParseFloat(allTotal, 64)
2451
-		order := &models.HisOrder{
2452
-			UserOrgId:             adminUser.CurrentOrgId,
2453
-			HisPatientId:          his.ID,
2454
-			PatientId:             id,
2455
-			SettleAccountsDate:    recordDateTime,
2456
-			Ctime:                 time.Now().Unix(),
2457
-			Mtime:                 time.Now().Unix(),
2458
-			Status:                1,
2459
-			OrderStatus:           2,
2460
-			Number:                chrg_bchno,
2461
-			MedfeeSumamt:          totals,
2462
-			PayWay:                pay_way,
2463
-			PayPrice:              pay_price,
2464
-			PayCardNo:             pay_card_no,
2465
-			DiscountPrice:         discount_price,
2466
-			PreferentialPrice:     preferential_price,
2467
-			RealityPrice:          reality_price,
2468
-			FoundPrice:            found_price,
2469
-			MedicalInsurancePrice: medical_insurance_price,
2470
-			PrivatePrice:          private_price,
2471
-		}
2472
-		err = service.CreateOrder(order)
2473
-		if err != nil {
2474
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
2475
-			return
2301
+			customs = append(customs, cus)
2476 2302
 		}
2477 2303
 
2478
-		var customs []*Custom
2479
-		for _, item := range prescriptions {
2480
-
2481
-			if item.Type == 1 { //药品
2482
-				for _, subItem := range item.HisDoctorAdviceInfo {
2483
-					cus := &Custom{
2484
-						AdviceId:         subItem.ID,
2485
-						ProjectId:        0,
2486
-						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
2487
-						Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
2488
-						FeedetlSn:        subItem.FeedetlSn,
2489
-						Price:            fmt.Sprintf("%.2f", subItem.Price),
2490
-						MedListCodg:      subItem.MedListCodg,
2491
-						Type:             1,
2492
-					}
2493
-					customs = append(customs, cus)
2494
-				}
2495
-			}
2496
-
2497
-			if item.Type == 2 { //项目
2498
-				for _, subItem := range item.HisPrescriptionProject {
2499
-
2500
-					cus := &Custom{
2501
-						AdviceId:         0,
2502
-						ProjectId:        subItem.ID,
2503
-						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
2504
-						Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
2505
-						FeedetlSn:        subItem.FeedetlSn,
2506
-						Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
2507
-						MedListCodg:      subItem.MedListCodg,
2508
-						Type:             2,
2509
-					}
2304
+	}
2510 2305
 
2511
-					customs = append(customs, cus)
2512
-				}
2513
-			}
2306
+	for _, item := range customs {
2307
+		var advice_id int64 = 0
2308
+		var project_id int64 = 0
2309
+		var item_id int64 = 0
2514 2310
 
2515
-			for _, item := range item.HisAdditionalCharge {
2516
-				cus := &Custom{
2517
-					ItemId:           item.ID,
2518
-					AdviceId:         0,
2519
-					ProjectId:        0,
2520
-					DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
2521
-					Cut:              fmt.Sprintf("%.2f", float64(item.Count)),
2522
-					FeedetlSn:        item.FeedetlSn,
2523
-					Price:            fmt.Sprintf("%.2f", float64(item.Price)),
2524
-					MedListCodg:      item.XtHisAddtionConfig.Code,
2525
-					Type:             3,
2526
-				}
2311
+		var types int64 = 0
2527 2312
 
2528
-				customs = append(customs, cus)
2529
-			}
2313
+		if item.Type == 1 {
2314
+			advice_id = item.AdviceId
2315
+			project_id = 0
2316
+			item_id = 0
2317
+		} else if item.Type == 2 {
2318
+			advice_id = 0
2319
+			item_id = 0
2530 2320
 
2321
+			project_id = item.ProjectId
2322
+		} else if item.Type == 3 {
2323
+			advice_id = 0
2324
+			item_id = item.ItemId
2325
+			project_id = 0
2531 2326
 		}
2532 2327
 
2533
-		for _, item := range customs {
2534
-			var advice_id int64 = 0
2535
-			var project_id int64 = 0
2536
-			var item_id int64 = 0
2537
-
2538
-			var types int64 = 0
2539
-
2540
-			if item.Type == 1 {
2541
-				advice_id = item.AdviceId
2542
-				project_id = 0
2543
-				item_id = 0
2544
-			} else if item.Type == 2 {
2545
-				advice_id = 0
2546
-				item_id = 0
2547
-
2548
-				project_id = item.ProjectId
2549
-			} else if item.Type == 3 {
2550
-				advice_id = 0
2551
-				item_id = item.ItemId
2552
-				project_id = 0
2553
-			}
2554
-
2555
-			detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
2556
-			cut, _ := strconv.ParseFloat(item.Cut, 32)
2557
-			pric, _ := strconv.ParseFloat(item.Price, 32)
2558
-
2559
-			info := &models.HisOrderInfo{
2560
-				OrderNumber:      order.Number,
2561
-				UploadDate:       time.Now().Unix(),
2562
-				AdviceId:         advice_id,
2563
-				DetItemFeeSumamt: detItemFeeSumamt,
2564
-				Cnt:              cut,
2565
-				Pric:             pric,
2566
-				PatientId:        id,
2567
-				Status:           1,
2568
-				Mtime:            time.Now().Unix(),
2569
-				Ctime:            time.Now().Unix(),
2570
-				UserOrgId:        adminUser.CurrentOrgId,
2571
-				HisPatientId:     his.ID,
2572
-				OrderId:          order.ID,
2573
-				ProjectId:        project_id,
2574
-				Type:             types,
2575
-				ItemId:           item_id,
2576
-			}
2577
-			service.CreateOrderInfo(info)
2578
-		}
2579
-		//err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
2580
-		err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
2581
-		err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
2582
-		err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
2583
-		if err == nil {
2584
-			c.ServeSuccessJSON(map[string]interface{}{
2585
-				"msg": "结算成功",
2586
-			})
2328
+		detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
2329
+		cut, _ := strconv.ParseFloat(item.Cut, 32)
2330
+		pric, _ := strconv.ParseFloat(item.Price, 32)
2331
+
2332
+		info := &models.HisOrderInfo{
2333
+			OrderNumber:      order.Number,
2334
+			UploadDate:       time.Now().Unix(),
2335
+			AdviceId:         advice_id,
2336
+			DetItemFeeSumamt: detItemFeeSumamt,
2337
+			Cnt:              cut,
2338
+			Pric:             pric,
2339
+			PatientId:        id,
2340
+			Status:           1,
2341
+			Mtime:            time.Now().Unix(),
2342
+			Ctime:            time.Now().Unix(),
2343
+			UserOrgId:        adminUser.CurrentOrgId,
2344
+			HisPatientId:     his.ID,
2345
+			OrderId:          order.ID,
2346
+			ProjectId:        project_id,
2347
+			Type:             types,
2348
+			ItemId:           item_id,
2587 2349
 		}
2350
+		service.CreateOrderInfo(info)
2351
+	}
2352
+	err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
2353
+	err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
2354
+	err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
2355
+	if err == nil {
2356
+		c.ServeSuccessJSON(map[string]interface{}{
2357
+			"msg": "结算成功",
2358
+		})
2588 2359
 	}
2589 2360
 }
2590 2361
 
@@ -2756,7 +2527,7 @@ func (this *HisApiController) GetHisDayPrescription() {
2756 2527
 	end_time := this.GetString("end_time")
2757 2528
 	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
2758 2529
 	adminUserInfo := this.GetAdminUserInfo()
2759
-	dayHisPrescription, err := service.GetMonthHisPrescription(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix())
2530
+	dayHisPrescription, err := service.GetMonthHisPrescriptionThree(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix())
2760 2531
 	if err == nil {
2761 2532
 		this.ServeSuccessJSON(map[string]interface{}{
2762 2533
 			"day_prescription": dayHisPrescription,
@@ -2781,16 +2552,21 @@ func (c *HisApiController) GetHisChargePatientList() {
2781 2552
 	adminInfo := c.GetAdminUserInfo()
2782 2553
 	tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
2783 2554
 	var patients []*service.Patients
2555
+	var patients_two []*service.Patients
2556
+
2784 2557
 	for _, item := range tempPatients {
2785 2558
 		//过滤掉没挂号的和没开处方的
2786 2559
 		if item.HisPatient.ID > 0 || len(item.HisPrescription) > 0 {
2787 2560
 			patients = append(patients, item)
2788 2561
 		}
2562
+		//过滤掉没挂号的
2563
+		if item.HisPatient.ID > 0 {
2564
+			patients_two = append(patients_two, item)
2565
+		}
2789 2566
 	}
2790
-	//patients_two, _ := service.GetChargeHisPatientListTwo(adminInfo.CurrentOrgId, "", recordDateTime)
2791 2567
 	c.ServeSuccessJSON(map[string]interface{}{
2792
-		"list": patients,
2793
-		//"list_two":	patients_two,
2568
+		"list":     patients,
2569
+		"list_two": patients_two,
2794 2570
 	})
2795 2571
 }
2796 2572
 
@@ -2838,3 +2614,95 @@ func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patie
2838 2614
 	}
2839 2615
 	return
2840 2616
 }
2617
+
2618
+func (c *HisApiController) GetHisChargePatientInfo() {
2619
+	patient_id, _ := c.GetInt64("patient_id")
2620
+	record_date := c.GetString("record_date")
2621
+	number := c.GetString("number")
2622
+
2623
+	start_time := c.GetString("start_time")
2624
+	end_time := c.GetString("end_time")
2625
+
2626
+	order_status, _ := c.GetInt64("type", 0)
2627
+
2628
+	timeLayout := "2006-01-02"
2629
+	loc, _ := time.LoadLocation("Local")
2630
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
2631
+	if err != nil {
2632
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2633
+		return
2634
+	}
2635
+	recordDateTime := theTime.Unix()
2636
+
2637
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
2638
+	if err != nil {
2639
+
2640
+	}
2641
+	startRecordDateTime := startTime.Unix()
2642
+
2643
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
2644
+	if err != nil {
2645
+
2646
+	}
2647
+	endRecordDateTime := endTime.Unix()
2648
+
2649
+	admin := c.GetAdminUserInfo()
2650
+	his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2651
+	xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
2652
+
2653
+	var prescriptions []*models.HisPrescription
2654
+
2655
+	if order_status == 1 || order_status == 0 {
2656
+		prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, recordDateTime)
2657
+	} else if order_status == 2 {
2658
+		prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, recordDateTime)
2659
+	}
2660
+
2661
+	var monthPrescriptions []*models.HisPrescription
2662
+
2663
+	if order_status == 1 || order_status == 0 {
2664
+		monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
2665
+	} else if order_status == 2 {
2666
+		monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime)
2667
+
2668
+	}
2669
+
2670
+	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2671
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
2672
+	order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
2673
+
2674
+	doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
2675
+	//获取所有科室信息
2676
+	department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
2677
+
2678
+	c.ServeSuccessJSON(map[string]interface{}{
2679
+		"his_info":            his_patient_info,
2680
+		"xt_info":             xt_patient_info,
2681
+		"prescription":        prescriptions,
2682
+		"case_history":        case_history,
2683
+		"info":                patientPrescriptionInfo,
2684
+		"month_prescriptions": monthPrescriptions,
2685
+		"order":               order,
2686
+		"doctors":             doctors,
2687
+		"department":          department,
2688
+	})
2689
+	return
2690
+
2691
+}
2692
+
2693
+func (c *HisApiController) GetAllOrderDetail() {
2694
+	order_id, _ := c.GetInt64("order_id", 0)
2695
+	order, _ := service.GetHisOrderByID(order_id)
2696
+	if order.ID == 0 {
2697
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
2698
+		return
2699
+	}
2700
+	order_info, _ := service.GetHisOrderInfoByNumber(order.Number)
2701
+
2702
+	c.ServeSuccessJSON(map[string]interface{}{
2703
+		"order":      order,
2704
+		"order_info": order_info,
2705
+	})
2706
+	return
2707
+
2708
+}

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

@@ -712,7 +712,10 @@ func (this *HisProjectApiController) SaveHisPatient() {
712 712
 	timeLayout := "2006-01-02"
713 713
 	loc, _ := time.LoadLocation("Local")
714 714
 	age, _ := this.GetInt64("age")
715
-	birthday := this.GetString("birthDay")
715
+	birthday := this.GetString("birthday")
716
+
717
+	patient_id, _ := this.GetInt64("id")
718
+
716 719
 	birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
717 720
 	birthUnix := birthdays.Unix()
718 721
 	certificates, _ := this.GetInt64("certificates")
@@ -722,19 +725,19 @@ func (this *HisProjectApiController) SaveHisPatient() {
722 725
 	cost_float, _ := strconv.ParseFloat(costs, 64)
723 726
 	department, _ := this.GetInt64("department")
724 727
 	doctor, _ := this.GetInt64("doctor")
725
-	medicalcare, _ := this.GetInt64("medicalCare")
726
-	idcard := this.GetString("idCard")
727
-	medicalExpenses, _ := this.GetInt64("medicalExpenses")
728
+	medicalcare, _ := this.GetInt64("medical_care")
729
+	idcard := this.GetString("id_card")
730
+	medicalExpenses, _ := this.GetInt64("medical_expenses")
728 731
 	medicalExpense := strconv.FormatInt(medicalExpenses, 10)
729 732
 	medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
730
-	medicalinsurancecard := this.GetString("medicalInsuranceCard")
733
+	medicalinsurancecard := this.GetString("medical_insurance_card")
731 734
 
732 735
 	name := this.GetString("name")
733 736
 	register, _ := this.GetInt64("register")
734
-	registrationfee, _ := this.GetInt64("registrationFee")
737
+	registrationfee, _ := this.GetInt64("registration_fee")
735 738
 	registrationfees := strconv.FormatInt(registrationfee, 10)
736 739
 	registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
737
-	settlementValue, _ := this.GetInt64("settlementValue")
740
+	settlementValue, _ := this.GetInt64("settlement_value")
738 741
 	sex, _ := this.GetInt64("sex")
739 742
 	total, _ := this.GetInt64("total")
740 743
 	totals := strconv.FormatInt(total, 10)
@@ -748,10 +751,44 @@ func (this *HisProjectApiController) SaveHisPatient() {
748 751
 	social_type, _ := this.GetInt64("social_type")
749 752
 	id_card_type, _ := this.GetInt64("id_card_type")
750 753
 
751
-	bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
752
-	if errcode == gorm.ErrRecordNotFound {
753
-		patient := models.XtHisPatient{
754
-			Age:                    age,
754
+	diagnosis_id, _ := this.GetInt64("diagnosis")
755
+	sick_type, _ := this.GetInt64("sick_type")
756
+	reg_type := this.GetString("p_type")
757
+
758
+	tempPatient, _ := service.GetPatientByIDCardAndName(idcard, adminUserInfo.CurrentOrgId, name)
759
+	if tempPatient.ID == 0 {
760
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
761
+		return
762
+	}
763
+
764
+	var patient service.Patients
765
+	if patient_id == 0 {
766
+		patient, _ = service.GetPatientByIDCard(idcard, adminUserInfo.CurrentOrgId)
767
+
768
+	} else {
769
+		patient, _ = service.GetPatientByIDTwo(adminUserInfo.CurrentOrgId, patient_id)
770
+
771
+	}
772
+
773
+	if patient.ID == 0 {
774
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
775
+		return
776
+	}
777
+	if len(patient.IdCardNo) == 0 {
778
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
779
+		return
780
+	}
781
+
782
+	timeStr := time.Now().Format("2006-01-02")
783
+	timeArr := strings.Split(timeStr, "-")
784
+	var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
785
+
786
+	his, err := service.GetHisPatientInfo(adminUserInfo.CurrentOrgId, patient.ID, recordDate.Unix())
787
+
788
+	var hisPatient models.XtHisPatient
789
+	if err == gorm.ErrRecordNotFound || his.ID == 0 {
790
+		hisPatient = models.XtHisPatient{
791
+			PatientId:              patient_id,
755 792
 			Birthday:               birthUnix,
756 793
 			IdType:                 certificates,
757 794
 			CostOfProduction:       cost_float,
@@ -764,6 +801,8 @@ func (this *HisProjectApiController) SaveHisPatient() {
764 801
 			TreatmentCost:          medicalExpense_float,
765 802
 			MedicalInsuranceNumber: medicalinsurancecard,
766 803
 			Name:                name,
804
+			Age:                 age,
805
+			Number:              str,
767 806
 			RegisterType:        register,
768 807
 			RegisterCost:        registrationfees_float,
769 808
 			BalanceAccountsType: settlementValue,
@@ -777,83 +816,19 @@ func (this *HisProjectApiController) SaveHisPatient() {
777 816
 			Phone:               phone,
778 817
 			SocialType:          social_type,
779 818
 			IdCardType:          id_card_type,
819
+			Diagnosis:           diagnosis_id,
820
+			PType:               reg_type,
821
+			SickType:            sick_type,
780 822
 		}
781
-
782
-		err := service.CreateHisPatient(&patient)
783
-		lastPatient, err := service.GetLastPatient(orgId)
784
-		timeStr := time.Now().Format("2006-01-02")
785
-		timeArr := strings.Split(timeStr, "-")
786
-		var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
787
-
788
-		hisPatient := models.HisPatient{
789
-			Number: str,
790
-		}
791
-		err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
792
-		fmt.Println("er", err)
793
-		if err != nil {
794
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
795
-			return
796
-		}
823
+		service.CreateHisPatient(&hisPatient)
797 824
 		this.ServeSuccessJSON(map[string]interface{}{
798
-			"patient": patient,
825
+			"his_info": hisPatient,
799 826
 		})
800
-	} else if errcode == nil {
801
-		patient := models.XtHisPatient{
802
-			Age:                    age,
803
-			Birthday:               birthUnix,
804
-			IdType:                 certificates,
805
-			CostOfProduction:       cost_float,
806
-			Departments:            department,
807
-			AdminUserId:            doctor,
808
-			MedicalTreatmentType:   medicalcare,
809
-			IdCardNo:               idcard,
810
-			IsNeedCostOfProduction: cost_checked,
811
-			TreatmentCost:          medicalExpense_float,
812
-			MedicalInsuranceNumber: medicalinsurancecard,
813
-			Name:                name,
814
-			RegisterType:        register,
815
-			RegisterCost:        registrationfees_float,
816
-			BalanceAccountsType: settlementValue,
817
-			Gender:              sex,
818
-			Total:               totals_float,
819
-			UserOrgId:           orgId,
820
-			PatientId:           bloodPatient.ID,
821
-			Ctime:               time.Now().Unix(),
822
-			Phone:               phone,
823
-			SocialType:          social_type,
824
-			IdCardType:          id_card_type,
825
-			RecordDate:          nowtime,
826
-			Status:              1,
827
-			IsReturn:            1,
828
-		}
829
-
830
-		//查询今日没有退号的患者是否已挂号
831
-		_, errcode := service.GetTodayHisPatient(nowtime, bloodPatient.ID, adminUserInfo.CurrentOrgId)
832
-		if errcode == gorm.ErrRecordNotFound {
833
-			err := service.CreateHisPatient(&patient)
834
-			lastPatient, err := service.GetLastPatient(orgId)
835
-			timeStr := time.Now().Format("2006-01-02")
836
-			timeArr := strings.Split(timeStr, "-")
837
-			var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
838
-
839
-			hisPatient := models.HisPatient{
840
-				Number: str,
841
-			}
842
-			err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
843
-			//fmt.Println("er", err)
844
-			if err != nil {
845
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
846
-				return
847
-			}
848
-			this.ServeSuccessJSON(map[string]interface{}{
849
-				"patient": patient,
850
-			})
851
-		} else if errcode == nil {
852
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
853
-			return
854
-		}
855
-
827
+	} else {
828
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
829
+		return
856 830
 	}
831
+
857 832
 }
858 833
 
859 834
 func (this *HisProjectApiController) GetAllProjectTeam() {

+ 646 - 0
controllers/new_mobile_api_controllers/mobile_his_api_controller.go Parādīt failu

@@ -0,0 +1,646 @@
1
+package new_mobile_api_controllers
2
+
3
+import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
7
+	"XT_New/utils"
8
+	"encoding/json"
9
+	"fmt"
10
+	"math/rand"
11
+	"reflect"
12
+	"strconv"
13
+	"time"
14
+)
15
+
16
+type MobileHisApiController struct {
17
+	NewMobileBaseAPIAuthController
18
+}
19
+
20
+func (c *MobileHisApiController) GetHisPrescriptionConfig() {
21
+	adminInfo := c.GetMobileAdminUserInfo()
22
+	//获取医嘱模版
23
+	advices, _ := service.FindAllHisAdviceTemplate(adminInfo.Org.Id)
24
+	//获取所有基础药
25
+	drugs, _ := service.GetAllDrugLibList(adminInfo.Org.Id)
26
+	drugways, _, _ := service.GetDrugWayDics(adminInfo.Org.Id)
27
+	efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.Org.Id)
28
+	doctors, _ := service.GetHisAdminUserDoctors(adminInfo.Org.Id)
29
+	team, _ := service.GetAllProjectTeamList(adminInfo.Org.Id)
30
+	projects, _ := service.GetHisProject(adminInfo.Org.Id)
31
+	//获取所有科室信息
32
+	department, _ := service.GetAllDepartMent(adminInfo.Org.Id)
33
+	c.ServeSuccessJSON(map[string]interface{}{
34
+		"drugs":            drugs,
35
+		"advices_template": advices,
36
+		"drugways":         drugways,
37
+		"efs":              efs,
38
+		"doctors":          doctors,
39
+		"department":       department,
40
+		"projects":         projects,
41
+		"team":             team,
42
+	})
43
+}
44
+func (c *MobileHisApiController) GetHisPatientInfo() {
45
+	patient_id, _ := c.GetInt64("patient_id")
46
+	record_date := c.GetString("record_date")
47
+	number := c.GetString("number")
48
+	start_time := c.GetString("start_time")
49
+	end_time := c.GetString("end_time")
50
+	timeLayout := "2006-01-02"
51
+	loc, _ := time.LoadLocation("Local")
52
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
53
+	if err != nil {
54
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
55
+		return
56
+	}
57
+	recordDateTime := theTime.Unix()
58
+
59
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
60
+	if err != nil {
61
+
62
+	}
63
+	startRecordDateTime := startTime.Unix()
64
+
65
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
66
+	if err != nil {
67
+
68
+	}
69
+	endRecordDateTime := endTime.Unix()
70
+
71
+	admin := c.GetMobileAdminUserInfo()
72
+	his_patient_info, _ := service.GetHisPatientInfo(admin.Org.Id, patient_id, recordDateTime)
73
+	xt_patient_info, _ := service.GetXTPatientInfo(admin.Org.Id, patient_id)
74
+	prescriptions, _ := service.GetHisPrescription(admin.Org.Id, patient_id, recordDateTime)
75
+	monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.Org.Id, patient_id, startRecordDateTime, endRecordDateTime)
76
+	case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.Org.Id, patient_id, recordDateTime)
77
+	patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.Org.Id, patient_id, recordDateTime)
78
+	order, _ := service.GetHisOrder(admin.Org.Id, number, patient_id)
79
+
80
+	doctors, _ := service.GetHisAdminUserDoctors(admin.Org.Id)
81
+	//获取所有科室信息
82
+	department, _ := service.GetAllDepartMent(admin.Org.Id)
83
+
84
+	c.ServeSuccessJSON(map[string]interface{}{
85
+		"his_info":            his_patient_info,
86
+		"xt_info":             xt_patient_info,
87
+		"prescription":        prescriptions,
88
+		"case_history":        case_history,
89
+		"info":                patientPrescriptionInfo,
90
+		"month_prescriptions": monthPrescriptions,
91
+		"order":               order,
92
+		"doctors":             doctors,
93
+		"department":          department,
94
+	})
95
+	return
96
+
97
+}
98
+func (this *MobileHisApiController) GetCallHisPrescription() {
99
+	patient_id, _ := this.GetInt64("patient_id", 0)
100
+	timeLayout := "2006-01-02"
101
+	loc, _ := time.LoadLocation("Local")
102
+	start_time := this.GetString("start_time")
103
+	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
104
+	end_time := this.GetString("end_time")
105
+	endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
106
+	adminUserInfo := this.GetMobileAdminUserInfo()
107
+	prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.Org.Id, patient_id)
108
+	if err == nil {
109
+		this.ServeSuccessJSON(map[string]interface{}{
110
+			"prescriptions": prescriptions,
111
+		})
112
+		return
113
+	} else {
114
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
115
+		return
116
+	}
117
+}
118
+func (c *MobileHisApiController) DeletePrescription() {
119
+	prescription_id, _ := c.GetInt64("id")
120
+	err := service.DelelteHisPrescription(prescription_id, c.GetMobileAdminUserInfo().Org.Id)
121
+	if err == nil {
122
+		c.ServeSuccessJSON(map[string]interface{}{
123
+			"msg": "删除成功",
124
+		})
125
+		return
126
+	} else {
127
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
128
+		return
129
+	}
130
+}
131
+func (c *MobileHisApiController) DeleteDoctorAdvice() {
132
+	id, _ := c.GetInt64("id")
133
+	//TODO 需要判断是否已经结算
134
+	err := service.DelelteDoctorAdvice(id, c.GetMobileAdminUserInfo().Org.Id)
135
+	if err == nil {
136
+		c.ServeSuccessJSON(map[string]interface{}{
137
+			"msg": "删除成功",
138
+		})
139
+		return
140
+	} else {
141
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
142
+		return
143
+	}
144
+}
145
+func (c *MobileHisApiController) DeleteProject() {
146
+	id, _ := c.GetInt64("id")
147
+	//TODO 需要判断是否已经结算
148
+	err := service.DelelteProject(id, c.GetMobileAdminUserInfo().Org.Id)
149
+	if err == nil {
150
+		c.ServeSuccessJSON(map[string]interface{}{
151
+			"msg": "删除成功",
152
+		})
153
+		return
154
+	} else {
155
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
156
+		return
157
+	}
158
+}
159
+func (c *MobileHisApiController) CreateHisPrescription() {
160
+	record_date := c.GetString("record_date")
161
+	patient_id, _ := c.GetInt64("patient_id")
162
+	reg_type, _ := c.GetInt64("reg_type")
163
+	diagnose, _ := c.GetInt64("diagnose")
164
+	sick_type, _ := c.GetInt64("sick_type")
165
+	sick_history := c.GetString("sick_history")
166
+	doctor_id, _ := c.GetInt64("doctor", 0)
167
+	department, _ := c.GetInt64("department", 0)
168
+	his_patient_id, _ := c.GetInt64("his_patient_id")
169
+	dataBody := make(map[string]interface{}, 0)
170
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
171
+	if err != nil {
172
+		utils.ErrorLog(err.Error())
173
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
174
+		return
175
+	}
176
+
177
+	timeLayout := "2006-01-02"
178
+	loc, _ := time.LoadLocation("Local")
179
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
180
+	if err != nil {
181
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
182
+		return
183
+	}
184
+	adminInfo := c.GetMobileAdminUserInfo()
185
+	recordDateTime := theTime.Unix()
186
+
187
+	role, _ := service.GetAdminUserInfoByID(adminInfo.Org.Id, doctor_id)
188
+
189
+	info, _ := service.FindPatientPrescriptionInfo(adminInfo.Org.Id, patient_id, recordDateTime)
190
+	var hpInfo models.HisPrescriptionInfo
191
+	if info.ID == 0 {
192
+		var randNum int
193
+		randNum = rand.Intn(10000) + 1000
194
+		timestamp := time.Now().Unix()
195
+		tempTime := time.Unix(timestamp, 0)
196
+		timeFormat := tempTime.Format("20060102150405")
197
+		p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.Org.Id), 10) + strconv.FormatInt(int64(patient_id), 10)
198
+
199
+		hpInfo = models.HisPrescriptionInfo{
200
+			UserOrgId:          adminInfo.Org.Id,
201
+			RecordDate:         theTime.Unix(),
202
+			PatientId:          patient_id,
203
+			Status:             1,
204
+			Ctime:              time.Now().Unix(),
205
+			Mtime:              time.Now().Unix(),
206
+			Creator:            adminInfo.AdminUser.Id,
207
+			Modifier:           adminInfo.AdminUser.Id,
208
+			Diagnosis:          diagnose,
209
+			SickHistory:        sick_history,
210
+			Departments:        department,
211
+			RegisterType:       reg_type,
212
+			PrescriptionNumber: p_number,
213
+			PrescriptionStatus: 1,
214
+			Doctor:             role.UserName,
215
+			DoctorId:           doctor_id,
216
+			SickType:           sick_type,
217
+		}
218
+		service.SavePatientPrescriptionInfo(hpInfo)
219
+
220
+	} else {
221
+		hpInfo = models.HisPrescriptionInfo{
222
+			ID:                 info.ID,
223
+			UserOrgId:          adminInfo.Org.Id,
224
+			RecordDate:         info.RecordDate,
225
+			PatientId:          info.PatientId,
226
+			Status:             1,
227
+			Ctime:              info.Ctime,
228
+			Mtime:              time.Now().Unix(),
229
+			Creator:            info.Creator,
230
+			Modifier:           adminInfo.AdminUser.Id,
231
+			Diagnosis:          diagnose,
232
+			SickHistory:        sick_history,
233
+			Departments:        department,
234
+			RegisterType:       reg_type,
235
+			PrescriptionNumber: info.PrescriptionNumber,
236
+			Doctor:             role.UserName,
237
+			PrescriptionStatus: info.PrescriptionStatus,
238
+			DoctorId:           doctor_id,
239
+			SickType:           sick_type,
240
+		}
241
+		service.SavePatientPrescriptionInfo(hpInfo)
242
+	}
243
+
244
+	if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
245
+		prescriptions, _ := dataBody["prescriptions"].([]interface{})
246
+
247
+		if len(prescriptions) > 0 {
248
+			for _, item := range prescriptions {
249
+				items := item.(map[string]interface{})
250
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
251
+					utils.ErrorLog("id")
252
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
253
+					return
254
+				}
255
+				id := int64(items["id"].(float64))
256
+
257
+				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
258
+					utils.ErrorLog("type")
259
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
260
+					return
261
+				}
262
+				types := int64(items["type"].(float64))
263
+
264
+				if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
265
+					utils.ErrorLog("pre_time")
266
+				}
267
+				preTime, _ := items["pre_time"].(string)
268
+				timeLayout := "2006-01-02"
269
+				loc, _ := time.LoadLocation("Local")
270
+				theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
271
+				if err != nil {
272
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
273
+					return
274
+				}
275
+				pTime := theTime2.Unix()
276
+
277
+				ctime := time.Now().Unix()
278
+				prescription := &models.HisPrescription{
279
+					ID:                 id,
280
+					PatientId:          patient_id,
281
+					UserOrgId:          adminInfo.Org.Id,
282
+					RecordDate:         recordDateTime,
283
+					Ctime:              ctime,
284
+					Mtime:              ctime,
285
+					Type:               types,
286
+					Modifier:           adminInfo.AdminUser.Id,
287
+					Creator:            adminInfo.AdminUser.Id,
288
+					Status:             1,
289
+					Doctor:             role.UserName,
290
+					HisPatientId:       his_patient_id,
291
+					OrderStatus:        1,
292
+					BatchNumber:        "",
293
+					PrescriptionNumber: hpInfo.PrescriptionNumber,
294
+					PreTime:            pTime,
295
+				}
296
+				service.SaveHisPrescription(prescription)
297
+
298
+				//更改患者挂号状态
299
+				_, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.Org.Id)
300
+				fmt.Println("更改失败", err2)
301
+				if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
302
+					advices := items["advices"].([]interface{})
303
+					//group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
304
+					groupNo := int64(0)
305
+					ctime := time.Now().Unix()
306
+					mtime := ctime
307
+					if len(advices) > 0 {
308
+						for _, advice := range advices {
309
+							var s models.HisDoctorAdviceInfo
310
+							s.PrescriptionId = prescription.ID
311
+							s.AdviceType = 2
312
+							s.AdviceDoctor = adminInfo.AdminUser.Id
313
+							s.StopState = 2
314
+							s.ExecutionState = 2
315
+							s.AdviceDate = recordDateTime
316
+							s.Status = 1
317
+							s.UserOrgId = adminInfo.Org.Id
318
+							s.RecordDate = recordDateTime
319
+							s.StartTime = prescription.PreTime
320
+							s.Groupno = groupNo
321
+							s.CreatedTime = ctime
322
+							s.UpdatedTime = mtime
323
+							s.PatientId = patient_id
324
+							s.HisPatientId = his_patient_id
325
+							errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
326
+							if errcode > 0 {
327
+								c.ServeFailJSONWithSGJErrorCode(errcode)
328
+								return
329
+							}
330
+							service.CreateHisDoctorAdvice(&s)
331
+							var randNum int
332
+							randNum = rand.Intn(10000) + 1000
333
+							timestamp := time.Now().Unix()
334
+							tempTime := time.Unix(timestamp, 0)
335
+							timeFormat := tempTime.Format("20060102150405")
336
+							s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
337
+							service.CreateHisDoctorAdvice(&s)
338
+
339
+						}
340
+					}
341
+				}
342
+				if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
343
+					projects := items["project"].([]interface{})
344
+					if len(projects) > 0 {
345
+						for _, project := range projects {
346
+							var p models.HisPrescriptionProject
347
+							p.PrescriptionId = prescription.ID
348
+							p.Ctime = time.Now().Unix()
349
+							p.Mtime = time.Now().Unix()
350
+							p.PatientId = patient_id
351
+							p.RecordDate = recordDateTime
352
+							p.UserOrgId = adminInfo.Org.Id
353
+							p.HisPatientId = his_patient_id
354
+							p.Status = 1
355
+							errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
356
+							if errcode > 0 {
357
+								c.ServeFailJSONWithSGJErrorCode(errcode)
358
+								return
359
+							}
360
+							service.CreateHisProjectTwo(&p)
361
+							var randNum int
362
+							randNum = rand.Intn(10000) + 1000
363
+							timestamp := time.Now().Unix()
364
+							tempTime := time.Unix(timestamp, 0)
365
+							timeFormat := tempTime.Format("20060102150405")
366
+							p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
367
+							service.SaveHisProjectTwo(&p)
368
+
369
+						}
370
+					}
371
+				}
372
+
373
+			}
374
+		}
375
+	}
376
+	if err == nil {
377
+		c.ServeSuccessJSON(map[string]interface{}{
378
+			"msg": "保存成功",
379
+		})
380
+		return
381
+
382
+	} else {
383
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
384
+		return
385
+	}
386
+}
387
+func (this *MobileHisApiController) GetLastOrNextHisPrescription() {
388
+	change_type, _ := this.GetInt64("type", 0)
389
+	record_date := this.GetString("record_time")
390
+	patient_id, _ := this.GetInt64("patient_id", 0)
391
+
392
+	timeLayout := "2006-01-02"
393
+	loc, _ := time.LoadLocation("Local")
394
+	theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
395
+	record_time := theAdviceRecordTime.Unix()
396
+	adminUserInfo := this.GetMobileAdminUserInfo()
397
+	prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
398
+	if err == nil {
399
+		if len(prescriptions) == 0 {
400
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
401
+			return
402
+		} else {
403
+			this.ServeSuccessJSON(map[string]interface{}{
404
+				"prescriptions": prescriptions,
405
+			})
406
+			return
407
+		}
408
+	} else {
409
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
410
+		return
411
+	}
412
+}
413
+func (c *MobileHisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
414
+
415
+	if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
416
+		utils.ErrorLog("drug_name")
417
+		return enums.ErrorCodeParamWrong
418
+	}
419
+	adviceName, _ := json["drug_name"].(string)
420
+	if len(adviceName) == 0 {
421
+		utils.ErrorLog("len(advice_name) == 0")
422
+		return enums.ErrorCodeParamWrong
423
+	}
424
+	advice.AdviceName = adviceName
425
+	adviceDesc, _ := json["advice_desc"].(string)
426
+	advice.AdviceDesc = adviceDesc
427
+	if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
428
+		drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
429
+		advice.DrugSpec = drugSpec
430
+	}
431
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
432
+		remark, _ := json["remark"].(string)
433
+		advice.Remark = remark
434
+	}
435
+	if json["id"] == nil {
436
+		advice.DrugId = 0
437
+	} else {
438
+		if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
439
+			drug_id := int64(json["id"].(float64))
440
+			advice.DrugId = drug_id
441
+		}
442
+	}
443
+	if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
444
+		advice_id := int64(json["advice_id"].(float64))
445
+		advice.ID = advice_id
446
+		if advice.ID > 0 {
447
+			hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
448
+			if err == nil {
449
+				if hisAdvice.ID > 0 {
450
+					advice.ExecutionTime = hisAdvice.ExecutionTime
451
+					advice.ExecutionStaff = hisAdvice.ExecutionStaff
452
+					advice.ExecutionState = hisAdvice.ExecutionState
453
+					advice.CheckTime = hisAdvice.CheckTime
454
+					advice.Checker = hisAdvice.Checker
455
+					advice.CheckState = hisAdvice.CheckState
456
+					advice.StartTime = hisAdvice.StartTime
457
+
458
+				}
459
+			}
460
+		}
461
+	}
462
+
463
+	//
464
+	//if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
465
+	//	execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
466
+	//	advice.ExecutionTime = execution_time
467
+	//}
468
+	//
469
+	//
470
+	//
471
+	//if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
472
+	//	execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
473
+	//	advice.ExecutionStaff = execution_staff
474
+	//}
475
+	//
476
+	//
477
+	//
478
+	//if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
479
+	//	execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
480
+	//	advice.ExecutionState = execution_state
481
+	//}
482
+	//
483
+	//
484
+	//if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
485
+	//	check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
486
+	//	advice.CheckTime = check_time
487
+	//}
488
+	//
489
+	//
490
+	//if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
491
+	//	check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
492
+	//	advice.CheckState = check_state
493
+	//}
494
+	//
495
+	//
496
+	//if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
497
+	//	checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
498
+	//	advice.Checker = checker
499
+	//}
500
+	//
501
+	//if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
502
+	//	start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
503
+	//	advice.StartTime = start_time
504
+	//}
505
+
506
+	if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
507
+		drugSpecUnit, _ := json["min_unit"].(string)
508
+		advice.DrugSpecUnit = drugSpecUnit
509
+	}
510
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
511
+		singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
512
+		advice.SingleDose = singleDose
513
+	}
514
+	if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
515
+		singleDoseUnit, _ := json["single_dose_unit"].(string)
516
+		advice.SingleDoseUnit = singleDoseUnit
517
+	}
518
+	if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
519
+		prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
520
+		advice.PrescribingNumber = prescribingNumber
521
+	}
522
+	if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
523
+		prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
524
+		advice.PrescribingNumberUnit = prescribingNumberUnit
525
+	}
526
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
527
+		deliveryWay, _ := json["delivery_way"].(string)
528
+		advice.DeliveryWay = deliveryWay
529
+	}
530
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
531
+		executionFrequency, _ := json["execution_frequency"].(string)
532
+		advice.ExecutionFrequency = executionFrequency
533
+	}
534
+
535
+	if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
536
+		price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
537
+		advice.Price = price
538
+	}
539
+	if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
540
+		med_list_codg, _ := json["medical_insurance_number"].(string)
541
+		advice.MedListCodg = med_list_codg
542
+	}
543
+	if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
544
+		day := int64(json["day"].(float64))
545
+		advice.Day = day
546
+	}
547
+	return 0
548
+}
549
+func (c *MobileHisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
550
+	if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
551
+		id := int64(json["id"].(float64))
552
+		project.ID = id
553
+	}
554
+	if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
555
+		project_id := int64(json["project_id"].(float64))
556
+		project.ProjectId = project_id
557
+		fmt.Println(project_id)
558
+		fmt.Println(project.ProjectId)
559
+	}
560
+	// if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
561
+	// 	price := int64(json["price"].(float64))
562
+	// 	formatInt_price := strconv.FormatInt(price, 10)
563
+	// 	float_price, _ := strconv.ParseFloat(formatInt_price, 64)
564
+	// 	project.Price = float_price
565
+	// }
566
+	if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
567
+		price, _ := strconv.ParseFloat(json["price"].(string), 64)
568
+		project.Price = price
569
+	}
570
+
571
+	if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
572
+		total, _ := json["total"].(string)
573
+		totals, _ := strconv.ParseInt(total, 10, 64)
574
+		project.Count = totals
575
+	}
576
+
577
+	if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
578
+		medical_code, _ := json["medical_code"].(string)
579
+		project.MedListCodg = medical_code
580
+	}
581
+	if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
582
+		single_dose, _ := json["single_dose"].(string)
583
+		project.SingleDose = single_dose
584
+	}
585
+
586
+	if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
587
+		delivery_way, _ := json["delivery_way"].(string)
588
+		project.DeliveryWay = delivery_way
589
+	}
590
+	if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
591
+		execution_frequency, _ := json["execution_frequency"].(string)
592
+		project.ExecutionFrequency = execution_frequency
593
+	}
594
+	if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
595
+		remark, _ := json["remark"].(string)
596
+		project.Remark = remark
597
+	}
598
+	if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
599
+		day, _ := json["number_days"].(string)
600
+		project.Day = day
601
+	}
602
+
603
+	if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
604
+		unit, _ := json["unit"].(string)
605
+		project.Unit = unit
606
+	}
607
+	return 0
608
+}
609
+func (c *MobileHisApiController) GetHisPatientList() {
610
+	record_date := c.GetString("record_date")
611
+	timeLayout := "2006-01-02"
612
+	loc, _ := time.LoadLocation("Local")
613
+
614
+	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
615
+	if err != nil {
616
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
617
+		return
618
+	}
619
+	recordDateTime := theTime.Unix()
620
+	adminInfo := c.GetMobileAdminUserInfo()
621
+	patients, _ := service.GetScheduleHisPatientList(adminInfo.Org.Id, "", recordDateTime)
622
+	patients_two, _ := service.GetHisPatientList(adminInfo.Org.Id, "", recordDateTime)
623
+	patients = append(patients, patients_two...)
624
+	patients = RemoveRepeatedPatient(patients)
625
+	c.ServeSuccessJSON(map[string]interface{}{
626
+		"list": patients,
627
+	})
628
+
629
+}
630
+
631
+func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
632
+	newArr = make([]*service.Patients, 0)
633
+	for i := 0; i < len(patient); i++ {
634
+		repeat := false
635
+		for j := i + 1; j < len(patient); j++ {
636
+			if patient[i].ID == patient[j].ID {
637
+				repeat = true
638
+				break
639
+			}
640
+		}
641
+		if !repeat {
642
+			newArr = append(newArr, patient[i])
643
+		}
644
+	}
645
+	return
646
+}

+ 12 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go Parādīt failu

@@ -162,4 +162,16 @@ func NewMobileAPIControllersRegisterRouters() {
162 162
 	beego.Router("/m/api/patient/deletemanagementtwo", &NewDialysisApiController{}, "Delete:DeleteManageMentTwo")
163 163
 	beego.Router("/m/api/patient/savecouresemanagement", &NewDialysisApiController{}, "Get:SaveCourseManageMent")
164 164
 	beego.Router("/m/api/patient/savecoursemanagementtwo", &NewDialysisApiController{}, "Get:SaveCourseManageMentTwo")
165
+
166
+	//His相关
167
+	beego.Router("/m/api/hispatientlist/get", &MobileHisApiController{}, "Get:GetHisPatientList")
168
+	beego.Router("/m/api/prescriptionconfig/get", &MobileHisApiController{}, "Get:GetHisPrescriptionConfig")
169
+	beego.Router("/m/api/prescriptioninfo/get", &MobileHisApiController{}, "Get:GetHisPatientInfo")
170
+	beego.Router("/m/api/prescription/cell", &MobileHisApiController{}, "Get:GetCallHisPrescription")
171
+	beego.Router("/m/api/lastornextprescription/get", &MobileHisApiController{}, "Get:GetLastOrNextHisPrescription")
172
+	beego.Router("/m/api/prescription/delete", &MobileHisApiController{}, "Post:DeletePrescription")
173
+	beego.Router("/m/api/hisdoctoradvice/delete", &MobileHisApiController{}, "Post:DeletePrescription")
174
+	beego.Router("/m/api/hisproject/delete", &MobileHisApiController{}, "Post:DeleteDoctorAdvice")
175
+	beego.Router("/m/api/prescription/create", &MobileHisApiController{}, "Post:CreateHisPrescription")
176
+
165 177
 }

+ 14 - 0
controllers/public_api_controller.go Parādīt failu

@@ -9,6 +9,7 @@ import (
9 9
 	"os"
10 10
 	"path"
11 11
 	"runtime"
12
+	"strconv"
12 13
 	"strings"
13 14
 	"time"
14 15
 
@@ -29,6 +30,8 @@ func PublicApiRegistRouters() {
29 30
 	beego.Router("/api/public/handlecomdata", &PublicApiController{}, "get:HandleComData")
30 31
 	beego.Router("/hello", &PublicApiController{}, "get:HandleComData")
31 32
 
33
+	beego.Router("/handel", &PublicApiController{}, "get:HandleHIS")
34
+
32 35
 }
33 36
 
34 37
 func (c *PublicApiController) GetDoctorAdviceConfig() {
@@ -1633,3 +1636,14 @@ func (c *PublicApiController) HandleComData() {
1633 1636
 	}
1634 1637
 
1635 1638
 }
1639
+
1640
+func (c *PublicApiController) HandleHIS() {
1641
+	his, _ := service.GetAllHisInfo(9919)
1642
+	for _, item := range his {
1643
+		fsn := strings.Split(item.FeedetlSn, "-")
1644
+		item.FeedetlSn = fsn[0] + "-" + fsn[1] + "-" + strconv.FormatInt(item.ID, 10)
1645
+		fmt.Println(item.FeedetlSn)
1646
+		service.UpDateHis2(item)
1647
+	}
1648
+
1649
+}

+ 12 - 0
enums/error_code.go Parādīt failu

@@ -222,6 +222,12 @@ const ( // ErrorCode
222 222
 	ErrorCodeCreateOrderException = 20068
223 223
 
224 224
 	ErrorCodeCalOrderException = 20069
225
+
226
+	ErrorCodeHisRegisterException = 300001
227
+
228
+	ErrorCodeNoBloodPatientException = 300002
229
+
230
+	ErrorCodeOrderParamWrong = 300003
225 231
 )
226 232
 
227 233
 var ErrCodeMsgs = map[int]string{
@@ -434,6 +440,12 @@ var ErrCodeMsgs = map[int]string{
434 440
 	ErrorCodeCreateOrderException: "创建预结算订单失败",
435 441
 
436 442
 	ErrorCodeCalOrderException: "结算失败",
443
+
444
+	ErrorCodeHisRegisterException: "一天只能挂一个号",
445
+
446
+	ErrorCodeNoBloodPatientException: "找不到该患者,请先在系统录入患者信息或检查患者身份证信息",
447
+
448
+	ErrorCodeOrderParamWrong: "结算记录不存在",
437 449
 }
438 450
 
439 451
 type SGJError struct {

+ 16 - 1
models/his_models.go Parādīt failu

@@ -118,6 +118,9 @@ type HisPatient struct {
118 118
 	Phone                  string  `gorm:"column:phone" json:"phone" form:"phone"`
119 119
 	SocialType             int64   `gorm:"column:social_type" json:"social_type" form:"social_type"`
120 120
 	IdCardType             int64   `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
121
+	PType                  int64   `gorm:"column:p_type" json:"p_type" form:"p_type"`
122
+	Diagnosis              int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
123
+	SickType               int64   `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
121 124
 }
122 125
 
123 126
 func (HisPatient) TableName() string {
@@ -600,6 +603,9 @@ type XtHisPatient struct {
600 603
 	Phone                  string  `gorm:"column:phone" json:"phone" form:"phone"`
601 604
 	SocialType             int64   `gorm:"column:social_type" json:"social_type" form:"social_type"`
602 605
 	IdCardType             int64   `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
606
+	PType                  string  `gorm:"column:p_type" json:"p_type" form:"p_type"`
607
+	Diagnosis              int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
608
+	SickType               int64   `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
603 609
 }
604 610
 
605 611
 func (XtHisPatient) TableName() string {
@@ -675,11 +681,17 @@ type HisOrder struct {
675 681
 	FoundPrice            float64   `gorm:"column:found_price" json:"found_price" form:"found_price"`
676 682
 	MedicalInsurancePrice float64   `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
677 683
 	PrivatePrice          float64   `gorm:"column:private_price" json:"private_price" form:"private_price"`
684
+	DepartmentName        string    `gorm:"-" json:"department_name" form:"department_name"`
685
+	DoctorName            string    `gorm:"-" json:"doctor_name" form:"doctor_name"`
686
+
687
+	SettleType      int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
688
+	SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
689
+	SettleEndTime   int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
678 690
 
679 691
 	HisOrderInfo        HisOrderInfo        `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
680 692
 	Patients            Patients            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
681 693
 	HisPatient          HisPatient          `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
682
-	HisPrescriptionInfo HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
694
+	HisPrescriptionInfo HisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"p_info"`
683 695
 }
684 696
 
685 697
 func (HisOrder) TableName() string {
@@ -765,6 +777,9 @@ type VMHisPatient struct {
765 777
 	Iinfo                  string  `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
766 778
 	Idetinfo               string  `gorm:"column:idetinfo" json:"idetinfo" form:"idetinfo"`
767 779
 	IptOtpNo               string  `gorm:"column:ipt_otp_no" json:"ipt_otp_no" form:"ipt_otp_no"`
780
+	PType                  string  `gorm:"column:p_type" json:"p_type" form:"p_type"`
781
+	Diagnosis              int64   `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
782
+	SickType               int64   `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
768 783
 }
769 784
 
770 785
 func (VMHisPatient) TableName() string {

+ 193 - 10
service/his_service.go Parādīt failu

@@ -3,6 +3,7 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"github.com/jinzhu/gorm"
6
+	"strings"
6 7
 	"time"
7 8
 )
8 9
 
@@ -157,6 +158,7 @@ func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64
157 158
 	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
158 159
 	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
159 160
 	db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
161
+	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
160 162
 	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
161 163
 	return
162 164
 }
@@ -171,7 +173,8 @@ func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64
171 173
 }
172 174
 
173 175
 func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
174
-	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
176
+	db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
177
+		Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
175 178
 	db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
176 179
 	db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
177 180
 	err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
@@ -284,15 +287,83 @@ func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (pres
284 287
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
285 288
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
286 289
 		}).
287
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
290
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?  ", org_id, record_date, patient_id).
291
+		Find(&prescription).Error
292
+	return
293
+}
294
+
295
+func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
296
+	err = readDb.Model(&models.HisPrescription{}).
297
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
298
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
299
+		}).
300
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
301
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
302
+		}).
303
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
304
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
305
+		}).
306
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2", org_id, record_date, patient_id).
307
+		Find(&prescription).Error
308
+	return
309
+}
310
+
311
+func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
312
+	err = readDb.Model(&models.HisPrescription{}).
313
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
314
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
315
+		}).
316
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
317
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
318
+		}).
319
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
320
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
321
+		}).
322
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3", org_id, record_date, patient_id).
323
+		Find(&prescription).Error
324
+	return
325
+}
326
+
327
+func GetSettleHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
328
+	err = readDb.Model(&models.HisPrescription{}).
329
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
330
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
331
+		}).
332
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
333
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
334
+		}).
335
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
336
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
337
+		}).
338
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2", org_id, record_date, patient_id).
288 339
 		Find(&prescription).Error
289 340
 	return
290 341
 }
291 342
 
292 343
 func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
293 344
 	err = readDb.Model(&models.HisPrescription{}).
294
-		Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
295
-		Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
345
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
346
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
347
+		}).
348
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
349
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
350
+		}).
351
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
352
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
353
+		}).
354
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id).
355
+		Find(&prescription).Error
356
+	return
357
+}
358
+
359
+func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
360
+	err = readDb.Model(&models.HisPrescription{}).
361
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
362
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
363
+		}).
364
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
365
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
366
+		}).
296 367
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
297 368
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
298 369
 		}).
@@ -301,6 +372,56 @@ func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, e
301 372
 	return
302 373
 }
303 374
 
375
+func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
376
+	err = readDb.Model(&models.HisPrescription{}).
377
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
378
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
379
+		}).
380
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
381
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
382
+		}).
383
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
384
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
385
+		}).
386
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  ", org_id, start_date, end_date, patient_id).
387
+		Find(&prescription).Error
388
+	return
389
+}
390
+
391
+//未收费
392
+func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
393
+	err = readDb.Model(&models.HisPrescription{}).
394
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
395
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
396
+		}).
397
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
398
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
399
+		}).
400
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
401
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
402
+		}).
403
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ?  AND  order_status <> 2 AND order_status <> 3 ", org_id, start_date, end_date, patient_id).
404
+		Find(&prescription).Error
405
+	return
406
+}
407
+
408
+//已收费
409
+func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
410
+	err = readDb.Model(&models.HisPrescription{}).
411
+		Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
412
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
413
+		}).
414
+		Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
415
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
416
+		}).
417
+		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
418
+			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
419
+		}).
420
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2", org_id, start_date, end_date, patient_id).
421
+		Find(&prescription).Error
422
+	return
423
+}
424
+
304 425
 type OtherDrugWarehouseInfo struct {
305 426
 	ID               int64 `gorm:"column:id" json:"id" form:"id"`
306 427
 	DrugId           int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
@@ -527,10 +648,8 @@ func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int6
527 648
 
528 649
 	db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
529 650
 		Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
530
-		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
531
-		Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
532
-			return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
533
-		})
651
+		Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id)
652
+
534 653
 	db = db.Count(&total)
535 654
 	err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
536 655
 	return
@@ -596,14 +715,14 @@ func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisO
596 715
 	return
597 716
 }
598 717
 
599
-func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
718
+func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
600 719
 	err = readDb.Model(&models.HisPrescription{}).
601 720
 		Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
602 721
 		Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
603 722
 			return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
604 723
 		}).
605 724
 		Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
606
-		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
725
+		Where("user_org_id = ? AND status = 1  AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
607 726
 		Find(&prescription).Error
608 727
 	return
609 728
 }
@@ -944,6 +1063,11 @@ func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients,
944 1063
 	return
945 1064
 }
946 1065
 
1066
+func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
1067
+	err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
1068
+	return
1069
+}
1070
+
947 1071
 func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
948 1072
 	err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
949 1073
 	return
@@ -954,3 +1078,62 @@ func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
954 1078
 	err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
955 1079
 	return patient, err
956 1080
 }
1081
+
1082
+func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
1083
+	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
1084
+	return
1085
+}
1086
+
1087
+type VMHisProjectTeam struct {
1088
+	ID           int64   `gorm:"column:id" json:"id" form:"id"`
1089
+	ProjectTeam  string  `gorm:"column:project_team" json:"project_team" form:"project_team"`
1090
+	Price        float64 `gorm:"column:price" json:"price" form:"price"`
1091
+	Pinyin       string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
1092
+	Wubi         string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
1093
+	TubeColor    int64   `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
1094
+	TeamType     int64   `gorm:"column:team_type" json:"team_type" form:"team_type"`
1095
+	Remark       string  `gorm:"column:remark" json:"remark" form:"remark"`
1096
+	UserOrgId    int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1097
+	Status       int64   `gorm:"column:status" json:"status" form:"status"`
1098
+	CreatedTime  int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
1099
+	UpdatedTime  int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
1100
+	ProjectId    string  `gorm:"column:project_id" json:"project_id" form:"project_id"`
1101
+	VMHisProject []*VMHisProject
1102
+}
1103
+
1104
+func (VMHisProjectTeam) TableName() string {
1105
+	return "xt_his_project_team"
1106
+}
1107
+
1108
+type VMHisProject struct {
1109
+	ID                        int64   `gorm:"column:id" json:"id" form:"id"`
1110
+	ProjectName               string  `gorm:"column:project_name" json:"project_name" form:"project_name"`
1111
+	Price                     float64 `gorm:"column:price" json:"price" form:"price"`
1112
+	Unit                      string  `gorm:"column:unit" json:"unit" form:"unit"`
1113
+	CostClassify              int64   `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
1114
+	StatisticalClassification int64   `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
1115
+	UserOrgId                 int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
1116
+	Status                    int64   `gorm:"column:status" json:"status" form:"status"`
1117
+	SingleDose                string  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
1118
+	ExecutionFrequency        string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
1119
+	DeliveryWay               string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
1120
+	NumberDays                string  `gorm:"column:number_days" json:"number_days" form:"number_days"`
1121
+	MedicalCode               string  `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
1122
+}
1123
+
1124
+func (VMHisProject) TableName() string {
1125
+	return "xt_his_project"
1126
+}
1127
+
1128
+func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
1129
+	err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
1130
+	for _, item := range project {
1131
+		var project_item *VMHisProject
1132
+		ids := strings.Split(item.ProjectId, ",")
1133
+		for _, id := range ids {
1134
+			XTReadDB().Model(&VMSchedule{}).Where("user_org_id = ? and status = 1 AND id = ?", id).First(&project_item)
1135
+			item.VMHisProject = append(item.VMHisProject, project_item)
1136
+		}
1137
+	}
1138
+	return
1139
+}