his_api_controller.go 128KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664
  1. package sg
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/controllers"
  8. "gdyb/enums"
  9. "gdyb/models"
  10. "gdyb/service"
  11. "gdyb/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "github.com/shopspring/decimal"
  15. "io"
  16. "io/ioutil"
  17. "math/rand"
  18. "net/http"
  19. "os"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "time"
  25. "unsafe"
  26. )
  27. type HisApiController struct {
  28. controllers.BaseAuthAPIController
  29. }
  30. func HisManagerApiRegistRouters() {
  31. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  32. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  33. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  34. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  35. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  36. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  37. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  38. //beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  39. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  40. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  41. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  42. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  43. beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  44. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  45. beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  46. beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  47. beego.Router("/api/pre_upload/get", &HisApiController{}, "get:GetPreUploadInfo")
  48. beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  49. }
  50. func (c *HisApiController) TestPay() {
  51. DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  52. readCards := DllDef2.MustFindProc("BankTrans")
  53. inputData := make(map[string]interface{})
  54. inputData["transId"] = "05"
  55. inputData["amount"] = "0.01"
  56. inputData["traceNo"] = "20210227093601325405377"
  57. inputData["cardNo"] = "F36084348"
  58. inputData["id"] = "44022919620927046X"
  59. //jsonStr := `
  60. // {
  61. // "transId": "05",
  62. // "amount":"1.00",
  63. // "traceNo":"20210227093601325405377",
  64. // "cardNo":"F36084348",
  65. // "id":"44022919620927046X"
  66. //
  67. // }
  68. //`
  69. bytes_arr, _ := json.Marshal(inputData)
  70. str3 := make([]byte, 256)
  71. ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  72. fmt.Println(":", string(str3))
  73. if err4 != nil {
  74. fmt.Println("SSCard的运算结果为:", ret4)
  75. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  76. return
  77. }
  78. }
  79. func (c *HisApiController) TestGetBasBaseInfo() {
  80. //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  81. //fmt.Println(result)
  82. //cs1 := C.CString("")
  83. //cs2 := C.CString("")
  84. //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  85. //fmt.Println(cs1)
  86. //fmt.Println(cs2)
  87. //C.free(unsafe.Pointer(cs1))
  88. //C.free(unsafe.Pointer(cs2))
  89. //
  90. DllDef := syscall.MustLoadDLL("SSCard.dll")
  91. Iinit := DllDef.MustFindProc("Init")
  92. readCard := DllDef.MustFindProc("ReadCardBas")
  93. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  94. if ret != 0 {
  95. fmt.Println("SSCard的报错原因:", err)
  96. fmt.Println("SSCard的运算结果为:", ret)
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  98. return
  99. }
  100. result := int(ret)
  101. fmt.Println("SSCard的运算结果为1:", result)
  102. //path := ""
  103. //bytePath := []byte( "\x00")
  104. //bytePath2 := []byte( "\x00")
  105. //ssss
  106. str := make([]byte, 256)
  107. str1 := make([]byte, 256)
  108. s2 := []byte(string(str))
  109. s3 := []byte(string(str1))
  110. ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  111. fmt.Println(" Add(4,5)的结果为:", ret2)
  112. fmt.Println(" str:", s2)
  113. fmt.Println(" str1:", s3)
  114. if err2 != nil {
  115. fmt.Println("SSCard的运算结果为:", ret2)
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  117. return
  118. }
  119. //DllDef := syscall.MustLoadDLL("SSCard.dll")
  120. }
  121. func (c *HisApiController) GetOrgInfo() {
  122. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  123. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  124. }
  125. func (c *HisApiController) GetHisPatientInfo() {
  126. medical_insurance_card := c.GetString("medical_insurance_card")
  127. id_card_type, _ := c.GetInt64("id_card_type")
  128. id_card := c.GetString("id_card")
  129. adminInfo := c.GetAdminUserInfo()
  130. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  131. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  132. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  133. IdCardNo := ""
  134. if id_card_type == 1 {
  135. IdCardNo = medical_insurance_card
  136. } else if id_card_type == 2 {
  137. IdCardNo = id_card
  138. }
  139. if config.IsOpen == 1 {
  140. 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
  141. resp, requestErr := http.Get(api)
  142. if requestErr != nil {
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  144. return
  145. }
  146. defer resp.Body.Close()
  147. body, ioErr := ioutil.ReadAll(resp.Body)
  148. if ioErr != nil {
  149. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  151. return
  152. }
  153. var respJSON map[string]interface{}
  154. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  155. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  157. return
  158. }
  159. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  160. userJSONBytes, _ := json.Marshal(userJSON)
  161. var res ResultTwo
  162. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  163. utils.ErrorLog("解析失败:%v", err)
  164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  165. return
  166. }
  167. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  168. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  169. infoStr := string(Iinfos)
  170. idetinfoStr := string(Idetinfos)
  171. if res.Infcode == 0 {
  172. his := models.VMHisPatient{
  173. Status: 1,
  174. Ctime: time.Now().Unix(),
  175. Mtime: time.Now().Unix(),
  176. PsnNo: res.Output.Baseinfo.PsnNo,
  177. PsnCertType: res.Output.Baseinfo.PsnCertType,
  178. Certno: res.Output.Baseinfo.Certno,
  179. PsnName: res.Output.Baseinfo.PsnName,
  180. Gend: res.Output.Baseinfo.Gend,
  181. Naty: res.Output.Baseinfo.Naty,
  182. Brdy: res.Output.Baseinfo.Brdy,
  183. Age: res.Output.Baseinfo.Age,
  184. Iinfo: infoStr,
  185. Idetinfo: idetinfoStr,
  186. UserOrgId: adminInfo.CurrentOrgId,
  187. IsReturn: 1,
  188. IdCardType: id_card_type,
  189. }
  190. c.ServeSuccessJSON(map[string]interface{}{
  191. "info": his,
  192. })
  193. } else {
  194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  195. return
  196. }
  197. }
  198. }
  199. //func (c *HisApiController) Sscard() {
  200. // id_card_type, _ := c.GetInt64("id_card_type")
  201. // adminUser := c.GetAdminUserInfo()
  202. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  203. //
  204. // r := CardInit()
  205. // fmt.Println(r)
  206. // //if r == 0 {
  207. // switch id_card_type {
  208. // case 1:
  209. // basStr, err := GetBasBaseInfo()
  210. //
  211. // if err != nil {
  212. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  213. // return
  214. //
  215. // } else {
  216. // fmt.Println(basStr)
  217. //
  218. // bas := strings.Split(basStr, "|")
  219. //
  220. // basNumber := bas[1]
  221. //
  222. // //basNumber := bas[2]
  223. // card_sn := bas[3]
  224. //
  225. // appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  226. //
  227. // 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
  228. // resp, requestErr := http.Get(api)
  229. // if requestErr != nil {
  230. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  231. // return
  232. // }
  233. // defer resp.Body.Close()
  234. // body, ioErr := ioutil.ReadAll(resp.Body)
  235. // if ioErr != nil {
  236. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  238. // return
  239. // }
  240. // var respJSON map[string]interface{}
  241. //
  242. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  243. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. // return
  246. // }
  247. //
  248. // userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  249. // userJSONBytes, _ := json.Marshal(userJSON)
  250. // var res ResultTwo
  251. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  252. // utils.ErrorLog("解析失败:%v", err)
  253. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  254. // return
  255. // }
  256. // Iinfos, _ := json.Marshal(res.Output.Iinfo)
  257. // Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  258. // infoStr := string(Iinfos)
  259. // idetinfoStr := string(Idetinfos)
  260. //
  261. // if res.Infcode == 0 {
  262. // his := models.VMHisPatient{
  263. // Status: 1,
  264. // Ctime: time.Now().Unix(),
  265. // Mtime: time.Now().Unix(),
  266. // PsnNo: res.Output.Baseinfo.PsnNo,
  267. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  268. // Certno: res.Output.Baseinfo.Certno,
  269. // PsnName: res.Output.Baseinfo.PsnName,
  270. // Gend: res.Output.Baseinfo.Gend,
  271. // Naty: res.Output.Baseinfo.Naty,
  272. // Brdy: res.Output.Baseinfo.Brdy,
  273. // Age: res.Output.Baseinfo.Age,
  274. // Iinfo: infoStr,
  275. // Idetinfo: idetinfoStr,
  276. // UserOrgId: adminUser.CurrentOrgId,
  277. // IsReturn: 1,
  278. // IdCardType: id_card_type,
  279. // }
  280. //
  281. // patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  282. // if err == gorm.ErrRecordNotFound {
  283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  284. // return
  285. //
  286. // } else if err != nil {
  287. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  288. // return
  289. //
  290. // } else {
  291. // c.ServeSuccessJSON(map[string]interface{}{
  292. // "patient": patient,
  293. // "his": his,
  294. // "number": basNumber,
  295. // })
  296. // }
  297. // } else {
  298. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  299. // return
  300. // }
  301. //
  302. // }
  303. //
  304. // break
  305. // case 2:
  306. // ////SFZStr, err := GetSFZBaseInfo()
  307. // //if err != nil {
  308. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  309. // // return
  310. // //
  311. // //} else {
  312. // //
  313. // // id_card_str := strings.Split(SFZStr, "^")
  314. // // id_card_number := id_card_str[0]
  315. // //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  316. // //
  317. // //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)
  318. // //resp, requestErr := http.Get(api)
  319. // //if requestErr != nil {
  320. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  321. // // return
  322. // //}
  323. // //defer resp.Body.Close()
  324. // //body, ioErr := ioutil.ReadAll(resp.Body)
  325. // //if ioErr != nil {
  326. // // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  327. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  328. // // return
  329. // //}
  330. // //var respJSON map[string]interface{}
  331. // //
  332. // //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  333. // // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  334. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  335. // // return
  336. // //}
  337. // //
  338. // //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  339. // //userJSONBytes, _ := json.Marshal(userJSON)
  340. // //var res ResultTwo
  341. // //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  342. // // utils.ErrorLog("解析失败:%v", err)
  343. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  344. // // return
  345. // //}
  346. // //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  347. // //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  348. // //infoStr := string(Iinfos)
  349. // //idetinfoStr := string(Idetinfos)
  350. // //
  351. // //if res.Infcode == 0 {
  352. // // his := models.VMHisPatient{
  353. // // Status: 1,
  354. // // Ctime: time.Now().Unix(),
  355. // // Mtime: time.Now().Unix(),
  356. // // PsnNo: res.Output.Baseinfo.PsnNo,
  357. // // PsnCertType: res.Output.Baseinfo.PsnCertType,
  358. // // Certno: res.Output.Baseinfo.Certno,
  359. // // PsnName: res.Output.Baseinfo.PsnName,
  360. // // Gend: res.Output.Baseinfo.Gend,
  361. // // Naty: res.Output.Baseinfo.Naty,
  362. // // Brdy: res.Output.Baseinfo.Brdy,
  363. // // Age: res.Output.Baseinfo.Age,
  364. // // Iinfo: infoStr,
  365. // // Idetinfo: idetinfoStr,
  366. // // UserOrgId: adminUser.CurrentOrgId,
  367. // // IsReturn: 1,
  368. // // IdCardType: id_card_type,
  369. // // }
  370. //
  371. // // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  372. // // if err == gorm.ErrRecordNotFound {
  373. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  374. // // return
  375. // //
  376. // // } else if err != nil {
  377. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  378. // // return
  379. // //
  380. // // } else {
  381. // // c.ServeSuccessJSON(map[string]interface{}{
  382. // // "patient": patient,
  383. // // "number": id_card_number,
  384. // // })
  385. // // }
  386. // //}
  387. // break
  388. // case 3:
  389. //
  390. // break
  391. //
  392. // }
  393. //}
  394. //func GetBasBaseInfo() (jsonStr string, err error) {
  395. //
  396. // handle, err := syscall.LoadLibrary("SSCard.dll")
  397. // if err != nil {
  398. // fmt.Printf("Error: %s\n", err)
  399. // return "", err
  400. // }
  401. // defer syscall.FreeLibrary(handle)
  402. // str := make([]byte, 256)
  403. // str1 := make([]byte, 256)
  404. // add, err := syscall.GetProcAddress(handle, "ReadCardBas")
  405. // if err != nil {
  406. // fmt.Printf("Error: %s\n", err)
  407. // return "", err
  408. // }
  409. // ret, _, _ := syscall.Syscall(add, (uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  410. // if err != nil {
  411. // fmt.Printf("Error: %s\n", err)
  412. // }
  413. // fmt.Println("> Add(4,5)的结果为:", ret)
  414. // //return nil
  415. //
  416. // //
  417. // //handle := syscall.NewLazyDLL("SSCard.dll")
  418. // //ReadCardBas := handle.NewProc("ReadCardBas")
  419. // //
  420. // //var str2 [1024]C.char
  421. // //var str3 [1024]C.char
  422. // //
  423. // //
  424. // //
  425. // ////sssssswwwww
  426. // ////a := 256
  427. // //
  428. // //r, _, _ := ReadCardBas.Call(&str2, 1024, &str3, 1024)
  429. // //fmt.Println(r)
  430. // ////p := (*byte)(unsafe.Pointer(r))
  431. // // define a slice to fill with the p string
  432. // //data := make([]byte, 0)
  433. //
  434. // // loop until find '\0'
  435. // //if *p != 0 {
  436. // //
  437. // // //data = append(data, *p) // append 1 byte
  438. // // //r += unsafe.Sizeof(byte(0)) // move r to next byte
  439. // // //p = (*byte)(unsafe.Pointer(r)) // get the byte value
  440. // //} else {
  441. // // return "", nil
  442. // //
  443. // //}
  444. //
  445. // return "", nil
  446. //
  447. //}
  448. //func GetSFZBaseInfo() (jsonStr string, err error) {
  449. // //handle := syscall.MustLoadDLL("SSCard.dll")
  450. //
  451. // str := make([]byte, 256)
  452. // str1 := make([]byte, 256)
  453. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  454. //
  455. // fmt.Println(r)
  456. // return string(str), nil
  457. //}
  458. //func GetQRBaseInfo() (jsonStr string, err error) {
  459. // handle := syscall.LoadDLL("SSCard.dll")
  460. // ReadCardBas := handle.FindProc("GetQRBase")
  461. //
  462. // str := make([]byte, 256)
  463. // str1 := make([]byte, 256)
  464. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  465. //
  466. // fmt.Println(string(str))
  467. // fmt.Println(r)
  468. // return string(str), nil
  469. //}
  470. func CardInit() int {
  471. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  472. add := DllTestDef.MustFindProc("Init")
  473. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  474. if err != nil {
  475. fmt.Println("SSCard的运算结果为:", ret)
  476. }
  477. result := int(ret)
  478. return result
  479. }
  480. //func CardInit() int {
  481. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  482. // if err != nil {
  483. // fmt.Println("SSCard的运算结果为:", ret)
  484. // }
  485. // fmt.Println(err)
  486. // result := int(ret)
  487. // return result
  488. //}
  489. func IntPtr(n int) uintptr {
  490. return uintptr(n)
  491. }
  492. func StrPtr(s string) uintptr {
  493. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  494. }
  495. type ResultTwo struct {
  496. ErrMsg string `json:"err_msg"`
  497. InfRefmsgid string `json:"inf_refmsgid"`
  498. Infcode int64 `json:"infcode"`
  499. Output struct {
  500. Baseinfo struct {
  501. Age float64 `json:"age"`
  502. Brdy string `json:"brdy"`
  503. Certno string `json:"certno"`
  504. Gend string `json:"gend"`
  505. Naty string `json:"naty"`
  506. PsnCertType string `json:"psn_cert_type"`
  507. PsnName string `json:"psn_name"`
  508. PsnNo string `json:"psn_no"`
  509. } `json:"baseinfo"`
  510. Idetinfo []interface{} `json:"idetinfo"`
  511. Iinfo []struct {
  512. Balc int64 `json:"balc"`
  513. CvlservFlag string `json:"cvlserv_flag"`
  514. EmpName string `json:"emp_name"`
  515. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  516. Insutype string `json:"insutype"`
  517. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  518. PausInsuDate interface{} `json:"paus_insu_date"`
  519. PsnInsuDate string `json:"psn_insu_date"`
  520. PsnInsuStas string `json:"psn_insu_stas"`
  521. PsnType string `json:"psn_type"`
  522. } `json:"insuinfo"`
  523. } `json:"output"`
  524. RefmsgTime string `json:"refmsg_time"`
  525. RespondTime string `json:"respond_time"`
  526. Signtype interface{} `json:"signtype"`
  527. WarnInfo interface{} `json:"warn_info"`
  528. }
  529. type ResultThree struct {
  530. Cainfo interface{} `json:"cainfo"`
  531. ErrMsg string `json:"err_msg"`
  532. InfRefmsgid string `json:"inf_refmsgid"`
  533. Infcode int64 `json:"infcode"`
  534. Output struct {
  535. Data struct {
  536. IptOtpNo string `json:"ipt_otp_no"`
  537. MdtrtID string `json:"mdtrt_id"`
  538. PsnNo string `json:"psn_no"`
  539. } `json:"data"`
  540. } `json:"output"`
  541. RefmsgTime string `json:"refmsg_time"`
  542. RespondTime string `json:"respond_time"`
  543. Signtype interface{} `json:"signtype"`
  544. WarnMsg interface{} `json:"warn_msg"`
  545. }
  546. type ResultFour struct {
  547. Cainfo string `json:"cainfo"`
  548. ErrMsg string `json:"err_msg"`
  549. InfRefmsgid string `json:"inf_refmsgid"`
  550. Infcode int64 `json:"infcode"`
  551. Output struct {
  552. Result []struct {
  553. BasMednFlag string `json:"bas_medn_flag"`
  554. ChldMedcFlag string `json:"chld_medc_flag"`
  555. ChrgitmLv string `json:"chrgitm_lv"`
  556. Cnt float64 `json:"cnt"`
  557. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  558. DrtReimFlag string `json:"drt_reim_flag"`
  559. FeedetlSn string `json:"feedetl_sn"`
  560. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  561. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  562. InscpScpAmt float64 `json:"inscp_scp_amt"`
  563. ListSpItemFlag string `json:"list_sp_item_flag"`
  564. LmtUsedFlag string `json:"lmt_used_flag"`
  565. MedChrgitmType string `json:"med_chrgitm_type"`
  566. Memo string `json:"memo"`
  567. OverlmtAmt float64 `json:"overlmt_amt"`
  568. PreselfpayAmt float64 `json:"preselfpay_amt"`
  569. Pric float64 `json:"pric"`
  570. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  571. SelfpayProp float64 `json:"selfpay_prop"`
  572. } `json:"result"`
  573. } `json:"output"`
  574. RefmsgTime string `json:"refmsg_time"`
  575. RespondTime string `json:"respond_time"`
  576. Signtype string `json:"signtype"`
  577. WarnMsg string `json:"warn_msg"`
  578. }
  579. type ResultFive struct {
  580. Insutype string `json:"insutype"`
  581. }
  582. type ResultSix struct {
  583. Cainfo interface{} `json:"cainfo"`
  584. ErrMsg string `json:"err_msg"`
  585. InfRefmsgid string `json:"inf_refmsgid"`
  586. Infcode int64 `json:"infcode"`
  587. Output struct {
  588. } `json:"output"`
  589. RefmsgTime string `json:"refmsg_time"`
  590. RespondTime string `json:"respond_time"`
  591. Signtype interface{} `json:"signtype"`
  592. WarnMsg interface{} `json:"warn_msg"`
  593. }
  594. type ResultSeven struct {
  595. Cainfo string `json:"cainfo"`
  596. ErrMsg string `json:"err_msg"`
  597. InfRefmsgid string `json:"inf_refmsgid"`
  598. Infcode int64 `json:"infcode"`
  599. Output struct {
  600. Setldetail []interface{} `json:"setldetail"`
  601. Setlinfo struct {
  602. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  603. AcctPay float64 `json:"acct_pay"`
  604. ActPayDedc float64 `json:"act_pay_dedc"`
  605. Age float64 `json:"age"`
  606. Balc float64 `json:"balc"`
  607. Brdy string `json:"brdy"`
  608. Certno string `json:"certno"`
  609. ClrOptins string `json:"clr_optins"`
  610. ClrType string `json:"clr_type"`
  611. ClrWay string `json:"clr_way"`
  612. CvlservFlag string `json:"cvlserv_flag"`
  613. CvlservPay float64 `json:"cvlserv_pay"`
  614. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  615. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  616. Gend string `json:"gend"`
  617. HifesPay float64 `json:"hifes_pay"`
  618. HifmiPay float64 `json:"hifmi_pay"`
  619. HifpPay float64 `json:"hifp_pay"`
  620. HospPartAmt float64 `json:"hosp_part_amt"`
  621. InscpScpAmt float64 `json:"inscp_scp_amt"`
  622. Insutype string `json:"insutype"`
  623. MafPay float64 `json:"maf_pay"`
  624. MdtrtCertType string `json:"mdtrt_cert_type"`
  625. HifobPay float64 `json:"hifob_pay"`
  626. MdtrtID string `json:"mdtrt_id"`
  627. MedType string `json:"med_type"`
  628. MedfeeSumamt float64 `json:"medfee_sumamt"`
  629. MedinsSetlID string `json:"medins_setl_id"`
  630. Naty string `json:"naty"`
  631. OthPay float64 `json:"oth_pay"`
  632. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  633. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  634. PreselfpayAmt float64 `json:"preselfpay_amt"`
  635. PsnCashPay float64 `json:"psn_cash_pay"`
  636. PsnCertType string `json:"psn_cert_type"`
  637. PsnName string `json:"psn_name"`
  638. PsnNo string `json:"psn_no"`
  639. PsnPartAmt float64 `json:"psn_part_amt"`
  640. PsnType string `json:"psn_type"`
  641. SetlID string `json:"setl_id"`
  642. SetlTime string `json:"setl_time"`
  643. } `json:"setlinfo"`
  644. } `json:"output"`
  645. RefmsgTime string `json:"refmsg_time"`
  646. RespondTime string `json:"respond_time"`
  647. Signtype interface{} `json:"signtype"`
  648. WarnMsg interface{} `json:"warn_msg"`
  649. }
  650. type ResultEight struct {
  651. Cainfo string `json:"cainfo"`
  652. ErrMsg string `json:"err_msg"`
  653. InfRefmsgid string `json:"inf_refmsgid"`
  654. Infcode int64 `json:"infcode"`
  655. Output struct {
  656. Stmtinfo struct {
  657. SetlOptins string `json:"setl_optins"`
  658. StmtRslt string `json:"stmt_rslt"`
  659. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  660. } `json:"stmtinfo"`
  661. } `json:"output"`
  662. RefmsgTime string `json:"refmsg_time"`
  663. RespondTime string `json:"respond_time"`
  664. Signtype interface{} `json:"signtype"`
  665. WarnMsg interface{} `json:"warn_msg"`
  666. }
  667. type ResultNine struct {
  668. Cainfo string `json:"cainfo"`
  669. ErrMsg string `json:"err_msg"`
  670. InfRefmsgid string `json:"inf_refmsgid"`
  671. Infcode int64 `json:"infcode"`
  672. Output struct {
  673. FileQuryNo string `json:"file_qury_no"`
  674. } `json:"output"`
  675. RefmsgTime string `json:"refmsg_time"`
  676. RespondTime string `json:"respond_time"`
  677. Signtype interface{} `json:"signtype"`
  678. WarnMsg interface{} `json:"warn_msg"`
  679. }
  680. type ResultTen struct {
  681. Cainfo string `json:"cainfo"`
  682. ErrMsg string `json:"err_msg"`
  683. InfRefmsgid string `json:"inf_refmsgid"`
  684. Infcode int64 `json:"infcode"`
  685. Output struct {
  686. DldEndtime string `json:"dld_endtime"`
  687. FileQuryNo string `json:"file_qury_no"`
  688. Filename string `json:"filename"`
  689. } `json:"output"`
  690. RefmsgTime string `json:"refmsg_time"`
  691. RespondTime string `json:"respond_time"`
  692. Signtype interface{} `json:"signtype"`
  693. WarnMsg interface{} `json:"warn_msg"`
  694. }
  695. type ResultEleven struct {
  696. Cainfo string `json:"cainfo"`
  697. ErrMsg string `json:"err_msg"`
  698. InfRefmsgid string `json:"inf_refmsgid"`
  699. Infcode int64 `json:"infcode"`
  700. Output struct {
  701. Setlinfo struct {
  702. FixmedinsName string `json:"fixmedins_name"`
  703. FixmedinsCode string `json:"fixmedins_code"`
  704. PsnNo string `json:"psn_no"`
  705. PsnName string `json:"psn_name"`
  706. HifobPay float64 `json:"hifob_pay"`
  707. Gend string `json:"gend"`
  708. Brdy string `json:"brdy"`
  709. PsnCertType string `json:"psn_cert_type"`
  710. PsnType string `json:"psn_type"`
  711. EmpName string `json:"emp_name"`
  712. Certno string `json:"certno"`
  713. Insutype string `json:"insutype"`
  714. MedfeeSumamt float64 `json:"medfee_sumamt"`
  715. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  716. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  717. PreselfpayAmt float64 `json:"preselfpay_amt"`
  718. InscpScpAmt float64 `json:"inscp_scp_amt"`
  719. ActPayDedc float64 `json:"act_pay_dedc"`
  720. HifpPay float64 `json:"hifp_pay"`
  721. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  722. CvlservPay float64 `json:"cvlserv_pay"`
  723. HifesPay float64 `json:"hifes_pay"`
  724. HifmiPay float64 `json:"hifmi_pay"`
  725. MafPay float64 `json:"maf_pay"`
  726. OthPay float64 `json:"oth_pay"`
  727. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  728. PsnPay float64 `json:"psn_pay"`
  729. AcctPay float64 `json:"acct_pay"`
  730. CashPayamt float64 `json:"cash_payamt"`
  731. Balc float64 `json:"balc"`
  732. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  733. MedinsSetlId string `json:"medins_setl_id"`
  734. RefdSetlFlag string `json:"refd_setl_flag"`
  735. SetlTime string `json:"setl_time"`
  736. MedType string `json:"med_type"`
  737. HospLv string `json:"hosp_lv"`
  738. } `json:"setlinfo"`
  739. } `json:"output"`
  740. RefmsgTime string `json:"refmsg_time"`
  741. RespondTime string `json:"respond_time"`
  742. Signtype interface{} `json:"signtype"`
  743. WarnMsg interface{} `json:"warn_msg"`
  744. }
  745. type ResultTwelve struct {
  746. Cainfo string `json:"cainfo"`
  747. ErrMsg string `json:"err_msg"`
  748. InfRefmsgid string `json:"inf_refmsgid"`
  749. Infcode int64 `json:"infcode"`
  750. Output struct {
  751. MdtrtId string `json:"mdtrt_id"`
  752. ChrgBchno string `json:"chrg_bchno"`
  753. PsnNo string `json:"psn_no"`
  754. } `json:"output"`
  755. RefmsgTime string `json:"refmsg_time"`
  756. RespondTime string `json:"respond_time"`
  757. Signtype interface{} `json:"signtype"`
  758. WarnMsg interface{} `json:"warn_msg"`
  759. }
  760. type Custom struct {
  761. DetItemFeeSumamt string
  762. Cut string
  763. FeedetlSn string
  764. Price string
  765. MedListCodg string
  766. Type int64
  767. AdviceId int64
  768. ProjectId int64
  769. ItemId int64
  770. }
  771. //获取个人信息----挂号-----上传就诊信息
  772. func (c *HisApiController) GetRegisterInfo() {
  773. id, _ := c.GetInt64("id")
  774. record_time := c.GetString("record_time")
  775. settlementValue, _ := c.GetInt64("settlement_value")
  776. medical_insurance_card := c.GetString("medical_insurance_card")
  777. name := c.GetString("name")
  778. id_card_type, _ := c.GetInt64("id_card_type")
  779. certificates, _ := c.GetInt64("certificates")
  780. medical_care, _ := c.GetInt64("medical_care")
  781. birthday := c.GetString("birthday")
  782. age, _ := c.GetInt64("age")
  783. id_card := c.GetString("id_card")
  784. register_type, _ := c.GetInt64("register")
  785. doctor, _ := c.GetInt64("doctor")
  786. department, _ := c.GetInt64("department")
  787. gender, _ := c.GetInt64("sex")
  788. phone := c.GetString("phone")
  789. registration_fee, _ := c.GetFloat("registration_fee")
  790. medical_expenses, _ := c.GetFloat("medical_expenses")
  791. social_type, _ := c.GetInt64("social_type")
  792. admin_user_id, _ := c.GetInt64("admin_user_id")
  793. diagnosis_id, _ := c.GetInt64("diagnosis")
  794. sick_type, _ := c.GetInt64("sick_type")
  795. reg_type := c.GetString("p_type")
  796. timeLayout := "2006-01-02"
  797. loc, _ := time.LoadLocation("Local")
  798. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  799. birthUnix := birthdays.Unix()
  800. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  801. if err != nil {
  802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  803. return
  804. }
  805. recordDateTime := theTime.Unix()
  806. adminInfo := c.GetAdminUserInfo()
  807. var patient service.Patients
  808. if id == 0 {
  809. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  810. } else {
  811. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  812. }
  813. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  814. if patientPrescription.ID == 0 {
  815. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  816. }
  817. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  818. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  819. sickConfig, _ := service.FindSickById(sick_type)
  820. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  821. if patient.ID == 0 {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  823. return
  824. }
  825. if len(patient.IdCardNo) == 0 {
  826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  827. return
  828. }
  829. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  830. if config.IsOpen == 1 {
  831. 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
  832. resp, requestErr := http.Get(api)
  833. if requestErr != nil {
  834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  835. return
  836. }
  837. defer resp.Body.Close()
  838. body, ioErr := ioutil.ReadAll(resp.Body)
  839. if ioErr != nil {
  840. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  842. return
  843. }
  844. var respJSON map[string]interface{}
  845. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  846. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  848. return
  849. }
  850. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  851. userJSONBytes, _ := json.Marshal(userJSON)
  852. var res ResultTwo
  853. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  854. utils.ErrorLog("解析失败:%v", err)
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  856. return
  857. }
  858. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  859. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  860. infoStr := string(Iinfos)
  861. idetinfoStr := string(Idetinfos)
  862. if res.Infcode == 0 {
  863. his := models.VMHisPatient{
  864. Name: name,
  865. Gender: gender,
  866. Birthday: birthUnix,
  867. MedicalTreatmentType: medical_care,
  868. IdType: certificates,
  869. IdCardNo: id_card,
  870. BalanceAccountsType: settlementValue,
  871. SocialType: social_type,
  872. MedicalInsuranceNumber: medical_insurance_card,
  873. RegisterType: register_type,
  874. RegisterCost: registration_fee,
  875. TreatmentCost: medical_expenses,
  876. Status: 1,
  877. Ctime: time.Now().Unix(),
  878. Mtime: time.Now().Unix(),
  879. PsnNo: res.Output.Baseinfo.PsnNo,
  880. PsnCertType: res.Output.Baseinfo.PsnCertType,
  881. Certno: res.Output.Baseinfo.Certno,
  882. PsnName: res.Output.Baseinfo.PsnName,
  883. Gend: res.Output.Baseinfo.Gend,
  884. Naty: res.Output.Baseinfo.Naty,
  885. Brdy: res.Output.Baseinfo.Brdy,
  886. Age: res.Output.Baseinfo.Age,
  887. Iinfo: infoStr,
  888. Idetinfo: idetinfoStr,
  889. PatientId: patient.ID,
  890. RecordDate: theTime.Unix(),
  891. UserOrgId: adminInfo.CurrentOrgId,
  892. AdminUserId: admin_user_id,
  893. IsReturn: 1,
  894. IdCardType: id_card_type,
  895. Doctor: doctor,
  896. Departments: department,
  897. }
  898. timestamp := time.Now().Unix()
  899. tempTime := time.Unix(timestamp, 0)
  900. timeFormat := tempTime.Format("20060102150405")
  901. chrgBchno := rand.Intn(100000) + 10000
  902. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  903. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  904. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  905. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  906. IdCardNo := ""
  907. if id_card_type == 1 {
  908. IdCardNo = medical_insurance_card
  909. } else {
  910. IdCardNo = patient.IdCardNo
  911. }
  912. if count <= 0 {
  913. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  914. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  915. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  916. "&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)
  917. resp, requestErr := http.Get(api)
  918. if requestErr != nil {
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  920. return
  921. }
  922. defer resp.Body.Close()
  923. body, ioErr := ioutil.ReadAll(resp.Body)
  924. if ioErr != nil {
  925. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  927. return
  928. }
  929. var respJSON map[string]interface{}
  930. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  931. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  933. return
  934. }
  935. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  936. userJSONBytes, _ := json.Marshal(respJSON)
  937. var res ResultThree
  938. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  939. utils.ErrorLog("解析失败:%v", err)
  940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  941. return
  942. }
  943. if res.Infcode == -1 {
  944. adminUser := c.GetAdminUserInfo()
  945. errlog := &models.HisOrderError{
  946. UserOrgId: adminUser.CurrentOrgId,
  947. Ctime: time.Now().Unix(),
  948. Mtime: time.Now().Unix(),
  949. ErrMsg: res.ErrMsg,
  950. Status: 1,
  951. PatientId: id,
  952. RecordTime: recordDateTime,
  953. Stage: 2,
  954. }
  955. service.CreateErrMsgLog(errlog)
  956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  957. return
  958. }
  959. his.Number = res.Output.Data.MdtrtID
  960. his.PsnNo = res.Output.Data.PsnNo
  961. his.IptOtpNo = res.Output.Data.IptOtpNo
  962. his.IdCardNo = patient.IdCardNo
  963. his.PhoneNumber = patient.Phone
  964. his.UserOrgId = adminInfo.CurrentOrgId
  965. his.Ctime = time.Now().Unix()
  966. his.Mtime = time.Now().Unix()
  967. his.Status = 1
  968. err := service.CreateHisPatientTwo(&his)
  969. if err == nil {
  970. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  971. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  972. "&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 +
  973. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  974. resp2, requestErr2 := http.Get(api2)
  975. if requestErr2 != nil {
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  977. return
  978. }
  979. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  980. if ioErr2 != nil {
  981. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  983. return
  984. }
  985. var respJSON2 map[string]interface{}
  986. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  987. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  989. return
  990. }
  991. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  992. userJSONBytes2, _ := json.Marshal(respJSON2)
  993. var res2 ResultSix
  994. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  995. utils.ErrorLog("解析失败:%v", err)
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  997. return
  998. }
  999. if res2.Infcode == -1 {
  1000. adminUser := c.GetAdminUserInfo()
  1001. errlog := &models.HisOrderError{
  1002. UserOrgId: adminUser.CurrentOrgId,
  1003. Ctime: time.Now().Unix(),
  1004. Mtime: time.Now().Unix(),
  1005. ErrMsg: res2.ErrMsg,
  1006. Status: 1,
  1007. PatientId: id,
  1008. RecordTime: recordDateTime,
  1009. Stage: 3,
  1010. }
  1011. service.CreateErrMsgLog(errlog)
  1012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  1013. return
  1014. }
  1015. c.ServeSuccessJSON(map[string]interface{}{
  1016. "his_info": his,
  1017. })
  1018. } else {
  1019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1020. return
  1021. }
  1022. } else {
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1024. return
  1025. }
  1026. } else {
  1027. adminUser := c.GetAdminUserInfo()
  1028. errlog := &models.HisOrderError{
  1029. UserOrgId: adminUser.CurrentOrgId,
  1030. Ctime: time.Now().Unix(),
  1031. Mtime: time.Now().Unix(),
  1032. ErrMsg: res.ErrMsg,
  1033. Status: 1,
  1034. PatientId: id,
  1035. RecordTime: recordDateTime,
  1036. Stage: 1,
  1037. }
  1038. service.CreateErrMsgLog(errlog)
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1040. return
  1041. }
  1042. } else {
  1043. timeStr := time.Now().Format("2006-01-02")
  1044. timeArr := strings.Split(timeStr, "-")
  1045. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1046. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1047. var hisPatient models.XtHisPatient
  1048. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1049. hisPatient = models.XtHisPatient{
  1050. Name: name,
  1051. Age: age,
  1052. Gender: gender,
  1053. Birthday: birthUnix,
  1054. Phone: phone,
  1055. MedicalTreatmentType: medical_care,
  1056. IdType: certificates,
  1057. IdCardNo: id_card,
  1058. BalanceAccountsType: settlementValue,
  1059. SocialType: social_type,
  1060. MedicalInsuranceNumber: medical_insurance_card,
  1061. RegisterType: register_type,
  1062. RegisterCost: registration_fee,
  1063. TreatmentCost: medical_expenses,
  1064. AdminUserId: admin_user_id,
  1065. UserOrgId: adminInfo.CurrentOrgId,
  1066. Status: 1,
  1067. RecordDate: recordDateTime,
  1068. IsReturn: 1,
  1069. PatientId: patient.ID,
  1070. Ctime: time.Now().Unix(),
  1071. Mtime: time.Now().Unix(),
  1072. Number: str,
  1073. }
  1074. service.CreateHisPatient(&hisPatient)
  1075. }
  1076. c.ServeSuccessJSON(map[string]interface{}{
  1077. "his_info": hisPatient,
  1078. })
  1079. }
  1080. }
  1081. //上传明细----预结算----确认订单
  1082. func (c *HisApiController) GetUploadInfo() {
  1083. id, _ := c.GetInt64("id")
  1084. record_time := c.GetString("record_time")
  1085. pay_way, _ := c.GetInt64("pay_way")
  1086. pay_price, _ := c.GetFloat("pay_price")
  1087. pay_card_no := c.GetString("pay_card_no")
  1088. discount_price, _ := c.GetFloat("discount_price")
  1089. preferential_price, _ := c.GetFloat("preferential_price")
  1090. reality_price, _ := c.GetFloat("reality_price")
  1091. found_price, _ := c.GetFloat("found_price")
  1092. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1093. private_price, _ := c.GetFloat("private_price")
  1094. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1095. admin_user_id, _ := c.GetInt64("admin_user_id")
  1096. timeLayout := "2006-01-02"
  1097. loc, _ := time.LoadLocation("Local")
  1098. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1099. if err != nil {
  1100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1101. return
  1102. }
  1103. recordDateTime := theTime.Unix()
  1104. adminUser := c.GetAdminUserInfo()
  1105. var prescriptions []*models.HisPrescription
  1106. var start_time int64
  1107. var end_time int64
  1108. data := make(map[string]interface{})
  1109. if settle_accounts_type == 1 { //日结
  1110. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1111. data["pre"] = prescriptions
  1112. } else { //月结
  1113. start_time_str := c.GetString("start_time")
  1114. end_time_str := c.GetString("end_time")
  1115. timeLayout := "2006-01-02"
  1116. loc, _ := time.LoadLocation("Local")
  1117. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1118. if err != nil {
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1120. return
  1121. }
  1122. recordStartTime := theStartTime.Unix()
  1123. start_time = recordStartTime
  1124. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1125. if err != nil {
  1126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1127. return
  1128. }
  1129. recordEndTime := theEndTime.Unix()
  1130. end_time = recordEndTime
  1131. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1132. data["pre"] = prescriptions
  1133. }
  1134. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1135. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1136. timestamp := time.Now().Unix()
  1137. tempTime := time.Unix(timestamp, 0)
  1138. timeFormat := tempTime.Format("20060102150405")
  1139. chrgBchno := rand.Intn(100000) + 10000
  1140. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1141. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1142. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1143. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1144. strconv.FormatInt(his.PatientId, 10)
  1145. client := &http.Client{}
  1146. data["psn_no"] = his.PsnNo
  1147. data["mdtrt_id"] = his.Number
  1148. data["chrg_bchno"] = chrg_bchno
  1149. data["org_name"] = miConfig.OrgName
  1150. data["doctor"] = roles.UserName
  1151. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1152. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1153. data["fixmedins_code"] = miConfig.Code
  1154. if department.ID == 0 && adminUser.CurrentOrgId == 9919 {
  1155. data["dept_code"] = "15"
  1156. } else {
  1157. data["dept_code"] = department.Number
  1158. }
  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) GetPreUploadInfo() {
  1596. id, _ := c.GetInt64("id")
  1597. record_time := c.GetString("record_time")
  1598. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1599. admin_user_id, _ := c.GetInt64("admin_user_id")
  1600. timeLayout := "2006-01-02"
  1601. loc, _ := time.LoadLocation("Local")
  1602. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1603. if err != nil {
  1604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1605. return
  1606. }
  1607. recordDateTime := theTime.Unix()
  1608. adminUser := c.GetAdminUserInfo()
  1609. var prescriptions []*models.HisPrescription
  1610. var start_time int64
  1611. var end_time int64
  1612. data := make(map[string]interface{})
  1613. if settle_accounts_type == 1 { //日结
  1614. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1615. data["pre"] = prescriptions
  1616. } else { //月结
  1617. start_time_str := c.GetString("start_time")
  1618. end_time_str := c.GetString("end_time")
  1619. timeLayout := "2006-01-02"
  1620. loc, _ := time.LoadLocation("Local")
  1621. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1622. if err != nil {
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. recordStartTime := theStartTime.Unix()
  1627. start_time = recordStartTime
  1628. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1629. if err != nil {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1631. return
  1632. }
  1633. recordEndTime := theEndTime.Unix()
  1634. end_time = recordEndTime
  1635. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1636. data["pre"] = prescriptions
  1637. }
  1638. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1639. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1640. timestamp := time.Now().Unix()
  1641. tempTime := time.Unix(timestamp, 0)
  1642. timeFormat := tempTime.Format("20060102150405")
  1643. chrgBchno := rand.Intn(100000) + 10000
  1644. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1645. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1646. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1647. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1648. strconv.FormatInt(his.PatientId, 10)
  1649. client := &http.Client{}
  1650. data["psn_no"] = his.PsnNo
  1651. data["mdtrt_id"] = his.Number
  1652. data["chrg_bchno"] = chrg_bchno
  1653. data["org_name"] = miConfig.OrgName
  1654. data["doctor"] = roles.UserName
  1655. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1656. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1657. data["fixmedins_code"] = miConfig.Code
  1658. data["dept_code"] = department.Number
  1659. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1660. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1661. data["secret_key"] = miConfig.SecretKey
  1662. var ids []int64
  1663. for _, item := range prescriptions {
  1664. ids = append(ids, item.ID)
  1665. }
  1666. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1667. if config.IsOpen == 1 { //对接了医保,走医保流程
  1668. bytesData, _ := json.Marshal(data)
  1669. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1670. resp, _ := client.Do(req)
  1671. defer resp.Body.Close()
  1672. body, ioErr := ioutil.ReadAll(resp.Body)
  1673. if ioErr != nil {
  1674. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1676. return
  1677. }
  1678. var respJSON map[string]interface{}
  1679. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1680. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1682. return
  1683. }
  1684. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1685. userJSONBytes, _ := json.Marshal(respJSON)
  1686. var res ResultFour
  1687. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1688. utils.ErrorLog("解析失败:%v", err)
  1689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1690. return
  1691. }
  1692. if res.Infcode == 0 {
  1693. order := &models.HisOrder{
  1694. UserOrgId: adminUser.CurrentOrgId,
  1695. HisPatientId: his.ID,
  1696. PatientId: his.PatientId,
  1697. SettleAccountsDate: recordDateTime,
  1698. Ctime: time.Now().Unix(),
  1699. Mtime: time.Now().Unix(),
  1700. Status: 1,
  1701. Number: chrg_bchno,
  1702. Infcode: res.Infcode,
  1703. WarnMsg: res.WarnMsg,
  1704. Cainfo: res.Cainfo,
  1705. ErrMsg: res.ErrMsg,
  1706. RespondTime: res.RefmsgTime,
  1707. InfRefmsgid: res.InfRefmsgid,
  1708. OrderStatus: 1,
  1709. IsMedicineInsurance: 1,
  1710. SettleType: settle_accounts_type,
  1711. SettleStartTime: start_time,
  1712. SettleEndTime: end_time,
  1713. Creator: roles.ID,
  1714. Modify: roles.ID,
  1715. }
  1716. err = service.CreateOrder(order)
  1717. if err != nil {
  1718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1719. return
  1720. }
  1721. for _, item := range res.Output.Result {
  1722. temp := strings.Split(item.FeedetlSn, "-")
  1723. var advice_id int64 = 0
  1724. var project_id int64 = 0
  1725. var types int64 = 0
  1726. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1727. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1728. if temp[1] == "1" {
  1729. advice_id = id
  1730. project_id = 0
  1731. } else if temp[1] == "2" {
  1732. advice_id = 0
  1733. project_id = id
  1734. }
  1735. info := &models.HisOrderInfo{
  1736. OrderNumber: order.Number,
  1737. FeedetlSn: item.FeedetlSn,
  1738. UploadDate: time.Now().Unix(),
  1739. AdviceId: advice_id,
  1740. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1741. Cnt: item.Cnt,
  1742. Pric: float64(item.Pric),
  1743. PatientId: his.PatientId,
  1744. PricUplmtAmt: item.PricUplmtAmt,
  1745. SelfpayProp: item.SelfpayProp,
  1746. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1747. OverlmtAmt: item.OverlmtAmt,
  1748. PreselfpayAmt: item.PreselfpayAmt,
  1749. BasMednFlag: item.BasMednFlag,
  1750. MedChrgitmType: item.MedChrgitmType,
  1751. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1752. Status: 1,
  1753. Memo: item.Memo,
  1754. Mtime: time.Now().Unix(),
  1755. InscpScpAmt: item.InscpScpAmt,
  1756. DrtReimFlag: item.DrtReimFlag,
  1757. Ctime: time.Now().Unix(),
  1758. ListSpItemFlag: item.ListSpItemFlag,
  1759. ChldMedcFlag: item.ChldMedcFlag,
  1760. LmtUsedFlag: item.LmtUsedFlag,
  1761. ChrgitmLv: item.ChrgitmLv,
  1762. UserOrgId: adminUser.CurrentOrgId,
  1763. HisPatientId: his.ID,
  1764. OrderId: order.ID,
  1765. ProjectId: project_id,
  1766. Type: types,
  1767. }
  1768. service.CreateOrderInfo(info)
  1769. }
  1770. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1771. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1772. var total float64
  1773. for _, item := range prescriptions {
  1774. if item.Type == 1 { //药品
  1775. for _, subItem := range item.HisDoctorAdviceInfo {
  1776. total = total + (subItem.Price * subItem.PrescribingNumber)
  1777. }
  1778. }
  1779. if item.Type == 2 { //项目
  1780. for _, subItem := range item.HisPrescriptionProject {
  1781. total = total + (subItem.Price * float64(subItem.Count))
  1782. }
  1783. }
  1784. }
  1785. for _, item := range prescriptions {
  1786. for _, subItem := range item.HisAdditionalCharge {
  1787. total = total + (subItem.Price * float64(subItem.Count))
  1788. }
  1789. }
  1790. allTotal := fmt.Sprintf("%.2f", total)
  1791. if res.Infcode == 0 {
  1792. var rf []*ResultFive
  1793. json.Unmarshal([]byte(his.Iinfo), &rf)
  1794. psn_no := his.PsnNo
  1795. mdtrt_id := his.Number
  1796. chrg_bchno := chrg_bchno
  1797. cert_no := his.Certno
  1798. insutype := rf[0].Insutype
  1799. if his.IdCardType == 1 {
  1800. cert_no = his.MedicalInsuranceNumber
  1801. } else {
  1802. cert_no = his.Certno
  1803. }
  1804. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  1805. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1806. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1807. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1808. resp, requestErr := http.Get(api)
  1809. if requestErr != nil {
  1810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1811. return
  1812. }
  1813. defer resp.Body.Close()
  1814. body, ioErr := ioutil.ReadAll(resp.Body)
  1815. if ioErr != nil {
  1816. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1818. return
  1819. }
  1820. var respJSON map[string]interface{}
  1821. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1822. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1824. return
  1825. }
  1826. fmt.Println(respJSON)
  1827. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1828. userJSONBytes, _ := json.Marshal(respJSON)
  1829. var res ResultSeven
  1830. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1831. utils.ErrorLog("解析失败:%v", err)
  1832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1833. return
  1834. }
  1835. if res.Infcode == -1 {
  1836. errlog := &models.HisOrderError{
  1837. UserOrgId: adminUser.CurrentOrgId,
  1838. Ctime: time.Now().Unix(),
  1839. Mtime: time.Now().Unix(),
  1840. Number: chrg_bchno,
  1841. ErrMsg: res.ErrMsg,
  1842. Status: 1,
  1843. PatientId: id,
  1844. RecordTime: recordDateTime,
  1845. Stage: 7,
  1846. }
  1847. service.CreateErrMsgLog(errlog)
  1848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1849. return
  1850. } else {
  1851. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1852. order.OrderStatus = 1
  1853. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1854. order.SetlId = res.Output.Setlinfo.SetlID
  1855. order.PsnNo = res.Output.Setlinfo.PsnNo
  1856. order.PsnName = res.Output.Setlinfo.PsnName
  1857. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1858. order.Certno = res.Output.Setlinfo.Certno
  1859. order.Gend = res.Output.Setlinfo.Gend
  1860. order.Naty = res.Output.Setlinfo.Naty
  1861. order.Age = res.Output.Setlinfo.Age
  1862. order.Insutype = res.Output.Setlinfo.Insutype
  1863. order.PsnType = res.Output.Setlinfo.PsnType
  1864. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1865. order.SetlTime = res.Output.Setlinfo.SetlTime
  1866. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1867. order.MedType = res.Output.Setlinfo.MedType
  1868. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1869. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1870. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1871. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1872. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1873. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1874. order.HifpPay = res.Output.Setlinfo.HifpPay
  1875. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1876. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1877. order.HifesPay = res.Output.Setlinfo.HifesPay
  1878. order.HifobPay = res.Output.Setlinfo.HifobPay
  1879. order.MafPay = res.Output.Setlinfo.MafPay
  1880. order.OthPay = res.Output.Setlinfo.OthPay
  1881. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1882. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1883. order.AcctPay = res.Output.Setlinfo.AcctPay
  1884. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1885. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1886. order.Balc = res.Output.Setlinfo.Balc
  1887. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1888. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1889. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1890. order.ClrWay = res.Output.Setlinfo.ClrWay
  1891. order.Creator = order.Creator
  1892. order.Modify = roles.ID
  1893. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1894. detailStr := string(setlDetail)
  1895. order.SetlDetail = detailStr
  1896. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1897. err = service.UpDateOrder(order)
  1898. if err == nil {
  1899. c.ServeSuccessJSON(map[string]interface{}{
  1900. "msg": "预结算成功",
  1901. })
  1902. } else {
  1903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1904. return
  1905. }
  1906. }
  1907. } else {
  1908. adminUser := c.GetAdminUserInfo()
  1909. errlog := &models.HisOrderError{
  1910. UserOrgId: adminUser.CurrentOrgId,
  1911. Ctime: time.Now().Unix(),
  1912. Mtime: time.Now().Unix(),
  1913. ErrMsg: res.ErrMsg,
  1914. Status: 1,
  1915. PatientId: id,
  1916. RecordTime: recordDateTime,
  1917. Stage: 4,
  1918. }
  1919. service.CreateErrMsgLog(errlog)
  1920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1921. return
  1922. }
  1923. } else {
  1924. adminUser := c.GetAdminUserInfo()
  1925. errlog := &models.HisOrderError{
  1926. UserOrgId: adminUser.CurrentOrgId,
  1927. Ctime: time.Now().Unix(),
  1928. Mtime: time.Now().Unix(),
  1929. ErrMsg: res.ErrMsg,
  1930. Status: 1,
  1931. PatientId: id,
  1932. RecordTime: recordDateTime,
  1933. Stage: 4,
  1934. }
  1935. service.CreateErrMsgLog(errlog)
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1937. return
  1938. }
  1939. } else {
  1940. var total float64
  1941. for _, item := range prescriptions {
  1942. if item.Type == 1 { //药品
  1943. for _, subItem := range item.HisDoctorAdviceInfo {
  1944. total = total + (subItem.Price * subItem.PrescribingNumber)
  1945. }
  1946. }
  1947. if item.Type == 2 { //项目
  1948. for _, subItem := range item.HisPrescriptionProject {
  1949. total = total + (subItem.Price * float64(subItem.Count))
  1950. }
  1951. }
  1952. for _, subItem := range item.HisAdditionalCharge {
  1953. total = total + (subItem.Price * float64(subItem.Count))
  1954. }
  1955. }
  1956. allTotal := fmt.Sprintf("%.2f", total)
  1957. totals, _ := strconv.ParseFloat(allTotal, 64)
  1958. order := &models.HisOrder{
  1959. UserOrgId: adminUser.CurrentOrgId,
  1960. HisPatientId: his.ID,
  1961. PatientId: id,
  1962. SettleAccountsDate: recordDateTime,
  1963. Ctime: time.Now().Unix(),
  1964. Mtime: time.Now().Unix(),
  1965. Status: 1,
  1966. OrderStatus: 2,
  1967. Number: chrg_bchno,
  1968. MedfeeSumamt: totals,
  1969. }
  1970. err = service.CreateOrder(order)
  1971. if err != nil {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1973. return
  1974. }
  1975. var customs []*Custom
  1976. for _, item := range prescriptions {
  1977. if item.Type == 1 { //药品
  1978. for _, subItem := range item.HisDoctorAdviceInfo {
  1979. cus := &Custom{
  1980. AdviceId: subItem.ID,
  1981. ProjectId: 0,
  1982. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1983. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1984. FeedetlSn: subItem.FeedetlSn,
  1985. Price: fmt.Sprintf("%.2f", subItem.Price),
  1986. MedListCodg: subItem.MedListCodg,
  1987. Type: 1,
  1988. }
  1989. customs = append(customs, cus)
  1990. }
  1991. }
  1992. if item.Type == 2 { //项目
  1993. for _, subItem := range item.HisPrescriptionProject {
  1994. cus := &Custom{
  1995. AdviceId: 0,
  1996. ProjectId: subItem.ID,
  1997. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1998. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1999. FeedetlSn: subItem.FeedetlSn,
  2000. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2001. MedListCodg: subItem.MedListCodg,
  2002. Type: 2,
  2003. }
  2004. customs = append(customs, cus)
  2005. }
  2006. }
  2007. for _, item := range item.HisAdditionalCharge {
  2008. cus := &Custom{
  2009. ItemId: item.ID,
  2010. AdviceId: 0,
  2011. ProjectId: 0,
  2012. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2013. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2014. FeedetlSn: item.FeedetlSn,
  2015. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2016. MedListCodg: item.XtHisAddtionConfig.Code,
  2017. Type: 3,
  2018. }
  2019. customs = append(customs, cus)
  2020. }
  2021. }
  2022. for _, item := range customs {
  2023. var advice_id int64 = 0
  2024. var project_id int64 = 0
  2025. var item_id int64 = 0
  2026. var types int64 = 0
  2027. if item.Type == 1 {
  2028. advice_id = item.AdviceId
  2029. project_id = 0
  2030. item_id = 0
  2031. } else if item.Type == 2 {
  2032. advice_id = 0
  2033. item_id = 0
  2034. project_id = item.ProjectId
  2035. } else if item.Type == 3 {
  2036. advice_id = 0
  2037. item_id = item.ItemId
  2038. project_id = 0
  2039. }
  2040. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2041. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2042. pric, _ := strconv.ParseFloat(item.Price, 32)
  2043. info := &models.HisOrderInfo{
  2044. OrderNumber: order.Number,
  2045. UploadDate: time.Now().Unix(),
  2046. AdviceId: advice_id,
  2047. DetItemFeeSumamt: detItemFeeSumamt,
  2048. Cnt: cut,
  2049. Pric: pric,
  2050. PatientId: id,
  2051. Status: 1,
  2052. Mtime: time.Now().Unix(),
  2053. Ctime: time.Now().Unix(),
  2054. UserOrgId: adminUser.CurrentOrgId,
  2055. HisPatientId: his.ID,
  2056. OrderId: order.ID,
  2057. ProjectId: project_id,
  2058. Type: types,
  2059. ItemId: item_id,
  2060. }
  2061. service.CreateOrderInfo(info)
  2062. }
  2063. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2064. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2065. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2066. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2067. if err == nil {
  2068. c.ServeSuccessJSON(map[string]interface{}{
  2069. "msg": "结算成功",
  2070. })
  2071. } else {
  2072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2073. return
  2074. }
  2075. }
  2076. }
  2077. func (c *HisApiController) GetSettleInfo() {
  2078. id, _ := c.GetInt64("id")
  2079. order_id, _ := c.GetInt64("order_id")
  2080. record_time := c.GetString("record_time")
  2081. pay_way, _ := c.GetInt64("pay_way")
  2082. pay_price, _ := c.GetFloat("pay_price")
  2083. pay_card_no := c.GetString("pay_card_no")
  2084. discount_price, _ := c.GetFloat("discount_price")
  2085. preferential_price, _ := c.GetFloat("preferential_price")
  2086. reality_price, _ := c.GetFloat("reality_price")
  2087. found_price, _ := c.GetFloat("found_price")
  2088. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2089. private_price, _ := c.GetFloat("private_price")
  2090. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2091. admin_user_id, _ := c.GetInt64("admin_user_id")
  2092. timeLayout := "2006-01-02"
  2093. loc, _ := time.LoadLocation("Local")
  2094. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2095. if err != nil {
  2096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2097. return
  2098. }
  2099. recordDateTime := theTime.Unix()
  2100. adminUser := c.GetAdminUserInfo()
  2101. var prescriptions []*models.HisPrescription
  2102. data := make(map[string]interface{})
  2103. if settle_accounts_type == 1 { //日结
  2104. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2105. data["pre"] = prescriptions
  2106. } else { //月结
  2107. start_time_str := c.GetString("start_time")
  2108. end_time_str := c.GetString("end_time")
  2109. timeLayout := "2006-01-02"
  2110. loc, _ := time.LoadLocation("Local")
  2111. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2112. if err != nil {
  2113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2114. return
  2115. }
  2116. recordStartTime := theStartTime.Unix()
  2117. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2118. if err != nil {
  2119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2120. return
  2121. }
  2122. recordEndTime := theEndTime.Unix()
  2123. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2124. data["pre"] = prescriptions
  2125. }
  2126. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2127. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2128. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2129. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2130. strconv.FormatInt(his.PatientId, 10)
  2131. order_src, _ := service.GetHisOrderByID(order_id)
  2132. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2133. if config.IsOpen == 1 { //对接了医保,走医保流程
  2134. var total float64
  2135. for _, item := range prescriptions {
  2136. if item.Type == 1 { //药品
  2137. for _, subItem := range item.HisDoctorAdviceInfo {
  2138. total = total + (subItem.Price * subItem.PrescribingNumber)
  2139. }
  2140. }
  2141. if item.Type == 2 { //项目
  2142. for _, subItem := range item.HisPrescriptionProject {
  2143. total = total + (subItem.Price * float64(subItem.Count))
  2144. }
  2145. }
  2146. }
  2147. for _, item := range prescriptions {
  2148. for _, subItem := range item.HisAdditionalCharge {
  2149. total = total + (subItem.Price * float64(subItem.Count))
  2150. }
  2151. }
  2152. allTotal := fmt.Sprintf("%.2f", total)
  2153. var rf []*ResultFive
  2154. json.Unmarshal([]byte(his.Iinfo), &rf)
  2155. psn_no := order_src.PsnNo
  2156. mdtrt_id := order_src.MdtrtId
  2157. chrg_bchno := order_src.Number
  2158. cert_no := order_src.Certno
  2159. insutype := rf[0].Insutype
  2160. if his.IdCardType == 1 {
  2161. cert_no = his.MedicalInsuranceNumber
  2162. } else {
  2163. cert_no = his.Certno
  2164. }
  2165. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  2166. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2167. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2168. 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)
  2169. resp, requestErr := http.Get(api)
  2170. if requestErr != nil {
  2171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2172. return
  2173. }
  2174. defer resp.Body.Close()
  2175. body, ioErr := ioutil.ReadAll(resp.Body)
  2176. if ioErr != nil {
  2177. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2179. return
  2180. }
  2181. var respJSON map[string]interface{}
  2182. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2183. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2185. return
  2186. }
  2187. fmt.Println(respJSON)
  2188. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2189. userJSONBytes, _ := json.Marshal(respJSON)
  2190. var res ResultSeven
  2191. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2192. utils.ErrorLog("解析失败:%v", err)
  2193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2194. return
  2195. }
  2196. if res.Infcode == -1 {
  2197. errlog := &models.HisOrderError{
  2198. UserOrgId: adminUser.CurrentOrgId,
  2199. Ctime: time.Now().Unix(),
  2200. Mtime: time.Now().Unix(),
  2201. Number: chrg_bchno,
  2202. ErrMsg: res.ErrMsg,
  2203. Status: 1,
  2204. PatientId: id,
  2205. RecordTime: recordDateTime,
  2206. Stage: 6,
  2207. }
  2208. service.CreateErrMsgLog(errlog)
  2209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2210. return
  2211. } else {
  2212. order_src.OrderStatus = 2
  2213. order_src.PayWay = pay_way
  2214. order_src.PayPrice = pay_price
  2215. order_src.PayCardNo = pay_card_no
  2216. order_src.DiscountPrice = discount_price
  2217. order_src.PreferentialPrice = preferential_price
  2218. order_src.RealityPrice = reality_price
  2219. order_src.FoundPrice = found_price
  2220. order_src.MedicalInsurancePrice = medical_insurance_price
  2221. order_src.PrivatePrice = private_price
  2222. order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2223. order_src.SetlId = res.Output.Setlinfo.SetlID
  2224. order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2225. order_src.PsnName = res.Output.Setlinfo.PsnName
  2226. order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2227. order_src.Certno = res.Output.Setlinfo.Certno
  2228. order_src.Gend = res.Output.Setlinfo.Gend
  2229. order_src.Naty = res.Output.Setlinfo.Naty
  2230. order_src.Age = res.Output.Setlinfo.Age
  2231. order_src.Insutype = res.Output.Setlinfo.Insutype
  2232. order_src.PsnType = res.Output.Setlinfo.PsnType
  2233. order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2234. order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2235. order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2236. order_src.MedType = res.Output.Setlinfo.MedType
  2237. order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2238. order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2239. order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2240. order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2241. order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2242. order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2243. order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2244. order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2245. order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2246. order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2247. order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2248. order_src.MafPay = res.Output.Setlinfo.MafPay
  2249. order_src.OthPay = res.Output.Setlinfo.OthPay
  2250. order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2251. order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2252. order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2253. order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2254. order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2255. order_src.Balc = res.Output.Setlinfo.Balc
  2256. order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2257. order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2258. order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2259. order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2260. order_src.Creator = order_src.Creator
  2261. order_src.Modify = roles.ID
  2262. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2263. detailStr := string(setlDetail)
  2264. order_src.SetlDetail = detailStr
  2265. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2266. err = service.UpDateOrder(order_src)
  2267. if err == nil {
  2268. c.ServeSuccessJSON(map[string]interface{}{
  2269. "msg": "结算成功",
  2270. })
  2271. } else {
  2272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2273. return
  2274. }
  2275. }
  2276. }
  2277. }
  2278. //退款
  2279. func (c *HisApiController) Refund() {
  2280. order_id, _ := c.GetInt64("order_id")
  2281. number := c.GetString("number")
  2282. record_time := c.GetString("record_time")
  2283. patient_id, _ := c.GetInt64("patient_id")
  2284. timeLayout := "2006-01-02"
  2285. loc, _ := time.LoadLocation("Local")
  2286. adminUser := c.GetAdminUserInfo()
  2287. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2288. fmt.Println(err)
  2289. if err != nil {
  2290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2291. return
  2292. }
  2293. recordDateTime := theTime.Unix()
  2294. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2295. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2296. var order models.HisOrder
  2297. order, _ = service.GetHisOrderByID(order_id)
  2298. if order.ID == 0 {
  2299. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2300. }
  2301. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2302. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2303. if config.IsOpen == 1 { //对接了医保,走医保流程
  2304. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  2305. "&mdtrt_id=" + his.Number + "&doctor=" + "张俊杰" + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2306. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2307. resp, requestErr := http.Get(api)
  2308. if requestErr != nil {
  2309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2310. return
  2311. }
  2312. body, ioErr := ioutil.ReadAll(resp.Body)
  2313. if ioErr != nil {
  2314. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2316. return
  2317. }
  2318. var respJSON map[string]interface{}
  2319. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2320. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2322. return
  2323. }
  2324. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2325. userJSONBytes, _ := json.Marshal(respJSON)
  2326. fmt.Println(respJSON)
  2327. fmt.Println(userJSONBytes)
  2328. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2329. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2330. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2331. resp2, requestErr2 := http.Get(api2)
  2332. if requestErr2 != nil {
  2333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2334. return
  2335. }
  2336. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2337. if ioErr2 != nil {
  2338. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2340. return
  2341. }
  2342. var respJSON2 map[string]interface{}
  2343. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2344. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2346. return
  2347. }
  2348. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2349. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2350. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2351. //resp3, requestErr3 := http.Get(api3)
  2352. //if requestErr3 != nil {
  2353. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2354. // return
  2355. //}
  2356. //
  2357. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2358. //if ioErr3 != nil {
  2359. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2360. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2361. // return
  2362. //}
  2363. //var respJSON3 map[string]interface{}
  2364. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2365. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2367. // return
  2368. //}
  2369. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2370. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2371. if err == nil {
  2372. c.ServeSuccessJSON(map[string]interface{}{
  2373. "msg": "退费成功",
  2374. })
  2375. } else {
  2376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2377. return
  2378. }
  2379. } else {
  2380. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2381. if err == nil {
  2382. c.ServeSuccessJSON(map[string]interface{}{
  2383. "msg": "退费成功",
  2384. })
  2385. } else {
  2386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2387. return
  2388. }
  2389. }
  2390. }
  2391. func (c *HisApiController) RefundNumber() {
  2392. record_time := c.GetString("record_time")
  2393. patient_id, _ := c.GetInt64("patient_id")
  2394. timeLayout := "2006-01-02"
  2395. loc, _ := time.LoadLocation("Local")
  2396. adminUser := c.GetAdminUserInfo()
  2397. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2398. fmt.Println(err)
  2399. if err != nil {
  2400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2401. return
  2402. }
  2403. recordDateTime := theTime.Unix()
  2404. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2405. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2406. //order, _ := service.GetHisOrderByID(order_id)
  2407. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2408. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2409. if config.IsOpen == 1 { //对接了医保,走医保流程
  2410. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  2411. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + "张俊杰" + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2412. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2413. resp3, requestErr3 := http.Get(api3)
  2414. if requestErr3 != nil {
  2415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2416. return
  2417. }
  2418. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  2419. if ioErr3 != nil {
  2420. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  2421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2422. return
  2423. }
  2424. var respJSON3 map[string]interface{}
  2425. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  2426. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2428. return
  2429. }
  2430. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2431. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  2432. if err == nil {
  2433. c.ServeSuccessJSON(map[string]interface{}{
  2434. "msg": "退费成功",
  2435. })
  2436. } else {
  2437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2438. return
  2439. }
  2440. } else {
  2441. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2442. //if err == nil {
  2443. // c.ServeSuccessJSON(map[string]interface{}{
  2444. // "msg": "退费成功",
  2445. // })
  2446. //} else {
  2447. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2448. // return
  2449. //}
  2450. }
  2451. }
  2452. func (c *HisApiController) RefundDetail() {
  2453. order_id, _ := c.GetInt64("order_id")
  2454. number := c.GetString("number")
  2455. record_time := c.GetString("record_time")
  2456. patient_id, _ := c.GetInt64("patient_id")
  2457. timeLayout := "2006-01-02"
  2458. loc, _ := time.LoadLocation("Local")
  2459. adminUser := c.GetAdminUserInfo()
  2460. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2461. fmt.Println(err)
  2462. if err != nil {
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2464. return
  2465. }
  2466. recordDateTime := theTime.Unix()
  2467. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2468. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2469. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2470. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2471. var order models.HisOrder
  2472. order, _ = service.GetHisOrderByID(order_id)
  2473. if order.ID == 0 {
  2474. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2475. }
  2476. if config.IsOpen == 1 { //对接了医保,走医保流程
  2477. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  2478. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  2479. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2480. resp2, requestErr2 := http.Get(api2)
  2481. if requestErr2 != nil {
  2482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. return
  2484. }
  2485. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2486. if ioErr2 != nil {
  2487. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2489. return
  2490. }
  2491. var respJSON2 map[string]interface{}
  2492. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2493. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2495. return
  2496. }
  2497. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2498. if err == nil {
  2499. c.ServeSuccessJSON(map[string]interface{}{
  2500. "msg": "退费成功",
  2501. })
  2502. } else {
  2503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2504. return
  2505. }
  2506. } else {
  2507. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2508. if err == nil {
  2509. c.ServeSuccessJSON(map[string]interface{}{
  2510. "msg": "退费成功",
  2511. })
  2512. } else {
  2513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2514. return
  2515. }
  2516. }
  2517. }
  2518. //对账
  2519. func (c *HisApiController) GetCheckAccount() {
  2520. start_time := c.GetString("start_time")
  2521. end_time := c.GetString("end_time")
  2522. insutype := c.GetString("insutype")
  2523. clr_type := c.GetString("clr_type")
  2524. admin_user_id, _ := c.GetInt64("admin_user_id")
  2525. adminUser := c.GetAdminUserInfo()
  2526. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2527. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2528. timeLayout := "2006-01-02"
  2529. loc, _ := time.LoadLocation("Local")
  2530. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2531. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2532. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2533. decimal.DivisionPrecision = 2
  2534. var medfee_sumamt float64
  2535. var acct_pay float64
  2536. var fund_pay_sumamt float64
  2537. fixmedins_setl_cnt := int64(len(orders))
  2538. for _, item := range orders {
  2539. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2540. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  2541. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2542. }
  2543. var user_name string
  2544. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2545. if role.ID == 0 {
  2546. user_name = "xxx"
  2547. } else {
  2548. user_name = role.UserName
  2549. }
  2550. if config.IsOpen == 1 {
  2551. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2552. "insutype=" + insutype +
  2553. "&clr_type=" + clr_type +
  2554. "&setl_optins=" + miConfig.OrgName +
  2555. "&stmt_begndate=" + start_time +
  2556. "&stm_enddate=" + end_time +
  2557. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2558. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2559. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2560. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2561. "&fixmedins_code=" + miConfig.Code +
  2562. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2563. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2564. "&secret_key=" + miConfig.SecretKey +
  2565. "&org_name=" + miConfig.OrgName +
  2566. "&doctor=" + user_name
  2567. fmt.Println(api)
  2568. resp, requestErr := http.Get(api)
  2569. if requestErr != nil {
  2570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2571. return
  2572. }
  2573. body, ioErr := ioutil.ReadAll(resp.Body)
  2574. fmt.Println(body)
  2575. if ioErr != nil {
  2576. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2578. return
  2579. }
  2580. var respJSON map[string]interface{}
  2581. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2582. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2584. return
  2585. }
  2586. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2587. userJSONBytes, _ := json.Marshal(respJSON)
  2588. var res ResultEight
  2589. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2590. utils.ErrorLog("解析失败:%v", err)
  2591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2592. return
  2593. }
  2594. if res.Infcode == 0 {
  2595. micc := &models.MedicalInsuranceCostCompare{
  2596. StartTime: startime.Unix(),
  2597. EndTime: endtime.Unix(),
  2598. Insutype: insutype,
  2599. CheckType: 1,
  2600. Num: fixmedins_setl_cnt,
  2601. Mtime: time.Now().Unix(),
  2602. Status: 1,
  2603. UserOrgId: adminUser.CurrentOrgId,
  2604. CostTotal: medfee_sumamt,
  2605. FuncTotal: fund_pay_sumamt,
  2606. PsnPay: acct_pay,
  2607. Creator: admin_user_id,
  2608. Ctime: time.Now().Unix(),
  2609. }
  2610. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  2611. if err == nil {
  2612. c.ServeSuccessJSON(map[string]interface{}{
  2613. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2614. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2615. })
  2616. } else {
  2617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2618. }
  2619. } else {
  2620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2621. }
  2622. }
  2623. }
  2624. //对账明细
  2625. func (c *HisApiController) GetCheckDetailAccount() {
  2626. start_time := c.GetString("start_time")
  2627. end_time := c.GetString("end_time")
  2628. admin_user_id, _ := c.GetInt64("admin_user_id")
  2629. adminUser := c.GetAdminUserInfo()
  2630. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2631. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2632. timeLayout := "2006-01-02"
  2633. loc, _ := time.LoadLocation("Local")
  2634. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2635. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2636. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2637. Mkdir(miConfig.OrgName)
  2638. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2639. file_name := file + ".txt"
  2640. zip_name := file + ".zip"
  2641. zip_path := miConfig.OrgName + "/" + zip_name
  2642. file_path := miConfig.OrgName + "/" + file_name
  2643. decimal.DivisionPrecision = 2
  2644. var medfee_sumamt float64
  2645. var psn_cash_pay float64
  2646. var fund_pay_sumamt float64
  2647. fixmedins_setl_cnt := int64(len(orders))
  2648. for _, item := range orders {
  2649. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2650. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  2651. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2652. }
  2653. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2654. defer f.Close()
  2655. if err != nil {
  2656. fmt.Println(err.Error())
  2657. } else {
  2658. for _, item := range orders {
  2659. var refd_setl_flag string
  2660. if item.OrderStatus == 2 {
  2661. refd_setl_flag = "0"
  2662. }
  2663. if item.OrderStatus == 3 {
  2664. refd_setl_flag = "1"
  2665. }
  2666. var str string
  2667. str = item.SetlId + " " +
  2668. item.MdtrtId + " " +
  2669. item.PsnNo + " " +
  2670. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2671. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2672. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2673. _, err = f.Write([]byte(str))
  2674. }
  2675. }
  2676. Zip(file_path, zip_path)
  2677. fmt.Println(ReadFile(zip_path))
  2678. fmt.Println(string(ReadFile(zip_path)))
  2679. if config.IsOpen == 1 {
  2680. var user_name string
  2681. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2682. if role.ID == 0 {
  2683. user_name = "管理员"
  2684. } else {
  2685. user_name = role.UserName
  2686. }
  2687. baseParams := models.BaseParams{
  2688. SecretKey: miConfig.SecretKey,
  2689. FixmedinsCode: miConfig.Code,
  2690. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2691. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2692. OrgName: miConfig.OrgName,
  2693. Doctor: user_name,
  2694. }
  2695. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2696. var dat map[string]interface{}
  2697. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2698. fmt.Println(dat)
  2699. } else {
  2700. fmt.Println(err)
  2701. }
  2702. userJSONBytes, _ := json.Marshal(dat)
  2703. var res ResultNine
  2704. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2705. utils.ErrorLog("解析失败:%v", err)
  2706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2707. return
  2708. }
  2709. if res.Infcode == 0 {
  2710. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2711. "file_qury_no=" + res.Output.FileQuryNo +
  2712. "&setl_optins=" + miConfig.OrgName +
  2713. "&stmt_begndate=" + start_time +
  2714. "&stm_enddate=" + end_time +
  2715. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2716. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2717. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2718. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2719. "&fixmedins_code=" + miConfig.Code +
  2720. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2721. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2722. "&secret_key=" + miConfig.SecretKey +
  2723. "&org_name=" + miConfig.OrgName +
  2724. "&doctor=" + user_name
  2725. resp, requestErr := http.Get(api)
  2726. if requestErr != nil {
  2727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2728. return
  2729. }
  2730. body, ioErr := ioutil.ReadAll(resp.Body)
  2731. if ioErr != nil {
  2732. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2734. return
  2735. }
  2736. var respJSON map[string]interface{}
  2737. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2738. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2740. return
  2741. }
  2742. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2743. userJSONBytes, _ := json.Marshal(respJSON)
  2744. var res ResultTen
  2745. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2746. utils.ErrorLog("解析失败:%v", err)
  2747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2748. return
  2749. }
  2750. if res.Infcode == 0 {
  2751. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2752. micc := &models.MedicalInsuranceCostCompare{
  2753. StartTime: startime.Unix(),
  2754. EndTime: endtime.Unix(),
  2755. Insutype: "0",
  2756. CheckType: 2,
  2757. Num: fixmedins_setl_cnt,
  2758. Mtime: time.Now().Unix(),
  2759. Status: 1,
  2760. UserOrgId: adminUser.CurrentOrgId,
  2761. CostTotal: medfee_sumamt,
  2762. FuncTotal: fund_pay_sumamt,
  2763. PsnPay: psn_cash_pay,
  2764. Creator: admin_user_id,
  2765. Ctime: time.Now().Unix(),
  2766. }
  2767. service.CreateMedicalInsuranceCostCompareRecord(micc)
  2768. c.ServeSuccessJSON(map[string]interface{}{
  2769. "msg": "明细对账成功",
  2770. })
  2771. }
  2772. } else {
  2773. }
  2774. }
  2775. }
  2776. func (c *HisApiController) GetSettleAccounts() {
  2777. //id, _ := c.GetInt64("id")
  2778. //record_time := c.GetString("record_time")
  2779. order_id, _ := c.GetInt64("order_id")
  2780. admin_user_id, _ := c.GetInt64("admin_user_id")
  2781. //timeLayout := "2006-01-02"
  2782. //loc, _ := time.LoadLocation("Local")
  2783. //
  2784. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2785. //if err != nil {
  2786. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. // return
  2788. //}
  2789. //recordDateTime := theTime.Unix()
  2790. adminUser := c.GetAdminUserInfo()
  2791. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2792. order, _ := service.GetHisOrderByID(order_id)
  2793. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2794. var bedCostTotal float64 = 0 //床位总费
  2795. var bedCostSelfTotal float64 = 0 //床位自费
  2796. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2797. var operationCostTotal float64 = 0 //手术费
  2798. var operationCostSelfTotal float64 = 0 //手术费
  2799. var operationCostPartSelfTotal float64 = 0 //手术费
  2800. var otherCostTotal float64 = 0 //其他费用
  2801. var otherCostSelfTotal float64 = 0 //其他费用
  2802. var otherCostPartSelfTotal float64 = 0 //其他费用
  2803. var materialCostTotal float64 = 0 //材料费
  2804. var materialCostSelfTotal float64 = 0 //材料费
  2805. var materialCostPartSelfTotal float64 = 0 //材料费
  2806. var westernMedicineCostTotal float64 = 0 //西药费
  2807. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2808. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2809. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2810. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2811. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2812. var checkCostTotal float64 = 0 //检查费
  2813. var checkCostSelfTotal float64 = 0 //检查费
  2814. var checkCostPartSelfTotal float64 = 0 //检查费
  2815. var laboratoryCostTotal float64 = 0 //化验费
  2816. var laboratoryCostSelfTotal float64 = 0 //化验费
  2817. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2818. var treatCostTotal float64 = 0 //治疗费用
  2819. var treatCostSelfTotal float64 = 0 //治疗费用
  2820. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2821. decimal.DivisionPrecision = 2
  2822. for _, item := range orderInfos {
  2823. if item.MedChrgitmType == "01" { //床位费
  2824. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2825. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2826. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2827. }
  2828. if item.MedChrgitmType == "03" { //检查费
  2829. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2830. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2831. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2832. }
  2833. if item.MedChrgitmType == "04" { //化验费
  2834. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2835. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2836. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2837. }
  2838. if item.MedChrgitmType == "05" { //治疗费
  2839. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2840. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2841. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2842. }
  2843. if item.MedChrgitmType == "06" { //手术费
  2844. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2845. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2846. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2847. }
  2848. if item.MedChrgitmType == "08" { //材料费
  2849. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2850. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2851. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2852. }
  2853. if item.MedChrgitmType == "09" { //西药费
  2854. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2855. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2856. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2857. }
  2858. if item.MedChrgitmType == "11" { //中成费
  2859. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2860. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2861. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2862. }
  2863. if item.MedChrgitmType == "14" { //其他费
  2864. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2865. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2866. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2867. }
  2868. }
  2869. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2870. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2871. var user_name string
  2872. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2873. if role.ID == 0 {
  2874. user_name = "管理员"
  2875. } else {
  2876. user_name = role.UserName
  2877. }
  2878. baseParams := models.BaseParams{
  2879. SecretKey: miConfig.SecretKey,
  2880. FixmedinsCode: miConfig.Code,
  2881. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2882. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2883. OrgName: miConfig.OrgName,
  2884. Doctor: user_name,
  2885. }
  2886. businessParams := models.BusinessParams{
  2887. PsnNo: order.PsnNo,
  2888. MdtrtId: order.MdtrtId,
  2889. SetlId: order.SetlId,
  2890. }
  2891. if config.IsOpen == 1 {
  2892. result := service.Gdyb5203(baseParams, businessParams)
  2893. var dat map[string]interface{}
  2894. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2895. fmt.Println(dat)
  2896. } else {
  2897. fmt.Println(err)
  2898. }
  2899. userJSONBytes, _ := json.Marshal(dat)
  2900. var res ResultEleven
  2901. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2902. utils.ErrorLog("解析失败:%v", err)
  2903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2904. return
  2905. }
  2906. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2907. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  2908. if res.Infcode == 0 {
  2909. c.ServeSuccessJSON(map[string]interface{}{
  2910. "charge_admin": charge_admin,
  2911. "printor_admin": printor_admin,
  2912. "info": res.Output.Setlinfo,
  2913. "bedCostTotal": bedCostTotal,
  2914. "bedCostSelfTotal": bedCostSelfTotal,
  2915. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2916. "operationCostTotal": operationCostTotal,
  2917. "operationCostSelfTotal": operationCostSelfTotal,
  2918. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2919. "otherCostTotal": otherCostTotal,
  2920. "otherCostSelfTotal": otherCostSelfTotal,
  2921. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2922. "materialCostTotal": materialCostTotal,
  2923. "materialCostSelfTotal": materialCostSelfTotal,
  2924. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2925. "westernMedicineCostTotal": westernMedicineCostTotal,
  2926. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2927. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2928. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2929. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2930. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2931. "checkCostTotal": checkCostTotal,
  2932. "checkCostSelfTotal": checkCostSelfTotal,
  2933. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2934. "laboratoryCostTotal": laboratoryCostTotal,
  2935. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2936. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2937. "treatCostTotal": treatCostTotal,
  2938. "treatCostSelfTotal": treatCostSelfTotal,
  2939. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2940. })
  2941. }
  2942. }
  2943. }
  2944. func (c *HisApiController) GetCode() {
  2945. name := c.GetString("name")
  2946. codg := c.GetString("codg")
  2947. adminUser := c.GetAdminUserInfo()
  2948. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2949. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2950. var user_name string
  2951. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2952. if role.ID == 0 {
  2953. user_name = "xxx"
  2954. } else {
  2955. user_name = role.UserName
  2956. }
  2957. baseParams := &models.BaseParams{
  2958. SecretKey: miConfig.SecretKey,
  2959. FixmedinsCode: miConfig.Code,
  2960. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2961. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2962. OrgName: miConfig.OrgName,
  2963. Doctor: user_name,
  2964. }
  2965. if config.IsOpen == 1 {
  2966. result := service.Gdyb3301(baseParams, name, codg)
  2967. var dat map[string]interface{}
  2968. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2969. fmt.Println(dat)
  2970. } else {
  2971. fmt.Println(err)
  2972. }
  2973. }
  2974. }
  2975. func (c *HisApiController) CheckTreatment() {
  2976. patient_id, _ := c.GetInt64("patient_id", 0)
  2977. record_time := c.GetString("record_time")
  2978. insutype := c.GetString("insutype")
  2979. timeLayout := "2006-01-02"
  2980. loc, _ := time.LoadLocation("Local")
  2981. adminUser := c.GetAdminUserInfo()
  2982. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2983. fmt.Println(err)
  2984. if err != nil {
  2985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2986. return
  2987. }
  2988. recordDateTime := theTime.Unix()
  2989. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2990. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2991. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2992. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2993. var user_name string
  2994. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2995. if role.ID == 0 {
  2996. user_name = "xxx"
  2997. } else {
  2998. user_name = role.UserName
  2999. }
  3000. baseParams := models.BaseParams{
  3001. SecretKey: miConfig.SecretKey,
  3002. FixmedinsCode: miConfig.Code,
  3003. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3004. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3005. OrgName: miConfig.OrgName,
  3006. Doctor: user_name,
  3007. }
  3008. if config.IsOpen == 1 {
  3009. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3010. var dat map[string]interface{}
  3011. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3012. fmt.Println(dat)
  3013. } else {
  3014. fmt.Println(err)
  3015. }
  3016. }
  3017. }
  3018. func (c *HisApiController) PutRecord() {
  3019. id, _ := c.GetInt64("id")
  3020. record_time := c.GetString("record_time")
  3021. timeLayout := "2006-01-02"
  3022. loc, _ := time.LoadLocation("Local")
  3023. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3024. if err != nil {
  3025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3026. return
  3027. }
  3028. recordDateTime := theTime.Unix()
  3029. adminInfo := c.GetAdminUserInfo()
  3030. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3031. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3032. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3033. fmt.Println(miConfig.SecretKey)
  3034. if patient == nil {
  3035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3036. return
  3037. }
  3038. if len(patient.IdCardNo) == 0 {
  3039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3040. return
  3041. }
  3042. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3043. if config.IsOpen == 1 {
  3044. 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
  3045. resp, requestErr := http.Get(api)
  3046. if requestErr != nil {
  3047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3048. return
  3049. }
  3050. defer resp.Body.Close()
  3051. body, ioErr := ioutil.ReadAll(resp.Body)
  3052. if ioErr != nil {
  3053. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3055. return
  3056. }
  3057. var respJSON map[string]interface{}
  3058. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3059. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3061. return
  3062. }
  3063. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3064. userJSONBytes, _ := json.Marshal(userJSON)
  3065. var res ResultTwo
  3066. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3067. utils.ErrorLog("解析失败:%v", err)
  3068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3069. return
  3070. }
  3071. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3072. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3073. infoStr := string(Iinfos)
  3074. idetinfoStr := string(Idetinfos)
  3075. if res.Infcode == 0 {
  3076. his := models.VMHisPatient{
  3077. Status: 1,
  3078. Ctime: time.Now().Unix(),
  3079. Mtime: time.Now().Unix(),
  3080. PsnNo: res.Output.Baseinfo.PsnNo,
  3081. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3082. Certno: res.Output.Baseinfo.Certno,
  3083. PsnName: res.Output.Baseinfo.PsnName,
  3084. Gend: res.Output.Baseinfo.Gend,
  3085. Naty: res.Output.Baseinfo.Naty,
  3086. Brdy: res.Output.Baseinfo.Brdy,
  3087. Age: res.Output.Baseinfo.Age,
  3088. Iinfo: infoStr,
  3089. Idetinfo: idetinfoStr,
  3090. PatientId: patient.ID,
  3091. RecordDate: theTime.Unix(),
  3092. UserOrgId: adminInfo.CurrentOrgId,
  3093. AdminUserId: adminInfo.AdminUser.Id,
  3094. IsReturn: 1,
  3095. }
  3096. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3097. 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")
  3098. 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")
  3099. var dat map[string]interface{}
  3100. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3101. fmt.Println(dat)
  3102. } else {
  3103. fmt.Println(err)
  3104. }
  3105. var dat2 map[string]interface{}
  3106. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3107. fmt.Println(dat2)
  3108. } else {
  3109. fmt.Println(err)
  3110. }
  3111. } else {
  3112. adminUser := c.GetAdminUserInfo()
  3113. errlog := &models.HisOrderError{
  3114. UserOrgId: adminUser.CurrentOrgId,
  3115. Ctime: time.Now().Unix(),
  3116. Mtime: time.Now().Unix(),
  3117. ErrMsg: res.ErrMsg,
  3118. Status: 1,
  3119. PatientId: id,
  3120. RecordTime: recordDateTime,
  3121. Stage: 1,
  3122. }
  3123. service.CreateErrMsgLog(errlog)
  3124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3125. return
  3126. }
  3127. }
  3128. }
  3129. func (c *HisApiController) GetUploadDiag() {
  3130. id, _ := c.GetInt64("id")
  3131. record_time := c.GetString("record_time")
  3132. diagnosis_id, _ := c.GetInt64("diagnosis")
  3133. sick_type, _ := c.GetInt64("sick_type")
  3134. reg_type, _ := c.GetInt64("reg_type")
  3135. timeLayout := "2006-01-02"
  3136. loc, _ := time.LoadLocation("Local")
  3137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3138. if err != nil {
  3139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3140. return
  3141. }
  3142. var patientPrescription models.HisPrescriptionInfo
  3143. recordDateTime := theTime.Unix()
  3144. adminInfo := c.GetAdminUserInfo()
  3145. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3146. if patientPrescription.ID == 0 {
  3147. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3148. }
  3149. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3150. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3151. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3152. sickConfig, _ := service.FindSickById(sick_type)
  3153. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3154. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3155. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3156. "&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 +
  3157. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3158. resp2, requestErr2 := http.Get(api2)
  3159. if requestErr2 != nil {
  3160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3161. return
  3162. }
  3163. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3164. if ioErr2 != nil {
  3165. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3167. return
  3168. }
  3169. var respJSON2 map[string]interface{}
  3170. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3171. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3173. return
  3174. }
  3175. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3176. userJSONBytes2, _ := json.Marshal(respJSON2)
  3177. var res2 ResultSix
  3178. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3179. utils.ErrorLog("解析失败:%v", err)
  3180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3181. return
  3182. }
  3183. if res2.Infcode == -1 {
  3184. adminUser := c.GetAdminUserInfo()
  3185. errlog := &models.HisOrderError{
  3186. UserOrgId: adminUser.CurrentOrgId,
  3187. Ctime: time.Now().Unix(),
  3188. Mtime: time.Now().Unix(),
  3189. ErrMsg: res2.ErrMsg,
  3190. Status: 1,
  3191. PatientId: id,
  3192. RecordTime: recordDateTime,
  3193. Stage: 3,
  3194. }
  3195. service.CreateErrMsgLog(errlog)
  3196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3197. return
  3198. }
  3199. c.ServeSuccessJSON(map[string]interface{}{
  3200. "msg": "上传成功",
  3201. })
  3202. }
  3203. func PathExists(path string) (bool, error) {
  3204. _, err := os.Stat(path)
  3205. if err == nil {
  3206. return true, nil
  3207. }
  3208. if os.IsNotExist(err) {
  3209. return false, nil
  3210. }
  3211. return false, err
  3212. }
  3213. //创建文件夹
  3214. func Mkdir(dir string) {
  3215. // 创建文件夹
  3216. exist, err := PathExists(dir)
  3217. if err != nil {
  3218. fmt.Println(err.Error())
  3219. } else {
  3220. if exist {
  3221. fmt.Println(dir + "文件夹已存在!")
  3222. } else {
  3223. // 文件夹名称,权限
  3224. err := os.Mkdir(dir, os.ModePerm)
  3225. if err != nil {
  3226. fmt.Println(dir+"文件夹创建失败:", err.Error())
  3227. } else {
  3228. fmt.Println(dir + "文件夹创建成功!")
  3229. }
  3230. }
  3231. }
  3232. }
  3233. //压缩文件
  3234. func Zip(srcFile string, destZip string) error {
  3235. zipfile, err := os.Create(destZip)
  3236. if err != nil {
  3237. return err
  3238. }
  3239. defer zipfile.Close()
  3240. archive := zip.NewWriter(zipfile)
  3241. defer archive.Close()
  3242. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  3243. if err != nil {
  3244. return err
  3245. }
  3246. header, err := zip.FileInfoHeader(info)
  3247. if err != nil {
  3248. return err
  3249. }
  3250. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  3251. // header.Name = path
  3252. if info.IsDir() {
  3253. header.Name += "/"
  3254. } else {
  3255. header.Method = zip.Deflate
  3256. }
  3257. writer, err := archive.CreateHeader(header)
  3258. if err != nil {
  3259. return err
  3260. }
  3261. if !info.IsDir() {
  3262. file, err := os.Open(path)
  3263. if err != nil {
  3264. return err
  3265. }
  3266. defer file.Close()
  3267. _, err = io.Copy(writer, file)
  3268. }
  3269. return err
  3270. })
  3271. return err
  3272. }
  3273. func ReadFile(filePath string) []byte {
  3274. f, err := os.Open(filePath)
  3275. if err != nil {
  3276. fmt.Println("read file fail", err)
  3277. return nil
  3278. }
  3279. defer f.Close()
  3280. fd, err := ioutil.ReadAll(f)
  3281. if err != nil {
  3282. fmt.Println("read to fd fail", err)
  3283. return nil
  3284. }
  3285. return fd
  3286. }
  3287. func RemoveRepeatedCode(arr []string) (newArr []string) {
  3288. newArr = make([]string, 0)
  3289. for i := 0; i < len(arr); i++ {
  3290. repeat := false
  3291. for j := i + 1; j < len(arr); j++ {
  3292. if arr[i] == arr[j] {
  3293. repeat = true
  3294. break
  3295. }
  3296. }
  3297. if !repeat {
  3298. newArr = append(newArr, arr[i])
  3299. }
  3300. }
  3301. return
  3302. }
  3303. //func ShowMessage1(caption, text string, style uintptr) (result int) {
  3304. // user32, _ := syscall.LoadLibrary("SSCard.dll")
  3305. // messageBox, _ := syscall.GetProcAddress(user32, "MessageBoxW")
  3306. // defer syscall.FreeLibrary(user32)
  3307. //
  3308. // ret, _, _ := syscall.Syscall9(messageBox,
  3309. // 4,
  3310. // 0,
  3311. // StrPtr(text),
  3312. // StrPtr(caption),
  3313. // style,
  3314. // 0, 0, 0, 0, 0)
  3315. // result = int(ret)
  3316. // return
  3317. //}
  3318. //func StrPtr3(s string) uintptr {
  3319. // return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
  3320. //}