his_api_controller.go 109KB

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