csx 4 年 前
コミット
60aaf1f97b
共有2 個のファイルを変更した48 個の追加208 個の削除を含む
  1. 31 208
      controllers/his_api_controller.go
  2. 17 0
      service/his_service.go

+ 31 - 208
controllers/his_api_controller.go ファイルの表示

2015
 func (c *HisApiController) GetRegisterInfo() {
2015
 func (c *HisApiController) GetRegisterInfo() {
2016
 	id, _ := c.GetInt64("id")
2016
 	id, _ := c.GetInt64("id")
2017
 	record_time := c.GetString("record_time")
2017
 	record_time := c.GetString("record_time")
2018
-
2018
+	settlementValue, _ := c.GetInt64("settlement_value")
2019
+	medical_insurance_card := c.GetString("medical_insurance_card")
2019
 	name := c.GetString("name")
2020
 	name := c.GetString("name")
2020
-	gender, _ := c.GetInt64("gender")
2021
-	age, _ := c.GetInt64("age")
2021
+	id_card_type, _ := c.GetInt64("id_card_type")
2022
+	certificates, _ := c.GetInt64("certificates")
2023
+	medical_care, _ := c.GetInt64("medical_care")
2022
 	birthday := c.GetString("birthday")
2024
 	birthday := c.GetString("birthday")
2025
+	age, _ := c.GetInt64("age")
2026
+	id_card := c.GetString("idCard")
2027
+	register_type, _ := c.GetInt64("register")
2028
+	doctor, _ := c.GetInt64("doctor")
2029
+	department, _ := c.GetInt64("department")
2030
+	gender, _ := c.GetInt64("sex")
2023
 	phone := c.GetString("phone")
2031
 	phone := c.GetString("phone")
2024
-	medical_care, _ := c.GetInt64("medical_care")
2025
-	id_card := c.GetString("id_card")
2026
-	register_type, _ := c.GetInt64("register_type")
2027
 	registration_fee, _ := c.GetFloat("registration_fee")
2032
 	registration_fee, _ := c.GetFloat("registration_fee")
2028
 	medical_expenses, _ := c.GetFloat("medical_expenses")
2033
 	medical_expenses, _ := c.GetFloat("medical_expenses")
2029
-	certificates, _ := c.GetInt64("certificates")
2030
-	settlementValue, _ := c.GetInt64("settlement_value")
2031
 	social_type, _ := c.GetInt64("social_type")
2034
 	social_type, _ := c.GetInt64("social_type")
2032
-	medical_insurance_card := c.GetString("medical_insurance_card")
2033
-	id_card_type, _ := c.GetInt64("id_card_type")
2034
 
2035
 
2035
 	timeLayout := "2006-01-02"
2036
 	timeLayout := "2006-01-02"
2036
 	loc, _ := time.LoadLocation("Local")
2037
 	loc, _ := time.LoadLocation("Local")
2045
 	recordDateTime := theTime.Unix()
2046
 	recordDateTime := theTime.Unix()
2046
 
2047
 
2047
 	adminInfo := c.GetAdminUserInfo()
2048
 	adminInfo := c.GetAdminUserInfo()
2048
-	patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
2049
-	patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
2050
 
2049
 
2051
-	miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
2050
+	var patient service.Patients
2051
+
2052
+	if id == 0 {
2053
+		patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
2052
 
2054
 
2053
-	if patient == nil {
2055
+	} else {
2056
+		patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
2057
+
2058
+	}
2059
+
2060
+	if patient.ID == 0 {
2054
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
2061
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
2055
 		return
2062
 		return
2056
 	}
2063
 	}
2059
 		return
2066
 		return
2060
 	}
2067
 	}
2061
 
2068
 
2062
-	//org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
2063
 	config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
2069
 	config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
2064
 
2070
 
2065
 	if config.IsOpen == 1 {
2071
 	if config.IsOpen == 1 {
2066
 
2072
 
2067
-		api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
2068
-		resp, requestErr := http.Get(api)
2069
-
2070
-		if requestErr != nil {
2071
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2072
-			return
2073
-		}
2074
-		defer resp.Body.Close()
2075
-		body, ioErr := ioutil.ReadAll(resp.Body)
2076
-		if ioErr != nil {
2077
-			utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2078
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2079
-			return
2080
-		}
2081
-		var respJSON map[string]interface{}
2082
-
2083
-		if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
2084
-			utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2085
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2086
-			return
2087
-		}
2088
-
2089
-		userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2090
-		userJSONBytes, _ := json.Marshal(userJSON)
2091
-		var res ResultTwo
2092
-		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2093
-			utils.ErrorLog("解析失败:%v", err)
2094
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2095
-			return
2096
-		}
2097
-		Iinfos, _ := json.Marshal(res.Output.Iinfo)
2098
-		Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
2099
-		infoStr := string(Iinfos)
2100
-		idetinfoStr := string(Idetinfos)
2101
-
2102
-		his := models.VMHisPatient{
2103
-			PsnNo:       res.Output.Baseinfo.PsnNo,
2104
-			PsnCertType: res.Output.Baseinfo.PsnCertType,
2105
-			Certno:      res.Output.Baseinfo.Certno,
2106
-			PsnName:     res.Output.Baseinfo.PsnName,
2107
-			Gend:        res.Output.Baseinfo.Gend,
2108
-			Naty:        res.Output.Baseinfo.Naty,
2109
-			Brdy:        res.Output.Baseinfo.Brdy,
2110
-			Age:         res.Output.Baseinfo.Age,
2111
-			Iinfo:       infoStr,
2112
-			Idetinfo:    idetinfoStr,
2113
-			PatientId:   patient.ID,
2114
-			RecordDate:  theTime.Unix(),
2115
-			UserOrgId:   adminInfo.CurrentOrgId,
2116
-			AdminUserId: adminInfo.AdminUser.Id,
2117
-			IsReturn:    1,
2118
-		}
2119
-		fmt.Println(his)
2120
-
2121
-		lastPatient, _ := service.GetLastPatient(adminInfo.CurrentOrgId)
2122
-		timeStr := time.Now().Format("2006-01-02")
2123
-		timeArr := strings.Split(timeStr, "-")
2124
-		var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
2125
-
2126
-		hisPatient := models.HisPatient{
2127
-			Number: str,
2128
-		}
2129
-		err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
2130
-
2131
-		if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
2132
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
2133
-			return
2134
-		}
2135
-
2136
-		timestamp := time.Now().Unix()
2137
-		tempTime := time.Unix(timestamp, 0)
2138
-		timeFormat := tempTime.Format("20060102150405")
2139
-		chrgBchno := rand.Intn(100000) + 10000
2140
-		ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
2141
-
2142
-		count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
2143
-
2144
-		department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
2145
-
2146
-		//department_id := strconv.FormatInt(department.ID, 10)
2147
-		doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
2148
-
2149
-		if count <= 0 {
2150
-			api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
2151
-				res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
2152
-				"&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
2153
-				"&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
2154
-			resp, requestErr := http.Get(api)
2155
-			if requestErr != nil {
2156
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2157
-				return
2158
-			}
2159
-			defer resp.Body.Close()
2160
-			body, ioErr := ioutil.ReadAll(resp.Body)
2161
-			if ioErr != nil {
2162
-				utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2163
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2164
-				return
2165
-			}
2166
-			var respJSON map[string]interface{}
2167
-			if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
2168
-				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2169
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2170
-				return
2171
-			}
2172
-
2173
-			respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2174
-			userJSONBytes, _ := json.Marshal(respJSON)
2175
-			var res ResultThree
2176
-			if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2177
-				utils.ErrorLog("解析失败:%v", err)
2178
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2179
-				return
2180
-			}
2181
-			if res.Infcode == -1 {
2182
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
2183
-				return
2184
-			}
2185
-			fmt.Println("000!!!!!!")
2186
-			fmt.Println(res)
2187
-			fmt.Println(res.Output.Data.MdtrtID)
2188
-			fmt.Println(res.Output.Data.PsnNo)
2189
-			fmt.Println(res.Output.Data.IptOtpNo)
2190
-
2191
-			his.Number = res.Output.Data.MdtrtID
2192
-			his.PsnNo = res.Output.Data.PsnNo
2193
-			his.IptOtpNo = res.Output.Data.IptOtpNo
2194
-			his.IdCardNo = patient.IdCardNo
2195
-			his.PhoneNumber = patient.Phone
2196
-			his.UserOrgId = adminInfo.CurrentOrgId
2197
-			his.Status = 1
2198
-			his.Ctime = time.Now().Unix()
2199
-			his.Mtime = time.Now().Unix()
2200
-			err := service.CreateHisPatientTwo(&his)
2201
-
2202
-			diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
2203
-
2204
-			if err == nil {
2205
-				api := "http://127.0.0.1:9531/" + "gdyb/four?psn_no=" + his.PsnNo +
2206
-					"&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
2207
-					"&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + "11" + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
2208
-					"&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
2209
-				resp, requestErr := http.Get(api)
2210
-				if requestErr != nil {
2211
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2212
-					return
2213
-				}
2214
-
2215
-				body, ioErr := ioutil.ReadAll(resp.Body)
2216
-				if ioErr != nil {
2217
-					utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
2218
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2219
-					return
2220
-				}
2221
-				var respJSON map[string]interface{}
2222
-				if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
2223
-					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
2224
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2225
-					return
2226
-				}
2227
-
2228
-				respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
2229
-				userJSONBytes, _ := json.Marshal(respJSON)
2230
-				fmt.Println(respJSON)
2231
-				fmt.Println(userJSONBytes)
2232
-
2233
-				var res ResultSix
2234
-				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
2235
-					utils.ErrorLog("解析失败:%v", err)
2236
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2237
-					return
2238
-				}
2239
-				if res.Infcode == -1 {
2240
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
2241
-					return
2242
-				}
2243
-
2244
-				c.ServeSuccessJSON(map[string]interface{}{
2245
-					"his_info": his,
2246
-				})
2247
-			} else {
2248
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
2249
-				return
2250
-			}
2251
-		}
2252
-
2253
 	} else {
2073
 	} else {
2254
 		timeStr := time.Now().Format("2006-01-02")
2074
 		timeStr := time.Now().Format("2006-01-02")
2255
 		timeArr := strings.Split(timeStr, "-")
2075
 		timeArr := strings.Split(timeStr, "-")
2283
 				Mtime:                  time.Now().Unix(),
2103
 				Mtime:                  time.Now().Unix(),
2284
 				Number:                 str,
2104
 				Number:                 str,
2285
 				IdCardType:             id_card_type,
2105
 				IdCardType:             id_card_type,
2106
+				Departments:            department,
2107
+				Doctor:                 doctor,
2286
 			}
2108
 			}
2287
 			service.CreateHisPatient(&hisPatient)
2109
 			service.CreateHisPatient(&hisPatient)
2288
 
2110
 
2957
 	}
2779
 	}
2958
 	recordDateTime := theTime.Unix()
2780
 	recordDateTime := theTime.Unix()
2959
 	adminInfo := c.GetAdminUserInfo()
2781
 	adminInfo := c.GetAdminUserInfo()
2960
-	patients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
2961
-	//var patients []*service.Patients
2962
-	//for _, item := range tempPatients{
2963
-	//	if len(item.HisPrescription) > 0 {
2964
-	//		patients = append(patients, item)
2965
-	//	}
2966
-	//}
2782
+	tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
2783
+	var patients []*service.Patients
2784
+	for _, item := range tempPatients {
2785
+		//过滤掉没挂号的和没开处方的
2786
+		if item.HisPatient.ID > 0 || len(item.HisPrescription) > 0 {
2787
+			patients = append(patients, item)
2788
+		}
2789
+	}
2967
 	//patients_two, _ := service.GetChargeHisPatientListTwo(adminInfo.CurrentOrgId, "", recordDateTime)
2790
 	//patients_two, _ := service.GetChargeHisPatientListTwo(adminInfo.CurrentOrgId, "", recordDateTime)
2968
 	c.ServeSuccessJSON(map[string]interface{}{
2791
 	c.ServeSuccessJSON(map[string]interface{}{
2969
 		"list": patients,
2792
 		"list": patients,

+ 17 - 0
service/his_service.go ファイルの表示

111
 	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
111
 	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
112
 	Name                  string                `gorm:"column:name" json:"name" form:"name"`
112
 	Name                  string                `gorm:"column:name" json:"name" form:"name"`
113
 	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
113
 	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
114
+	IdCardNo              string                `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
114
 	Schedule              Schedule              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
115
 	Schedule              Schedule              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
115
 	HisPatient            HisPatient            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
116
 	HisPatient            HisPatient            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
116
 	HisPrescription       []*HisPrescription    `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
117
 	HisPrescription       []*HisPrescription    `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
937
 	err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1  AND id = ?", id).First(&addition).Error
938
 	err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1  AND id = ?", id).First(&addition).Error
938
 	return
939
 	return
939
 }
940
 }
941
+
942
+func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
943
+	err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
944
+	return
945
+}
946
+
947
+func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
948
+	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
+	return
950
+}
951
+
952
+func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
953
+	var patient Patients
954
+	err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
955
+	return patient, err
956
+}