his_api_controller.go 110KB

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