his_api_controller.go 109KB

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