coordinate_controller.go 23KB

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