his_api_controller.go 109KB

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