coordinate_controller.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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 int `json:"vaa01"`
  41. Vaa07 int `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.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  259. infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  260. infoItem.Vaf35 = "0"
  261. infoItem.Vaf32 = "0"
  262. infoItem.Bck01b = departmwnt.Number
  263. infoItem.Bck01d = departmwnt.Number
  264. infoItem.Vaf58 = "0"
  265. infoItem.Vaf61 = "1"
  266. infoItems = append(infoItems, &infoItem)
  267. }
  268. presDetail.Item = infoItems
  269. presDetails = append(presDetails, &presDetail)
  270. presInfo.PresDetail = presDetails
  271. presInfos = append(presInfos, &presInfo)
  272. }
  273. for index, item := range prescriptions {
  274. var presDetail models.PresDetail
  275. var presInfo models.PresInfo
  276. presInfo.Cbmid = strconv.FormatInt(item.ID, 10)
  277. if item.Type == 1 {
  278. presInfo.Cbm06 = "0"
  279. } else {
  280. presInfo.Cbm06 = "5"
  281. }
  282. if item.Type == 1 {
  283. presInfo.Cbm07 = item.MedType
  284. } else {
  285. presInfo.Cbm07 = item.MedType
  286. }
  287. presDetail.Vaf59 = strconv.FormatInt(int64(index+1), 10)
  288. var infoItems []*models.Item
  289. //for index, subItem := range item.HisDoctorAdviceInfo {
  290. // ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  291. //
  292. // var infoItem models.Item
  293. // infoItem.Rownr = strconv.FormatInt(int64(index+1), 10)
  294. // infoItem.Vaf11 = "2"
  295. // infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  296. // infoItem.Bbx01 = subItem.BaseDrugLib.MedicalInsuranceNumber
  297. // infoItem.Bda01 = "1"
  298. // infoItem.Bby01 = ""
  299. // if subItem.BaseDrugLib.MinUnit != subItem.BaseDrugLib.DoseUnit {
  300. // infoItem.Vaf22 = subItem.BaseDrugLib.DrugName + " " + subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  301. // }
  302. // infoItem.Vaf14 = subItem.BaseDrugLib.DrugName
  303. // infoItem.Bdi01 = ef.Code
  304. // infoItem.Vaf17 = strconv.FormatInt(subItem.Day, 10)
  305. // infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  306. // infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  307. // infoItem.Vaf35 = "0"
  308. // infoItem.Vaf32 = "0"
  309. // infoItem.Bck01b = departmwnt.Number
  310. // infoItem.Bck01d = departmwnt.Number
  311. // infoItem.Vaf58 = "0"
  312. // infoItem.Vaf61 = "1"
  313. // infoItems = append(infoItems, &infoItem)
  314. //}
  315. for _, subItem := range item.HisPrescriptionProject {
  316. //ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  317. if subItem.Type == 2 {
  318. if subItem.HisProject.CostClassify == 10 {
  319. var infoItem models.Item
  320. infoItem.Rownr = "0"
  321. infoItem.Vaf11 = "2"
  322. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  323. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  324. infoItem.Bda01 = "Z"
  325. infoItem.Bby01 = ""
  326. infoItem.Vaf14 = subItem.HisProject.ProjectName
  327. infoItem.Vaf15 = subItem.HisProject.ProjectName
  328. infoItem.Bdi01 = "160"
  329. infoItem.Vaf17 = subItem.Day
  330. infoItem.Vaf20 = subItem.SingleDose
  331. infoItem.Vaf21 = subItem.Count
  332. infoItem.Vaf35 = "0"
  333. infoItem.Vaf18 = 0
  334. infoItem.Vaf32 = "1"
  335. infoItem.Bck01b = departmwnt.Number
  336. infoItem.Bck01d = departmwnt.Number
  337. infoItem.Vaf58 = "0"
  338. infoItem.Vaf61 = "1"
  339. infoItems = append(infoItems, &infoItem)
  340. } else {
  341. var infoItem models.Item
  342. infoItem.Rownr = "0"
  343. infoItem.Vaf11 = "1"
  344. infoItem.Vaf36 = time.Unix(subItem.Ctime, 0).Format("2006-01-02 15:04:05")
  345. infoItem.Bbx01 = subItem.HisProject.MedicalCode
  346. if subItem.HisProject.CostClassify == 2 {
  347. infoItem.Bda01 = "T"
  348. } else if subItem.HisProject.CostClassify == 3 {
  349. infoItem.Bda01 = "L"
  350. } else {
  351. infoItem.Bda01 = "T"
  352. }
  353. infoItem.Bby01 = ""
  354. infoItem.Vaf14 = subItem.HisProject.ProjectName
  355. infoItem.Bdi01 = "160"
  356. infoItem.Vaf17 = subItem.Day
  357. infoItem.Vaf20 = subItem.SingleDose
  358. infoItem.Vaf21 = subItem.Count
  359. infoItem.Vaf35 = "0"
  360. infoItem.Vaf18 = 0
  361. infoItem.Vaf32 = "0"
  362. infoItem.Bck01b = departmwnt.Number
  363. infoItem.Bck01d = departmwnt.Number
  364. infoItem.Vaf58 = "0"
  365. infoItem.Vaf61 = "1"
  366. infoItems = append(infoItems, &infoItem)
  367. }
  368. } else {
  369. var infoItem models.Item
  370. infoItem.Rownr = "0"
  371. infoItem.Vaf11 = "1"
  372. infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  373. infoItem.Bbx01 = subItem.GoodInfo.MedicalInsuranceNumber
  374. infoItem.Bda01 = "M"
  375. infoItem.Bby01 = ""
  376. infoItem.Vaf14 = subItem.GoodInfo.GoodName + " " + subItem.GoodInfo.SpecificationName
  377. infoItem.Bdi01 = "160"
  378. infoItem.Vaf17 = subItem.Day
  379. infoItem.Vaf20 = subItem.SingleDose
  380. infoItem.Vaf21 = subItem.Count
  381. infoItem.Vaf35 = "0"
  382. infoItem.Vaf32 = "0"
  383. infoItem.Bck01b = departmwnt.Number
  384. infoItem.Bck01d = departmwnt.Number
  385. infoItem.Vaf58 = "0"
  386. infoItem.Vaf61 = "1"
  387. infoItems = append(infoItems, &infoItem)
  388. }
  389. }
  390. presDetail.Item = infoItems
  391. presDetails = append(presDetails, &presDetail)
  392. presInfo.PresDetail = presDetails
  393. presInfos = append(presInfos, &presInfo)
  394. }
  395. info.PresInfo = presInfos
  396. var result2 string
  397. var request2 string
  398. if res.Result[0].Type == "1" {
  399. result2, request2 = service.UploadPrescriptionForCoordinate(info)
  400. } else {
  401. result2, request2 = service.UploadPrescriptionForCoordinateHospital(info)
  402. }
  403. saveLog(result2, request2, "上传明细", "上传明细", org.OrgName)
  404. var res2 ResultUpload
  405. if err := json.Unmarshal([]byte(result2), &res2); err != nil {
  406. utils.ErrorLog("解析失败:%v", err)
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  408. return
  409. }
  410. if res2.Code == "10000" && len(res2.Result) > 0 && res2.Result[0].Code != "500" && len(res2.Result[0].List) > 0 {
  411. timestamp := time.Now().Unix()
  412. tempTime := time.Unix(timestamp, 0)
  413. timeFormat := tempTime.Format("20060102150405")
  414. chrgBchno := rand.Intn(100000) + 10000
  415. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  416. his := models.VMHisPatient{
  417. Name: patient.Name,
  418. Gender: patient.Gender,
  419. Birthday: patient.Birthday,
  420. MedicalTreatmentType: 0,
  421. IdType: 1,
  422. IdCardNo: patient.IdCardNo,
  423. BalanceAccountsType: 1,
  424. MedicalInsuranceNumber: "",
  425. RegisterType: 0,
  426. RegisterCost: 0,
  427. TreatmentCost: 0,
  428. Status: 1,
  429. Ctime: time.Now().Unix(),
  430. Mtime: time.Now().Unix(),
  431. PsnNo: strconv.FormatInt(int64(res.Result[0].Vaa01), 10),
  432. PsnCertType: "",
  433. Certno: patient.IdCardNo,
  434. PsnName: patient.Name,
  435. Gend: "",
  436. Naty: "",
  437. Brdy: "",
  438. Age: 0,
  439. Iinfo: "",
  440. Idetinfo: "",
  441. PatientId: patient.ID,
  442. RecordDate: theTime.Unix(),
  443. UserOrgId: org_id,
  444. AdminUserId: admin_user_id,
  445. IsReturn: 1,
  446. Doctor: patientPrescription.DoctorId,
  447. Departments: patientPrescription.Departments,
  448. IptOtpNo: ipt_otp_no,
  449. Number: strconv.FormatInt(int64(res.Result[0].Vaa07), 10),
  450. PhoneNumber: patient.Phone,
  451. }
  452. service.UpdateHisPatientStatusTwo(&his)
  453. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  454. tm := time.Unix(time.Now().Unix(), 0)
  455. order := &models.HisOrder{
  456. PsnNo: his.PsnNo,
  457. UserOrgId: org_id,
  458. HisPatientId: his.ID,
  459. PatientId: patient_id,
  460. SettleAccountsDate: recordDateTime,
  461. Ctime: time.Now().Unix(),
  462. Mtime: time.Now().Unix(),
  463. Status: 1,
  464. OrderStatus: 1,
  465. MdtrtId: his.Number,
  466. Number: ipt_otp_no,
  467. SetlId: "",
  468. MedfeeSumamt: total,
  469. MedType: strconv.Itoa(int(reg_type)),
  470. SettleEndTime: 0,
  471. SettleStartTime: 0,
  472. SettleType: settle_accounts_type,
  473. Diagnosis: diagnosis_id,
  474. PType: 2,
  475. SetlTime: tm.Format("2006-01-02 15:04:05"),
  476. }
  477. err = service.CreateOrder(order)
  478. if err != nil {
  479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  480. return
  481. }
  482. for _, item := range customs {
  483. var advice_id int64 = 0
  484. var project_id int64 = 0
  485. var item_id int64 = 0
  486. var types int64 = 0
  487. if item.Type == 1 {
  488. advice_id = item.AdviceId
  489. project_id = 0
  490. item_id = 0
  491. } else if item.Type == 2 {
  492. advice_id = 0
  493. item_id = 0
  494. project_id = item.ProjectId
  495. } else if item.Type == 3 {
  496. advice_id = 0
  497. item_id = item.ItemId
  498. project_id = 0
  499. }
  500. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  501. cut, _ := strconv.ParseFloat(item.Cut, 32)
  502. pric, _ := strconv.ParseFloat(item.Price, 32)
  503. info := &models.HisOrderInfo{
  504. OrderNumber: order.Number,
  505. UploadDate: time.Now().Unix(),
  506. AdviceId: advice_id,
  507. DetItemFeeSumamt: detItemFeeSumamt,
  508. Cnt: cut,
  509. Pric: pric,
  510. PatientId: patient_id,
  511. Status: 1,
  512. Mtime: time.Now().Unix(),
  513. Ctime: time.Now().Unix(),
  514. UserOrgId: org_id,
  515. HisPatientId: his.ID,
  516. OrderId: order.ID,
  517. ProjectId: project_id,
  518. Type: types,
  519. ItemId: item_id,
  520. }
  521. service.CreateOrderInfo(info)
  522. }
  523. his.Diagnosis = diagnosis_id
  524. his.SickType = sick_type
  525. his.RegisterType = reg_type
  526. his.MedicalTreatmentType = reg_type
  527. service.UpdataHisPateintTwoTen(&his)
  528. err = service.UpDatePrescriptionNumber(org_id, ids, order.Number)
  529. err = service.UpDateHisPrescriptionInfoNumberTen(org_id, patient_id, order.Number, recordDateTime, his.ID)
  530. err = service.UpdataOrderStatusThreeTen(strconv.FormatInt(int64(chrgBchno), 10), org_id)
  531. c.ServeSuccessJSON(map[string]interface{}{
  532. "msg": "医嘱保存成功",
  533. })
  534. } else {
  535. c.ServeSuccessJSON(map[string]interface{}{
  536. "failed_code": -10,
  537. "msg": res2.Msg + "----" + res2.Result[0].ResultMsg,
  538. })
  539. }
  540. } else {
  541. c.ServeSuccessJSON(map[string]interface{}{
  542. "failed_code": -10,
  543. "msg": res.Msg,
  544. })
  545. }
  546. }
  547. type Charset string
  548. const (
  549. UTF8 = Charset("UTF-8")
  550. GB18030 = Charset("GB18030")
  551. )
  552. func saveLog(result string, request string, infno string, desc string, org_name string) {
  553. //org_id, _ := beego.AppConfig.Int64("org_id")
  554. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  555. dir := org_name + "日志"
  556. utils.Mkdir(dir)
  557. month := time.Unix(1557042972, 0).Format("1")
  558. year := time.Now().Format("2006")
  559. month = time.Now().Format("01")
  560. day := time.Now().Format("02")
  561. hour := time.Now().Format("15")
  562. min := time.Now().Format("04")
  563. sec := time.Now().Format("05")
  564. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  565. file := org_name + "_" + year + month + day + "_log"
  566. file_name := file + ".txt"
  567. file_path := org_name + "日志" + "/" + file_name
  568. exist, _ := utils.PathExists(file_path)
  569. if exist { //存在
  570. fmt.Println("存在")
  571. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  572. if err != nil {
  573. fmt.Println("read fail")
  574. }
  575. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  576. n, _ := f.Seek(0, 2)
  577. _, err = f.WriteAt([]byte(content), n)
  578. } else { //不存在
  579. fmt.Println("文件不存在,创建文件")
  580. f, err := os.Create(org_name + "日志" + "/" + file_name)
  581. defer f.Close()
  582. if err != nil {
  583. } else {
  584. _, err = f.Write([]byte("记录日志"))
  585. }
  586. }
  587. }
  588. func RemoveRepeatedGroupElement(arr []int64) (newArr []int64) {
  589. newArr = make([]int64, 0)
  590. for i := 0; i < len(arr); i++ {
  591. repeat := false
  592. for j := i + 1; j < len(arr); j++ {
  593. if arr[i] == arr[j] {
  594. repeat = true
  595. break
  596. }
  597. }
  598. if !repeat {
  599. newArr = append(newArr, arr[i])
  600. }
  601. }
  602. return
  603. }