his_api_controller.go 94KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668
  1. package controllers
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type HisApiController struct {
  27. BaseAuthAPIController
  28. }
  29. func HisManagerApiRegistRouters() {
  30. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  31. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  32. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  33. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  34. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  35. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  36. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  37. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  38. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  39. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  40. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  41. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  42. beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  43. }
  44. func (c *HisApiController) GetHisPatientInfo() {
  45. medical_insurance_card := c.GetString("medical_insurance_card")
  46. id_card_type, _ := c.GetInt64("id_card_type")
  47. id_card := c.GetString("id_card")
  48. adminInfo := c.GetAdminUserInfo()
  49. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  50. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  51. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  52. IdCardNo := ""
  53. if id_card_type == 1 {
  54. IdCardNo = medical_insurance_card
  55. } else if id_card_type == 2 {
  56. IdCardNo = id_card
  57. }
  58. if config.IsOpen == 1 {
  59. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  60. resp, requestErr := http.Get(api)
  61. if requestErr != nil {
  62. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  63. return
  64. }
  65. defer resp.Body.Close()
  66. body, ioErr := ioutil.ReadAll(resp.Body)
  67. if ioErr != nil {
  68. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  69. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  70. return
  71. }
  72. var respJSON map[string]interface{}
  73. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  74. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  75. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  76. return
  77. }
  78. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  79. userJSONBytes, _ := json.Marshal(userJSON)
  80. var res ResultTwo
  81. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  82. utils.ErrorLog("解析失败:%v", err)
  83. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  84. return
  85. }
  86. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  87. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  88. infoStr := string(Iinfos)
  89. idetinfoStr := string(Idetinfos)
  90. if res.Infcode == 0 {
  91. his := models.VMHisPatient{
  92. Status: 1,
  93. Ctime: time.Now().Unix(),
  94. Mtime: time.Now().Unix(),
  95. PsnNo: res.Output.Baseinfo.PsnNo,
  96. PsnCertType: res.Output.Baseinfo.PsnCertType,
  97. Certno: res.Output.Baseinfo.Certno,
  98. PsnName: res.Output.Baseinfo.PsnName,
  99. Gend: res.Output.Baseinfo.Gend,
  100. Naty: res.Output.Baseinfo.Naty,
  101. Brdy: res.Output.Baseinfo.Brdy,
  102. Age: res.Output.Baseinfo.Age,
  103. Iinfo: infoStr,
  104. Idetinfo: idetinfoStr,
  105. UserOrgId: adminInfo.CurrentOrgId,
  106. IsReturn: 1,
  107. IdCardType: id_card_type,
  108. }
  109. c.ServeSuccessJSON(map[string]interface{}{
  110. "info": his,
  111. })
  112. } else {
  113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  114. return
  115. }
  116. }
  117. }
  118. func (c *HisApiController) Sscard() {
  119. id_card_type, _ := c.GetInt64("id_card_type")
  120. adminUser := c.GetAdminUserInfo()
  121. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  122. r := CardInit()
  123. if r == 0 {
  124. switch id_card_type {
  125. case 1:
  126. basStr, err := GetBasBaseInfo()
  127. if err != nil {
  128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  129. return
  130. } else {
  131. bas := strings.Split(basStr, "|")
  132. basNumber := bas[1]
  133. card_sn := bas[3]
  134. appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  135. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
  136. resp, requestErr := http.Get(api)
  137. if requestErr != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  139. return
  140. }
  141. defer resp.Body.Close()
  142. body, ioErr := ioutil.ReadAll(resp.Body)
  143. if ioErr != nil {
  144. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  146. return
  147. }
  148. var respJSON map[string]interface{}
  149. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  150. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  152. return
  153. }
  154. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  155. userJSONBytes, _ := json.Marshal(userJSON)
  156. var res ResultTwo
  157. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  158. utils.ErrorLog("解析失败:%v", err)
  159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  160. return
  161. }
  162. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  163. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  164. infoStr := string(Iinfos)
  165. idetinfoStr := string(Idetinfos)
  166. if res.Infcode == 0 {
  167. his := models.VMHisPatient{
  168. Status: 1,
  169. Ctime: time.Now().Unix(),
  170. Mtime: time.Now().Unix(),
  171. PsnNo: res.Output.Baseinfo.PsnNo,
  172. PsnCertType: res.Output.Baseinfo.PsnCertType,
  173. Certno: res.Output.Baseinfo.Certno,
  174. PsnName: res.Output.Baseinfo.PsnName,
  175. Gend: res.Output.Baseinfo.Gend,
  176. Naty: res.Output.Baseinfo.Naty,
  177. Brdy: res.Output.Baseinfo.Brdy,
  178. Age: res.Output.Baseinfo.Age,
  179. Iinfo: infoStr,
  180. Idetinfo: idetinfoStr,
  181. UserOrgId: adminUser.CurrentOrgId,
  182. IsReturn: 1,
  183. IdCardType: id_card_type,
  184. }
  185. patient, err := service.GetPatientByNumber(his.Certno, adminUser.CurrentOrgId)
  186. if err == gorm.ErrRecordNotFound {
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  188. return
  189. } else if err != nil {
  190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  191. return
  192. } else {
  193. c.ServeSuccessJSON(map[string]interface{}{
  194. "patient": patient,
  195. "info": his,
  196. "number": basNumber,
  197. })
  198. }
  199. } else {
  200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  201. return
  202. }
  203. }
  204. break
  205. case 2:
  206. SFZStr, err := GetSFZBaseInfo()
  207. if err != nil {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  209. return
  210. } else {
  211. id_card_str := strings.Split(SFZStr, "^")
  212. id_card_number := id_card_str[0]
  213. appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  214. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  215. resp, requestErr := http.Get(api)
  216. if requestErr != nil {
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  218. return
  219. }
  220. defer resp.Body.Close()
  221. body, ioErr := ioutil.ReadAll(resp.Body)
  222. if ioErr != nil {
  223. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  225. return
  226. }
  227. var respJSON map[string]interface{}
  228. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  229. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  231. return
  232. }
  233. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  234. userJSONBytes, _ := json.Marshal(userJSON)
  235. var res ResultTwo
  236. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  237. utils.ErrorLog("解析失败:%v", err)
  238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  239. return
  240. }
  241. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  242. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  243. infoStr := string(Iinfos)
  244. idetinfoStr := string(Idetinfos)
  245. if res.Infcode == 0 {
  246. his := models.VMHisPatient{
  247. Status: 1,
  248. Ctime: time.Now().Unix(),
  249. Mtime: time.Now().Unix(),
  250. PsnNo: res.Output.Baseinfo.PsnNo,
  251. PsnCertType: res.Output.Baseinfo.PsnCertType,
  252. Certno: res.Output.Baseinfo.Certno,
  253. PsnName: res.Output.Baseinfo.PsnName,
  254. Gend: res.Output.Baseinfo.Gend,
  255. Naty: res.Output.Baseinfo.Naty,
  256. Brdy: res.Output.Baseinfo.Brdy,
  257. Age: res.Output.Baseinfo.Age,
  258. Iinfo: infoStr,
  259. Idetinfo: idetinfoStr,
  260. UserOrgId: adminUser.CurrentOrgId,
  261. IsReturn: 1,
  262. IdCardType: id_card_type,
  263. }
  264. patient, err := service.GetPatientByNumber(his.Certno, adminUser.CurrentOrgId)
  265. if err == gorm.ErrRecordNotFound {
  266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  267. return
  268. } else if err != nil {
  269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  270. return
  271. } else {
  272. c.ServeSuccessJSON(map[string]interface{}{
  273. "patient": patient,
  274. "info": his,
  275. "number": id_card_number,
  276. })
  277. }
  278. } else {
  279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  280. return
  281. }
  282. }
  283. break
  284. case 3:
  285. break
  286. }
  287. }
  288. c.ServeSuccessJSON(map[string]interface{}{
  289. "list": "11",
  290. })
  291. }
  292. func GetBasBaseInfo() (jsonStr string, err error) {
  293. handle := syscall.MustLoadDLL("SSCard.dll")
  294. ReadCardBas := handle.MustFindProc("ReadCardBas")
  295. str := make([]byte, 256)
  296. str1 := make([]byte, 256)
  297. r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  298. fmt.Println(r)
  299. fmt.Println(string(str))
  300. return string(str), nil
  301. }
  302. func GetSFZBaseInfo() (jsonStr string, err error) {
  303. handle := syscall.MustLoadDLL("SSCard.dll")
  304. ReadCardBas := handle.MustFindProc("ReadSFZ")
  305. str := make([]byte, 256)
  306. str1 := make([]byte, 256)
  307. r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  308. fmt.Println(r)
  309. return string(str), nil
  310. }
  311. func GetQRBaseInfo() (jsonStr string, err error) {
  312. handle := syscall.MustLoadDLL("SSCard.dll")
  313. ReadCardBas := handle.MustFindProc("GetQRBase")
  314. str := make([]byte, 256)
  315. str1 := make([]byte, 256)
  316. r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  317. fmt.Println(string(str))
  318. fmt.Println(r)
  319. return string(str), nil
  320. }
  321. func CardInit() int {
  322. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  323. add := DllTestDef.MustFindProc("Init")
  324. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  325. if err != nil {
  326. fmt.Println("SSCard的运算结果为:", ret)
  327. }
  328. result := int(ret)
  329. return result
  330. }
  331. func IntPtr(n int) uintptr {
  332. return uintptr(n)
  333. }
  334. func StrPtr(s string) uintptr {
  335. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  336. }
  337. type ResultTwo struct {
  338. ErrMsg string `json:"err_msg"`
  339. InfRefmsgid string `json:"inf_refmsgid"`
  340. Infcode int64 `json:"infcode"`
  341. Output struct {
  342. Baseinfo struct {
  343. Age float64 `json:"age"`
  344. Brdy string `json:"brdy"`
  345. Certno string `json:"certno"`
  346. Gend string `json:"gend"`
  347. Naty string `json:"naty"`
  348. PsnCertType string `json:"psn_cert_type"`
  349. PsnName string `json:"psn_name"`
  350. PsnNo string `json:"psn_no"`
  351. } `json:"baseinfo"`
  352. Idetinfo []interface{} `json:"idetinfo"`
  353. Iinfo []struct {
  354. Balc int64 `json:"balc"`
  355. CvlservFlag string `json:"cvlserv_flag"`
  356. EmpName string `json:"emp_name"`
  357. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  358. Insutype string `json:"insutype"`
  359. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  360. PausInsuDate interface{} `json:"paus_insu_date"`
  361. PsnInsuDate string `json:"psn_insu_date"`
  362. PsnInsuStas string `json:"psn_insu_stas"`
  363. PsnType string `json:"psn_type"`
  364. } `json:"insuinfo"`
  365. } `json:"output"`
  366. RefmsgTime string `json:"refmsg_time"`
  367. RespondTime string `json:"respond_time"`
  368. Signtype interface{} `json:"signtype"`
  369. WarnInfo interface{} `json:"warn_info"`
  370. }
  371. type ResultThree struct {
  372. Cainfo interface{} `json:"cainfo"`
  373. ErrMsg string `json:"err_msg"`
  374. InfRefmsgid string `json:"inf_refmsgid"`
  375. Infcode int64 `json:"infcode"`
  376. Output struct {
  377. Data struct {
  378. IptOtpNo string `json:"ipt_otp_no"`
  379. MdtrtID string `json:"mdtrt_id"`
  380. PsnNo string `json:"psn_no"`
  381. } `json:"data"`
  382. } `json:"output"`
  383. RefmsgTime string `json:"refmsg_time"`
  384. RespondTime string `json:"respond_time"`
  385. Signtype interface{} `json:"signtype"`
  386. WarnMsg interface{} `json:"warn_msg"`
  387. }
  388. type ResultFour struct {
  389. Cainfo string `json:"cainfo"`
  390. ErrMsg string `json:"err_msg"`
  391. InfRefmsgid string `json:"inf_refmsgid"`
  392. Infcode int64 `json:"infcode"`
  393. Output struct {
  394. Result []struct {
  395. BasMednFlag string `json:"bas_medn_flag"`
  396. ChldMedcFlag string `json:"chld_medc_flag"`
  397. ChrgitmLv string `json:"chrgitm_lv"`
  398. Cnt float64 `json:"cnt"`
  399. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  400. DrtReimFlag string `json:"drt_reim_flag"`
  401. FeedetlSn string `json:"feedetl_sn"`
  402. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  403. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  404. InscpScpAmt float64 `json:"inscp_scp_amt"`
  405. ListSpItemFlag string `json:"list_sp_item_flag"`
  406. LmtUsedFlag string `json:"lmt_used_flag"`
  407. MedChrgitmType string `json:"med_chrgitm_type"`
  408. Memo string `json:"memo"`
  409. OverlmtAmt float64 `json:"overlmt_amt"`
  410. PreselfpayAmt float64 `json:"preselfpay_amt"`
  411. Pric float64 `json:"pric"`
  412. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  413. SelfpayProp float64 `json:"selfpay_prop"`
  414. } `json:"result"`
  415. } `json:"output"`
  416. RefmsgTime string `json:"refmsg_time"`
  417. RespondTime string `json:"respond_time"`
  418. Signtype string `json:"signtype"`
  419. WarnMsg string `json:"warn_msg"`
  420. }
  421. type ResultFive struct {
  422. Insutype string `json:"insutype"`
  423. }
  424. type ResultSix struct {
  425. Cainfo interface{} `json:"cainfo"`
  426. ErrMsg string `json:"err_msg"`
  427. InfRefmsgid string `json:"inf_refmsgid"`
  428. Infcode int64 `json:"infcode"`
  429. Output struct {
  430. } `json:"output"`
  431. RefmsgTime string `json:"refmsg_time"`
  432. RespondTime string `json:"respond_time"`
  433. Signtype interface{} `json:"signtype"`
  434. WarnMsg interface{} `json:"warn_msg"`
  435. }
  436. type ResultSeven struct {
  437. Cainfo string `json:"cainfo"`
  438. ErrMsg string `json:"err_msg"`
  439. InfRefmsgid string `json:"inf_refmsgid"`
  440. Infcode int64 `json:"infcode"`
  441. Output struct {
  442. Setldetail []interface{} `json:"setldetail"`
  443. Setlinfo struct {
  444. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  445. AcctPay float64 `json:"acct_pay"`
  446. ActPayDedc float64 `json:"act_pay_dedc"`
  447. Age float64 `json:"age"`
  448. Balc float64 `json:"balc"`
  449. Brdy string `json:"brdy"`
  450. Certno string `json:"certno"`
  451. ClrOptins string `json:"clr_optins"`
  452. ClrType string `json:"clr_type"`
  453. ClrWay string `json:"clr_way"`
  454. CvlservFlag string `json:"cvlserv_flag"`
  455. CvlservPay float64 `json:"cvlserv_pay"`
  456. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  457. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  458. Gend string `json:"gend"`
  459. HifesPay float64 `json:"hifes_pay"`
  460. HifmiPay float64 `json:"hifmi_pay"`
  461. HifpPay float64 `json:"hifp_pay"`
  462. HospPartAmt float64 `json:"hosp_part_amt"`
  463. InscpScpAmt float64 `json:"inscp_scp_amt"`
  464. Insutype string `json:"insutype"`
  465. MafPay float64 `json:"maf_pay"`
  466. MdtrtCertType string `json:"mdtrt_cert_type"`
  467. HifobPay float64 `json:"hifob_pay"`
  468. MdtrtID string `json:"mdtrt_id"`
  469. MedType string `json:"med_type"`
  470. MedfeeSumamt float64 `json:"medfee_sumamt"`
  471. MedinsSetlID string `json:"medins_setl_id"`
  472. Naty string `json:"naty"`
  473. OthPay float64 `json:"oth_pay"`
  474. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  475. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  476. PreselfpayAmt float64 `json:"preselfpay_amt"`
  477. PsnCashPay float64 `json:"psn_cash_pay"`
  478. PsnCertType string `json:"psn_cert_type"`
  479. PsnName string `json:"psn_name"`
  480. PsnNo string `json:"psn_no"`
  481. PsnPartAmt float64 `json:"psn_part_amt"`
  482. PsnType string `json:"psn_type"`
  483. SetlID string `json:"setl_id"`
  484. SetlTime string `json:"setl_time"`
  485. } `json:"setlinfo"`
  486. } `json:"output"`
  487. RefmsgTime string `json:"refmsg_time"`
  488. RespondTime string `json:"respond_time"`
  489. Signtype interface{} `json:"signtype"`
  490. WarnMsg interface{} `json:"warn_msg"`
  491. }
  492. type ResultEight struct {
  493. Cainfo string `json:"cainfo"`
  494. ErrMsg string `json:"err_msg"`
  495. InfRefmsgid string `json:"inf_refmsgid"`
  496. Infcode int64 `json:"infcode"`
  497. Output struct {
  498. Stmtinfo struct {
  499. SetlOptins string `json:"setl_optins"`
  500. StmtRslt string `json:"stmt_rslt"`
  501. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  502. } `json:"stmtinfo"`
  503. } `json:"output"`
  504. RefmsgTime string `json:"refmsg_time"`
  505. RespondTime string `json:"respond_time"`
  506. Signtype interface{} `json:"signtype"`
  507. WarnMsg interface{} `json:"warn_msg"`
  508. }
  509. type ResultNine struct {
  510. Cainfo string `json:"cainfo"`
  511. ErrMsg string `json:"err_msg"`
  512. InfRefmsgid string `json:"inf_refmsgid"`
  513. Infcode int64 `json:"infcode"`
  514. Output struct {
  515. FileQuryNo string `json:"file_qury_no"`
  516. } `json:"output"`
  517. RefmsgTime string `json:"refmsg_time"`
  518. RespondTime string `json:"respond_time"`
  519. Signtype interface{} `json:"signtype"`
  520. WarnMsg interface{} `json:"warn_msg"`
  521. }
  522. type ResultTen struct {
  523. Cainfo string `json:"cainfo"`
  524. ErrMsg string `json:"err_msg"`
  525. InfRefmsgid string `json:"inf_refmsgid"`
  526. Infcode int64 `json:"infcode"`
  527. Output struct {
  528. DldEndtime string `json:"dld_endtime"`
  529. FileQuryNo string `json:"file_qury_no"`
  530. Filename string `json:"filename"`
  531. } `json:"output"`
  532. RefmsgTime string `json:"refmsg_time"`
  533. RespondTime string `json:"respond_time"`
  534. Signtype interface{} `json:"signtype"`
  535. WarnMsg interface{} `json:"warn_msg"`
  536. }
  537. type ResultEleven struct {
  538. Cainfo string `json:"cainfo"`
  539. ErrMsg string `json:"err_msg"`
  540. InfRefmsgid string `json:"inf_refmsgid"`
  541. Infcode int64 `json:"infcode"`
  542. Output struct {
  543. Setlinfo struct {
  544. FixmedinsName string `json:"fixmedins_name"`
  545. FixmedinsCode string `json:"fixmedins_code"`
  546. PsnNo string `json:"psn_no"`
  547. PsnName string `json:"psn_name"`
  548. HifobPay float64 `json:"hifob_pay"`
  549. Gend string `json:"gend"`
  550. Brdy string `json:"brdy"`
  551. PsnCertType string `json:"psn_cert_type"`
  552. PsnType string `json:"psn_type"`
  553. EmpName string `json:"emp_name"`
  554. Certno string `json:"certno"`
  555. Insutype string `json:"insutype"`
  556. MedfeeSumamt float64 `json:"medfee_sumamt"`
  557. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  558. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  559. PreselfpayAmt float64 `json:"preselfpay_amt"`
  560. InscpScpAmt float64 `json:"inscp_scp_amt"`
  561. ActPayDedc float64 `json:"act_pay_dedc"`
  562. HifpPay float64 `json:"hifp_pay"`
  563. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  564. CvlservPay float64 `json:"cvlserv_pay"`
  565. HifesPay float64 `json:"hifes_pay"`
  566. HifmiPay float64 `json:"hifmi_pay"`
  567. MafPay float64 `json:"maf_pay"`
  568. OthPay float64 `json:"oth_pay"`
  569. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  570. PsnPay float64 `json:"psn_pay"`
  571. AcctPay float64 `json:"acct_pay"`
  572. CashPayamt float64 `json:"cash_payamt"`
  573. Balc float64 `json:"balc"`
  574. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  575. MedinsSetlId string `json:"medins_setl_id"`
  576. RefdSetlFlag string `json:"refd_setl_flag"`
  577. SetlTime string `json:"setl_time"`
  578. MedType string `json:"med_type"`
  579. } `json:"setlinfo"`
  580. } `json:"output"`
  581. RefmsgTime string `json:"refmsg_time"`
  582. RespondTime string `json:"respond_time"`
  583. Signtype interface{} `json:"signtype"`
  584. WarnMsg interface{} `json:"warn_msg"`
  585. }
  586. type Custom struct {
  587. DetItemFeeSumamt string
  588. Cut string
  589. FeedetlSn string
  590. Price string
  591. MedListCodg string
  592. Type int64
  593. AdviceId int64
  594. ProjectId int64
  595. ItemId int64
  596. }
  597. //获取个人信息----挂号-----上传就诊信息
  598. func (c *HisApiController) GetRegisterInfo() {
  599. id, _ := c.GetInt64("id")
  600. record_time := c.GetString("record_time")
  601. settlementValue, _ := c.GetInt64("settlement_value")
  602. medical_insurance_card := c.GetString("medical_insurance_card")
  603. name := c.GetString("name")
  604. id_card_type, _ := c.GetInt64("id_card_type")
  605. certificates, _ := c.GetInt64("certificates")
  606. medical_care, _ := c.GetInt64("medical_care")
  607. birthday := c.GetString("birthday")
  608. age, _ := c.GetInt64("age")
  609. id_card := c.GetString("idCard")
  610. register_type, _ := c.GetInt64("register")
  611. doctor, _ := c.GetInt64("doctor")
  612. department, _ := c.GetInt64("department")
  613. gender, _ := c.GetInt64("sex")
  614. phone := c.GetString("phone")
  615. registration_fee, _ := c.GetFloat("registration_fee")
  616. medical_expenses, _ := c.GetFloat("medical_expenses")
  617. social_type, _ := c.GetInt64("social_type")
  618. admin_user_id, _ := c.GetInt64("admin_user_id")
  619. timeLayout := "2006-01-02"
  620. loc, _ := time.LoadLocation("Local")
  621. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  622. birthUnix := birthdays.Unix()
  623. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  624. if err != nil {
  625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  626. return
  627. }
  628. recordDateTime := theTime.Unix()
  629. adminInfo := c.GetAdminUserInfo()
  630. var patient service.Patients
  631. if id == 0 {
  632. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  633. } else {
  634. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  635. }
  636. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  637. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  638. if patient.ID == 0 {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  640. return
  641. }
  642. if len(patient.IdCardNo) == 0 {
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  644. return
  645. }
  646. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  647. if config.IsOpen == 1 {
  648. api := "http://127.0.0.1:9532/" + "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
  649. resp, requestErr := http.Get(api)
  650. if requestErr != nil {
  651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  652. return
  653. }
  654. defer resp.Body.Close()
  655. body, ioErr := ioutil.ReadAll(resp.Body)
  656. if ioErr != nil {
  657. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  659. return
  660. }
  661. var respJSON map[string]interface{}
  662. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  663. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  665. return
  666. }
  667. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  668. userJSONBytes, _ := json.Marshal(userJSON)
  669. var res ResultTwo
  670. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  671. utils.ErrorLog("解析失败:%v", err)
  672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  673. return
  674. }
  675. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  676. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  677. infoStr := string(Iinfos)
  678. idetinfoStr := string(Idetinfos)
  679. if res.Infcode == 0 {
  680. his := models.VMHisPatient{
  681. Name: name,
  682. Gender: gender,
  683. Birthday: birthUnix,
  684. MedicalTreatmentType: medical_care,
  685. IdType: certificates,
  686. IdCardNo: id_card,
  687. BalanceAccountsType: settlementValue,
  688. SocialType: social_type,
  689. MedicalInsuranceNumber: medical_insurance_card,
  690. RegisterType: register_type,
  691. RegisterCost: registration_fee,
  692. TreatmentCost: medical_expenses,
  693. Status: 1,
  694. Ctime: time.Now().Unix(),
  695. Mtime: time.Now().Unix(),
  696. PsnNo: res.Output.Baseinfo.PsnNo,
  697. PsnCertType: res.Output.Baseinfo.PsnCertType,
  698. Certno: res.Output.Baseinfo.Certno,
  699. PsnName: res.Output.Baseinfo.PsnName,
  700. Gend: res.Output.Baseinfo.Gend,
  701. Naty: res.Output.Baseinfo.Naty,
  702. Brdy: res.Output.Baseinfo.Brdy,
  703. Age: res.Output.Baseinfo.Age,
  704. Iinfo: infoStr,
  705. Idetinfo: idetinfoStr,
  706. PatientId: patient.ID,
  707. RecordDate: theTime.Unix(),
  708. UserOrgId: adminInfo.CurrentOrgId,
  709. AdminUserId: admin_user_id,
  710. IsReturn: 1,
  711. IdCardType: id_card_type,
  712. Doctor: doctor,
  713. Departments: department,
  714. }
  715. timestamp := time.Now().Unix()
  716. tempTime := time.Unix(timestamp, 0)
  717. timeFormat := tempTime.Format("20060102150405")
  718. chrgBchno := rand.Intn(100000) + 10000
  719. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  720. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  721. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  722. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  723. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  724. sickConfig, _ := service.FindSickById(patientPrescription.SickType)
  725. IdCardNo := ""
  726. if id_card_type == 1 {
  727. IdCardNo = medical_insurance_card
  728. } else {
  729. IdCardNo = patient.IdCardNo
  730. }
  731. if count <= 0 {
  732. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  733. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  734. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  735. "&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 + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  736. resp, requestErr := http.Get(api)
  737. if requestErr != nil {
  738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  739. return
  740. }
  741. defer resp.Body.Close()
  742. body, ioErr := ioutil.ReadAll(resp.Body)
  743. if ioErr != nil {
  744. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  746. return
  747. }
  748. var respJSON map[string]interface{}
  749. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  750. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  752. return
  753. }
  754. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  755. userJSONBytes, _ := json.Marshal(respJSON)
  756. var res ResultThree
  757. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  758. utils.ErrorLog("解析失败:%v", err)
  759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  760. return
  761. }
  762. if res.Infcode == -1 {
  763. adminUser := c.GetAdminUserInfo()
  764. errlog := &models.HisOrderError{
  765. UserOrgId: adminUser.CurrentOrgId,
  766. Ctime: time.Now().Unix(),
  767. Mtime: time.Now().Unix(),
  768. ErrMsg: res.ErrMsg,
  769. Status: 1,
  770. PatientId: id,
  771. RecordTime: recordDateTime,
  772. Stage: 2,
  773. }
  774. service.CreateErrMsgLog(errlog)
  775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  776. return
  777. }
  778. his.Number = res.Output.Data.MdtrtID
  779. his.PsnNo = res.Output.Data.PsnNo
  780. his.IptOtpNo = res.Output.Data.IptOtpNo
  781. his.IdCardNo = patient.IdCardNo
  782. his.PhoneNumber = patient.Phone
  783. his.UserOrgId = adminInfo.CurrentOrgId
  784. his.Ctime = time.Now().Unix()
  785. his.Mtime = time.Now().Unix()
  786. his.Status = 1
  787. err := service.CreateHisPatientTwo(&his)
  788. if err == nil {
  789. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  790. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  791. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  792. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  793. resp2, requestErr2 := http.Get(api2)
  794. if requestErr2 != nil {
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  796. return
  797. }
  798. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  799. if ioErr2 != nil {
  800. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  802. return
  803. }
  804. var respJSON2 map[string]interface{}
  805. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  806. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  808. return
  809. }
  810. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  811. userJSONBytes2, _ := json.Marshal(respJSON2)
  812. var res2 ResultSix
  813. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  814. utils.ErrorLog("解析失败:%v", err)
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  816. return
  817. }
  818. if res2.Infcode == -1 {
  819. adminUser := c.GetAdminUserInfo()
  820. errlog := &models.HisOrderError{
  821. UserOrgId: adminUser.CurrentOrgId,
  822. Ctime: time.Now().Unix(),
  823. Mtime: time.Now().Unix(),
  824. ErrMsg: res2.ErrMsg,
  825. Status: 1,
  826. PatientId: id,
  827. RecordTime: recordDateTime,
  828. Stage: 3,
  829. }
  830. service.CreateErrMsgLog(errlog)
  831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  832. return
  833. }
  834. c.ServeSuccessJSON(map[string]interface{}{
  835. "his_info": his,
  836. })
  837. } else {
  838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  839. return
  840. }
  841. } else {
  842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  843. return
  844. }
  845. } else {
  846. adminUser := c.GetAdminUserInfo()
  847. errlog := &models.HisOrderError{
  848. UserOrgId: adminUser.CurrentOrgId,
  849. Ctime: time.Now().Unix(),
  850. Mtime: time.Now().Unix(),
  851. ErrMsg: res.ErrMsg,
  852. Status: 1,
  853. PatientId: id,
  854. RecordTime: recordDateTime,
  855. Stage: 1,
  856. }
  857. service.CreateErrMsgLog(errlog)
  858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  859. return
  860. }
  861. } else {
  862. timeStr := time.Now().Format("2006-01-02")
  863. timeArr := strings.Split(timeStr, "-")
  864. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  865. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  866. var hisPatient models.XtHisPatient
  867. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  868. hisPatient = models.XtHisPatient{
  869. Name: name,
  870. Age: age,
  871. Gender: gender,
  872. Birthday: birthUnix,
  873. Phone: phone,
  874. MedicalTreatmentType: medical_care,
  875. IdType: certificates,
  876. IdCardNo: id_card,
  877. BalanceAccountsType: settlementValue,
  878. SocialType: social_type,
  879. MedicalInsuranceNumber: medical_insurance_card,
  880. RegisterType: register_type,
  881. RegisterCost: registration_fee,
  882. TreatmentCost: medical_expenses,
  883. AdminUserId: admin_user_id,
  884. UserOrgId: adminInfo.CurrentOrgId,
  885. Status: 1,
  886. RecordDate: recordDateTime,
  887. IsReturn: 1,
  888. PatientId: patient.ID,
  889. Ctime: time.Now().Unix(),
  890. Mtime: time.Now().Unix(),
  891. Number: str,
  892. }
  893. service.CreateHisPatient(&hisPatient)
  894. }
  895. c.ServeSuccessJSON(map[string]interface{}{
  896. "his_info": hisPatient,
  897. })
  898. }
  899. }
  900. //上传明细----结算
  901. func (c *HisApiController) GetUploadInfo() {
  902. id, _ := c.GetInt64("id")
  903. record_time := c.GetString("record_time")
  904. pay_way, _ := c.GetInt64("pay_way")
  905. pay_price, _ := c.GetFloat("pay_price")
  906. pay_card_no := c.GetString("pay_card_no")
  907. discount_price, _ := c.GetFloat("discount_price")
  908. preferential_price, _ := c.GetFloat("preferential_price")
  909. reality_price, _ := c.GetFloat("reality_price")
  910. found_price, _ := c.GetFloat("found_price")
  911. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  912. private_price, _ := c.GetFloat("private_price")
  913. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  914. //admin_user_id, _ := c.GetInt64("admin_user_id")
  915. timeLayout := "2006-01-02"
  916. loc, _ := time.LoadLocation("Local")
  917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  918. if err != nil {
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. recordDateTime := theTime.Unix()
  923. adminUser := c.GetAdminUserInfo()
  924. var prescriptions []*models.HisPrescription
  925. var start_time int64
  926. var end_time int64
  927. data := make(map[string]interface{})
  928. if settle_accounts_type == 1 { //日结
  929. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  930. data["pre"] = prescriptions
  931. } else { //月结
  932. start_time_str := c.GetString("start_time")
  933. end_time_str := c.GetString("end_time")
  934. timeLayout := "2006-01-02"
  935. loc, _ := time.LoadLocation("Local")
  936. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  937. if err != nil {
  938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  939. return
  940. }
  941. recordStartTime := theStartTime.Unix()
  942. start_time = recordStartTime
  943. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  944. if err != nil {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  946. return
  947. }
  948. recordEndTime := theEndTime.Unix()
  949. end_time = recordEndTime
  950. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  951. data["pre"] = prescriptions
  952. }
  953. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  954. timestamp := time.Now().Unix()
  955. tempTime := time.Unix(timestamp, 0)
  956. timeFormat := tempTime.Format("20060102150405")
  957. chrgBchno := rand.Intn(100000) + 10000
  958. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  959. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  960. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  961. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  962. strconv.FormatInt(his.PatientId, 10)
  963. client := &http.Client{}
  964. data["psn_no"] = his.PsnNo
  965. data["mdtrt_id"] = his.Number
  966. data["chrg_bchno"] = chrg_bchno
  967. data["org_name"] = miConfig.OrgName
  968. data["doctor"] = patientPrescription.Doctor
  969. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  970. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  971. data["fixmedins_code"] = miConfig.Code
  972. data["dept_code"] = department.Number
  973. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  974. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  975. data["secret_key"] = miConfig.SecretKey
  976. var ids []int64
  977. for _, item := range prescriptions {
  978. ids = append(ids, item.ID)
  979. }
  980. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  981. if config.IsOpen == 1 { //对接了医保,走医保流程
  982. bytesData, _ := json.Marshal(data)
  983. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  984. resp, _ := client.Do(req)
  985. defer resp.Body.Close()
  986. body, ioErr := ioutil.ReadAll(resp.Body)
  987. if ioErr != nil {
  988. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  990. return
  991. }
  992. var respJSON map[string]interface{}
  993. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  994. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  996. return
  997. }
  998. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  999. userJSONBytes, _ := json.Marshal(respJSON)
  1000. var res ResultFour
  1001. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1002. utils.ErrorLog("解析失败:%v", err)
  1003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1004. return
  1005. }
  1006. if res.Infcode == 0 {
  1007. order := &models.HisOrder{
  1008. UserOrgId: adminUser.CurrentOrgId,
  1009. HisPatientId: his.ID,
  1010. PatientId: his.PatientId,
  1011. SettleAccountsDate: recordDateTime,
  1012. Ctime: time.Now().Unix(),
  1013. Mtime: time.Now().Unix(),
  1014. Status: 1,
  1015. Number: chrg_bchno,
  1016. Infcode: res.Infcode,
  1017. WarnMsg: res.WarnMsg,
  1018. Cainfo: res.Cainfo,
  1019. ErrMsg: res.ErrMsg,
  1020. RespondTime: res.RefmsgTime,
  1021. InfRefmsgid: res.InfRefmsgid,
  1022. OrderStatus: 1,
  1023. PayWay: pay_way,
  1024. PayPrice: pay_price,
  1025. PayCardNo: pay_card_no,
  1026. DiscountPrice: discount_price,
  1027. PreferentialPrice: preferential_price,
  1028. RealityPrice: reality_price,
  1029. FoundPrice: found_price,
  1030. MedicalInsurancePrice: medical_insurance_price,
  1031. PrivatePrice: private_price,
  1032. IsMedicineInsurance: 1,
  1033. SettleType: settle_accounts_type,
  1034. SettleStartTime: start_time,
  1035. SettleEndTime: end_time,
  1036. }
  1037. err = service.CreateOrder(order)
  1038. if err != nil {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1040. return
  1041. }
  1042. for _, item := range res.Output.Result {
  1043. temp := strings.Split(item.FeedetlSn, "-")
  1044. var advice_id int64 = 0
  1045. var project_id int64 = 0
  1046. var types int64 = 0
  1047. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1048. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1049. if temp[1] == "1" {
  1050. advice_id = id
  1051. project_id = 0
  1052. } else if temp[1] == "2" {
  1053. advice_id = 0
  1054. project_id = id
  1055. }
  1056. info := &models.HisOrderInfo{
  1057. OrderNumber: order.Number,
  1058. FeedetlSn: item.FeedetlSn,
  1059. UploadDate: time.Now().Unix(),
  1060. AdviceId: advice_id,
  1061. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1062. Cnt: item.Cnt,
  1063. Pric: float64(item.Pric),
  1064. PatientId: his.PatientId,
  1065. PricUplmtAmt: item.PricUplmtAmt,
  1066. SelfpayProp: item.SelfpayProp,
  1067. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1068. OverlmtAmt: item.OverlmtAmt,
  1069. PreselfpayAmt: item.PreselfpayAmt,
  1070. BasMednFlag: item.BasMednFlag,
  1071. MedChrgitmType: item.MedChrgitmType,
  1072. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1073. Status: 1,
  1074. Memo: item.Memo,
  1075. Mtime: time.Now().Unix(),
  1076. InscpScpAmt: item.InscpScpAmt,
  1077. DrtReimFlag: item.DrtReimFlag,
  1078. Ctime: time.Now().Unix(),
  1079. ListSpItemFlag: item.ListSpItemFlag,
  1080. ChldMedcFlag: item.ChldMedcFlag,
  1081. LmtUsedFlag: item.LmtUsedFlag,
  1082. ChrgitmLv: item.ChrgitmLv,
  1083. UserOrgId: adminUser.CurrentOrgId,
  1084. HisPatientId: his.ID,
  1085. OrderId: order.ID,
  1086. ProjectId: project_id,
  1087. Type: types,
  1088. }
  1089. service.CreateOrderInfo(info)
  1090. }
  1091. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1092. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1093. var total float64
  1094. for _, item := range prescriptions {
  1095. if item.Type == 1 { //药品
  1096. for _, subItem := range item.HisDoctorAdviceInfo {
  1097. total = total + (subItem.Price * subItem.PrescribingNumber)
  1098. }
  1099. }
  1100. if item.Type == 2 { //项目
  1101. for _, subItem := range item.HisPrescriptionProject {
  1102. total = total + (subItem.Price * float64(subItem.Count))
  1103. }
  1104. }
  1105. }
  1106. for _, item := range prescriptions {
  1107. for _, subItem := range item.HisAdditionalCharge {
  1108. total = total + (subItem.Price * float64(subItem.Count))
  1109. }
  1110. }
  1111. allTotal := fmt.Sprintf("%.2f", total)
  1112. if res.Infcode == 0 {
  1113. var rf []*ResultFive
  1114. json.Unmarshal([]byte(his.Iinfo), &rf)
  1115. psn_no := his.PsnNo
  1116. mdtrt_id := his.Number
  1117. chrg_bchno := chrg_bchno
  1118. cert_no := his.Certno
  1119. insutype := rf[0].Insutype
  1120. if his.IdCardType == 1 {
  1121. cert_no = his.MedicalInsuranceNumber
  1122. } else {
  1123. cert_no = his.Certno
  1124. }
  1125. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1126. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1127. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1128. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1129. resp, requestErr := http.Get(api)
  1130. if requestErr != nil {
  1131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1132. return
  1133. }
  1134. defer resp.Body.Close()
  1135. body, ioErr := ioutil.ReadAll(resp.Body)
  1136. if ioErr != nil {
  1137. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1139. return
  1140. }
  1141. var respJSON map[string]interface{}
  1142. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1143. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1145. return
  1146. }
  1147. fmt.Println(respJSON)
  1148. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1149. userJSONBytes, _ := json.Marshal(respJSON)
  1150. var res ResultSeven
  1151. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1152. utils.ErrorLog("解析失败:%v", err)
  1153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1154. return
  1155. }
  1156. if res.Infcode == -1 {
  1157. errlog := &models.HisOrderError{
  1158. UserOrgId: adminUser.CurrentOrgId,
  1159. Ctime: time.Now().Unix(),
  1160. Mtime: time.Now().Unix(),
  1161. Number: chrg_bchno,
  1162. ErrMsg: res.ErrMsg,
  1163. Status: 1,
  1164. PatientId: id,
  1165. RecordTime: recordDateTime,
  1166. Stage: 6,
  1167. }
  1168. service.CreateErrMsgLog(errlog)
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1170. return
  1171. } else {
  1172. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1173. order.OrderStatus = 2
  1174. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1175. order.SetlId = res.Output.Setlinfo.SetlID
  1176. order.PsnNo = res.Output.Setlinfo.PsnNo
  1177. order.PsnName = res.Output.Setlinfo.PsnName
  1178. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1179. order.Certno = res.Output.Setlinfo.Certno
  1180. order.Gend = res.Output.Setlinfo.Gend
  1181. order.Naty = res.Output.Setlinfo.Naty
  1182. order.Age = res.Output.Setlinfo.Age
  1183. order.Insutype = res.Output.Setlinfo.Insutype
  1184. order.PsnType = res.Output.Setlinfo.PsnType
  1185. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1186. order.SetlTime = res.Output.Setlinfo.SetlTime
  1187. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1188. order.MedType = res.Output.Setlinfo.MedType
  1189. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1190. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1191. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1192. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1193. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1194. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1195. order.HifpPay = res.Output.Setlinfo.HifpPay
  1196. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1197. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1198. order.HifesPay = res.Output.Setlinfo.HifesPay
  1199. order.HifobPay = res.Output.Setlinfo.HifobPay
  1200. order.MafPay = res.Output.Setlinfo.MafPay
  1201. order.OthPay = res.Output.Setlinfo.OthPay
  1202. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1203. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1204. order.AcctPay = res.Output.Setlinfo.AcctPay
  1205. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1206. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1207. order.Balc = res.Output.Setlinfo.Balc
  1208. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1209. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1210. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1211. order.ClrWay = res.Output.Setlinfo.ClrWay
  1212. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1213. detailStr := string(setlDetail)
  1214. order.SetlDetail = detailStr
  1215. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1216. err = service.UpDateOrder(order)
  1217. if err == nil {
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "msg": "结算成功",
  1220. })
  1221. } else {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1223. return
  1224. }
  1225. }
  1226. } else {
  1227. adminUser := c.GetAdminUserInfo()
  1228. errlog := &models.HisOrderError{
  1229. UserOrgId: adminUser.CurrentOrgId,
  1230. Ctime: time.Now().Unix(),
  1231. Mtime: time.Now().Unix(),
  1232. ErrMsg: res.ErrMsg,
  1233. Status: 1,
  1234. PatientId: id,
  1235. RecordTime: recordDateTime,
  1236. Stage: 4,
  1237. }
  1238. service.CreateErrMsgLog(errlog)
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1240. return
  1241. }
  1242. } else {
  1243. adminUser := c.GetAdminUserInfo()
  1244. errlog := &models.HisOrderError{
  1245. UserOrgId: adminUser.CurrentOrgId,
  1246. Ctime: time.Now().Unix(),
  1247. Mtime: time.Now().Unix(),
  1248. ErrMsg: res.ErrMsg,
  1249. Status: 1,
  1250. PatientId: id,
  1251. RecordTime: recordDateTime,
  1252. Stage: 4,
  1253. }
  1254. service.CreateErrMsgLog(errlog)
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1256. return
  1257. }
  1258. } else {
  1259. var total float64
  1260. for _, item := range prescriptions {
  1261. if item.Type == 1 { //药品
  1262. for _, subItem := range item.HisDoctorAdviceInfo {
  1263. total = total + (subItem.Price * subItem.PrescribingNumber)
  1264. }
  1265. }
  1266. if item.Type == 2 { //项目
  1267. for _, subItem := range item.HisPrescriptionProject {
  1268. total = total + (subItem.Price * float64(subItem.Count))
  1269. }
  1270. }
  1271. for _, subItem := range item.HisAdditionalCharge {
  1272. total = total + (subItem.Price * float64(subItem.Count))
  1273. }
  1274. }
  1275. allTotal := fmt.Sprintf("%.2f", total)
  1276. totals, _ := strconv.ParseFloat(allTotal, 64)
  1277. order := &models.HisOrder{
  1278. UserOrgId: adminUser.CurrentOrgId,
  1279. HisPatientId: his.ID,
  1280. PatientId: id,
  1281. SettleAccountsDate: recordDateTime,
  1282. Ctime: time.Now().Unix(),
  1283. Mtime: time.Now().Unix(),
  1284. Status: 1,
  1285. OrderStatus: 2,
  1286. Number: chrg_bchno,
  1287. MedfeeSumamt: totals,
  1288. PayWay: pay_way,
  1289. PayPrice: pay_price,
  1290. PayCardNo: pay_card_no,
  1291. DiscountPrice: discount_price,
  1292. PreferentialPrice: preferential_price,
  1293. RealityPrice: reality_price,
  1294. FoundPrice: found_price,
  1295. MedicalInsurancePrice: medical_insurance_price,
  1296. PrivatePrice: private_price,
  1297. }
  1298. err = service.CreateOrder(order)
  1299. if err != nil {
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1301. return
  1302. }
  1303. var customs []*Custom
  1304. for _, item := range prescriptions {
  1305. if item.Type == 1 { //药品
  1306. for _, subItem := range item.HisDoctorAdviceInfo {
  1307. cus := &Custom{
  1308. AdviceId: subItem.ID,
  1309. ProjectId: 0,
  1310. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1311. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1312. FeedetlSn: subItem.FeedetlSn,
  1313. Price: fmt.Sprintf("%.2f", subItem.Price),
  1314. MedListCodg: subItem.MedListCodg,
  1315. Type: 1,
  1316. }
  1317. customs = append(customs, cus)
  1318. }
  1319. }
  1320. if item.Type == 2 { //项目
  1321. for _, subItem := range item.HisPrescriptionProject {
  1322. cus := &Custom{
  1323. AdviceId: 0,
  1324. ProjectId: subItem.ID,
  1325. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1326. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1327. FeedetlSn: subItem.FeedetlSn,
  1328. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1329. MedListCodg: subItem.MedListCodg,
  1330. Type: 2,
  1331. }
  1332. customs = append(customs, cus)
  1333. }
  1334. }
  1335. for _, item := range item.HisAdditionalCharge {
  1336. cus := &Custom{
  1337. ItemId: item.ID,
  1338. AdviceId: 0,
  1339. ProjectId: 0,
  1340. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1341. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1342. FeedetlSn: item.FeedetlSn,
  1343. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1344. MedListCodg: item.XtHisAddtionConfig.Code,
  1345. Type: 3,
  1346. }
  1347. customs = append(customs, cus)
  1348. }
  1349. }
  1350. for _, item := range customs {
  1351. var advice_id int64 = 0
  1352. var project_id int64 = 0
  1353. var item_id int64 = 0
  1354. var types int64 = 0
  1355. if item.Type == 1 {
  1356. advice_id = item.AdviceId
  1357. project_id = 0
  1358. item_id = 0
  1359. } else if item.Type == 2 {
  1360. advice_id = 0
  1361. item_id = 0
  1362. project_id = item.ProjectId
  1363. } else if item.Type == 3 {
  1364. advice_id = 0
  1365. item_id = item.ItemId
  1366. project_id = 0
  1367. }
  1368. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1369. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1370. pric, _ := strconv.ParseFloat(item.Price, 32)
  1371. info := &models.HisOrderInfo{
  1372. OrderNumber: order.Number,
  1373. UploadDate: time.Now().Unix(),
  1374. AdviceId: advice_id,
  1375. DetItemFeeSumamt: detItemFeeSumamt,
  1376. Cnt: cut,
  1377. Pric: pric,
  1378. PatientId: id,
  1379. Status: 1,
  1380. Mtime: time.Now().Unix(),
  1381. Ctime: time.Now().Unix(),
  1382. UserOrgId: adminUser.CurrentOrgId,
  1383. HisPatientId: his.ID,
  1384. OrderId: order.ID,
  1385. ProjectId: project_id,
  1386. Type: types,
  1387. ItemId: item_id,
  1388. }
  1389. service.CreateOrderInfo(info)
  1390. }
  1391. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1392. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1393. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1394. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1395. if err == nil {
  1396. c.ServeSuccessJSON(map[string]interface{}{
  1397. "msg": "结算成功",
  1398. })
  1399. } else {
  1400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1401. return
  1402. }
  1403. }
  1404. }
  1405. //退款
  1406. func (c *HisApiController) Refund() {
  1407. order_id, _ := c.GetInt64("order_id")
  1408. number := c.GetString("number")
  1409. record_time := c.GetString("record_time")
  1410. patient_id, _ := c.GetInt64("patient_id")
  1411. timeLayout := "2006-01-02"
  1412. loc, _ := time.LoadLocation("Local")
  1413. adminUser := c.GetAdminUserInfo()
  1414. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1415. fmt.Println(err)
  1416. if err != nil {
  1417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1418. return
  1419. }
  1420. recordDateTime := theTime.Unix()
  1421. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1422. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1423. var order models.HisOrder
  1424. order, _ = service.GetHisOrderByID(order_id)
  1425. if order.ID == 0 {
  1426. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1427. }
  1428. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1429. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1430. if config.IsOpen == 1 { //对接了医保,走医保流程
  1431. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1432. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1433. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1434. resp, requestErr := http.Get(api)
  1435. if requestErr != nil {
  1436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1437. return
  1438. }
  1439. body, ioErr := ioutil.ReadAll(resp.Body)
  1440. if ioErr != nil {
  1441. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1443. return
  1444. }
  1445. var respJSON map[string]interface{}
  1446. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1447. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1449. return
  1450. }
  1451. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1452. userJSONBytes, _ := json.Marshal(respJSON)
  1453. fmt.Println(respJSON)
  1454. fmt.Println(userJSONBytes)
  1455. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1456. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1457. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1458. resp2, requestErr2 := http.Get(api2)
  1459. if requestErr2 != nil {
  1460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1461. return
  1462. }
  1463. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1464. if ioErr2 != nil {
  1465. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1466. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1467. return
  1468. }
  1469. var respJSON2 map[string]interface{}
  1470. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1471. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1473. return
  1474. }
  1475. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1476. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1477. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1478. //resp3, requestErr3 := http.Get(api3)
  1479. //if requestErr3 != nil {
  1480. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1481. // return
  1482. //}
  1483. //
  1484. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1485. //if ioErr3 != nil {
  1486. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1487. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1488. // return
  1489. //}
  1490. //var respJSON3 map[string]interface{}
  1491. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1492. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1493. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1494. // return
  1495. //}
  1496. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1497. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1498. if err == nil {
  1499. c.ServeSuccessJSON(map[string]interface{}{
  1500. "msg": "退费成功",
  1501. })
  1502. } else {
  1503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1504. return
  1505. }
  1506. } else {
  1507. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1508. if err == nil {
  1509. c.ServeSuccessJSON(map[string]interface{}{
  1510. "msg": "退费成功",
  1511. })
  1512. } else {
  1513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1514. return
  1515. }
  1516. }
  1517. }
  1518. func (c *HisApiController) RefundNumber() {
  1519. record_time := c.GetString("record_time")
  1520. patient_id, _ := c.GetInt64("patient_id")
  1521. timeLayout := "2006-01-02"
  1522. loc, _ := time.LoadLocation("Local")
  1523. adminUser := c.GetAdminUserInfo()
  1524. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1525. fmt.Println(err)
  1526. if err != nil {
  1527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1528. return
  1529. }
  1530. recordDateTime := theTime.Unix()
  1531. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1532. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1533. //order, _ := service.GetHisOrderByID(order_id)
  1534. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1535. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1536. if config.IsOpen == 1 { //对接了医保,走医保流程
  1537. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1538. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1539. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1540. resp3, requestErr3 := http.Get(api3)
  1541. if requestErr3 != nil {
  1542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1543. return
  1544. }
  1545. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1546. if ioErr3 != nil {
  1547. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1549. return
  1550. }
  1551. var respJSON3 map[string]interface{}
  1552. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1553. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1555. return
  1556. }
  1557. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1558. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1559. if err == nil {
  1560. c.ServeSuccessJSON(map[string]interface{}{
  1561. "msg": "退费成功",
  1562. })
  1563. } else {
  1564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1565. return
  1566. }
  1567. } else {
  1568. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1569. //if err == nil {
  1570. // c.ServeSuccessJSON(map[string]interface{}{
  1571. // "msg": "退费成功",
  1572. // })
  1573. //} else {
  1574. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1575. // return
  1576. //}
  1577. }
  1578. }
  1579. func (c *HisApiController) RefundDetail() {
  1580. order_id, _ := c.GetInt64("order_id")
  1581. number := c.GetString("number")
  1582. record_time := c.GetString("record_time")
  1583. patient_id, _ := c.GetInt64("patient_id")
  1584. timeLayout := "2006-01-02"
  1585. loc, _ := time.LoadLocation("Local")
  1586. adminUser := c.GetAdminUserInfo()
  1587. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1588. fmt.Println(err)
  1589. if err != nil {
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. recordDateTime := theTime.Unix()
  1594. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1595. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1596. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1597. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1598. var order models.HisOrder
  1599. order, _ = service.GetHisOrderByID(order_id)
  1600. if order.ID == 0 {
  1601. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1602. }
  1603. if config.IsOpen == 1 { //对接了医保,走医保流程
  1604. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1605. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1606. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1607. resp2, requestErr2 := http.Get(api2)
  1608. if requestErr2 != nil {
  1609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1610. return
  1611. }
  1612. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1613. if ioErr2 != nil {
  1614. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1616. return
  1617. }
  1618. var respJSON2 map[string]interface{}
  1619. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1620. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1622. return
  1623. }
  1624. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1625. if err == nil {
  1626. c.ServeSuccessJSON(map[string]interface{}{
  1627. "msg": "退费成功",
  1628. })
  1629. } else {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1631. return
  1632. }
  1633. } else {
  1634. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1635. if err == nil {
  1636. c.ServeSuccessJSON(map[string]interface{}{
  1637. "msg": "退费成功",
  1638. })
  1639. } else {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1641. return
  1642. }
  1643. }
  1644. }
  1645. //对账
  1646. func (c *HisApiController) GetCheckAccount() {
  1647. start_time := c.GetString("start_time")
  1648. end_time := c.GetString("end_time")
  1649. insutype := c.GetString("insutype")
  1650. clr_type := c.GetString("clr_type")
  1651. admin_user_id, _ := c.GetInt64("admin_user_id")
  1652. adminUser := c.GetAdminUserInfo()
  1653. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1654. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1655. timeLayout := "2006-01-02"
  1656. loc, _ := time.LoadLocation("Local")
  1657. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1658. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1659. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1660. decimal.DivisionPrecision = 2
  1661. var medfee_sumamt float64
  1662. var acct_pay float64
  1663. var fund_pay_sumamt float64
  1664. fixmedins_setl_cnt := int64(len(orders))
  1665. for _, item := range orders {
  1666. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1667. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1668. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1669. }
  1670. var user_name string
  1671. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1672. if role.ID == 0 {
  1673. user_name = "xxx"
  1674. } else {
  1675. user_name = role.UserName
  1676. }
  1677. if config.IsOpen == 1 {
  1678. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1679. "insutype=" + insutype +
  1680. "&clr_type=" + clr_type +
  1681. "&setl_optins=" + miConfig.OrgName +
  1682. "&stmt_begndate=" + start_time +
  1683. "&stm_enddate=" + end_time +
  1684. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1685. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1686. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1687. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1688. "&fixmedins_code=" + miConfig.Code +
  1689. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1690. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1691. "&secret_key=" + miConfig.SecretKey +
  1692. "&org_name=" + miConfig.OrgName +
  1693. "&doctor=" + user_name
  1694. fmt.Println(api)
  1695. resp, requestErr := http.Get(api)
  1696. if requestErr != nil {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1698. return
  1699. }
  1700. body, ioErr := ioutil.ReadAll(resp.Body)
  1701. fmt.Println(body)
  1702. if ioErr != nil {
  1703. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1705. return
  1706. }
  1707. var respJSON map[string]interface{}
  1708. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1709. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1711. return
  1712. }
  1713. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1714. userJSONBytes, _ := json.Marshal(respJSON)
  1715. var res ResultEight
  1716. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1717. utils.ErrorLog("解析失败:%v", err)
  1718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1719. return
  1720. }
  1721. if res.Infcode == 0 {
  1722. c.ServeSuccessJSON(map[string]interface{}{
  1723. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1724. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1725. })
  1726. } else {
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1728. }
  1729. }
  1730. }
  1731. //对账明细
  1732. func (c *HisApiController) GetCheckDetailAccount() {
  1733. start_time := c.GetString("start_time")
  1734. end_time := c.GetString("end_time")
  1735. admin_user_id, _ := c.GetInt64("admin_user_id")
  1736. adminUser := c.GetAdminUserInfo()
  1737. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1738. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1739. timeLayout := "2006-01-02"
  1740. loc, _ := time.LoadLocation("Local")
  1741. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1742. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1743. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1744. Mkdir(miConfig.OrgName)
  1745. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1746. file_name := file + ".txt"
  1747. zip_name := file + ".zip"
  1748. zip_path := miConfig.OrgName + "/" + zip_name
  1749. file_path := miConfig.OrgName + "/" + file_name
  1750. decimal.DivisionPrecision = 2
  1751. var medfee_sumamt float64
  1752. var psn_cash_pay float64
  1753. var fund_pay_sumamt float64
  1754. fixmedins_setl_cnt := int64(len(orders))
  1755. for _, item := range orders {
  1756. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1757. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1758. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1759. }
  1760. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1761. defer f.Close()
  1762. if err != nil {
  1763. fmt.Println(err.Error())
  1764. } else {
  1765. for _, item := range orders {
  1766. var refd_setl_flag string
  1767. if item.OrderStatus == 2 {
  1768. refd_setl_flag = "0"
  1769. }
  1770. if item.OrderStatus == 3 {
  1771. refd_setl_flag = "1"
  1772. }
  1773. var str string
  1774. str = item.SetlId + " " +
  1775. item.MdtrtId + " " +
  1776. item.PsnNo + " " +
  1777. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1778. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1779. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1780. _, err = f.Write([]byte(str))
  1781. }
  1782. }
  1783. Zip(file_path, zip_path)
  1784. fmt.Println(ReadFile(zip_path))
  1785. fmt.Println(string(ReadFile(zip_path)))
  1786. if config.IsOpen == 1 {
  1787. var user_name string
  1788. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1789. if role.ID == 0 {
  1790. user_name = "管理员"
  1791. } else {
  1792. user_name = role.UserName
  1793. }
  1794. baseParams := models.BaseParams{
  1795. SecretKey: miConfig.SecretKey,
  1796. FixmedinsCode: miConfig.Code,
  1797. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1798. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1799. OrgName: miConfig.OrgName,
  1800. Doctor: user_name,
  1801. }
  1802. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1803. var dat map[string]interface{}
  1804. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1805. fmt.Println(dat)
  1806. } else {
  1807. fmt.Println(err)
  1808. }
  1809. userJSONBytes, _ := json.Marshal(dat)
  1810. var res ResultNine
  1811. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1812. utils.ErrorLog("解析失败:%v", err)
  1813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1814. return
  1815. }
  1816. if res.Infcode == 0 {
  1817. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1818. "file_qury_no=" + res.Output.FileQuryNo +
  1819. "&setl_optins=" + miConfig.OrgName +
  1820. "&stmt_begndate=" + start_time +
  1821. "&stm_enddate=" + end_time +
  1822. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1823. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1824. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1825. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1826. "&fixmedins_code=" + miConfig.Code +
  1827. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1828. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1829. "&secret_key=" + miConfig.SecretKey +
  1830. "&org_name=" + miConfig.OrgName +
  1831. "&doctor=" + user_name
  1832. resp, requestErr := http.Get(api)
  1833. if requestErr != nil {
  1834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1835. return
  1836. }
  1837. body, ioErr := ioutil.ReadAll(resp.Body)
  1838. if ioErr != nil {
  1839. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1841. return
  1842. }
  1843. var respJSON map[string]interface{}
  1844. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1845. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1847. return
  1848. }
  1849. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1850. userJSONBytes, _ := json.Marshal(respJSON)
  1851. var res ResultTen
  1852. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1853. utils.ErrorLog("解析失败:%v", err)
  1854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1855. return
  1856. }
  1857. if res.Infcode == 0 {
  1858. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  1859. c.ServeSuccessJSON(map[string]interface{}{
  1860. "msg": "明细对账成功",
  1861. })
  1862. }
  1863. } else {
  1864. }
  1865. }
  1866. }
  1867. func (c *HisApiController) GetSettleAccounts() {
  1868. //id, _ := c.GetInt64("id")
  1869. //record_time := c.GetString("record_time")
  1870. order_id, _ := c.GetInt64("order_id")
  1871. admin_user_id, _ := c.GetInt64("admin_user_id")
  1872. //timeLayout := "2006-01-02"
  1873. //loc, _ := time.LoadLocation("Local")
  1874. //
  1875. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1876. //if err != nil {
  1877. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1878. // return
  1879. //}
  1880. //recordDateTime := theTime.Unix()
  1881. adminUser := c.GetAdminUserInfo()
  1882. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1883. order, _ := service.GetHisOrderByID(order_id)
  1884. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  1885. var bedCostTotal float64 = 0 //床位总费
  1886. var bedCostSelfTotal float64 = 0 //床位自费
  1887. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  1888. var operationCostTotal float64 = 0 //手术费
  1889. var operationCostSelfTotal float64 = 0 //手术费
  1890. var operationCostPartSelfTotal float64 = 0 //手术费
  1891. var otherCostTotal float64 = 0 //其他费用
  1892. var otherCostSelfTotal float64 = 0 //其他费用
  1893. var otherCostPartSelfTotal float64 = 0 //其他费用
  1894. var materialCostTotal float64 = 0 //材料费
  1895. var materialCostSelfTotal float64 = 0 //材料费
  1896. var materialCostPartSelfTotal float64 = 0 //材料费
  1897. var westernMedicineCostTotal float64 = 0 //西药费
  1898. var westernMedicineCostSelfTotal float64 = 0 //西药费
  1899. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  1900. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  1901. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  1902. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  1903. var checkCostTotal float64 = 0 //检查费
  1904. var checkCostSelfTotal float64 = 0 //检查费
  1905. var checkCostPartSelfTotal float64 = 0 //检查费
  1906. var laboratoryCostTotal float64 = 0 //化验费
  1907. var laboratoryCostSelfTotal float64 = 0 //化验费
  1908. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  1909. var treatCostTotal float64 = 0 //治疗费用
  1910. var treatCostSelfTotal float64 = 0 //治疗费用
  1911. var treatCostPartSelfTotal float64 = 0 //治疗费用
  1912. decimal.DivisionPrecision = 2
  1913. for _, item := range orderInfos {
  1914. if item.MedChrgitmType == "01" { //床位费
  1915. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1916. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1917. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1918. }
  1919. if item.MedChrgitmType == "03" { //检查费
  1920. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1921. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1922. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1923. }
  1924. if item.MedChrgitmType == "04" { //化验费
  1925. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1926. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1927. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1928. }
  1929. if item.MedChrgitmType == "05" { //治疗费
  1930. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1931. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1932. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1933. }
  1934. if item.MedChrgitmType == "06" { //手术费
  1935. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1936. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1937. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1938. }
  1939. if item.MedChrgitmType == "08" { //材料费
  1940. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1941. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1942. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1943. }
  1944. if item.MedChrgitmType == "09" { //西药费
  1945. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1946. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1947. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1948. }
  1949. if item.MedChrgitmType == "11" { //中成费
  1950. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1951. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1952. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1953. }
  1954. if item.MedChrgitmType == "14" { //其他费
  1955. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1956. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1957. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1958. }
  1959. }
  1960. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1961. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1962. var user_name string
  1963. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1964. if role.ID == 0 {
  1965. user_name = "管理员"
  1966. } else {
  1967. user_name = role.UserName
  1968. }
  1969. baseParams := models.BaseParams{
  1970. SecretKey: miConfig.SecretKey,
  1971. FixmedinsCode: miConfig.Code,
  1972. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1973. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1974. OrgName: miConfig.OrgName,
  1975. Doctor: user_name,
  1976. }
  1977. businessParams := models.BusinessParams{
  1978. PsnNo: order.PsnNo,
  1979. MdtrtId: order.MdtrtId,
  1980. SetlId: order.SetlId,
  1981. }
  1982. if config.IsOpen == 1 {
  1983. result := service.Gdyb5203(baseParams, businessParams)
  1984. var dat map[string]interface{}
  1985. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1986. fmt.Println(dat)
  1987. } else {
  1988. fmt.Println(err)
  1989. }
  1990. userJSONBytes, _ := json.Marshal(dat)
  1991. var res ResultEleven
  1992. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1993. utils.ErrorLog("解析失败:%v", err)
  1994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1995. return
  1996. }
  1997. if res.Infcode == 0 {
  1998. c.ServeSuccessJSON(map[string]interface{}{
  1999. "info": res.Output.Setlinfo,
  2000. "bedCostTotal": bedCostTotal,
  2001. "bedCostSelfTotal": bedCostSelfTotal,
  2002. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2003. "operationCostTotal": operationCostTotal,
  2004. "operationCostSelfTotal": operationCostSelfTotal,
  2005. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2006. "otherCostTotal": otherCostTotal,
  2007. "otherCostSelfTotal": otherCostSelfTotal,
  2008. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2009. "materialCostTotal": materialCostTotal,
  2010. "materialCostSelfTotal": materialCostSelfTotal,
  2011. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2012. "westernMedicineCostTotal": westernMedicineCostTotal,
  2013. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2014. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2015. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2016. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2017. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2018. "checkCostTotal": checkCostTotal,
  2019. "checkCostSelfTotal": checkCostSelfTotal,
  2020. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2021. "laboratoryCostTotal": laboratoryCostTotal,
  2022. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2023. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2024. "treatCostTotal": treatCostTotal,
  2025. "treatCostSelfTotal": treatCostSelfTotal,
  2026. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2027. })
  2028. }
  2029. }
  2030. }
  2031. func (c *HisApiController) GetCode() {
  2032. name := c.GetString("name")
  2033. codg := c.GetString("codg")
  2034. adminUser := c.GetAdminUserInfo()
  2035. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2036. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2037. var user_name string
  2038. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2039. if role.ID == 0 {
  2040. user_name = "xxx"
  2041. } else {
  2042. user_name = role.UserName
  2043. }
  2044. baseParams := &models.BaseParams{
  2045. SecretKey: miConfig.SecretKey,
  2046. FixmedinsCode: miConfig.Code,
  2047. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2048. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2049. OrgName: miConfig.OrgName,
  2050. Doctor: user_name,
  2051. }
  2052. if config.IsOpen == 1 {
  2053. result := service.Gdyb3301(baseParams, name, codg)
  2054. var dat map[string]interface{}
  2055. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2056. fmt.Println(dat)
  2057. } else {
  2058. fmt.Println(err)
  2059. }
  2060. }
  2061. }
  2062. func (c *HisApiController) CheckTreatment() {
  2063. patient_id, _ := c.GetInt64("patient_id", 0)
  2064. record_time := c.GetString("record_time")
  2065. insutype := c.GetString("insutype")
  2066. timeLayout := "2006-01-02"
  2067. loc, _ := time.LoadLocation("Local")
  2068. adminUser := c.GetAdminUserInfo()
  2069. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2070. fmt.Println(err)
  2071. if err != nil {
  2072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2073. return
  2074. }
  2075. recordDateTime := theTime.Unix()
  2076. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2077. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2078. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2079. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2080. var user_name string
  2081. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2082. if role.ID == 0 {
  2083. user_name = "xxx"
  2084. } else {
  2085. user_name = role.UserName
  2086. }
  2087. baseParams := models.BaseParams{
  2088. SecretKey: miConfig.SecretKey,
  2089. FixmedinsCode: miConfig.Code,
  2090. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2091. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2092. OrgName: miConfig.OrgName,
  2093. Doctor: user_name,
  2094. }
  2095. if config.IsOpen == 1 {
  2096. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  2097. var dat map[string]interface{}
  2098. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2099. fmt.Println(dat)
  2100. } else {
  2101. fmt.Println(err)
  2102. }
  2103. }
  2104. }
  2105. func (c *HisApiController) PutRecord() {
  2106. id, _ := c.GetInt64("id")
  2107. record_time := c.GetString("record_time")
  2108. timeLayout := "2006-01-02"
  2109. loc, _ := time.LoadLocation("Local")
  2110. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2111. if err != nil {
  2112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2113. return
  2114. }
  2115. recordDateTime := theTime.Unix()
  2116. adminInfo := c.GetAdminUserInfo()
  2117. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  2118. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2119. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2120. fmt.Println(miConfig.SecretKey)
  2121. if patient == nil {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2123. return
  2124. }
  2125. if len(patient.IdCardNo) == 0 {
  2126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2127. return
  2128. }
  2129. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  2130. if config.IsOpen == 1 {
  2131. api := "http://127.0.0.1:9532/" + "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
  2132. resp, requestErr := http.Get(api)
  2133. if requestErr != nil {
  2134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2135. return
  2136. }
  2137. defer resp.Body.Close()
  2138. body, ioErr := ioutil.ReadAll(resp.Body)
  2139. if ioErr != nil {
  2140. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2142. return
  2143. }
  2144. var respJSON map[string]interface{}
  2145. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2146. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2148. return
  2149. }
  2150. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2151. userJSONBytes, _ := json.Marshal(userJSON)
  2152. var res ResultTwo
  2153. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2154. utils.ErrorLog("解析失败:%v", err)
  2155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2156. return
  2157. }
  2158. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2159. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2160. infoStr := string(Iinfos)
  2161. idetinfoStr := string(Idetinfos)
  2162. if res.Infcode == 0 {
  2163. his := models.VMHisPatient{
  2164. Status: 1,
  2165. Ctime: time.Now().Unix(),
  2166. Mtime: time.Now().Unix(),
  2167. PsnNo: res.Output.Baseinfo.PsnNo,
  2168. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2169. Certno: res.Output.Baseinfo.Certno,
  2170. PsnName: res.Output.Baseinfo.PsnName,
  2171. Gend: res.Output.Baseinfo.Gend,
  2172. Naty: res.Output.Baseinfo.Naty,
  2173. Brdy: res.Output.Baseinfo.Brdy,
  2174. Age: res.Output.Baseinfo.Age,
  2175. Iinfo: infoStr,
  2176. Idetinfo: idetinfoStr,
  2177. PatientId: patient.ID,
  2178. RecordDate: theTime.Unix(),
  2179. UserOrgId: adminInfo.CurrentOrgId,
  2180. AdminUserId: adminInfo.AdminUser.Id,
  2181. IsReturn: 1,
  2182. }
  2183. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  2184. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  2185. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  2186. var dat map[string]interface{}
  2187. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2188. fmt.Println(dat)
  2189. } else {
  2190. fmt.Println(err)
  2191. }
  2192. var dat2 map[string]interface{}
  2193. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  2194. fmt.Println(dat2)
  2195. } else {
  2196. fmt.Println(err)
  2197. }
  2198. } else {
  2199. adminUser := c.GetAdminUserInfo()
  2200. errlog := &models.HisOrderError{
  2201. UserOrgId: adminUser.CurrentOrgId,
  2202. Ctime: time.Now().Unix(),
  2203. Mtime: time.Now().Unix(),
  2204. ErrMsg: res.ErrMsg,
  2205. Status: 1,
  2206. PatientId: id,
  2207. RecordTime: recordDateTime,
  2208. Stage: 1,
  2209. }
  2210. service.CreateErrMsgLog(errlog)
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  2212. return
  2213. }
  2214. }
  2215. }
  2216. func (c *HisApiController) GetUploadDiag() {
  2217. id, _ := c.GetInt64("id")
  2218. record_time := c.GetString("record_time")
  2219. diagnosis_id, _ := c.GetInt64("diagnosis")
  2220. sick_type, _ := c.GetInt64("sick_type")
  2221. reg_type, _ := c.GetInt64("reg_type")
  2222. timeLayout := "2006-01-02"
  2223. loc, _ := time.LoadLocation("Local")
  2224. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2225. if err != nil {
  2226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2227. return
  2228. }
  2229. var patientPrescription models.HisPrescriptionInfo
  2230. recordDateTime := theTime.Unix()
  2231. adminInfo := c.GetAdminUserInfo()
  2232. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2233. if patientPrescription.ID == 0 {
  2234. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2235. }
  2236. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2237. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2238. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2239. sickConfig, _ := service.FindSickById(sick_type)
  2240. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2241. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  2242. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  2243. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  2244. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  2245. resp2, requestErr2 := http.Get(api2)
  2246. if requestErr2 != nil {
  2247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2248. return
  2249. }
  2250. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2251. if ioErr2 != nil {
  2252. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2254. return
  2255. }
  2256. var respJSON2 map[string]interface{}
  2257. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2258. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2260. return
  2261. }
  2262. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2263. userJSONBytes2, _ := json.Marshal(respJSON2)
  2264. var res2 ResultSix
  2265. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2266. utils.ErrorLog("解析失败:%v", err)
  2267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2268. return
  2269. }
  2270. if res2.Infcode == -1 {
  2271. adminUser := c.GetAdminUserInfo()
  2272. errlog := &models.HisOrderError{
  2273. UserOrgId: adminUser.CurrentOrgId,
  2274. Ctime: time.Now().Unix(),
  2275. Mtime: time.Now().Unix(),
  2276. ErrMsg: res2.ErrMsg,
  2277. Status: 1,
  2278. PatientId: id,
  2279. RecordTime: recordDateTime,
  2280. Stage: 3,
  2281. }
  2282. service.CreateErrMsgLog(errlog)
  2283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  2284. return
  2285. }
  2286. c.ServeSuccessJSON(map[string]interface{}{
  2287. "msg": "上传成功",
  2288. })
  2289. }
  2290. func PathExists(path string) (bool, error) {
  2291. _, err := os.Stat(path)
  2292. if err == nil {
  2293. return true, nil
  2294. }
  2295. if os.IsNotExist(err) {
  2296. return false, nil
  2297. }
  2298. return false, err
  2299. }
  2300. //创建文件夹
  2301. func Mkdir(dir string) {
  2302. // 创建文件夹
  2303. exist, err := PathExists(dir)
  2304. if err != nil {
  2305. fmt.Println(err.Error())
  2306. } else {
  2307. if exist {
  2308. fmt.Println(dir + "文件夹已存在!")
  2309. } else {
  2310. // 文件夹名称,权限
  2311. err := os.Mkdir(dir, os.ModePerm)
  2312. if err != nil {
  2313. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2314. } else {
  2315. fmt.Println(dir + "文件夹创建成功!")
  2316. }
  2317. }
  2318. }
  2319. }
  2320. //压缩文件
  2321. func Zip(srcFile string, destZip string) error {
  2322. zipfile, err := os.Create(destZip)
  2323. if err != nil {
  2324. return err
  2325. }
  2326. defer zipfile.Close()
  2327. archive := zip.NewWriter(zipfile)
  2328. defer archive.Close()
  2329. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2330. if err != nil {
  2331. return err
  2332. }
  2333. header, err := zip.FileInfoHeader(info)
  2334. if err != nil {
  2335. return err
  2336. }
  2337. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2338. // header.Name = path
  2339. if info.IsDir() {
  2340. header.Name += "/"
  2341. } else {
  2342. header.Method = zip.Deflate
  2343. }
  2344. writer, err := archive.CreateHeader(header)
  2345. if err != nil {
  2346. return err
  2347. }
  2348. if !info.IsDir() {
  2349. file, err := os.Open(path)
  2350. if err != nil {
  2351. return err
  2352. }
  2353. defer file.Close()
  2354. _, err = io.Copy(writer, file)
  2355. }
  2356. return err
  2357. })
  2358. return err
  2359. }
  2360. func ReadFile(filePath string) []byte {
  2361. f, err := os.Open(filePath)
  2362. if err != nil {
  2363. fmt.Println("read file fail", err)
  2364. return nil
  2365. }
  2366. defer f.Close()
  2367. fd, err := ioutil.ReadAll(f)
  2368. if err != nil {
  2369. fmt.Println("read to fd fail", err)
  2370. return nil
  2371. }
  2372. return fd
  2373. }
  2374. func RemoveRepeatedCode(arr []string) (newArr []string) {
  2375. newArr = make([]string, 0)
  2376. for i := 0; i < len(arr); i++ {
  2377. repeat := false
  2378. for j := i + 1; j < len(arr); j++ {
  2379. if arr[i] == arr[j] {
  2380. repeat = true
  2381. break
  2382. }
  2383. }
  2384. if !repeat {
  2385. newArr = append(newArr, arr[i])
  2386. }
  2387. }
  2388. return
  2389. }