coordinate_controller.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. package coordinate
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "gdyb/controllers"
  6. "gdyb/enums"
  7. "gdyb/models"
  8. "gdyb/service"
  9. "gdyb/utils"
  10. "github.com/astaxie/beego"
  11. "math/rand"
  12. "os"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type ResultUpload struct {
  18. Code string `json:"code"`
  19. Msg string `json:"msg"`
  20. Result []struct {
  21. List []interface{} `json:"list"`
  22. Page int64 `json:"page"`
  23. Pagenumber int64 `json:"pagenumber"`
  24. Records int64 `json:"records"`
  25. RecordsFiltered int64 `json:"recordsFiltered"`
  26. RecordsTotal int64 `json:"recordsTotal"`
  27. Result string `json:"result"`
  28. ResultMsg string `json:"resultMsg"`
  29. Total int64 `json:"total"`
  30. TotalPage int64 `json:"totalPage"`
  31. Userdata string `json:"userdata"`
  32. Code string `json:"code"`
  33. } `json:"result"`
  34. }
  35. type ResultQuery struct {
  36. Msg string `json:"msg"`
  37. Result []struct {
  38. Type string `json:"type"`
  39. Name string `json:"name"`
  40. Vaa01 int64 `json:"vaa01"`
  41. Vaa07 int64 `json:"vaa07"`
  42. Visittime string `json:"visittime"`
  43. } `json:"result"`
  44. Code string `json:"code"`
  45. }
  46. type CoordinateController struct {
  47. controllers.BaseAuthAPIController
  48. }
  49. type ResultReg struct {
  50. ResultCode string `json:"resultCode"`
  51. ResultDesc string `json:"resultDesc"`
  52. InfoSeq string `json:"infoSeq"`
  53. }
  54. func CoordinateRegistRouters() {
  55. beego.Router("/coordinate/settleAccount", &CoordinateController{}, "get:SettleAccount")
  56. }
  57. func (c *CoordinateController) SettleAccount() {
  58. patient_id, _ := c.GetInt64("patient_id")
  59. record_date := c.GetString("record_date")
  60. admin_user_id, _ := c.GetInt64("admin_user_id")
  61. diagnosis_id := c.GetString("diagnosis")
  62. sick_type, _ := c.GetInt64("sick_type")
  63. reg_type, _ := c.GetInt64("p_type")
  64. org_id, _ := c.GetInt64("org_id")
  65. org_id = 10340
  66. org, _ := service.GetOrgById(org_id)
  67. patient, _ := service.GetPatientByID(org.Id, patient_id)
  68. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  69. result, request := service.GetHisPatientForCoordinate(patient.IdCardNo)
  70. saveLog(result, request, "查询", "查询", org.OrgName)
  71. var res ResultQuery
  72. if err := json.Unmarshal([]byte(result), &res); err != nil {
  73. utils.ErrorLog("解析失败:%v", err)
  74. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  75. return
  76. }
  77. if res.Code == "10000" {
  78. if len(res.Result) == 0 {
  79. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientNoRegException)
  80. return
  81. }
  82. timeLayout := "2006-01-02"
  83. loc, _ := time.LoadLocation("Local")
  84. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  85. if err != nil {
  86. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  87. return
  88. }
  89. org_id := org.Id
  90. recordDateTime := theTime.Unix()
  91. patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  92. if patientPrescription.ID == 0 {
  93. patientPrescription, _ = service.FindLastPatientPrescriptionInfoTwoTen(org_id, patient.ID, recordDateTime)
  94. }
  95. departmwnt, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  96. doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  97. //admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  98. var prescriptions []*models.HisPrescription
  99. if settle_accounts_type == 1 { //日结
  100. prescriptions, _ = service.GetUnSettleHisPrescriptionFiveTen(org_id, patient_id, recordDateTime, 2)
  101. } else { //月结
  102. start_time_str := c.GetString("start_time")
  103. end_time_str := c.GetString("end_time")
  104. timeLayout := "2006-01-02"
  105. loc, _ := time.LoadLocation("Local")
  106. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  107. if err != nil {
  108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  109. return
  110. }
  111. recordStartTime := theStartTime.Unix()
  112. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  113. if err != nil {
  114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  115. return
  116. }
  117. recordEndTime := theEndTime.Unix()
  118. prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, patient_id, recordStartTime, recordEndTime)
  119. }
  120. var total float64
  121. for _, item := range prescriptions {
  122. fmt.Println(item)
  123. if item.Type == 1 { //药品
  124. for _, subItem := range item.HisDoctorAdviceInfo {
  125. total = total + (subItem.Price * subItem.PrescribingNumber)
  126. }
  127. }
  128. if item.Type == 2 { //项目
  129. for _, subItem := range item.HisPrescriptionProject {
  130. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  131. total = total + (subItem.Price * cnt)
  132. }
  133. }
  134. }
  135. var ids []int64
  136. for _, item := range prescriptions {
  137. ids = append(ids, item.ID)
  138. }
  139. var customs []*models.NewCustomTwo
  140. for _, item := range prescriptions {
  141. if item.Type == 1 { //药品
  142. for _, subItem := range item.HisDoctorAdviceInfo {
  143. cus := &models.NewCustomTwo{
  144. AdviceId: subItem.ID,
  145. ProjectId: 0,
  146. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  147. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  148. FeedetlSn: subItem.FeedetlSn,
  149. Price: fmt.Sprintf("%.2f", subItem.Price),
  150. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  151. Type: 1,
  152. }
  153. customs = append(customs, cus)
  154. }
  155. }
  156. if item.Type == 2 { //项目
  157. for _, subItem := range item.HisPrescriptionProject {
  158. if subItem.Type == 2 {
  159. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  160. cus := &models.NewCustomTwo{
  161. AdviceId: 0,
  162. ProjectId: subItem.ID,
  163. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  164. Cut: fmt.Sprintf("%.4f", cnt),
  165. FeedetlSn: subItem.FeedetlSn,
  166. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  167. MedListCodg: subItem.HisProject.MedicalCode,
  168. Type: 2,
  169. }
  170. customs = append(customs, cus)
  171. } else {
  172. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  173. cus := &models.NewCustomTwo{
  174. AdviceId: 0,
  175. ProjectId: subItem.ID,
  176. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  177. Cut: fmt.Sprintf("%.4f", cnt),
  178. FeedetlSn: subItem.FeedetlSn,
  179. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  180. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  181. Type: 3,
  182. }
  183. customs = append(customs, cus)
  184. }
  185. }
  186. }
  187. }
  188. var info models.UploadInfo
  189. info.Vaa01 = res.Result[0].Vaa01
  190. info.Fasong = "1"
  191. info.Vaa07 = res.Result[0].Vaa07
  192. info.Bck01c = departmwnt.Number
  193. info.Bce02a = doctor_info.DoctorNumber
  194. diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  195. var config []*models.HisXtDiagnoseConfig
  196. for _, item := range diagnosis_ids {
  197. id, _ := strconv.ParseInt(item, 10, 64)
  198. diagnosisConfig, _ := service.FindDiagnoseById(id)
  199. config = append(config, &diagnosisConfig)
  200. }
  201. for index, item := range config {
  202. var diag models.Diag
  203. diag.Vao06 = strconv.FormatInt(int64(index+1), 10)
  204. diag.Bak02 = item.CountryCode
  205. info.Diag = append(info.Diag, &diag)
  206. }
  207. var presInfos []*models.PresInfo
  208. var presDetails []*models.PresDetail
  209. var doctoradvices []*models.HisDoctorAdviceInfo
  210. var groups []int64
  211. for _, item := range prescriptions {
  212. for _, subItem := range item.HisDoctorAdviceInfo {
  213. doctoradvices = append(doctoradvices, subItem)
  214. }
  215. }
  216. for _, item := range doctoradvices {
  217. groups = append(groups, item.Groupno)
  218. }
  219. groups = RemoveRepeatedGroupElement(groups)
  220. type DoctorAdvices struct {
  221. GroupNo int64
  222. item []*models.HisDoctorAdviceInfo
  223. }
  224. var doctoradvice []*DoctorAdvices
  225. for _, group := range groups {
  226. var da DoctorAdvices
  227. da.GroupNo = group
  228. for _, item := range doctoradvices {
  229. if group == item.Groupno {
  230. da.item = append(da.item, item)
  231. }
  232. }
  233. doctoradvice = append(doctoradvice, &da)
  234. }
  235. for _, item := range doctoradvice {
  236. var presDetail models.PresDetail
  237. var presInfo models.PresInfo
  238. presInfo.Cbmid = strconv.FormatInt(item.GroupNo, 10)
  239. presInfo.Cbm06 = "0"
  240. presInfo.Cbm07 = ""
  241. presDetail.Vaf59 = strconv.FormatInt(item.GroupNo, 10)
  242. var infoItems []*models.Item
  243. for index, subItem := range item.item {
  244. ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  245. var infoItem models.Item
  246. infoItem.Rownr = strconv.FormatInt(int64(index), 10)
  247. infoItem.Vaf11 = "2"
  248. infoItem.Vaf36 = time.Unix(subItem.CreatedTime, 0).Format("2006-01-02 15:04:05")
  249. infoItem.Bbx01 = subItem.BaseDrugLib.MedicalInsuranceNumber
  250. infoItem.Bda01 = "1"
  251. infoItem.Bby01 = ""
  252. if subItem.BaseDrugLib.MinUnit != subItem.BaseDrugLib.DoseUnit {
  253. infoItem.Vaf22 = subItem.BaseDrugLib.DrugName + " " + subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  254. }
  255. infoItem.Vaf14 = subItem.BaseDrugLib.DrugName
  256. infoItem.Bdi01 = ef.Code
  257. infoItem.Vaf17 = strconv.FormatInt(subItem.Day, 10)
  258. infoItem.Vaf18 = fmt.Sprintf("%.2f", subItem.SingleDose)
  259. infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  260. infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  261. infoItem.Vaf35 = "0"
  262. infoItem.Vaf32 = "0"
  263. infoItem.Bck01b = departmwnt.Number
  264. infoItem.Bck01d = departmwnt.Number
  265. infoItem.Vaf58 = "0"
  266. infoItem.Vaf61 = "1"
  267. infoItems = append(infoItems, &infoItem)
  268. }
  269. presDetail.Item = infoItems
  270. presDetails = append(presDetails, &presDetail)
  271. presInfo.PresDetail = presDetails
  272. presInfos = append(presInfos, &presInfo)
  273. }
  274. for index, item := range prescriptions {
  275. var presDetail models.PresDetail
  276. var presInfo models.PresInfo
  277. presInfo.Cbmid = strconv.FormatInt(item.ID, 10)
  278. if item.Type == 1 {
  279. presInfo.Cbm06 = "0"
  280. } else {
  281. presInfo.Cbm06 = "5"
  282. }
  283. if item.Type == 1 {
  284. presInfo.Cbm07 = item.MedType
  285. } else {
  286. presInfo.Cbm07 = item.MedType
  287. }
  288. presDetail.Vaf59 = strconv.FormatInt(int64(index+1), 10)
  289. var infoItems []*models.Item
  290. //for index, subItem := range item.HisDoctorAdviceInfo {
  291. // ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  292. //
  293. // var infoItem models.Item
  294. // infoItem.Rownr = strconv.FormatInt(int64(index+1), 10)
  295. // infoItem.Vaf11 = "2"
  296. // infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  297. // infoItem.Bbx01 = subItem.BaseDrugLib.MedicalInsuranceNumber
  298. // infoItem.Bda01 = "1"
  299. // infoItem.Bby01 = ""
  300. // if subItem.BaseDrugLib.MinUnit != subItem.BaseDrugLib.DoseUnit {
  301. // infoItem.Vaf22 = subItem.BaseDrugLib.DrugName + " " + subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  302. // }
  303. // infoItem.Vaf14 = subItem.BaseDrugLib.DrugName
  304. // infoItem.Bdi01 = ef.Code
  305. // infoItem.Vaf17 = strconv.FormatInt(subItem.Day, 10)
  306. // infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  307. // infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  308. // infoItem.Vaf35 = "0"
  309. // infoItem.Vaf32 = "0"
  310. // infoItem.Bck01b = departmwnt.Number
  311. // infoItem.Bck01d = departmwnt.Number
  312. // infoItem.Vaf58 = "0"
  313. // infoItem.Vaf61 = "1"
  314. // infoItems = append(infoItems, &infoItem)
  315. //}
  316. for _, subItem := range item.HisPrescriptionProject {
  317. //ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  318. if subItem.Type == 2 {
  319. if subItem.HisProject.CostClassify == 10 {
  320. var infoItem models.Item
  321. infoItem.Rownr = "0"
  322. infoItem.Vaf11 = "2"
  323. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  324. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  325. infoItem.Bda01 = "Z"
  326. infoItem.Bby01 = ""
  327. infoItem.Vaf14 = subItem.HisProject.ProjectName
  328. infoItem.Vaf15 = subItem.HisProject.ProjectName
  329. infoItem.Bdi01 = "160"
  330. infoItem.Vaf17 = subItem.Day
  331. infoItem.Vaf20 = subItem.SingleDose
  332. infoItem.Vaf21 = subItem.Count
  333. infoItem.Vaf35 = "0"
  334. infoItem.Vaf18 = ""
  335. infoItem.Vaf32 = "1"
  336. infoItem.Bck01b = departmwnt.Number
  337. infoItem.Bck01d = departmwnt.Number
  338. infoItem.Vaf58 = "0"
  339. infoItem.Vaf61 = "1"
  340. infoItems = append(infoItems, &infoItem)
  341. } else {
  342. var infoItem models.Item
  343. infoItem.Rownr = "0"
  344. infoItem.Vaf11 = "1"
  345. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  346. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  347. if subItem.HisProject.CostClassify == 2 {
  348. infoItem.Bda01 = "T"
  349. } else if subItem.HisProject.CostClassify == 3 {
  350. infoItem.Bda01 = "L"
  351. } else {
  352. infoItem.Bda01 = "T"
  353. }
  354. infoItem.Bby01 = ""
  355. infoItem.Vaf14 = subItem.HisProject.ProjectName
  356. infoItem.Bdi01 = "160"
  357. infoItem.Vaf17 = subItem.Day
  358. infoItem.Vaf20 = subItem.SingleDose
  359. infoItem.Vaf21 = subItem.Count
  360. infoItem.Vaf35 = "0"
  361. infoItem.Vaf18 = fmt.Sprintf("%.2f", subItem.SingleDose)
  362. infoItem.Vaf32 = "0"
  363. infoItem.Bck01b = departmwnt.Number
  364. infoItem.Bck01d = departmwnt.Number
  365. infoItem.Vaf58 = "0"
  366. infoItem.Vaf61 = "1"
  367. infoItems = append(infoItems, &infoItem)
  368. }
  369. } else {
  370. var infoItem models.Item
  371. infoItem.Rownr = "0"
  372. infoItem.Vaf11 = "1"
  373. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  374. infoItem.Bbx01 = subItem.GoodInfo.MedicalInsuranceNumber
  375. infoItem.Bda01 = "M"
  376. infoItem.Bby01 = ""
  377. infoItem.Vaf14 = subItem.GoodInfo.GoodName + " " + subItem.GoodInfo.SpecificationName
  378. infoItem.Bdi01 = "160"
  379. infoItem.Vaf17 = subItem.Day
  380. infoItem.Vaf20 = subItem.SingleDose
  381. infoItem.Vaf21 = subItem.Count
  382. infoItem.Vaf35 = "0"
  383. infoItem.Vaf32 = "0"
  384. infoItem.Bck01b = departmwnt.Number
  385. infoItem.Bck01d = departmwnt.Number
  386. infoItem.Vaf58 = "0"
  387. infoItem.Vaf61 = "1"
  388. infoItems = append(infoItems, &infoItem)
  389. }
  390. }
  391. presDetail.Item = infoItems
  392. presDetails = append(presDetails, &presDetail)
  393. presInfo.PresDetail = presDetails
  394. presInfos = append(presInfos, &presInfo)
  395. }
  396. info.PresInfo = presInfos
  397. var result2 string
  398. var request2 string
  399. if res.Result[0].Type == "1" {
  400. result2, request2 = service.UploadPrescriptionForCoordinate(info)
  401. } else {
  402. result2, request2 = service.UploadPrescriptionForCoordinateHospital(info)
  403. }
  404. saveLog(result2, request2, "上传明细", "上传明细", org.OrgName)
  405. var res2 ResultUpload
  406. if err := json.Unmarshal([]byte(result2), &res2); err != nil {
  407. utils.ErrorLog("解析失败:%v", err)
  408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  409. return
  410. }
  411. if res2.Code == "10000" && len(res2.Result) > 0 && res2.Result[0].Code != "500" && len(res2.Result[0].List) > 0 {
  412. timestamp := time.Now().Unix()
  413. tempTime := time.Unix(timestamp, 0)
  414. timeFormat := tempTime.Format("20060102150405")
  415. chrgBchno := rand.Intn(100000) + 10000
  416. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  417. his := models.VMHisPatient{
  418. Name: patient.Name,
  419. Gender: patient.Gender,
  420. Birthday: patient.Birthday,
  421. MedicalTreatmentType: 0,
  422. IdType: 1,
  423. IdCardNo: patient.IdCardNo,
  424. BalanceAccountsType: 1,
  425. MedicalInsuranceNumber: "",
  426. RegisterType: 0,
  427. RegisterCost: 0,
  428. TreatmentCost: 0,
  429. Status: 1,
  430. Ctime: time.Now().Unix(),
  431. Mtime: time.Now().Unix(),
  432. PsnNo: strconv.FormatInt(int64(res.Result[0].Vaa01), 10),
  433. PsnCertType: "",
  434. Certno: patient.IdCardNo,
  435. PsnName: patient.Name,
  436. Gend: "",
  437. Naty: "",
  438. Brdy: "",
  439. Age: 0,
  440. Iinfo: "",
  441. Idetinfo: "",
  442. PatientId: patient.ID,
  443. RecordDate: theTime.Unix(),
  444. UserOrgId: org_id,
  445. AdminUserId: admin_user_id,
  446. IsReturn: 1,
  447. Doctor: patientPrescription.DoctorId,
  448. Departments: patientPrescription.Departments,
  449. IptOtpNo: ipt_otp_no,
  450. Number: strconv.FormatInt(int64(res.Result[0].Vaa07), 10),
  451. PhoneNumber: patient.Phone,
  452. }
  453. service.UpdateHisPatientStatusTwo(&his)
  454. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  455. tm := time.Unix(time.Now().Unix(), 0)
  456. order := &models.HisOrder{
  457. PsnNo: his.PsnNo,
  458. UserOrgId: org_id,
  459. HisPatientId: his.ID,
  460. PatientId: patient_id,
  461. SettleAccountsDate: recordDateTime,
  462. Ctime: time.Now().Unix(),
  463. Mtime: time.Now().Unix(),
  464. Status: 1,
  465. OrderStatus: 1,
  466. MdtrtId: his.Number,
  467. Number: ipt_otp_no,
  468. SetlId: "",
  469. MedfeeSumamt: total,
  470. MedType: strconv.Itoa(int(reg_type)),
  471. SettleEndTime: 0,
  472. SettleStartTime: 0,
  473. SettleType: settle_accounts_type,
  474. Diagnosis: diagnosis_id,
  475. PType: 2,
  476. SetlTime: tm.Format("2006-01-02 15:04:05"),
  477. }
  478. err = service.CreateOrder(order)
  479. if err != nil {
  480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderExceptionT)
  481. return
  482. }
  483. for _, item := range customs {
  484. var advice_id int64 = 0
  485. var project_id int64 = 0
  486. var item_id int64 = 0
  487. var types int64 = 0
  488. if item.Type == 1 {
  489. advice_id = item.AdviceId
  490. project_id = 0
  491. item_id = 0
  492. } else if item.Type == 2 {
  493. advice_id = 0
  494. item_id = 0
  495. project_id = item.ProjectId
  496. } else if item.Type == 3 {
  497. advice_id = 0
  498. item_id = item.ItemId
  499. project_id = 0
  500. }
  501. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  502. cut, _ := strconv.ParseFloat(item.Cut, 32)
  503. pric, _ := strconv.ParseFloat(item.Price, 32)
  504. info := &models.HisOrderInfo{
  505. OrderNumber: order.Number,
  506. UploadDate: time.Now().Unix(),
  507. AdviceId: advice_id,
  508. DetItemFeeSumamt: detItemFeeSumamt,
  509. Cnt: cut,
  510. Pric: pric,
  511. PatientId: patient_id,
  512. Status: 1,
  513. Mtime: time.Now().Unix(),
  514. Ctime: time.Now().Unix(),
  515. UserOrgId: org_id,
  516. HisPatientId: his.ID,
  517. OrderId: order.ID,
  518. ProjectId: project_id,
  519. Type: types,
  520. ItemId: item_id,
  521. }
  522. service.CreateOrderInfo(info)
  523. }
  524. his.Diagnosis = diagnosis_id
  525. his.SickType = sick_type
  526. his.RegisterType = reg_type
  527. his.MedicalTreatmentType = reg_type
  528. service.UpdataHisPateintTwoTen(&his)
  529. err = service.UpDatePrescriptionNumber(org_id, ids, order.Number)
  530. err = service.UpDateHisPrescriptionInfoNumberTen(org_id, patient_id, order.Number, recordDateTime, his.ID)
  531. err = service.UpdataOrderStatusThreeTen(strconv.FormatInt(int64(chrgBchno), 10), org_id)
  532. c.ServeSuccessJSON(map[string]interface{}{
  533. "msg": "医嘱保存成功",
  534. })
  535. } else {
  536. c.ServeSuccessJSON(map[string]interface{}{
  537. "failed_code": -10,
  538. "msg": res2.Msg + "----" + res2.Result[0].ResultMsg,
  539. })
  540. }
  541. } else {
  542. c.ServeSuccessJSON(map[string]interface{}{
  543. "failed_code": -10,
  544. "msg": res.Msg,
  545. })
  546. }
  547. }
  548. type Charset string
  549. const (
  550. UTF8 = Charset("UTF-8")
  551. GB18030 = Charset("GB18030")
  552. )
  553. func saveLog(result string, request string, infno string, desc string, org_name string) {
  554. //org_id, _ := beego.AppConfig.Int64("org_id")
  555. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  556. dir := org_name + "日志"
  557. utils.Mkdir(dir)
  558. month := time.Unix(1557042972, 0).Format("1")
  559. year := time.Now().Format("2006")
  560. month = time.Now().Format("01")
  561. day := time.Now().Format("02")
  562. hour := time.Now().Format("15")
  563. min := time.Now().Format("04")
  564. sec := time.Now().Format("05")
  565. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  566. file := org_name + "_" + year + month + day + "_log"
  567. file_name := file + ".txt"
  568. file_path := org_name + "日志" + "/" + file_name
  569. exist, _ := utils.PathExists(file_path)
  570. if exist { //存在
  571. fmt.Println("存在")
  572. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  573. if err != nil {
  574. fmt.Println("read fail")
  575. }
  576. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  577. n, _ := f.Seek(0, 2)
  578. _, err = f.WriteAt([]byte(content), n)
  579. } else { //不存在
  580. fmt.Println("文件不存在,创建文件")
  581. f, err := os.Create(org_name + "日志" + "/" + file_name)
  582. defer f.Close()
  583. if err != nil {
  584. } else {
  585. _, err = f.Write([]byte("记录日志"))
  586. }
  587. }
  588. }
  589. func RemoveRepeatedGroupElement(arr []int64) (newArr []int64) {
  590. newArr = make([]int64, 0)
  591. for i := 0; i < len(arr); i++ {
  592. repeat := false
  593. for j := i + 1; j < len(arr); j++ {
  594. if arr[i] == arr[j] {
  595. repeat = true
  596. break
  597. }
  598. }
  599. if !repeat {
  600. newArr = append(newArr, arr[i])
  601. }
  602. }
  603. return
  604. }