his_api_controller.go 128KB

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