his_api_controller.go 110KB

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