his_api_controller.go 150KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286
  1. package controllers
  2. import "C"
  3. import (
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "github.com/shopspring/decimal"
  13. "math/rand"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "syscall"
  18. "time"
  19. "unsafe"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. //beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. }
  70. func (c *HisApiController) Sscard() {
  71. //r := CardInit()
  72. //if r == 0 {
  73. // GetBaseInfo()
  74. //}
  75. //c.ServeSuccessJSON(map[string]interface{}{
  76. // "list": "11",
  77. //})
  78. }
  79. func GetBaseInfo() error {
  80. //handle := syscall.MustLoadDLL("SSCard.dll")
  81. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  82. //
  83. //str := make([]byte, 256)
  84. //str1 := make([]byte, 256)
  85. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  86. //if ferr != nil {
  87. // fmt.Println("ReadCardBas 报错", ferr.Error())
  88. // return ferr
  89. //}
  90. //
  91. //fmt.Println(string(str))
  92. //
  93. //fmt.Println(r)
  94. return nil
  95. }
  96. func CardInit() int {
  97. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  98. //add := DllTestDef.MustFindProc("Init")
  99. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  100. //if err != nil {
  101. // fmt.Println("SSCard的运算结果为:", ret)
  102. //}
  103. //result := int(ret)
  104. return 0
  105. }
  106. func IntPtr(n int) uintptr {
  107. return uintptr(n)
  108. }
  109. func StrPtr(s string) uintptr {
  110. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  111. }
  112. func (c *HisApiController) GetHisPatientList() {
  113. //types, _ := c.GetInt64("type", 0)
  114. record_date := c.GetString("record_date")
  115. sch_type, _ := c.GetInt64("sch_type")
  116. timeLayout := "2006-01-02"
  117. loc, _ := time.LoadLocation("Local")
  118. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  119. if err != nil {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  121. return
  122. }
  123. recordDateTime := theTime.Unix()
  124. adminInfo := c.GetAdminUserInfo()
  125. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  126. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  127. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  128. //获取当前用户的信息
  129. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  130. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  131. //获取所有科室信息
  132. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  133. c.ServeSuccessJSON(map[string]interface{}{
  134. "list": patients,
  135. "list_two": patients_two,
  136. "info": adminUserInfo,
  137. "doctors": doctors,
  138. "department": department,
  139. })
  140. }
  141. func (c *HisApiController) GetHisPatientInfo() {
  142. patient_id, _ := c.GetInt64("patient_id")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. record_date := c.GetString("record_date")
  145. number := c.GetString("number")
  146. start_time := c.GetString("start_time")
  147. end_time := c.GetString("end_time")
  148. p_type, _ := c.GetInt64("p_type")
  149. timeLayout := "2006-01-02"
  150. loc, _ := time.LoadLocation("Local")
  151. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  152. if err != nil {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. recordDateTime := theTime.Unix()
  157. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  158. if err != nil {
  159. }
  160. startRecordDateTime := startTime.Unix()
  161. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  162. if err != nil {
  163. }
  164. endRecordDateTime := endTime.Unix()
  165. admin := c.GetAdminUserInfo()
  166. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  167. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  168. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  169. var prescriptions []*models.HisPrescription
  170. var last_prescriptions []*models.HisPrescription
  171. var sch_prescriptions []*models.HisPrescriptionInfoTemplate
  172. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  173. if p_type == 1 { //住院
  174. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  175. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  176. } else { //门诊
  177. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  178. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  179. }
  180. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  181. if sch.ID > 0 {
  182. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  183. sch_prescriptions, _ = service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  184. }
  185. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  186. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  187. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  188. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  189. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  190. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  191. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  192. //获取所有科室信息
  193. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  194. c.ServeSuccessJSON(map[string]interface{}{
  195. "his_info": his_patient_info,
  196. "xt_info": xt_patient_info,
  197. "prescription": prescriptions,
  198. "case_history": case_history,
  199. "info": patientPrescriptionInfo,
  200. "month_prescriptions": monthPrescriptions,
  201. "order": order,
  202. "doctors": doctors,
  203. "department": department,
  204. "sch_prescriptions": sch_prescriptions,
  205. "last_prescriptions": last_prescriptions,
  206. "schedule": sch,
  207. "count": count,
  208. "drugStockConfig": drugStockConfig,
  209. })
  210. return
  211. }
  212. func (c *HisApiController) GetHisPrescriptionConfig() {
  213. adminInfo := c.GetAdminUserInfo()
  214. //获取医嘱模版
  215. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  216. //获取所有基础药
  217. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  218. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  219. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  220. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  221. //获取所有科室信息
  222. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  223. //获取诊断信息
  224. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  225. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  226. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  227. c.ServeSuccessJSON(map[string]interface{}{
  228. "drugs": drugs,
  229. "advices_template": advices,
  230. "drugways": drugways,
  231. "efs": efs,
  232. "doctors": doctors,
  233. "department": department,
  234. "sick": sick,
  235. "additions": additions,
  236. "diagnose": diagnose,
  237. })
  238. }
  239. func (c *HisApiController) CreateHisPrescription() {
  240. record_date := c.GetString("record_date")
  241. patient_id, _ := c.GetInt64("patient_id")
  242. reg_type, _ := c.GetInt64("reg_type")
  243. diagnose, _ := c.GetInt64("diagnose")
  244. sick_type, _ := c.GetInt64("sick_type")
  245. sick_history := c.GetString("sick_history")
  246. doctor_id, _ := c.GetInt64("doctor", 0)
  247. department, _ := c.GetInt64("department", 0)
  248. his_patient_id, _ := c.GetInt64("his_patient_id")
  249. p_type, _ := c.GetInt64("p_type")
  250. dataBody := make(map[string]interface{}, 0)
  251. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  252. if err != nil {
  253. utils.ErrorLog(err.Error())
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. timeLayout := "2006-01-02"
  258. loc, _ := time.LoadLocation("Local")
  259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  260. if err != nil {
  261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  262. return
  263. }
  264. adminInfo := c.GetAdminUserInfo()
  265. recordDateTime := theTime.Unix()
  266. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  267. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  268. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  269. if len(lists) == 1 {
  270. his_patient_id = lists[0].ID
  271. }
  272. }
  273. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  274. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  275. if drugStockConfig.IsOpen == 1 {
  276. //校验库存总量
  277. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  278. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  279. if len(prescriptions) > 0 {
  280. for _, item := range prescriptions {
  281. items := item.(map[string]interface{})
  282. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  283. advices := items["advices"].([]interface{})
  284. if len(advices) > 0 {
  285. for _, advice := range advices {
  286. var drug_id int64
  287. var prescribing_number float64
  288. var prescribingNumberUnit string
  289. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  290. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  291. }
  292. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  293. //prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
  294. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  295. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  296. }
  297. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  298. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  299. }
  300. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
  301. if drug.ID == 0 {
  302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  303. return
  304. }
  305. if prescribingNumberUnit == drug.MinUnit {
  306. if prescribing_number > drug.Total {
  307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  308. return
  309. }
  310. } else {
  311. if prescribingNumberUnit == drug.MaxUnit {
  312. num := prescribing_number * float64(drug.MinNumber)
  313. if num > drug.Total {
  314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  315. return
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. if stockConfig.IsOpen == 1 {
  327. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  328. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  329. if len(prescriptions) > 0 {
  330. for _, item := range prescriptions {
  331. items := item.(map[string]interface{})
  332. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  333. projects := items["project"].([]interface{})
  334. if len(projects) > 0 {
  335. for _, project := range projects {
  336. var project_id int64
  337. var project_type int64
  338. var totals float64
  339. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  340. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  341. }
  342. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  343. project_type = int64(project.(map[string]interface{})["type"].(float64))
  344. }
  345. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  346. total, _ := project.(map[string]interface{})["total"].(string)
  347. totals, _ = strconv.ParseFloat(total, 64)
  348. }
  349. if project_type == 3 {
  350. good, _ := service.FindGoodInfoByIdTwo(project_id)
  351. if good.ID == 0 {
  352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  353. return
  354. }
  355. if totals > good.Total {
  356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  357. return
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. }
  367. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  368. var hpInfo models.HisPrescriptionInfo
  369. if info.ID == 0 {
  370. var randNum int
  371. randNum = rand.Intn(10000) + 1000
  372. timestamp := time.Now().Unix()
  373. tempTime := time.Unix(timestamp, 0)
  374. timeFormat := tempTime.Format("20060102150405")
  375. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  376. hpInfo = models.HisPrescriptionInfo{
  377. HisPatientId: his_patient_id,
  378. UserOrgId: adminInfo.CurrentOrgId,
  379. RecordDate: theTime.Unix(),
  380. PatientId: patient_id,
  381. Status: 1,
  382. Ctime: time.Now().Unix(),
  383. Mtime: time.Now().Unix(),
  384. Creator: adminInfo.AdminUser.Id,
  385. Modifier: adminInfo.AdminUser.Id,
  386. Diagnosis: diagnose,
  387. SickHistory: sick_history,
  388. Departments: department,
  389. RegisterType: reg_type,
  390. PrescriptionNumber: p_number,
  391. PrescriptionStatus: 1,
  392. Doctor: role.UserName,
  393. DoctorId: doctor_id,
  394. SickType: sick_type,
  395. PType: p_type,
  396. }
  397. service.SavePatientPrescriptionInfo(hpInfo)
  398. } else {
  399. hpInfo = models.HisPrescriptionInfo{
  400. ID: info.ID,
  401. UserOrgId: adminInfo.CurrentOrgId,
  402. RecordDate: info.RecordDate,
  403. PatientId: info.PatientId,
  404. Status: 1,
  405. Ctime: info.Ctime,
  406. Mtime: time.Now().Unix(),
  407. Creator: info.Creator,
  408. Modifier: adminInfo.AdminUser.Id,
  409. Diagnosis: diagnose,
  410. SickHistory: sick_history,
  411. Departments: department,
  412. RegisterType: reg_type,
  413. PrescriptionNumber: info.PrescriptionNumber,
  414. Doctor: role.UserName,
  415. PrescriptionStatus: info.PrescriptionStatus,
  416. DoctorId: doctor_id,
  417. SickType: sick_type,
  418. PType: info.PType,
  419. HisPatientId: info.HisPatientId,
  420. }
  421. service.SavePatientPrescriptionInfo(hpInfo)
  422. }
  423. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  424. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  425. var tempPrescription *models.HisPrescription
  426. if len(prescriptions) > 0 {
  427. for _, item := range prescriptions {
  428. items := item.(map[string]interface{})
  429. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  430. utils.ErrorLog("id")
  431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  432. return
  433. }
  434. id := int64(items["id"].(float64))
  435. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  436. tempPrescription = &new_prescription
  437. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  438. utils.ErrorLog("type")
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  440. return
  441. }
  442. types := int64(items["type"].(float64))
  443. if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
  444. utils.ErrorLog("order_status")
  445. }
  446. order_status := int64(items["order_status"].(float64))
  447. if order_status == 0 {
  448. order_status = 1
  449. }
  450. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  451. utils.ErrorLog("pre_time")
  452. }
  453. preTime, _ := items["pre_time"].(string)
  454. timeLayout := "2006-01-02"
  455. loc, _ := time.LoadLocation("Local")
  456. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  457. if err != nil {
  458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  459. return
  460. }
  461. pTime := theTime2.Unix()
  462. ctime := time.Now().Unix()
  463. if tempPrescription.ID == 0 {
  464. prescription := &models.HisPrescription{
  465. ID: 0,
  466. PatientId: patient_id,
  467. UserOrgId: adminInfo.CurrentOrgId,
  468. RecordDate: recordDateTime,
  469. Ctime: ctime,
  470. Mtime: ctime,
  471. Type: types,
  472. Modifier: adminInfo.AdminUser.Id,
  473. Creator: adminInfo.AdminUser.Id,
  474. Status: 1,
  475. Doctor: role.UserName,
  476. HisPatientId: his_patient_id,
  477. OrderStatus: order_status,
  478. BatchNumber: "",
  479. PrescriptionNumber: hpInfo.PrescriptionNumber,
  480. PreTime: pTime,
  481. PType: p_type,
  482. }
  483. tempPrescription = prescription
  484. service.SaveHisPrescription(tempPrescription)
  485. } else {
  486. tempPrescription.ID = id
  487. tempPrescription.Type = types
  488. tempPrescription.Modifier = adminInfo.AdminUser.Id
  489. tempPrescription.Mtime = time.Now().Unix()
  490. tempPrescription.Doctor = role.UserName
  491. tempPrescription.OrderStatus = order_status
  492. tempPrescription.PreTime = pTime
  493. service.SaveHisPrescription(tempPrescription)
  494. }
  495. //service.SaveHisPrescription(prescription)
  496. //更改患者挂号状态
  497. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  498. fmt.Println("更改失败", err2)
  499. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  500. advices := items["advices"].([]interface{})
  501. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  502. groupNo := int64(0)
  503. ctime := time.Now().Unix()
  504. mtime := ctime
  505. if len(advices) > 0 {
  506. for _, advice := range advices {
  507. var s models.HisDoctorAdviceInfo
  508. s.PrescriptionId = tempPrescription.ID
  509. s.AdviceType = 2
  510. s.AdviceDoctor = doctor_id
  511. s.StopState = 2
  512. s.ExecutionState = 2
  513. s.AdviceDate = recordDateTime
  514. s.Status = 1
  515. s.UserOrgId = adminInfo.CurrentOrgId
  516. s.RecordDate = recordDateTime
  517. s.StartTime = tempPrescription.PreTime
  518. s.Groupno = groupNo
  519. s.CreatedTime = ctime
  520. s.UpdatedTime = mtime
  521. s.PatientId = patient_id
  522. s.HisPatientId = his_patient_id
  523. s.StartTime = pTime
  524. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  525. if errcode > 0 {
  526. c.ServeFailJSONWithSGJErrorCode(errcode)
  527. return
  528. }
  529. s.StartTime = pTime
  530. service.CreateHisDoctorAdvice(&s)
  531. var randNum int
  532. randNum = rand.Intn(10000) + 1000
  533. timestamp := time.Now().Unix()
  534. tempTime := time.Unix(timestamp, 0)
  535. timeFormat := tempTime.Format("20060102150405")
  536. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  537. service.CreateHisDoctorAdvice(&s)
  538. }
  539. }
  540. }
  541. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  542. projects := items["project"].([]interface{})
  543. if len(projects) > 0 {
  544. for _, project := range projects {
  545. var p models.HisPrescriptionProject
  546. p.PrescriptionId = tempPrescription.ID
  547. p.Ctime = time.Now().Unix()
  548. p.Mtime = time.Now().Unix()
  549. p.PatientId = patient_id
  550. p.RecordDate = recordDateTime
  551. p.Doctor = doctor_id
  552. p.UserOrgId = adminInfo.CurrentOrgId
  553. p.HisPatientId = his_patient_id
  554. p.Status = 1
  555. p.StartTime = pTime
  556. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  557. if errcode > 0 {
  558. c.ServeFailJSONWithSGJErrorCode(errcode)
  559. return
  560. }
  561. service.CreateHisProjectTwo(&p)
  562. var randNum int
  563. randNum = rand.Intn(10000) + 1000
  564. timestamp := time.Now().Unix()
  565. tempTime := time.Unix(timestamp, 0)
  566. timeFormat := tempTime.Format("20060102150405")
  567. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  568. service.SaveHisProjectTwo(&p)
  569. if p.Type == 3 { //处理透前准备耗材数量数据
  570. consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  571. if consumables.ID > 0 {
  572. consumables.Count = p.Count
  573. service.UpdateConsumables(&consumables)
  574. }
  575. }
  576. }
  577. }
  578. }
  579. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  580. addition := items["addition"].([]interface{})
  581. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  582. ctime := time.Now().Unix()
  583. mtime := ctime
  584. if len(addition) > 0 {
  585. for _, item := range addition {
  586. var s models.HisAdditionalCharge
  587. s.PrescriptionId = tempPrescription.ID
  588. s.Status = 1
  589. s.UserOrgId = adminInfo.CurrentOrgId
  590. s.RecordDate = recordDateTime
  591. s.CreatedTime = ctime
  592. s.UpdatedTime = mtime
  593. s.PatientId = patient_id
  594. s.HisPatientId = his_patient_id
  595. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  596. if errcode > 0 {
  597. c.ServeFailJSONWithSGJErrorCode(errcode)
  598. return
  599. }
  600. service.CreateAdditionalCharge(&s)
  601. var randNum int
  602. randNum = rand.Intn(10000) + 1000
  603. timestamp := time.Now().Unix()
  604. tempTime := time.Unix(timestamp, 0)
  605. timeFormat := tempTime.Format("20060102150405")
  606. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  607. service.CreateAdditionalCharge(&s)
  608. }
  609. }
  610. }
  611. }
  612. }
  613. }
  614. if err == nil {
  615. c.ServeSuccessJSON(map[string]interface{}{
  616. "msg": "保存成功",
  617. })
  618. return
  619. } else {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  621. return
  622. }
  623. }
  624. func (c *HisApiController) EditHisPrescription() {
  625. record_date := c.GetString("record_date")
  626. patient_id, _ := c.GetInt64("patient_id")
  627. reg_type, _ := c.GetInt64("reg_type")
  628. diagnose, _ := c.GetInt64("diagnose")
  629. sick_type, _ := c.GetInt64("sick_type")
  630. sick_history := c.GetString("sick_history")
  631. doctor_id, _ := c.GetInt64("doctor", 0)
  632. department, _ := c.GetInt64("department", 0)
  633. his_patient_id, _ := c.GetInt64("his_patient_id")
  634. p_type, _ := c.GetInt64("p_type")
  635. dataBody := make(map[string]interface{}, 0)
  636. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  637. if err != nil {
  638. utils.ErrorLog(err.Error())
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. timeLayout := "2006-01-02"
  643. loc, _ := time.LoadLocation("Local")
  644. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  645. if err != nil {
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  647. return
  648. }
  649. adminInfo := c.GetAdminUserInfo()
  650. recordDateTime := theTime.Unix()
  651. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  652. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type)
  653. var hpInfo models.HisPrescriptionInfo
  654. if info.ID == 0 {
  655. var randNum int
  656. randNum = rand.Intn(10000) + 1000
  657. timestamp := time.Now().Unix()
  658. tempTime := time.Unix(timestamp, 0)
  659. timeFormat := tempTime.Format("20060102150405")
  660. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  661. hpInfo = models.HisPrescriptionInfo{
  662. UserOrgId: adminInfo.CurrentOrgId,
  663. RecordDate: theTime.Unix(),
  664. PatientId: patient_id,
  665. Status: 1,
  666. Ctime: time.Now().Unix(),
  667. Mtime: time.Now().Unix(),
  668. Creator: adminInfo.AdminUser.Id,
  669. Modifier: adminInfo.AdminUser.Id,
  670. Diagnosis: diagnose,
  671. SickHistory: sick_history,
  672. Departments: department,
  673. RegisterType: reg_type,
  674. PrescriptionNumber: p_number,
  675. PrescriptionStatus: 1,
  676. Doctor: role.UserName,
  677. DoctorId: doctor_id,
  678. SickType: sick_type,
  679. PType: p_type,
  680. }
  681. service.SavePatientPrescriptionInfo(hpInfo)
  682. } else {
  683. hpInfo = models.HisPrescriptionInfo{
  684. ID: info.ID,
  685. UserOrgId: adminInfo.CurrentOrgId,
  686. RecordDate: info.RecordDate,
  687. PatientId: info.PatientId,
  688. Status: 1,
  689. Ctime: info.Ctime,
  690. Mtime: time.Now().Unix(),
  691. Creator: info.Creator,
  692. Modifier: adminInfo.AdminUser.Id,
  693. Diagnosis: diagnose,
  694. SickHistory: sick_history,
  695. Departments: department,
  696. RegisterType: reg_type,
  697. PrescriptionNumber: info.PrescriptionNumber,
  698. Doctor: role.UserName,
  699. PrescriptionStatus: info.PrescriptionStatus,
  700. DoctorId: doctor_id,
  701. SickType: sick_type,
  702. PType: info.PType,
  703. }
  704. service.SavePatientPrescriptionInfo(hpInfo)
  705. }
  706. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  707. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  708. if len(prescriptions) > 0 {
  709. for _, item := range prescriptions {
  710. items := item.(map[string]interface{})
  711. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  712. utils.ErrorLog("id")
  713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  714. return
  715. }
  716. id := int64(items["id"].(float64))
  717. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  718. utils.ErrorLog("type")
  719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  720. return
  721. }
  722. types := int64(items["type"].(float64))
  723. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  724. ctime := time.Now().Unix()
  725. prescription := &models.HisPrescription{
  726. ID: id,
  727. PatientId: patient_id,
  728. UserOrgId: adminInfo.CurrentOrgId,
  729. RecordDate: recordDateTime,
  730. Ctime: ctime,
  731. Mtime: ctime,
  732. Type: types,
  733. Modifier: adminInfo.AdminUser.Id,
  734. Creator: adminInfo.AdminUser.Id,
  735. Status: 1,
  736. Doctor: role.UserName,
  737. HisPatientId: his_patient_id,
  738. OrderStatus: 1,
  739. BatchNumber: "",
  740. PrescriptionNumber: hpInfo.PrescriptionNumber,
  741. PType: hpInfo.PType,
  742. }
  743. if historyPrescription.ID > 0 {
  744. prescription.PreTime = historyPrescription.PreTime
  745. }
  746. service.SaveHisPrescription(prescription)
  747. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  748. advices := items["advices"].([]interface{})
  749. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  750. groupNo := int64(0)
  751. ctime := time.Now().Unix()
  752. mtime := ctime
  753. if len(advices) > 0 {
  754. for _, advice := range advices {
  755. var s models.HisDoctorAdviceInfo
  756. s.PrescriptionId = prescription.ID
  757. s.AdviceType = 2
  758. s.AdviceDoctor = adminInfo.AdminUser.Id
  759. s.StopState = 2
  760. s.ExecutionState = 2
  761. s.AdviceDate = recordDateTime
  762. s.Status = 1
  763. s.UserOrgId = adminInfo.CurrentOrgId
  764. s.RecordDate = recordDateTime
  765. s.StartTime = prescription.PreTime
  766. s.Groupno = groupNo
  767. s.CreatedTime = ctime
  768. s.UpdatedTime = mtime
  769. s.PatientId = patient_id
  770. s.HisPatientId = his_patient_id
  771. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  772. if errcode > 0 {
  773. c.ServeFailJSONWithSGJErrorCode(errcode)
  774. return
  775. }
  776. service.CreateHisDoctorAdvice(&s)
  777. }
  778. }
  779. }
  780. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  781. projects := items["project"].([]interface{})
  782. if len(projects) > 0 {
  783. for _, project := range projects {
  784. var p models.HisPrescriptionProject
  785. p.PrescriptionId = prescription.ID
  786. p.Ctime = time.Now().Unix()
  787. p.Mtime = time.Now().Unix()
  788. p.PatientId = patient_id
  789. p.RecordDate = recordDateTime
  790. p.UserOrgId = adminInfo.CurrentOrgId
  791. p.HisPatientId = his_patient_id
  792. p.Status = 1
  793. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  794. if errcode > 0 {
  795. c.ServeFailJSONWithSGJErrorCode(errcode)
  796. return
  797. }
  798. service.CreateHisProjectTwo(&p)
  799. }
  800. }
  801. }
  802. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  803. addition := items["addition"].([]interface{})
  804. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  805. ctime := time.Now().Unix()
  806. mtime := ctime
  807. if len(addition) > 0 {
  808. for _, item := range addition {
  809. var s models.HisAdditionalCharge
  810. s.PrescriptionId = prescription.ID
  811. s.Status = 1
  812. s.UserOrgId = adminInfo.CurrentOrgId
  813. s.RecordDate = recordDateTime
  814. s.CreatedTime = ctime
  815. s.UpdatedTime = mtime
  816. s.PatientId = patient_id
  817. s.HisPatientId = his_patient_id
  818. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  819. if errcode > 0 {
  820. c.ServeFailJSONWithSGJErrorCode(errcode)
  821. return
  822. }
  823. service.CreateAdditionalCharge(&s)
  824. }
  825. }
  826. }
  827. }
  828. }
  829. }
  830. if err == nil {
  831. c.ServeSuccessJSON(map[string]interface{}{
  832. "msg": "保存成功",
  833. })
  834. return
  835. } else {
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  837. return
  838. }
  839. }
  840. func (c *HisApiController) DeletePrescription() {
  841. prescription_id, _ := c.GetInt64("id")
  842. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  843. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  844. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  845. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  846. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  847. if err == nil {
  848. if len(projects) > 0 {
  849. for _, item := range projects {
  850. if stockConfig.IsOpen == 1 {
  851. if item.Type == 3 {
  852. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  853. f_count, _ := strconv.ParseFloat(strconv.FormatInt(item.Count, 10), 64)
  854. good.Total = good.Total + f_count
  855. service.UpdateGoodInfo(&good)
  856. }
  857. }
  858. if item.Type == 3 { //处理透前准备耗材数量数据
  859. consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
  860. if consumables.ID > 0 {
  861. consumables.Count = 0
  862. service.UpdateConsumables(&consumables)
  863. }
  864. }
  865. }
  866. }
  867. if drugStockConfig.IsOpen == 1 {
  868. if len(advices) > 0 {
  869. for _, item := range advices {
  870. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  871. if item.PrescribingNumberUnit == drug.MinUnit {
  872. drug.Total = drug.Total + item.PrescribingNumber
  873. service.UpdateBaseDrugLib(&drug)
  874. } else {
  875. if item.PrescribingNumberUnit == drug.MaxUnit {
  876. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  877. drug.Total = drug.Total + item.PrescribingNumber
  878. service.UpdateBaseDrugLib(&drug)
  879. }
  880. }
  881. }
  882. }
  883. }
  884. c.ServeSuccessJSON(map[string]interface{}{
  885. "msg": "删除成功",
  886. })
  887. return
  888. } else {
  889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  890. return
  891. }
  892. }
  893. func (c *HisApiController) DeleteDoctorAdvice() {
  894. id, _ := c.GetInt64("id")
  895. advice, _ := service.GetHisDoctorAdvicesById(id)
  896. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  897. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  898. if err == nil {
  899. if drugStockConfig.IsOpen == 1 {
  900. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  901. if advice.PrescribingNumberUnit == drug.MinUnit {
  902. drug.Total = drug.Total + advice.PrescribingNumber
  903. service.UpdateBaseDrugLib(&drug)
  904. } else {
  905. if advice.PrescribingNumberUnit == drug.MaxUnit {
  906. advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
  907. drug.Total = drug.Total + advice.PrescribingNumber
  908. service.UpdateBaseDrugLib(&drug)
  909. }
  910. }
  911. }
  912. c.ServeSuccessJSON(map[string]interface{}{
  913. "msg": "删除成功",
  914. })
  915. return
  916. } else {
  917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  918. return
  919. }
  920. }
  921. func (c *HisApiController) DeleteProject() {
  922. id, _ := c.GetInt64("id")
  923. adminInfo := c.GetAdminUserInfo()
  924. project, _ := service.GetHisProjectByID(id)
  925. var consumable models.DialysisBeforePrepare
  926. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  927. if project.ID > 0 && project.Type == 3 {
  928. consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
  929. }
  930. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  931. if err == nil {
  932. if stockConfig.IsOpen == 1 {
  933. if project.Type == 3 {
  934. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  935. f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
  936. good.Total = good.Total + f_count
  937. service.UpdateGoodInfo(&good)
  938. }
  939. }
  940. if consumable.ID > 0 {
  941. consumable.Count = 0
  942. service.UpdateConsumables(&consumable)
  943. }
  944. c.ServeSuccessJSON(map[string]interface{}{
  945. "msg": "删除成功",
  946. })
  947. return
  948. } else {
  949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  950. return
  951. }
  952. }
  953. func (c *HisApiController) CreateHisAdditionalCharge() {
  954. his_patient_id, _ := c.GetInt64("his_patient_id")
  955. patient_id, _ := c.GetInt64("patient_id")
  956. record_date := c.GetString("record_date")
  957. timeLayout := "2006-01-02"
  958. loc, _ := time.LoadLocation("Local")
  959. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  960. if err != nil {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. adminInfo := c.GetAdminUserInfo()
  965. recordDateTime := theTime.Unix()
  966. dataBody := make(map[string]interface{}, 0)
  967. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  968. if err != nil {
  969. utils.ErrorLog(err.Error())
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  971. return
  972. }
  973. var additions []*models.HisAdditionalCharge
  974. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  975. additions, _ := dataBody["addition"].([]interface{})
  976. if len(additions) > 0 {
  977. for _, item := range additions {
  978. items := item.(map[string]interface{})
  979. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  980. utils.ErrorLog("item_id")
  981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  982. return
  983. }
  984. item_id := int64(items["item_id"].(float64))
  985. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  986. utils.ErrorLog("item_name")
  987. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  988. return
  989. }
  990. item_name := items["item_name"].(string)
  991. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  992. utils.ErrorLog("price")
  993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  994. return
  995. }
  996. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  997. ctime := time.Now().Unix()
  998. additional := &models.HisAdditionalCharge{
  999. PatientId: patient_id,
  1000. HisPatientId: his_patient_id,
  1001. UserOrgId: adminInfo.CurrentOrgId,
  1002. RecordDate: recordDateTime,
  1003. CreatedTime: ctime,
  1004. UpdatedTime: ctime,
  1005. Modifier: adminInfo.AdminUser.Id,
  1006. Creator: adminInfo.AdminUser.Id,
  1007. Price: price,
  1008. ItemName: item_name,
  1009. ItemId: item_id,
  1010. Status: 1,
  1011. }
  1012. additions = append(additions, additional)
  1013. }
  1014. }
  1015. }
  1016. for _, item := range additions {
  1017. service.CreateAddtionalCharge(item)
  1018. }
  1019. c.ServeSuccessJSON(map[string]interface{}{
  1020. "msg": "创建成功",
  1021. })
  1022. }
  1023. func (c *HisApiController) CreateHisPatientCaseHistory() {
  1024. blood_fat := c.GetString("blood_fat")
  1025. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  1026. blood_sugar := c.GetString("blood_sugar")
  1027. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  1028. fmt.Println(bloodsugarfloat)
  1029. chief_conplaint := c.GetString("chief_conplaint")
  1030. dbp := c.GetString("dbp")
  1031. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  1032. delivery_way, _ := c.GetInt64("delivery_way")
  1033. diagnostic := c.GetString("diagnostic")
  1034. family_history := c.GetString("family_history")
  1035. height := c.GetString("height")
  1036. history_of_present_illness := c.GetString("history_of_present_illness")
  1037. is_infect, _ := c.GetInt64("is_infect")
  1038. fmt.Println("is", is_infect)
  1039. past_history := c.GetString("past_history")
  1040. patient_id, _ := c.GetInt64("patient_id")
  1041. his_patient_id, _ := c.GetInt64("his_patient_id")
  1042. fmt.Println("patient_id", patient_id)
  1043. personal_history := c.GetString("personal_history")
  1044. pulse := c.GetString("pulse")
  1045. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  1046. sbp := c.GetString("sbp")
  1047. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  1048. heightfloat, _ := strconv.ParseFloat(height, 64)
  1049. sicktype := c.GetString("sick_type")
  1050. fmt.Println("sicketype", sicktype)
  1051. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  1052. symptom := c.GetString("symptom")
  1053. sick_date := c.GetString("sick_date")
  1054. temperatures := c.GetString("temperature")
  1055. fmt.Println("temperatures", temperatures)
  1056. temperature, _ := strconv.ParseFloat(temperatures, 64)
  1057. record_date := c.GetString("record_date")
  1058. breathing := c.GetString("breathing")
  1059. doctor_advice := c.GetString("doctor_advice")
  1060. remark := c.GetString("remark")
  1061. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  1062. sick, _ := c.GetInt64("sick")
  1063. diagnose, _ := c.GetInt64("diagnose")
  1064. id, _ := c.GetInt64("id")
  1065. timeLayout := "2006-01-02"
  1066. loc, _ := time.LoadLocation("Local")
  1067. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1068. allergic_history := c.GetString("allergic_history")
  1069. if err != nil {
  1070. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1071. return
  1072. }
  1073. recordDateTime := theTime.Unix()
  1074. fmt.Println("recordDataTime", recordDateTime)
  1075. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  1076. if err != nil {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. sickTimes := sickTime.Unix()
  1081. ctime := time.Now().Unix()
  1082. caseHistory := models.HisPatientCaseHistory{
  1083. HisPatientId: his_patient_id,
  1084. PatientId: patient_id,
  1085. Temperature: temperature,
  1086. BloodSugar: bloodsugarfloat,
  1087. Pulse: pulsefloat,
  1088. Sbp: sbpfloat,
  1089. Dbp: dbpfloat,
  1090. Height: heightfloat,
  1091. BloodFat: bloodfatfloat,
  1092. SickType: sick_type,
  1093. Symptom: symptom,
  1094. SickDate: sickTimes,
  1095. IsInfect: is_infect,
  1096. HistoryOfPresentIllness: history_of_present_illness,
  1097. PastHistory: past_history,
  1098. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  1099. ChiefConplaint: chief_conplaint,
  1100. PersonalHistory: personal_history,
  1101. FamilyHistory: family_history,
  1102. Diagnostic: diagnostic,
  1103. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1104. Status: 1,
  1105. Ctime: ctime,
  1106. Mtime: ctime,
  1107. RecordDate: recordDateTime,
  1108. DeliveryWay: delivery_way,
  1109. Breathing: breathingfloat,
  1110. DoctorAdvice: doctor_advice,
  1111. Remark: remark,
  1112. Sick: sick,
  1113. Diagnose: diagnose,
  1114. AllergicHistory: allergic_history,
  1115. }
  1116. //查询该患者是否有病历
  1117. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  1118. if errcodes == gorm.ErrRecordNotFound {
  1119. err = service.SaveHisPatientCaseHistory(&caseHistory)
  1120. if err != nil {
  1121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1122. return
  1123. }
  1124. c.ServeSuccessJSON(map[string]interface{}{
  1125. "caseHistory": caseHistory,
  1126. })
  1127. return
  1128. } else if errcodes == nil {
  1129. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  1130. if err != nil {
  1131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1132. return
  1133. }
  1134. c.ServeSuccessJSON(map[string]interface{}{
  1135. "caseHistory": caseHistory,
  1136. })
  1137. }
  1138. //查询该患者是否有病历
  1139. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  1140. //if errcode == gorm.ErrRecordNotFound {
  1141. // err = service.SaveHisPatientCaseHistory(caseHistory)
  1142. // if err != nil {
  1143. // c.ServeSuccessJSON(map[string]interface{}{
  1144. // "msg": "保存成功",
  1145. // })
  1146. // }
  1147. //} else if errcode == nil {
  1148. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1149. // return
  1150. //}
  1151. }
  1152. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  1153. patient_id, _ := c.GetInt64("patient_id", 0)
  1154. adminUser := c.GetAdminUserInfo()
  1155. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  1156. c.ServeSuccessJSON(map[string]interface{}{
  1157. "list": caseHistorys,
  1158. })
  1159. }
  1160. func (c *HisApiController) GetHisPatientCaseHistory() {
  1161. record_date, _ := c.GetInt64("record_date", 0)
  1162. patient_id, _ := c.GetInt64("patient_id", 0)
  1163. admin := c.GetAdminUserInfo()
  1164. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  1165. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  1166. c.ServeSuccessJSON(map[string]interface{}{
  1167. "info": info,
  1168. "case_history": case_history,
  1169. })
  1170. }
  1171. func (c *HisApiController) CreateCaseHistoryTemplate() {
  1172. template_name := c.GetString("template_name")
  1173. template_remark := c.GetString("template_remark")
  1174. doctor := c.GetAdminUserInfo().AdminUser.Id
  1175. diagnostic := c.GetString("diagnostic")
  1176. chief_conplaint := c.GetString("chief_conplain")
  1177. history_of_present_illness := c.GetString("history_of_present_illness")
  1178. past_history := c.GetString("past_history")
  1179. personal_history := c.GetString("personal_history")
  1180. family_history := c.GetString("family_history")
  1181. user_name := c.GetString("user_name")
  1182. doctor_advice := c.GetString("doctor_advice")
  1183. remark := c.GetString("remark")
  1184. //record_date := c.GetString("record_date")
  1185. //fmt.Println("record_date--------",record_date)
  1186. //timeLayout := "2006-01-02"
  1187. //loc, _ := time.LoadLocation("Local")
  1188. //
  1189. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1190. //if err != nil {
  1191. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1192. // return
  1193. //}
  1194. //recordDateTime := theTime.Unix()
  1195. ctime := time.Now().Unix()
  1196. template := models.HisCaseHistoryTemplate{
  1197. HistoryOfPresentIllness: history_of_present_illness,
  1198. PastHistory: past_history,
  1199. ChiefConplaint: chief_conplaint,
  1200. PersonalHistory: personal_history,
  1201. FamilyHistory: family_history,
  1202. Diagnostic: diagnostic,
  1203. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1204. Status: 1,
  1205. Ctime: ctime,
  1206. Mtime: ctime,
  1207. RecordDate: time.Now().Unix(),
  1208. TemplateName: template_name,
  1209. TemplateRemark: template_remark,
  1210. Creator: doctor,
  1211. Modifier: doctor,
  1212. UserName: user_name,
  1213. DoctorAdvice: doctor_advice,
  1214. Remark: remark,
  1215. }
  1216. err := service.SaveHisPatientCaseHistoryTemplate(template)
  1217. if err == nil {
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "msg": "保存成功",
  1220. })
  1221. } else {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1223. return
  1224. }
  1225. }
  1226. func (c *HisApiController) GetCaseHistoryTemplate() {
  1227. timeLayout := "2006-01-02"
  1228. loc, _ := time.LoadLocation("Local")
  1229. keyword := c.GetString("keyword")
  1230. start_time := c.GetString("start_time")
  1231. end_time := c.GetString("end_time")
  1232. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1233. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1234. admin := c.GetAdminUserInfo()
  1235. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  1236. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  1237. c.ServeSuccessJSON(map[string]interface{}{
  1238. "template": template,
  1239. //"history": history,
  1240. })
  1241. }
  1242. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1243. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1244. utils.ErrorLog("drug_name")
  1245. return enums.ErrorCodeParamWrong
  1246. }
  1247. adviceName, _ := json["drug_name"].(string)
  1248. if len(adviceName) == 0 {
  1249. utils.ErrorLog("len(advice_name) == 0")
  1250. return enums.ErrorCodeParamWrong
  1251. }
  1252. advice.AdviceName = adviceName
  1253. adviceDesc, _ := json["advice_desc"].(string)
  1254. advice.AdviceDesc = adviceDesc
  1255. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1256. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1257. advice.DrugSpec = drugSpec
  1258. }
  1259. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1260. remark, _ := json["remark"].(string)
  1261. advice.Remark = remark
  1262. }
  1263. if json["id"] == nil {
  1264. advice.DrugId = 0
  1265. } else {
  1266. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1267. drug_id := int64(json["id"].(float64))
  1268. advice.DrugId = drug_id
  1269. }
  1270. }
  1271. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1272. advice_id := int64(json["advice_id"].(float64))
  1273. advice.ID = advice_id
  1274. if advice.ID > 0 {
  1275. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1276. if err == nil {
  1277. if hisAdvice.ID > 0 {
  1278. advice.ExecutionTime = hisAdvice.ExecutionTime
  1279. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1280. advice.ExecutionState = hisAdvice.ExecutionState
  1281. advice.CheckTime = hisAdvice.CheckTime
  1282. advice.Checker = hisAdvice.Checker
  1283. advice.CheckState = hisAdvice.CheckState
  1284. advice.StartTime = hisAdvice.StartTime
  1285. advice.FeedetlSn = hisAdvice.FeedetlSn
  1286. }
  1287. }
  1288. }
  1289. }
  1290. //
  1291. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1292. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1293. // advice.ExecutionTime = execution_time
  1294. //}
  1295. //
  1296. //
  1297. //
  1298. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1299. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1300. // advice.ExecutionStaff = execution_staff
  1301. //}
  1302. //
  1303. //
  1304. //
  1305. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1306. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1307. // advice.ExecutionState = execution_state
  1308. //}
  1309. //
  1310. //
  1311. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1312. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1313. // advice.CheckTime = check_time
  1314. //}
  1315. //
  1316. //
  1317. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1318. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1319. // advice.CheckState = check_state
  1320. //}
  1321. //
  1322. //
  1323. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1324. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1325. // advice.Checker = checker
  1326. //}
  1327. //
  1328. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1329. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1330. // advice.StartTime = start_time
  1331. //}
  1332. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1333. drugSpecUnit, _ := json["min_unit"].(string)
  1334. advice.DrugSpecUnit = drugSpecUnit
  1335. }
  1336. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1337. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1338. advice.SingleDose = singleDose
  1339. }
  1340. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1341. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1342. advice.SingleDoseUnit = singleDoseUnit
  1343. }
  1344. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1345. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1346. advice.PrescribingNumber = prescribingNumber
  1347. }
  1348. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1349. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1350. advice.PrescribingNumberUnit = prescribingNumberUnit
  1351. }
  1352. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1353. deliveryWay, _ := json["delivery_way"].(string)
  1354. advice.DeliveryWay = deliveryWay
  1355. }
  1356. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1357. executionFrequency, _ := json["execution_frequency"].(string)
  1358. advice.ExecutionFrequency = executionFrequency
  1359. }
  1360. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1361. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1362. advice.Price = price
  1363. }
  1364. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1365. med_list_codg, _ := json["medical_insurance_number"].(string)
  1366. advice.MedListCodg = med_list_codg
  1367. }
  1368. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1369. day := int64(json["day"].(float64))
  1370. advice.Day = day
  1371. }
  1372. return 0
  1373. }
  1374. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1375. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1376. id := int64(json["id"].(float64))
  1377. project.ID = id
  1378. historyProject, _ := service.GetHisProjectByID(id)
  1379. project.FeedetlSn = historyProject.FeedetlSn
  1380. }
  1381. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1382. project_id := int64(json["project_id"].(float64))
  1383. project.ProjectId = project_id
  1384. }
  1385. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1386. // price := int64(json["price"].(float64))
  1387. // formatInt_price := strconv.FormatInt(price, 10)
  1388. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1389. // project.Price = float_price
  1390. // }
  1391. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1392. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1393. project.Price = price
  1394. }
  1395. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1396. total, _ := json["total"].(string)
  1397. totals, _ := strconv.ParseInt(total, 10, 64)
  1398. project.Count = totals
  1399. }
  1400. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1401. medical_code, _ := json["medical_code"].(string)
  1402. project.MedListCodg = medical_code
  1403. }
  1404. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1405. single_dose, _ := json["single_dose"].(string)
  1406. project.SingleDose = single_dose
  1407. }
  1408. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1409. delivery_way, _ := json["delivery_way"].(string)
  1410. project.DeliveryWay = delivery_way
  1411. }
  1412. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1413. execution_frequency, _ := json["execution_frequency"].(string)
  1414. project.ExecutionFrequency = execution_frequency
  1415. }
  1416. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1417. remark, _ := json["remark"].(string)
  1418. project.Remark = remark
  1419. }
  1420. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1421. day, _ := json["number_days"].(string)
  1422. project.Day = day
  1423. }
  1424. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1425. unit, _ := json["unit"].(string)
  1426. project.Unit = unit
  1427. }
  1428. return 0
  1429. }
  1430. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1431. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1432. id := int64(json["id"].(float64))
  1433. historyAddtions, _ := service.GetHisAdditionByID(id)
  1434. additionalCharge.ID = id
  1435. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  1436. }
  1437. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1438. item_id := int64(json["item_id"].(float64))
  1439. additionalCharge.ItemId = item_id
  1440. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1441. if config.ID > 0 {
  1442. if len(config.Code) > 0 {
  1443. additionalCharge.MedListCodg = config.Code
  1444. }
  1445. }
  1446. }
  1447. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1448. // price := int64(json["price"].(float64))
  1449. // formatInt_price := strconv.FormatInt(price, 10)
  1450. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1451. // additionalCharge.Price = float_price
  1452. // }
  1453. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1454. // price := int64(json["price"].(float64))
  1455. // formatInt_price := strconv.FormatInt(price, 10)
  1456. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1457. // additionalCharge.Price = float_price
  1458. //}
  1459. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1460. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1461. additionalCharge.Price = price
  1462. }
  1463. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1464. count, _ := json["count"].(string)
  1465. counts, _ := strconv.ParseInt(count, 10, 64)
  1466. additionalCharge.Count = counts
  1467. }
  1468. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1469. item_name, _ := json["item_name"].(string)
  1470. additionalCharge.ItemName = item_name
  1471. }
  1472. return 0
  1473. }
  1474. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1475. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1476. utils.ErrorLog("drug_name")
  1477. return enums.ErrorCodeParamWrong
  1478. }
  1479. adviceName, _ := json["drug_name"].(string)
  1480. if len(adviceName) == 0 {
  1481. utils.ErrorLog("len(advice_name) == 0")
  1482. return enums.ErrorCodeParamWrong
  1483. }
  1484. advice.AdviceName = adviceName
  1485. adviceDesc, _ := json["advice_desc"].(string)
  1486. advice.AdviceDesc = adviceDesc
  1487. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1488. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1489. advice.DrugSpec = drugSpec
  1490. }
  1491. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1492. remark, _ := json["remark"].(string)
  1493. advice.Remark = remark
  1494. }
  1495. if json["id"] == nil {
  1496. advice.DrugId = 0
  1497. } else {
  1498. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1499. drug_id := int64(json["id"].(float64))
  1500. advice.DrugId = drug_id
  1501. }
  1502. }
  1503. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1504. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1505. advice.PrescribingNumber = prescribingNumber
  1506. }
  1507. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1508. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1509. advice.PrescribingNumberUnit = prescribingNumberUnit
  1510. }
  1511. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1512. advice_id := int64(json["advice_id"].(float64))
  1513. advice.ID = advice_id
  1514. if advice.ID > 0 {
  1515. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1516. if err == nil {
  1517. if hisAdvice.ID > 0 {
  1518. advice.ExecutionTime = hisAdvice.ExecutionTime
  1519. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1520. advice.ExecutionState = hisAdvice.ExecutionState
  1521. advice.CheckTime = hisAdvice.CheckTime
  1522. advice.Checker = hisAdvice.Checker
  1523. advice.CheckState = hisAdvice.CheckState
  1524. advice.StartTime = hisAdvice.StartTime
  1525. }
  1526. }
  1527. }
  1528. }
  1529. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  1530. if drugStockConfig.IsOpen == 1 {
  1531. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  1532. if advice.ID == 0 { //医嘱不存在
  1533. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  1534. drug.Total = drug.Total - advice.PrescribingNumber
  1535. service.UpdateBaseDrugLib(&drug)
  1536. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  1537. num := advice.PrescribingNumber * float64(drug.MinNumber)
  1538. drug.Total = drug.Total - num
  1539. service.UpdateBaseDrugLib(&drug)
  1540. }
  1541. } else if advice.ID > 0 { //医嘱存在
  1542. hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  1543. var num float64
  1544. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  1545. if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  1546. if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  1547. num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  1548. drug.Total = drug.Total + num
  1549. service.UpdateBaseDrugLib(&drug)
  1550. } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  1551. num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  1552. drug.Total = drug.Total - num
  1553. service.UpdateBaseDrugLib(&drug)
  1554. }
  1555. } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  1556. num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1557. if num2 > advice.PrescribingNumber {
  1558. num = num2 - advice.PrescribingNumber
  1559. drug.Total = drug.Total + num
  1560. service.UpdateBaseDrugLib(&drug)
  1561. } else if num2 < advice.PrescribingNumber {
  1562. num = advice.PrescribingNumber - num2
  1563. drug.Total = drug.Total - num
  1564. service.UpdateBaseDrugLib(&drug)
  1565. }
  1566. }
  1567. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  1568. if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  1569. num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1570. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  1571. if num1 > num2 {
  1572. num = num1 - num2
  1573. drug.Total = drug.Total + num
  1574. service.UpdateBaseDrugLib(&drug)
  1575. } else if num1 < num2 {
  1576. num = num2 - num1
  1577. drug.Total = drug.Total - num
  1578. service.UpdateBaseDrugLib(&drug)
  1579. }
  1580. } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  1581. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  1582. //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  1583. if hisAdvice.PrescribingNumber > num2 {
  1584. num = hisAdvice.PrescribingNumber - num2
  1585. drug.Total = drug.Total + num
  1586. service.UpdateBaseDrugLib(&drug)
  1587. } else if num2 < advice.PrescribingNumber {
  1588. num = num2 - hisAdvice.PrescribingNumber
  1589. drug.Total = drug.Total - num
  1590. service.UpdateBaseDrugLib(&drug)
  1591. }
  1592. }
  1593. }
  1594. }
  1595. }
  1596. //
  1597. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1598. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1599. // advice.ExecutionTime = execution_time
  1600. //}
  1601. //
  1602. //
  1603. //
  1604. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1605. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1606. // advice.ExecutionStaff = execution_staff
  1607. //}
  1608. //
  1609. //
  1610. //
  1611. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1612. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1613. // advice.ExecutionState = execution_state
  1614. //}
  1615. //
  1616. //
  1617. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1618. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1619. // advice.CheckTime = check_time
  1620. //}
  1621. //
  1622. //
  1623. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1624. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1625. // advice.CheckState = check_state
  1626. //}
  1627. //
  1628. //
  1629. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1630. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1631. // advice.Checker = checker
  1632. //}
  1633. //
  1634. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1635. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1636. // advice.StartTime = start_time
  1637. //}
  1638. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1639. drugSpecUnit, _ := json["min_unit"].(string)
  1640. advice.DrugSpecUnit = drugSpecUnit
  1641. }
  1642. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1643. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1644. advice.SingleDose = singleDose
  1645. }
  1646. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1647. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1648. advice.SingleDoseUnit = singleDoseUnit
  1649. }
  1650. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1651. deliveryWay, _ := json["delivery_way"].(string)
  1652. advice.DeliveryWay = deliveryWay
  1653. }
  1654. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1655. executionFrequency, _ := json["execution_frequency"].(string)
  1656. advice.ExecutionFrequency = executionFrequency
  1657. }
  1658. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1659. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1660. advice.Price = price
  1661. }
  1662. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1663. med_list_codg, _ := json["medical_insurance_number"].(string)
  1664. advice.MedListCodg = med_list_codg
  1665. }
  1666. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1667. day := int64(json["day"].(float64))
  1668. advice.Day = day
  1669. }
  1670. return 0
  1671. }
  1672. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1673. project.ExecutionStaff = 0
  1674. project.ExecutionState = 2
  1675. project.ExecutionTime = 0
  1676. project.Checker = 0
  1677. project.CheckState = 2
  1678. project.CheckTime = 0
  1679. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1680. id := int64(json["id"].(float64))
  1681. project.ID = id
  1682. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  1683. project.ExecutionStaff = temp_project.ExecutionStaff
  1684. project.ExecutionState = temp_project.ExecutionState
  1685. project.ExecutionTime = temp_project.ExecutionTime
  1686. project.Checker = temp_project.Checker
  1687. project.CheckState = temp_project.CheckState
  1688. project.CheckTime = temp_project.CheckTime
  1689. }
  1690. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  1691. types := int64(json["type"].(float64))
  1692. project.Type = types
  1693. }
  1694. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1695. project_id := int64(json["project_id"].(float64))
  1696. project.ProjectId = project_id
  1697. fmt.Println(project_id)
  1698. fmt.Println(project.ProjectId)
  1699. }
  1700. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1701. // price := int64(json["price"].(float64))
  1702. // formatInt_price := strconv.FormatInt(price, 10)
  1703. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1704. // project.Price = float_price
  1705. // }
  1706. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1707. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1708. project.Price = price
  1709. }
  1710. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1711. total, _ := json["total"].(string)
  1712. totals, _ := strconv.ParseInt(total, 10, 64)
  1713. project.Count = totals
  1714. }
  1715. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1716. medical_code, _ := json["medical_code"].(string)
  1717. project.MedListCodg = medical_code
  1718. }
  1719. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1720. single_dose, _ := json["single_dose"].(string)
  1721. project.SingleDose = single_dose
  1722. }
  1723. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1724. delivery_way, _ := json["delivery_way"].(string)
  1725. project.DeliveryWay = delivery_way
  1726. }
  1727. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1728. execution_frequency, _ := json["execution_frequency"].(string)
  1729. project.ExecutionFrequency = execution_frequency
  1730. }
  1731. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1732. remark, _ := json["remark"].(string)
  1733. project.Remark = remark
  1734. }
  1735. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1736. day, _ := json["number_days"].(string)
  1737. project.Day = day
  1738. }
  1739. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1740. unit, _ := json["unit"].(string)
  1741. project.Unit = unit
  1742. }
  1743. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  1744. if project.ID == 0 {
  1745. if stockConfig.IsOpen == 1 {
  1746. if project.Type == 3 {
  1747. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  1748. f_count, _ := strconv.ParseFloat(strconv.FormatInt(project.Count, 10), 64)
  1749. good.Total = good.Total - f_count
  1750. service.UpdateGoodInfo(&good)
  1751. }
  1752. }
  1753. } else {
  1754. temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  1755. if stockConfig.IsOpen == 1 {
  1756. if project.Type == 3 {
  1757. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  1758. if project.Count < temp_project.Count {
  1759. other_count := temp_project.Count - project.Count
  1760. other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
  1761. good.Total = good.Total + other_count_two
  1762. service.UpdateGoodInfo(&good)
  1763. } else if project.Count > temp_project.Count {
  1764. other_count := project.Count - temp_project.Count
  1765. other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(other_count, 10), 64)
  1766. good.Total = good.Total - other_count_two
  1767. service.UpdateGoodInfo(&good)
  1768. }
  1769. }
  1770. }
  1771. }
  1772. return 0
  1773. }
  1774. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1775. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1776. id := int64(json["id"].(float64))
  1777. additionalCharge.ID = id
  1778. }
  1779. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1780. item_id := int64(json["item_id"].(float64))
  1781. additionalCharge.ItemId = item_id
  1782. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1783. if config.ID > 0 {
  1784. if len(config.Code) > 0 {
  1785. additionalCharge.MedListCodg = config.Code
  1786. }
  1787. }
  1788. }
  1789. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1790. // price := int64(json["price"].(float64))
  1791. // formatInt_price := strconv.FormatInt(price, 10)
  1792. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1793. // additionalCharge.Price = float_price
  1794. // }
  1795. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1796. // price := int64(json["price"].(float64))
  1797. // formatInt_price := strconv.FormatInt(price, 10)
  1798. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1799. // additionalCharge.Price = float_price
  1800. //}
  1801. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1802. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1803. additionalCharge.Price = price
  1804. }
  1805. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1806. count, _ := json["count"].(string)
  1807. counts, _ := strconv.ParseInt(count, 10, 64)
  1808. additionalCharge.Count = counts
  1809. }
  1810. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1811. item_name, _ := json["item_name"].(string)
  1812. additionalCharge.ItemName = item_name
  1813. }
  1814. return 0
  1815. }
  1816. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  1817. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1818. utils.ErrorLog("drug_name")
  1819. return enums.ErrorCodeParamWrong
  1820. }
  1821. adviceName, _ := json["drug_name"].(string)
  1822. if len(adviceName) == 0 {
  1823. utils.ErrorLog("len(advice_name) == 0")
  1824. return enums.ErrorCodeParamWrong
  1825. }
  1826. advice.AdviceName = adviceName
  1827. adviceDesc, _ := json["advice_desc"].(string)
  1828. advice.AdviceDesc = adviceDesc
  1829. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1830. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1831. advice.DrugSpec = drugSpec
  1832. }
  1833. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1834. remark, _ := json["remark"].(string)
  1835. advice.Remark = remark
  1836. }
  1837. if json["id"] == nil {
  1838. advice.DrugId = 0
  1839. } else {
  1840. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1841. drug_id := int64(json["id"].(float64))
  1842. advice.DrugId = drug_id
  1843. }
  1844. }
  1845. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1846. drugSpecUnit, _ := json["min_unit"].(string)
  1847. advice.DrugSpecUnit = drugSpecUnit
  1848. }
  1849. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1850. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1851. advice.SingleDose = singleDose
  1852. }
  1853. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1854. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1855. advice.SingleDoseUnit = singleDoseUnit
  1856. }
  1857. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1858. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1859. advice.PrescribingNumber = prescribingNumber
  1860. }
  1861. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1862. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1863. advice.PrescribingNumberUnit = prescribingNumberUnit
  1864. }
  1865. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1866. deliveryWay, _ := json["delivery_way"].(string)
  1867. advice.DeliveryWay = deliveryWay
  1868. }
  1869. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1870. executionFrequency, _ := json["execution_frequency"].(string)
  1871. advice.ExecutionFrequency = executionFrequency
  1872. }
  1873. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1874. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1875. advice.Price = price
  1876. }
  1877. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1878. med_list_codg, _ := json["medical_insurance_number"].(string)
  1879. advice.MedListCodg = med_list_codg
  1880. }
  1881. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1882. day := int64(json["day"].(float64))
  1883. advice.Day = day
  1884. }
  1885. return 0
  1886. }
  1887. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  1888. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  1889. types := int64(json["type"].(float64))
  1890. project.Type = types
  1891. }
  1892. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1893. project_id := int64(json["project_id"].(float64))
  1894. project.ProjectId = project_id
  1895. }
  1896. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1897. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1898. project.Price = price
  1899. }
  1900. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1901. total, _ := json["total"].(string)
  1902. totals, _ := strconv.ParseInt(total, 10, 64)
  1903. project.Count = totals
  1904. }
  1905. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1906. medical_code, _ := json["medical_code"].(string)
  1907. project.MedListCodg = medical_code
  1908. }
  1909. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1910. single_dose, _ := json["single_dose"].(string)
  1911. project.SingleDose = single_dose
  1912. }
  1913. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1914. delivery_way, _ := json["delivery_way"].(string)
  1915. project.DeliveryWay = delivery_way
  1916. }
  1917. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1918. execution_frequency, _ := json["execution_frequency"].(string)
  1919. project.ExecutionFrequency = execution_frequency
  1920. }
  1921. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1922. remark, _ := json["remark"].(string)
  1923. project.Remark = remark
  1924. }
  1925. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1926. day, _ := json["number_days"].(string)
  1927. project.Day = day
  1928. }
  1929. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1930. unit, _ := json["unit"].(string)
  1931. project.Unit = unit
  1932. }
  1933. return 0
  1934. }
  1935. func (c *HisApiController) GetHisOrderList() {
  1936. page, _ := c.GetInt64("page", -1)
  1937. limit, _ := c.GetInt64("limit", -1)
  1938. start_time := c.GetString("start_time")
  1939. end_time := c.GetString("end_time")
  1940. types, _ := c.GetInt64("type", 0)
  1941. keywords := c.GetString("keywords")
  1942. p_type, _ := c.GetInt64("p_type", 0)
  1943. timeLayout := "2006-01-02"
  1944. loc, _ := time.LoadLocation("Local")
  1945. var startTime int64
  1946. if len(start_time) > 0 {
  1947. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1948. if err != nil {
  1949. fmt.Println(err)
  1950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1951. return
  1952. }
  1953. startTime = theTime.Unix()
  1954. }
  1955. var endTime int64
  1956. if len(end_time) > 0 {
  1957. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1958. if err != nil {
  1959. utils.ErrorLog(err.Error())
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1961. return
  1962. }
  1963. endTime = theTime.Unix()
  1964. }
  1965. adminUser := c.GetAdminUserInfo()
  1966. org_id := adminUser.CurrentOrgId
  1967. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type)
  1968. for _, item := range order {
  1969. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  1970. item.DoctorName = info.Doctor
  1971. item.DepartmentName = info.XtHisDepartment.Name
  1972. }
  1973. if err == nil {
  1974. c.ServeSuccessJSON(map[string]interface{}{
  1975. "order": order,
  1976. "total": total,
  1977. })
  1978. } else {
  1979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1980. return
  1981. }
  1982. }
  1983. func (c *HisApiController) GetHisOrder() {
  1984. patient_id, _ := c.GetInt64("patient_id", 0)
  1985. number := c.GetString("number")
  1986. adminInfo := c.GetAdminUserInfo()
  1987. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  1988. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  1989. if err == nil {
  1990. c.ServeSuccessJSON(map[string]interface{}{
  1991. "order": order,
  1992. "prescription": prescriptions,
  1993. })
  1994. } else {
  1995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1996. return
  1997. }
  1998. }
  1999. func (c *HisApiController) GetHisPrescriptionList() {
  2000. record_date := c.GetString("record_date")
  2001. keywords := c.GetString("keywords")
  2002. page, _ := c.GetInt64("page")
  2003. limit, _ := c.GetInt64("limit")
  2004. timeLayout := "2006-01-02"
  2005. loc, _ := time.LoadLocation("Local")
  2006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2007. if err != nil {
  2008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2009. return
  2010. }
  2011. recordDateTime := theTime.Unix()
  2012. adminInfo := c.GetAdminUserInfo()
  2013. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  2014. //adminInfo := c.GetAdminUserInfo()
  2015. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  2016. //fmt.Println(prescriptionOrder)
  2017. if err == nil {
  2018. c.ServeSuccessJSON(map[string]interface{}{
  2019. "order": prescriptionOrder,
  2020. "total": total,
  2021. })
  2022. } else {
  2023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2024. return
  2025. }
  2026. }
  2027. func (c *HisApiController) GetHisPrescriptionInfo() {
  2028. id, _ := c.GetInt64("id")
  2029. adminInfo := c.GetAdminUserInfo()
  2030. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  2031. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  2032. if err == nil {
  2033. c.ServeSuccessJSON(map[string]interface{}{
  2034. "order": prescriptionOrder,
  2035. "prescription": prescription,
  2036. })
  2037. } else {
  2038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2039. return
  2040. }
  2041. }
  2042. func (c *HisApiController) GetMedicalInsuranceConfig() {
  2043. adminUser := c.GetAdminUserInfo()
  2044. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2045. c.ServeSuccessJSON(map[string]interface{}{
  2046. "config": config,
  2047. })
  2048. }
  2049. type ResultTwo struct {
  2050. ErrMsg interface{} `json:"err_msg"`
  2051. InfRefmsgid string `json:"inf_refmsgid"`
  2052. Infcode int64 `json:"infcode"`
  2053. Output struct {
  2054. Baseinfo struct {
  2055. Age float64 `json:"age"`
  2056. Brdy string `json:"brdy"`
  2057. Certno string `json:"certno"`
  2058. Gend string `json:"gend"`
  2059. Naty string `json:"naty"`
  2060. PsnCertType string `json:"psn_cert_type"`
  2061. PsnName string `json:"psn_name"`
  2062. PsnNo string `json:"psn_no"`
  2063. } `json:"baseinfo"`
  2064. Idetinfo []interface{} `json:"idetinfo"`
  2065. Iinfo []struct {
  2066. Balc float64 `json:"balc"`
  2067. CvlservFlag string `json:"cvlserv_flag"`
  2068. EmpName string `json:"emp_name"`
  2069. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  2070. Insutype string `json:"insutype"`
  2071. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  2072. PausInsuDate interface{} `json:"paus_insu_date"`
  2073. PsnInsuDate string `json:"psn_insu_date"`
  2074. PsnInsuStas string `json:"psn_insu_stas"`
  2075. PsnType string `json:"psn_type"`
  2076. } `json:"insuinfo"`
  2077. } `json:"output"`
  2078. RefmsgTime string `json:"refmsg_time"`
  2079. RespondTime string `json:"respond_time"`
  2080. Signtype interface{} `json:"signtype"`
  2081. WarnInfo interface{} `json:"warn_info"`
  2082. }
  2083. type ResultThree struct {
  2084. Cainfo interface{} `json:"cainfo"`
  2085. ErrMsg interface{} `json:"err_msg"`
  2086. InfRefmsgid string `json:"inf_refmsgid"`
  2087. Infcode int64 `json:"infcode"`
  2088. Output struct {
  2089. Data struct {
  2090. IptOtpNo string `json:"ipt_otp_no"`
  2091. MdtrtID string `json:"mdtrt_id"`
  2092. PsnNo string `json:"psn_no"`
  2093. } `json:"data"`
  2094. } `json:"output"`
  2095. RefmsgTime string `json:"refmsg_time"`
  2096. RespondTime string `json:"respond_time"`
  2097. Signtype interface{} `json:"signtype"`
  2098. WarnMsg interface{} `json:"warn_msg"`
  2099. }
  2100. type ResultFour struct {
  2101. Cainfo string `json:"cainfo"`
  2102. ErrMsg string `json:"err_msg"`
  2103. InfRefmsgid string `json:"inf_refmsgid"`
  2104. Infcode int64 `json:"infcode"`
  2105. Output struct {
  2106. Result []struct {
  2107. BasMednFlag string `json:"bas_medn_flag"`
  2108. ChldMedcFlag string `json:"chld_medc_flag"`
  2109. ChrgitmLv string `json:"chrgitm_lv"`
  2110. Cnt float64 `json:"cnt"`
  2111. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  2112. DrtReimFlag string `json:"drt_reim_flag"`
  2113. FeedetlSn string `json:"feedetl_sn"`
  2114. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2115. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  2116. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2117. ListSpItemFlag string `json:"list_sp_item_flag"`
  2118. LmtUsedFlag string `json:"lmt_used_flag"`
  2119. MedChrgitmType string `json:"med_chrgitm_type"`
  2120. Memo string `json:"memo"`
  2121. OverlmtAmt float64 `json:"overlmt_amt"`
  2122. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2123. Pric float64 `json:"pric"`
  2124. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  2125. SelfpayProp float64 `json:"selfpay_prop"`
  2126. } `json:"result"`
  2127. } `json:"output"`
  2128. RefmsgTime string `json:"refmsg_time"`
  2129. RespondTime string `json:"respond_time"`
  2130. Signtype string `json:"signtype"`
  2131. WarnMsg string `json:"warn_msg"`
  2132. }
  2133. type ResultFive struct {
  2134. Insutype string `json:"insutype"`
  2135. }
  2136. type ResultSix struct {
  2137. Cainfo interface{} `json:"cainfo"`
  2138. ErrMsg interface{} `json:"err_msg"`
  2139. InfRefmsgid string `json:"inf_refmsgid"`
  2140. Infcode int64 `json:"infcode"`
  2141. Output struct {
  2142. } `json:"output"`
  2143. RefmsgTime string `json:"refmsg_time"`
  2144. RespondTime string `json:"respond_time"`
  2145. Signtype interface{} `json:"signtype"`
  2146. WarnMsg interface{} `json:"warn_msg"`
  2147. }
  2148. type ResultSeven struct {
  2149. Cainfo string `json:"cainfo"`
  2150. ErrMsg string `json:"err_msg"`
  2151. InfRefmsgid string `json:"inf_refmsgid"`
  2152. Infcode int64 `json:"infcode"`
  2153. Output struct {
  2154. Setldetail []interface{} `json:"setldetail"`
  2155. Setlinfo struct {
  2156. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2157. AcctPay float64 `json:"acct_pay"`
  2158. ActPayDedc float64 `json:"act_pay_dedc"`
  2159. Age float64 `json:"age"`
  2160. Balc float64 `json:"balc"`
  2161. Brdy string `json:"brdy"`
  2162. Certno string `json:"certno"`
  2163. ClrOptins string `json:"clr_optins"`
  2164. ClrType string `json:"clr_type"`
  2165. ClrWay string `json:"clr_way"`
  2166. CvlservFlag string `json:"cvlserv_flag"`
  2167. CvlservPay float64 `json:"cvlserv_pay"`
  2168. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2169. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2170. Gend string `json:"gend"`
  2171. HifesPay float64 `json:"hifes_pay"`
  2172. HifmiPay float64 `json:"hifmi_pay"`
  2173. HifobPay float64 `json:"hifob_pay"`
  2174. HifpPay float64 `json:"hifp_pay"`
  2175. HospPartAmt float64 `json:"hosp_part_amt"`
  2176. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2177. Insutype string `json:"insutype"`
  2178. MafPay float64 `json:"maf_pay"`
  2179. MdtrtCertType string `json:"mdtrt_cert_type"`
  2180. MdtrtID string `json:"mdtrt_id"`
  2181. MedType string `json:"med_type"`
  2182. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2183. MedinsSetlID string `json:"medins_setl_id"`
  2184. Naty string `json:"naty"`
  2185. OthPay float64 `json:"oth_pay"`
  2186. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2187. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2188. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2189. PsnCashPay float64 `json:"psn_cash_pay"`
  2190. PsnCertType string `json:"psn_cert_type"`
  2191. PsnName string `json:"psn_name"`
  2192. PsnNo string `json:"psn_no"`
  2193. PsnPartAmt float64 `json:"psn_part_amt"`
  2194. PsnType string `json:"psn_type"`
  2195. SetlID string `json:"setl_id"`
  2196. SetlTime string `json:"setl_time"`
  2197. } `json:"setlinfo"`
  2198. } `json:"output"`
  2199. RefmsgTime string `json:"refmsg_time"`
  2200. RespondTime string `json:"respond_time"`
  2201. Signtype interface{} `json:"signtype"`
  2202. WarnMsg interface{} `json:"warn_msg"`
  2203. }
  2204. type ResultEight struct {
  2205. Cainfo string `json:"cainfo"`
  2206. ErrMsg string `json:"err_msg"`
  2207. InfRefmsgid string `json:"inf_refmsgid"`
  2208. Infcode int64 `json:"infcode"`
  2209. Output struct {
  2210. Stmtinfo struct {
  2211. SetlOptins string `json:"setl_optins"`
  2212. StmtRslt string `json:"stmt_rslt"`
  2213. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  2214. } `json:"stmtinfo"`
  2215. } `json:"output"`
  2216. RefmsgTime string `json:"refmsg_time"`
  2217. RespondTime string `json:"respond_time"`
  2218. Signtype interface{} `json:"signtype"`
  2219. WarnMsg interface{} `json:"warn_msg"`
  2220. }
  2221. type ResultNine struct {
  2222. Cainfo string `json:"cainfo"`
  2223. ErrMsg string `json:"err_msg"`
  2224. InfRefmsgid string `json:"inf_refmsgid"`
  2225. Infcode int64 `json:"infcode"`
  2226. Output struct {
  2227. FileQuryNo string `json:"file_qury_no"`
  2228. } `json:"output"`
  2229. RefmsgTime string `json:"refmsg_time"`
  2230. RespondTime string `json:"respond_time"`
  2231. Signtype interface{} `json:"signtype"`
  2232. WarnMsg interface{} `json:"warn_msg"`
  2233. }
  2234. type ResultTen struct {
  2235. Cainfo string `json:"cainfo"`
  2236. ErrMsg string `json:"err_msg"`
  2237. InfRefmsgid string `json:"inf_refmsgid"`
  2238. Infcode int64 `json:"infcode"`
  2239. Output struct {
  2240. DldEndtime string `json:"dld_endtime"`
  2241. FileQuryNo string `json:"file_qury_no"`
  2242. Filename string `json:"filename"`
  2243. } `json:"output"`
  2244. RefmsgTime string `json:"refmsg_time"`
  2245. RespondTime string `json:"respond_time"`
  2246. Signtype interface{} `json:"signtype"`
  2247. WarnMsg interface{} `json:"warn_msg"`
  2248. }
  2249. type ResultEleven struct {
  2250. Cainfo string `json:"cainfo"`
  2251. ErrMsg string `json:"err_msg"`
  2252. InfRefmsgid string `json:"inf_refmsgid"`
  2253. Infcode int64 `json:"infcode"`
  2254. Output struct {
  2255. Setlinfo struct {
  2256. FixmedinsName string `json:"fixmedins_name"`
  2257. FixmedinsCode string `json:"fixmedins_code"`
  2258. PsnNo string `json:"psn_no"`
  2259. PsnName string `json:"psn_name"`
  2260. HifobPay float64 `json:"hifob_pay"`
  2261. Gend string `json:"gend"`
  2262. Brdy string `json:"brdy"`
  2263. PsnCertType string `json:"psn_cert_type"`
  2264. PsnType string `json:"psn_type"`
  2265. EmpName string `json:"emp_name"`
  2266. Certno string `json:"certno"`
  2267. Insutype string `json:"insutype"`
  2268. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2269. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2270. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2271. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2272. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2273. ActPayDedc float64 `json:"act_pay_dedc"`
  2274. HifpPay float64 `json:"hifp_pay"`
  2275. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2276. CvlservPay float64 `json:"cvlserv_pay"`
  2277. HifesPay float64 `json:"hifes_pay"`
  2278. HifmiPay float64 `json:"hifmi_pay"`
  2279. MafPay float64 `json:"maf_pay"`
  2280. OthPay float64 `json:"oth_pay"`
  2281. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2282. PsnPay float64 `json:"psn_pay"`
  2283. AcctPay float64 `json:"acct_pay"`
  2284. CashPayamt float64 `json:"cash_payamt"`
  2285. Balc float64 `json:"balc"`
  2286. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2287. MedinsSetlId string `json:"medins_setl_id"`
  2288. RefdSetlFlag string `json:"refd_setl_flag"`
  2289. SetlTime string `json:"setl_time"`
  2290. MedType string `json:"med_type"`
  2291. } `json:"setlinfo"`
  2292. } `json:"output"`
  2293. RefmsgTime string `json:"refmsg_time"`
  2294. RespondTime string `json:"respond_time"`
  2295. Signtype interface{} `json:"signtype"`
  2296. WarnMsg interface{} `json:"warn_msg"`
  2297. }
  2298. type Custom struct {
  2299. DetItemFeeSumamt string
  2300. Cut string
  2301. FeedetlSn string
  2302. Price string
  2303. MedListCodg string
  2304. Type int64
  2305. AdviceId int64
  2306. ProjectId int64
  2307. ItemId int64
  2308. }
  2309. //获取个人信息----挂号-----上传就诊信息
  2310. func (c *HisApiController) GetRegisterInfo() {
  2311. id, _ := c.GetInt64("id")
  2312. record_time := c.GetString("record_time")
  2313. settlementValue, _ := c.GetInt64("settlement_value")
  2314. medical_insurance_card := c.GetString("medical_insurance_card")
  2315. name := c.GetString("name")
  2316. id_card_type, _ := c.GetInt64("id_card_type")
  2317. certificates, _ := c.GetInt64("certificates")
  2318. medical_care, _ := c.GetInt64("medical_care")
  2319. birthday := c.GetString("birthday")
  2320. age, _ := c.GetInt64("age")
  2321. id_card := c.GetString("id_card")
  2322. register_type, _ := c.GetInt64("register")
  2323. doctor, _ := c.GetInt64("doctor")
  2324. department, _ := c.GetInt64("department")
  2325. gender, _ := c.GetInt64("sex")
  2326. phone := c.GetString("phone")
  2327. registration_fee, _ := c.GetFloat("registration_fee")
  2328. medical_expenses, _ := c.GetFloat("medical_expenses")
  2329. social_type, _ := c.GetInt64("social_type")
  2330. diagnosis_id, _ := c.GetInt64("diagnosis")
  2331. sick_type, _ := c.GetInt64("sick_type")
  2332. reg_type := c.GetString("p_type")
  2333. timeLayout := "2006-01-02"
  2334. loc, _ := time.LoadLocation("Local")
  2335. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  2336. birthUnix := birthdays.Unix()
  2337. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2338. if err != nil {
  2339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2340. return
  2341. }
  2342. recordDateTime := theTime.Unix()
  2343. adminInfo := c.GetAdminUserInfo()
  2344. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  2345. if tempPatient.ID == 0 {
  2346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  2347. return
  2348. }
  2349. var patient service.Patients
  2350. if id == 0 {
  2351. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  2352. } else {
  2353. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  2354. }
  2355. if patient.ID == 0 {
  2356. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2357. return
  2358. }
  2359. if len(patient.IdCardNo) == 0 {
  2360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2361. return
  2362. }
  2363. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2364. if len(his) >= 1 {
  2365. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  2366. if len(his) >= 1 && order.ID == 0 {
  2367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  2368. return
  2369. }
  2370. }
  2371. timeStr := time.Now().Format("2006-01-02 15:04:05")
  2372. fmt.Println(timeStr)
  2373. timeArr := strings.Split(timeStr, " ")
  2374. fmt.Println(timeArr)
  2375. timeArrTwo := strings.Split(timeArr[0], "-")
  2376. timeArrThree := strings.Split(timeArr[1], ":")
  2377. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  2378. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2379. if len(lists) == 0 {
  2380. var hisPatient models.XtHisPatient
  2381. hisPatient = models.XtHisPatient{
  2382. Name: name,
  2383. Age: age,
  2384. Gender: gender,
  2385. Birthday: birthUnix,
  2386. Phone: phone,
  2387. MedicalTreatmentType: medical_care,
  2388. IdType: certificates,
  2389. IdCardNo: id_card,
  2390. BalanceAccountsType: settlementValue,
  2391. SocialType: social_type,
  2392. MedicalInsuranceNumber: medical_insurance_card,
  2393. RegisterType: register_type,
  2394. RegisterCost: registration_fee,
  2395. TreatmentCost: medical_expenses,
  2396. AdminUserId: adminInfo.AdminUser.Id,
  2397. UserOrgId: adminInfo.CurrentOrgId,
  2398. Status: 1,
  2399. RecordDate: recordDateTime,
  2400. IsReturn: 1,
  2401. PatientId: patient.ID,
  2402. Ctime: time.Now().Unix(),
  2403. Mtime: time.Now().Unix(),
  2404. Number: str,
  2405. IdCardType: id_card_type,
  2406. Departments: department,
  2407. Doctor: doctor,
  2408. PType: reg_type,
  2409. Diagnosis: diagnosis_id,
  2410. SickType: sick_type,
  2411. }
  2412. service.CreateHisPatient(&hisPatient)
  2413. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  2414. c.ServeSuccessJSON(map[string]interface{}{
  2415. "his_info": hisPatient,
  2416. })
  2417. } else {
  2418. //chrgBchno := rand.Intn(1000000) + 10000
  2419. var hisPatient models.XtHisPatient
  2420. hisPatient = models.XtHisPatient{
  2421. Name: name,
  2422. Age: age,
  2423. Gender: gender,
  2424. Birthday: birthUnix,
  2425. Phone: phone,
  2426. MedicalTreatmentType: medical_care,
  2427. IdType: certificates,
  2428. IdCardNo: id_card,
  2429. BalanceAccountsType: settlementValue,
  2430. SocialType: social_type,
  2431. MedicalInsuranceNumber: medical_insurance_card,
  2432. RegisterType: register_type,
  2433. RegisterCost: registration_fee,
  2434. TreatmentCost: medical_expenses,
  2435. AdminUserId: adminInfo.AdminUser.Id,
  2436. UserOrgId: adminInfo.CurrentOrgId,
  2437. Status: 1,
  2438. RecordDate: recordDateTime,
  2439. IsReturn: 1,
  2440. PatientId: patient.ID,
  2441. Ctime: time.Now().Unix(),
  2442. Mtime: time.Now().Unix(),
  2443. Number: str,
  2444. IdCardType: id_card_type,
  2445. Departments: department,
  2446. Doctor: doctor,
  2447. PType: reg_type,
  2448. Diagnosis: diagnosis_id,
  2449. SickType: sick_type,
  2450. }
  2451. service.CreateHisPatient(&hisPatient)
  2452. c.ServeSuccessJSON(map[string]interface{}{
  2453. "his_info": hisPatient,
  2454. })
  2455. }
  2456. //timeStr := time.Now().Format("2006-01-02")
  2457. //timeArr := strings.Split(timeStr, "-")
  2458. //var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)+ ""
  2459. }
  2460. //上传明细----结算
  2461. func (c *HisApiController) GetUploadInfo() {
  2462. id, _ := c.GetInt64("id")
  2463. record_time := c.GetString("record_time")
  2464. his_patient_id, _ := c.GetInt64("his_patient_id")
  2465. pay_way, _ := c.GetInt64("pay_way")
  2466. pay_price, _ := c.GetFloat("pay_price")
  2467. pay_card_no := c.GetString("pay_card_no")
  2468. discount_price, _ := c.GetFloat("discount_price")
  2469. preferential_price, _ := c.GetFloat("preferential_price")
  2470. reality_price, _ := c.GetFloat("reality_price")
  2471. found_price, _ := c.GetFloat("found_price")
  2472. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2473. private_price, _ := c.GetFloat("private_price")
  2474. timeLayout := "2006-01-02"
  2475. loc, _ := time.LoadLocation("Local")
  2476. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2477. fapiao_code := c.GetString("fapiao_code")
  2478. fapiao_number := c.GetString("fapiao_number")
  2479. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2480. if err != nil {
  2481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2482. return
  2483. }
  2484. recordDateTime := theTime.Unix()
  2485. adminUser := c.GetAdminUserInfo()
  2486. var prescriptions []*models.HisPrescription
  2487. var start_time int64
  2488. var end_time int64
  2489. if settle_accounts_type == 1 { //日结
  2490. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime)
  2491. } else { //月结
  2492. start_time_str := c.GetString("start_time")
  2493. end_time_str := c.GetString("end_time")
  2494. timeLayout := "2006-01-02"
  2495. loc, _ := time.LoadLocation("Local")
  2496. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2497. if err != nil {
  2498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2499. return
  2500. }
  2501. recordStartTime := theStartTime.Unix()
  2502. start_time = recordStartTime
  2503. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2504. if err != nil {
  2505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2506. return
  2507. }
  2508. recordEndTime := theEndTime.Unix()
  2509. end_time = recordEndTime
  2510. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2511. }
  2512. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2513. fmt.Println("~~~~~~~~~")
  2514. fmt.Println(his.Number)
  2515. fmt.Println("~~~~~~~~~")
  2516. timestamp := time.Now().Unix()
  2517. tempTime := time.Unix(timestamp, 0)
  2518. timeFormat := tempTime.Format("20060102150405")
  2519. chrgBchno := rand.Intn(100000) + 10000
  2520. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2521. strconv.FormatInt(his.PatientId, 10)
  2522. var ids []int64
  2523. for _, item := range prescriptions {
  2524. ids = append(ids, item.ID)
  2525. }
  2526. var total float64
  2527. for _, item := range prescriptions {
  2528. if item.Type == 1 { //药品
  2529. for _, subItem := range item.HisDoctorAdviceInfo {
  2530. total = total + (subItem.Price * subItem.PrescribingNumber)
  2531. }
  2532. }
  2533. if item.Type == 2 { //项目
  2534. for _, subItem := range item.HisPrescriptionProject {
  2535. total = total + (subItem.Price * float64(subItem.Count))
  2536. }
  2537. }
  2538. for _, subItem := range item.HisAdditionalCharge {
  2539. total = total + (subItem.Price * float64(subItem.Count))
  2540. }
  2541. }
  2542. allTotal := fmt.Sprintf("%.2f", total)
  2543. totals, _ := strconv.ParseFloat(allTotal, 64)
  2544. order := &models.HisOrder{
  2545. UserOrgId: adminUser.CurrentOrgId,
  2546. HisPatientId: his.ID,
  2547. PatientId: id,
  2548. SettleAccountsDate: recordDateTime,
  2549. Ctime: time.Now().Unix(),
  2550. Mtime: time.Now().Unix(),
  2551. Status: 1,
  2552. OrderStatus: 2,
  2553. MdtrtId: his.Number,
  2554. Number: chrg_bchno,
  2555. MedfeeSumamt: totals,
  2556. PayWay: pay_way,
  2557. PayPrice: pay_price,
  2558. PayCardNo: pay_card_no,
  2559. DiscountPrice: discount_price,
  2560. PreferentialPrice: preferential_price,
  2561. RealityPrice: reality_price,
  2562. FoundPrice: found_price,
  2563. MedicalInsurancePrice: medical_insurance_price,
  2564. PrivatePrice: private_price,
  2565. SettleEndTime: end_time,
  2566. SettleStartTime: start_time,
  2567. SettleType: settle_accounts_type,
  2568. FaPiaoCode: fapiao_code,
  2569. FaPiaoNumber: fapiao_number,
  2570. PType: 2,
  2571. }
  2572. err = service.CreateOrder(order)
  2573. if err != nil {
  2574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2575. return
  2576. }
  2577. var customs []*Custom
  2578. for _, item := range prescriptions {
  2579. if item.Type == 1 { //药品
  2580. for _, subItem := range item.HisDoctorAdviceInfo {
  2581. cus := &Custom{
  2582. AdviceId: subItem.ID,
  2583. ProjectId: 0,
  2584. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2585. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2586. FeedetlSn: subItem.FeedetlSn,
  2587. Price: fmt.Sprintf("%.2f", subItem.Price),
  2588. MedListCodg: subItem.MedListCodg,
  2589. Type: 1,
  2590. }
  2591. customs = append(customs, cus)
  2592. }
  2593. }
  2594. if item.Type == 2 { //项目
  2595. for _, subItem := range item.HisPrescriptionProject {
  2596. cus := &Custom{
  2597. AdviceId: 0,
  2598. ProjectId: subItem.ID,
  2599. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2600. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2601. FeedetlSn: subItem.FeedetlSn,
  2602. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2603. MedListCodg: subItem.MedListCodg,
  2604. Type: 2,
  2605. }
  2606. customs = append(customs, cus)
  2607. }
  2608. }
  2609. for _, item := range item.HisAdditionalCharge {
  2610. cus := &Custom{
  2611. ItemId: item.ID,
  2612. AdviceId: 0,
  2613. ProjectId: 0,
  2614. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2615. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2616. FeedetlSn: item.FeedetlSn,
  2617. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2618. MedListCodg: item.XtHisAddtionConfig.Code,
  2619. Type: 3,
  2620. }
  2621. customs = append(customs, cus)
  2622. }
  2623. }
  2624. for _, item := range customs {
  2625. var advice_id int64 = 0
  2626. var project_id int64 = 0
  2627. var item_id int64 = 0
  2628. var types int64 = 0
  2629. if item.Type == 1 {
  2630. advice_id = item.AdviceId
  2631. project_id = 0
  2632. item_id = 0
  2633. } else if item.Type == 2 {
  2634. advice_id = 0
  2635. item_id = 0
  2636. project_id = item.ProjectId
  2637. } else if item.Type == 3 {
  2638. advice_id = 0
  2639. item_id = item.ItemId
  2640. project_id = 0
  2641. }
  2642. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2643. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2644. pric, _ := strconv.ParseFloat(item.Price, 32)
  2645. info := &models.HisOrderInfo{
  2646. OrderNumber: order.Number,
  2647. UploadDate: time.Now().Unix(),
  2648. AdviceId: advice_id,
  2649. DetItemFeeSumamt: detItemFeeSumamt,
  2650. Cnt: cut,
  2651. Pric: pric,
  2652. PatientId: id,
  2653. Status: 1,
  2654. Mtime: time.Now().Unix(),
  2655. Ctime: time.Now().Unix(),
  2656. UserOrgId: adminUser.CurrentOrgId,
  2657. HisPatientId: his.ID,
  2658. OrderId: order.ID,
  2659. ProjectId: project_id,
  2660. Type: types,
  2661. ItemId: item_id,
  2662. }
  2663. service.CreateOrderInfo(info)
  2664. }
  2665. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2666. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  2667. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2668. if err == nil {
  2669. c.ServeSuccessJSON(map[string]interface{}{
  2670. "msg": "结算成功",
  2671. })
  2672. }
  2673. }
  2674. //退款
  2675. func (c *HisApiController) Refund() {
  2676. order_id, _ := c.GetInt64("order_id")
  2677. //number := c.GetString("number")
  2678. order, _ := service.GetHisOrderByID(order_id)
  2679. adminUser := c.GetAdminUserInfo()
  2680. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2681. if config.IsOpen == 1 { //对接了医保,走医保流程
  2682. } else {
  2683. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  2684. if err == nil {
  2685. c.ServeSuccessJSON(map[string]interface{}{
  2686. "msg": "退费成功",
  2687. })
  2688. } else {
  2689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2690. return
  2691. }
  2692. }
  2693. }
  2694. func (this *HisApiController) AdditionalCharge() {
  2695. dataBody := make(map[string]interface{}, 0)
  2696. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2697. fmt.Println(err)
  2698. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  2699. patient_id := int64(dataBody["patient_id"].(float64))
  2700. medicineData, _ := dataBody["medicineData"].([]interface{})
  2701. adminUserInfo := this.GetAdminUserInfo()
  2702. orgId := adminUserInfo.CurrentOrgId
  2703. admin_user_id := adminUserInfo.AdminUser.Id
  2704. timeStr := time.Now().Format("2006-01-02")
  2705. timeLayout := "2006-01-02 15:04:05"
  2706. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2707. timenow := timeStringToTime.Unix()
  2708. var additionalCharges []*models.HisAdditionalCharge
  2709. for _, item := range medicineData {
  2710. var randNum int
  2711. randNum = rand.Intn(10000) + 1000
  2712. timestamp := time.Now().Unix()
  2713. tempTime := time.Unix(timestamp, 0)
  2714. timeFormat := tempTime.Format("20060102150405")
  2715. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2716. items := item.(map[string]interface{})
  2717. money := items["price"].(string)
  2718. item_id_str := items["item_id"].(string)
  2719. name := items["name"].(string)
  2720. id_str := items["id"].(string)
  2721. moneys, _ := strconv.ParseInt(money, 10, 64)
  2722. monStr := strconv.FormatInt(moneys, 10)
  2723. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  2724. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  2725. id, _ := strconv.ParseInt(id_str, 10, 64)
  2726. additionalCharge := &models.HisAdditionalCharge{
  2727. ID: id,
  2728. HisPatientId: his_patient_id,
  2729. UserOrgId: orgId,
  2730. PatientId: patient_id,
  2731. RecordDate: timenow,
  2732. Price: monneyStr,
  2733. Status: 1,
  2734. ItemName: name,
  2735. ItemId: item_id,
  2736. AdminUserId: admin_user_id,
  2737. CreatedTime: time.Now().Unix(),
  2738. OrderStatus: 0,
  2739. PrescriptionNumber: "",
  2740. BatchNumber: "",
  2741. FeedetlSn: p_number,
  2742. }
  2743. service.CreateAdditionalCharge(additionalCharge)
  2744. additionalCharges = append(additionalCharges, additionalCharge)
  2745. }
  2746. this.ServeSuccessJSON(map[string]interface{}{
  2747. "msg": "添加成功",
  2748. "additional_charges": additionalCharges,
  2749. })
  2750. }
  2751. func (this *HisApiController) DeleteAddition() {
  2752. id, _ := this.GetInt64("id")
  2753. //TODO 需要判断是否已经结算
  2754. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  2755. if err == nil {
  2756. this.ServeSuccessJSON(map[string]interface{}{
  2757. "msg": "删除成功",
  2758. })
  2759. return
  2760. } else {
  2761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2762. return
  2763. }
  2764. }
  2765. func (this *HisApiController) GetAdminUsers() {
  2766. adminUser := this.GetAdminUserInfo()
  2767. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  2768. this.ServeSuccessJSON(map[string]interface{}{
  2769. "doctors": doctors,
  2770. })
  2771. }
  2772. func (this *HisApiController) GetLastOrNextHisPrescription() {
  2773. change_type, _ := this.GetInt64("type", 0)
  2774. record_date := this.GetString("record_time")
  2775. patient_id, _ := this.GetInt64("patient_id", 0)
  2776. p_type, _ := this.GetInt64("p_type", 0)
  2777. timeLayout := "2006-01-02"
  2778. loc, _ := time.LoadLocation("Local")
  2779. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2780. record_time := theAdviceRecordTime.Unix()
  2781. adminUserInfo := this.GetAdminUserInfo()
  2782. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  2783. if err == nil {
  2784. if len(prescriptions) == 0 {
  2785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2786. return
  2787. } else {
  2788. this.ServeSuccessJSON(map[string]interface{}{
  2789. "prescriptions": prescriptions,
  2790. })
  2791. return
  2792. }
  2793. } else {
  2794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2795. return
  2796. }
  2797. }
  2798. func (this *HisApiController) GetCallHisPrescription() {
  2799. patient_id, _ := this.GetInt64("patient_id", 0)
  2800. timeLayout := "2006-01-02"
  2801. loc, _ := time.LoadLocation("Local")
  2802. start_time := this.GetString("start_time")
  2803. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2804. end_time := this.GetString("end_time")
  2805. p_type, _ := this.GetInt64("p_type")
  2806. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2807. adminUserInfo := this.GetAdminUserInfo()
  2808. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  2809. if err == nil {
  2810. this.ServeSuccessJSON(map[string]interface{}{
  2811. "prescriptions": prescriptions,
  2812. })
  2813. return
  2814. } else {
  2815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2816. return
  2817. }
  2818. }
  2819. func (this *HisApiController) GetHisDayPrescription() {
  2820. timeLayout := "2006-01-02"
  2821. loc, _ := time.LoadLocation("Local")
  2822. start_time := this.GetString("start_time")
  2823. patient_id, _ := this.GetInt64("patient_id", 0)
  2824. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2825. end_time := this.GetString("end_time")
  2826. p_type, _ := this.GetInt64("p_type")
  2827. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2828. adminUserInfo := this.GetAdminUserInfo()
  2829. dayHisPrescription, err := service.GetMonthHisPrescriptionThree(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  2830. if err == nil {
  2831. this.ServeSuccessJSON(map[string]interface{}{
  2832. "day_prescription": dayHisPrescription,
  2833. })
  2834. return
  2835. } else {
  2836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2837. return
  2838. }
  2839. }
  2840. func (c *HisApiController) GetHisChargePatientList() {
  2841. record_date := c.GetString("record_date")
  2842. timeLayout := "2006-01-02"
  2843. loc, _ := time.LoadLocation("Local")
  2844. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2845. if err != nil {
  2846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2847. return
  2848. }
  2849. recordDateTime := theTime.Unix()
  2850. adminInfo := c.GetAdminUserInfo()
  2851. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  2852. tempPatients, _ := service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  2853. var patients []*service.NewTempPatients
  2854. var patients_two []*service.NewTempPatients
  2855. for _, item := range tempPatients {
  2856. //过滤掉没挂号的和没开处方的
  2857. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  2858. patients = append(patients, item)
  2859. }
  2860. //过滤掉没挂号的
  2861. if len(item.HisPatient) > 0 {
  2862. patients_two = append(patients_two, item)
  2863. }
  2864. }
  2865. c.ServeSuccessJSON(map[string]interface{}{
  2866. "list": patients,
  2867. "list_two": patients_two,
  2868. })
  2869. }
  2870. func (c *HisApiController) GetHisUnRegisterPatientList() {
  2871. record_date := c.GetString("record_date")
  2872. timeLayout := "2006-01-02"
  2873. loc, _ := time.LoadLocation("Local")
  2874. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2875. if err != nil {
  2876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2877. return
  2878. }
  2879. recordDateTime := theTime.Unix()
  2880. adminUser := c.GetAdminUserInfo()
  2881. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  2882. var patients []*service.Patients
  2883. for _, item := range tempPatients {
  2884. if item.HisPatient.ID == 0 {
  2885. patients = append(patients, item)
  2886. }
  2887. }
  2888. c.ServeSuccessJSON(map[string]interface{}{
  2889. "list": patients,
  2890. //"list_two": patients_two,
  2891. })
  2892. }
  2893. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  2894. newArr = make([]*service.Patients, 0)
  2895. for i := 0; i < len(patient); i++ {
  2896. repeat := false
  2897. for j := i + 1; j < len(patient); j++ {
  2898. if patient[i].ID == patient[j].ID {
  2899. repeat = true
  2900. break
  2901. }
  2902. }
  2903. if !repeat {
  2904. newArr = append(newArr, patient[i])
  2905. }
  2906. }
  2907. return
  2908. }
  2909. func (c *HisApiController) GetHisChargePatientInfo() {
  2910. patient_id, _ := c.GetInt64("patient_id")
  2911. his_patient_id, _ := c.GetInt64("his_patient_id")
  2912. record_date := c.GetString("record_date")
  2913. start_time := c.GetString("start_time")
  2914. end_time := c.GetString("end_time")
  2915. order_status, _ := c.GetInt64("type", 0)
  2916. p_type, _ := c.GetInt64("p_type", 0)
  2917. timeLayout := "2006-01-02"
  2918. loc, _ := time.LoadLocation("Local")
  2919. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2920. if err != nil {
  2921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2922. return
  2923. }
  2924. recordDateTime := theTime.Unix()
  2925. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2926. if err != nil {
  2927. }
  2928. startRecordDateTime := startTime.Unix()
  2929. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2930. if err != nil {
  2931. }
  2932. endRecordDateTime := endTime.Unix()
  2933. admin := c.GetAdminUserInfo()
  2934. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  2935. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  2936. var prescriptions []*models.HisPrescription
  2937. if order_status == 1 || order_status == 0 {
  2938. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  2939. } else if order_status == 2 {
  2940. prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  2941. }
  2942. var monthPrescriptions []*models.HisPrescription
  2943. if order_status == 1 || order_status == 0 {
  2944. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  2945. } else if order_status == 2 {
  2946. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  2947. }
  2948. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  2949. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  2950. order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
  2951. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  2952. //获取所有科室信息
  2953. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  2954. c.ServeSuccessJSON(map[string]interface{}{
  2955. "his_info": his_patient_info,
  2956. "xt_info": xt_patient_info,
  2957. "prescription": prescriptions,
  2958. "case_history": case_history,
  2959. "info": patientPrescriptionInfo,
  2960. "month_prescriptions": monthPrescriptions,
  2961. "order": order,
  2962. "doctors": doctors,
  2963. "department": department,
  2964. })
  2965. return
  2966. }
  2967. func (c *HisApiController) GetAllOrderDetail() {
  2968. order_id, _ := c.GetInt64("id", 0)
  2969. order, _ := service.GetHisOrderByID(order_id)
  2970. if order.ID == 0 {
  2971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  2972. return
  2973. }
  2974. org_id := c.GetAdminUserInfo().CurrentOrgId
  2975. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  2976. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  2977. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  2978. c.ServeSuccessJSON(map[string]interface{}{
  2979. "order": order,
  2980. "order_info": order_info,
  2981. "patient": patient,
  2982. "admin_info": adminInfo,
  2983. })
  2984. return
  2985. }
  2986. func (c *HisApiController) GetAllOrderDetailCollect() {
  2987. order_id, _ := c.GetInt64("id", 0)
  2988. order, _ := service.GetHisOrderByID(order_id)
  2989. if order.ID == 0 {
  2990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  2991. return
  2992. }
  2993. org_id := c.GetAdminUserInfo().CurrentOrgId
  2994. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  2995. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  2996. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  2997. c.ServeSuccessJSON(map[string]interface{}{
  2998. "order": order,
  2999. "order_info": order_info,
  3000. "patient": patient,
  3001. "admin_info": adminInfo,
  3002. })
  3003. return
  3004. }
  3005. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  3006. page, _ := c.GetInt64("page")
  3007. limit, _ := c.GetInt64("limit")
  3008. keywords := c.GetString("keywords")
  3009. start_time := c.GetString("start_time")
  3010. end_time := c.GetString("end_time")
  3011. //clr_type := c.GetString("clr_type")
  3012. insutype := c.GetString("insutype")
  3013. timeLayout := "2006-01-02"
  3014. loc, _ := time.LoadLocation("Local")
  3015. var theStartTIme int64
  3016. if len(start_time) > 0 {
  3017. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3018. theStartTIme = theTime.Unix()
  3019. }
  3020. var theEndtTIme int64
  3021. if len(end_time) > 0 {
  3022. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3023. theEndtTIme = theTime.Unix()
  3024. }
  3025. if page <= 0 {
  3026. page = 1
  3027. }
  3028. if limit <= 0 {
  3029. limit = 10
  3030. }
  3031. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  3032. c.ServeSuccessJSON(map[string]interface{}{
  3033. "total": total,
  3034. "list": list,
  3035. })
  3036. return
  3037. }
  3038. func (c *HisApiController) GetPutOnRecordList() {
  3039. page, _ := c.GetInt64("page")
  3040. limit, _ := c.GetInt64("limit")
  3041. keywords := c.GetString("keywords")
  3042. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  3043. if page <= 0 {
  3044. page = 1
  3045. }
  3046. if limit <= 0 {
  3047. limit = 10
  3048. }
  3049. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  3050. c.ServeSuccessJSON(map[string]interface{}{
  3051. "total": total,
  3052. "list": list,
  3053. })
  3054. return
  3055. }
  3056. func (c *HisApiController) GetCompareData() {
  3057. start_time := c.GetString("start_time")
  3058. end_time := c.GetString("end_time")
  3059. insutype := c.GetString("insutype")
  3060. timeLayout := "2006-01-02"
  3061. loc, _ := time.LoadLocation("Local")
  3062. var theStartTIme int64
  3063. if len(start_time) > 0 {
  3064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3065. if err != nil {
  3066. theStartTIme = 0
  3067. }
  3068. theStartTIme = theTime.Unix()
  3069. }
  3070. var theEndtTIme int64
  3071. if len(end_time) > 0 {
  3072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3073. if err != nil {
  3074. theEndtTIme = 0
  3075. }
  3076. theEndtTIme = theTime.Unix()
  3077. }
  3078. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  3079. if err == nil {
  3080. c.ServeSuccessJSON(map[string]interface{}{
  3081. "list": formData,
  3082. })
  3083. } else {
  3084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3085. return
  3086. }
  3087. }
  3088. func (c *HisApiController) GetFaPiaoData() {
  3089. order_id, _ := c.GetInt64("order_id")
  3090. patient_id, _ := c.GetInt64("patient_id")
  3091. adminUser := c.GetAdminUserInfo()
  3092. order, _ := service.GetHisOrderByID(order_id)
  3093. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3094. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  3095. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3096. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  3097. var bedCostTotal float64 = 0 //床位总费
  3098. var bedCostSelfTotal float64 = 0 //床位自费
  3099. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3100. var operationCostTotal float64 = 0 //手术费
  3101. var operationCostSelfTotal float64 = 0 //手术费
  3102. var operationCostPartSelfTotal float64 = 0 //手术费
  3103. var otherCostTotal float64 = 0 //其他费用
  3104. var otherCostSelfTotal float64 = 0 //其他费用
  3105. var otherCostPartSelfTotal float64 = 0 //其他费用
  3106. var materialCostTotal float64 = 0 //材料费
  3107. var materialCostSelfTotal float64 = 0 //材料费
  3108. var materialCostPartSelfTotal float64 = 0 //材料费
  3109. var westernMedicineCostTotal float64 = 0 //西药费
  3110. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3111. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3112. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3113. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3114. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3115. var checkCostTotal float64 = 0 //检查费
  3116. var checkCostSelfTotal float64 = 0 //检查费
  3117. var checkCostPartSelfTotal float64 = 0 //检查费
  3118. var laboratoryCostTotal float64 = 0 //化验费
  3119. var laboratoryCostSelfTotal float64 = 0 //化验费
  3120. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3121. var treatCostTotal float64 = 0 //治疗费用
  3122. var treatCostSelfTotal float64 = 0 //治疗费用
  3123. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3124. decimal.DivisionPrecision = 2
  3125. for _, item := range orderInfos {
  3126. if item.MedChrgitmType == "01" { //床位费
  3127. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3128. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3129. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3130. }
  3131. if item.MedChrgitmType == "03" { //检查费
  3132. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3133. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3134. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3135. }
  3136. if item.MedChrgitmType == "04" { //化验费
  3137. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3138. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3139. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3140. }
  3141. if item.MedChrgitmType == "05" { //治疗费
  3142. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3143. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3144. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3145. }
  3146. if item.MedChrgitmType == "06" { //手术费
  3147. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3148. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3149. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3150. }
  3151. if item.MedChrgitmType == "08" { //材料费
  3152. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3153. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3154. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3155. }
  3156. if item.MedChrgitmType == "09" { //西药费
  3157. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3158. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3159. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3160. }
  3161. if item.MedChrgitmType == "11" { //中成费
  3162. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3163. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3164. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3165. }
  3166. if item.MedChrgitmType == "14" { //其他费
  3167. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3168. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3169. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3170. }
  3171. }
  3172. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3173. c.ServeSuccessJSON(map[string]interface{}{
  3174. "order_number": order.Number, //业务流水号
  3175. "id_card_no": his.IdCardNo, //社会保障号
  3176. "department_name": department.Name, //科室
  3177. "number": his.Number, //门诊号
  3178. "date": order.SettleAccountsDate, //结算日期
  3179. "name": order.PsnName, //姓名
  3180. "gender": order.Gend, //性别
  3181. "psn_cash_money": order.PsnCashPay, //个人支付
  3182. "pay_way": "门诊", //结算方式
  3183. "medfee_sumamt": order.MedfeeSumamt, //总费用
  3184. "admin_user_name": admin.UserName, //收款员
  3185. "bedCostTotal": bedCostTotal,
  3186. "bedCostSelfTotal": bedCostSelfTotal,
  3187. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3188. "operationCostTotal": operationCostTotal,
  3189. "operationCostSelfTotal": operationCostSelfTotal,
  3190. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3191. "otherCostTotal": otherCostTotal,
  3192. "otherCostSelfTotal": otherCostSelfTotal,
  3193. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3194. "materialCostTotal": materialCostTotal,
  3195. "materialCostSelfTotal": materialCostSelfTotal,
  3196. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3197. "westernMedicineCostTotal": westernMedicineCostTotal,
  3198. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3199. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3200. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3201. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3202. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3203. "checkCostTotal": checkCostTotal,
  3204. "checkCostSelfTotal": checkCostSelfTotal,
  3205. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3206. "laboratoryCostTotal": laboratoryCostTotal,
  3207. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3208. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3209. "treatCostTotal": treatCostTotal,
  3210. "treatCostSelfTotal": treatCostSelfTotal,
  3211. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3212. })
  3213. }
  3214. func (this *HisApiController) GetIncomeStatisticsData() {
  3215. start_time := this.GetString("start_time")
  3216. end_time := this.GetString("end_time")
  3217. key_words := this.GetString("key_words")
  3218. limit, _ := this.GetInt64("limit")
  3219. page, _ := this.GetInt64("page")
  3220. if page <= 0 {
  3221. page = 1
  3222. }
  3223. if limit <= 0 {
  3224. limit = 10
  3225. }
  3226. statistics_type, _ := this.GetInt64("statistics_type")
  3227. admin := this.GetAdminUserInfo()
  3228. timeLayout := "2006-01-02"
  3229. loc, _ := time.LoadLocation("Local")
  3230. var theStartTIme int64
  3231. if len(start_time) > 0 {
  3232. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3233. if err != nil {
  3234. theStartTIme = 0
  3235. }
  3236. theStartTIme = theTime.Unix()
  3237. }
  3238. var theEndtTIme int64
  3239. if len(end_time) > 0 {
  3240. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3241. if err != nil {
  3242. theEndtTIme = 0
  3243. }
  3244. theEndtTIme = theTime.Unix()
  3245. }
  3246. if statistics_type == 1 {
  3247. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3248. this.ServeSuccessJSON(map[string]interface{}{
  3249. "list": list,
  3250. "total": total,
  3251. })
  3252. } else {
  3253. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3254. this.ServeSuccessJSON(map[string]interface{}{
  3255. "list": list,
  3256. "total": total,
  3257. })
  3258. }
  3259. }
  3260. func (c *HisApiController) PostProjectInformation() {
  3261. adminUser := c.GetAdminUserInfo()
  3262. orgId := adminUser.CurrentOrgId
  3263. dataBody := make(map[string]interface{}, 0)
  3264. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3265. if err != nil {
  3266. utils.ErrorLog(err.Error())
  3267. return
  3268. }
  3269. utils.ErrorLog("%v", dataBody)
  3270. var projectList []*models.HisProject
  3271. var total_goods []interface{}
  3272. tempProjects := dataBody["projects"].([]interface{})
  3273. total_goods = tempProjects
  3274. for index, projectMap := range tempProjects {
  3275. projectM := projectMap.(map[string]interface{})
  3276. var project models.HisProject
  3277. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  3278. utils.ErrorLog("project_name")
  3279. return
  3280. }
  3281. project_name, _ := projectM["project_name"].(string)
  3282. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  3283. err_log := models.ExportErrLog{
  3284. LogType: 6,
  3285. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3286. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  3287. Status: 1,
  3288. CreateTime: time.Now().Unix(),
  3289. UpdateTime: time.Now().Unix(),
  3290. ExportTime: time.Now().Unix(),
  3291. }
  3292. service.CreateExportErrLog(&err_log)
  3293. continue
  3294. }
  3295. project.ProjectName = project_name
  3296. prices := projectM["price"].(string)
  3297. price, _ := strconv.ParseFloat(prices, 64)
  3298. if price <= 0 { //名字为空则生成一条导入错误日志
  3299. err_log := models.ExportErrLog{
  3300. LogType: 6,
  3301. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3302. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  3303. Status: 1,
  3304. CreateTime: time.Now().Unix(),
  3305. UpdateTime: time.Now().Unix(),
  3306. ExportTime: time.Now().Unix(),
  3307. }
  3308. service.CreateExportErrLog(&err_log)
  3309. continue
  3310. }
  3311. project.Price = price
  3312. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  3313. utils.ErrorLog("unit_id")
  3314. return
  3315. }
  3316. unit := projectM["unit"].(string)
  3317. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  3318. err_log := models.ExportErrLog{
  3319. LogType: 6,
  3320. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3321. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  3322. Status: 1,
  3323. CreateTime: time.Now().Unix(),
  3324. UpdateTime: time.Now().Unix(),
  3325. ExportTime: time.Now().Unix(),
  3326. }
  3327. service.CreateExportErrLog(&err_log)
  3328. continue
  3329. }
  3330. project.Unit = unit
  3331. cost_classify := projectM["cost_classify"].(string)
  3332. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  3333. err_log := models.ExportErrLog{
  3334. LogType: 6,
  3335. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3336. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3337. Status: 1,
  3338. CreateTime: time.Now().Unix(),
  3339. UpdateTime: time.Now().Unix(),
  3340. ExportTime: time.Now().Unix(),
  3341. }
  3342. service.CreateExportErrLog(&err_log)
  3343. continue
  3344. }
  3345. var costClassify = "费用类别"
  3346. var cost_classify_id int64
  3347. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  3348. if len(cost_classify) != 0 {
  3349. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  3350. if errcode == gorm.ErrRecordNotFound {
  3351. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  3352. dataconfig := models.DictDataconfig{
  3353. ParentId: costClassifyConfig.ID,
  3354. Module: "system",
  3355. OrgId: orgId,
  3356. Name: cost_classify,
  3357. FieldName: "",
  3358. Value: costConfig.Value + 1,
  3359. CreatedTime: "",
  3360. UpdatedTime: "",
  3361. CreateUserId: adminUser.AdminUser.Id,
  3362. Status: 1,
  3363. Remark: "",
  3364. DeleteIdSystem: 0,
  3365. Title: "",
  3366. Content: "",
  3367. Order: 0,
  3368. Code: "",
  3369. }
  3370. service.CreatedDicConfig(&dataconfig)
  3371. }
  3372. }
  3373. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  3374. for _, it := range costClassList {
  3375. if cost_classify == it.Name {
  3376. cost_classify_id = int64(it.Value)
  3377. }
  3378. }
  3379. project.CostClassify = cost_classify_id
  3380. executive_section := projectM["executive_section"].(string)
  3381. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  3382. err_log := models.ExportErrLog{
  3383. LogType: 6,
  3384. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3385. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  3386. Status: 1,
  3387. CreateTime: time.Now().Unix(),
  3388. UpdateTime: time.Now().Unix(),
  3389. ExportTime: time.Now().Unix(),
  3390. }
  3391. service.CreateExportErrLog(&err_log)
  3392. continue
  3393. }
  3394. if len(executive_section) != 0 {
  3395. //查找科室是否有内容
  3396. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  3397. if errcodedepart == gorm.ErrRecordNotFound {
  3398. department := models.XtHisDepartment{
  3399. Name: executive_section,
  3400. Status: 1,
  3401. UserOrgId: adminUser.CurrentOrgId,
  3402. CreatedTime: time.Now().Unix(),
  3403. }
  3404. service.CreateDePartment(&department)
  3405. }
  3406. }
  3407. var executive_section_id int64
  3408. departMentList, _ := service.GetAllDepartMent(orgId)
  3409. for _, it := range departMentList {
  3410. if executive_section == it.Name {
  3411. executive_section_id = it.ID
  3412. }
  3413. }
  3414. project.ExecutiveSection = executive_section_id
  3415. medical_coverage := projectM["medical_coverage"].(string)
  3416. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  3417. err_log := models.ExportErrLog{
  3418. LogType: 6,
  3419. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3420. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3421. Status: 1,
  3422. CreateTime: time.Now().Unix(),
  3423. UpdateTime: time.Now().Unix(),
  3424. ExportTime: time.Now().Unix(),
  3425. }
  3426. service.CreateExportErrLog(&err_log)
  3427. continue
  3428. }
  3429. var medicalCoverage = "医保等级"
  3430. var medical_coverage_id int64
  3431. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  3432. if len(medical_coverage) != 0 {
  3433. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  3434. if errormedicalcoverage == gorm.ErrRecordNotFound {
  3435. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  3436. dataconfig := models.DictDataconfig{
  3437. ParentId: medicalCoverageConfig.ID,
  3438. Module: "system",
  3439. OrgId: orgId,
  3440. Name: medical_coverage,
  3441. FieldName: "",
  3442. Value: medicalCoverageConfig.Value + 1,
  3443. CreatedTime: "",
  3444. UpdatedTime: "",
  3445. CreateUserId: adminUser.AdminUser.Id,
  3446. Status: 1,
  3447. Remark: "",
  3448. DeleteIdSystem: 0,
  3449. Title: "",
  3450. Content: "",
  3451. Order: 0,
  3452. Code: "",
  3453. }
  3454. service.CreatedDicConfig(&dataconfig)
  3455. }
  3456. }
  3457. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  3458. for _, it := range medicalCoverageList {
  3459. if medical_coverage == it.Name {
  3460. medical_coverage_id = int64(it.Value)
  3461. }
  3462. }
  3463. project.MedicalCoverage = medical_coverage_id
  3464. pinyin := projectM["pinyin"].(string)
  3465. project.Pinyin = pinyin
  3466. wubi := projectM["wubi"].(string)
  3467. project.Wubi = wubi
  3468. statistical_classification := projectM["statistical_classification"].(string)
  3469. var statisticalClassification = "统计分类"
  3470. var statistical_classification_id int64
  3471. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  3472. if len(statistical_classification) != 0 {
  3473. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  3474. if classificationerrcodes == gorm.ErrRecordNotFound {
  3475. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  3476. dataconfig := models.DictDataconfig{
  3477. ParentId: classiFication.ID,
  3478. Module: "system",
  3479. OrgId: orgId,
  3480. Name: statistical_classification,
  3481. FieldName: "",
  3482. Value: classiFicationConfig.Value + 1,
  3483. CreatedTime: "",
  3484. UpdatedTime: "",
  3485. CreateUserId: adminUser.AdminUser.Id,
  3486. Status: 1,
  3487. Remark: "",
  3488. DeleteIdSystem: 0,
  3489. Title: "",
  3490. Content: "",
  3491. Order: 0,
  3492. Code: "",
  3493. }
  3494. service.CreatedDicConfig(&dataconfig)
  3495. }
  3496. }
  3497. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  3498. for _, it := range classiFicationList {
  3499. if statistical_classification == it.Name {
  3500. statistical_classification_id = int64(it.Value)
  3501. }
  3502. }
  3503. project.StatisticalClassification = statistical_classification_id
  3504. disease_directory := int64(projectM["disease_directory"].(float64))
  3505. project.DiseaseDirectory = disease_directory
  3506. is_record := int64(projectM["is_record"].(float64))
  3507. project.IsRecord = is_record
  3508. medical_code := projectM["medical_code"].(string)
  3509. project.MedicalCode = medical_code
  3510. tube_color := projectM["tube_color"].(string)
  3511. var tubeColor = "试管颜色"
  3512. var tube_color_id int64
  3513. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  3514. if len(tube_color) != 0 {
  3515. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  3516. if errcodetube == gorm.ErrRecordNotFound {
  3517. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  3518. dataconfig := models.DictDataconfig{
  3519. ParentId: tubeColorConfig.ID,
  3520. Module: "system",
  3521. OrgId: orgId,
  3522. Name: tube_color,
  3523. FieldName: "",
  3524. Value: tubeConfig.Value + 1,
  3525. CreatedTime: "",
  3526. UpdatedTime: "",
  3527. CreateUserId: adminUser.AdminUser.Id,
  3528. Status: 1,
  3529. Remark: "",
  3530. DeleteIdSystem: 0,
  3531. Title: "",
  3532. Content: "",
  3533. Order: 0,
  3534. Code: "",
  3535. }
  3536. service.CreatedDicConfig(&dataconfig)
  3537. }
  3538. }
  3539. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  3540. for _, it := range tubeColorList {
  3541. if tube_color == it.Name {
  3542. tube_color_id = int64(it.Value)
  3543. }
  3544. }
  3545. project.TubeColor = tube_color_id
  3546. single_dose := projectM["single_dose"].(string)
  3547. project.SingleDose = single_dose
  3548. execution_frequency := projectM["execution_frequency"].(string)
  3549. project.ExecutionFrequency = execution_frequency
  3550. delivery_way := projectM["delivery_way"].(string)
  3551. project.DeliveryWay = delivery_way
  3552. number_days := projectM["number_days"].(string)
  3553. project.NumberDays = number_days
  3554. total := projectM["total"].(string)
  3555. project.Total = total
  3556. medical_status := int64(projectM["medical_status"].(float64))
  3557. project.MedicalStatus = medical_status
  3558. category := int64(projectM["category"].(float64))
  3559. project.Category = category
  3560. specail_project := int64(projectM["specail_project"].(float64))
  3561. project.SpecailProject = specail_project
  3562. social_security_directory_code := projectM["social_security_directory_code"].(string)
  3563. project.SocialSecurityDirectoryCode = social_security_directory_code
  3564. remark := projectM["remark"].(string)
  3565. project.Remark = remark
  3566. record_date := projectM["record_date"].(string)
  3567. timeLayout := "2006-01-02"
  3568. loc, _ := time.LoadLocation("Local")
  3569. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3570. project.RecordDate = theTime.Unix()
  3571. projectList = append(projectList, &project)
  3572. }
  3573. export_time := time.Now().Unix()
  3574. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3575. if len(projectList) > 0 {
  3576. for _, item := range projectList {
  3577. project := models.HisProject{
  3578. ProjectName: item.ProjectName,
  3579. Price: item.Price,
  3580. Unit: item.Unit,
  3581. CostClassify: item.CostClassify,
  3582. ExecutiveSection: item.ExecutiveSection,
  3583. MedicalCoverage: item.MedicalCoverage,
  3584. UserOrgId: orgId,
  3585. Status: 1,
  3586. CreatedTime: time.Now().Unix(),
  3587. Pinyin: item.Pinyin,
  3588. Wubi: item.Wubi,
  3589. StatisticalClassification: item.StatisticalClassification,
  3590. DiseaseDirectory: item.DiseaseDirectory,
  3591. IsRecord: item.IsRecord,
  3592. MedicalCode: item.MedicalCode,
  3593. TubeColor: item.TubeColor,
  3594. SingleDose: item.SingleDose,
  3595. DeliveryWay: item.DeliveryWay,
  3596. NumberDays: item.NumberDays,
  3597. Total: item.Total,
  3598. Category: item.Category,
  3599. MedicalStatus: item.MedicalStatus,
  3600. SpecailProject: item.SpecailProject,
  3601. RecordDate: item.RecordDate,
  3602. Remark: item.Remark,
  3603. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3604. ExecutionFrequency: item.ExecutionFrequency,
  3605. }
  3606. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  3607. if errcodeproject == gorm.ErrRecordNotFound {
  3608. service.CreateProjectInfomation(&project)
  3609. } else if errcodeproject == nil {
  3610. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  3611. }
  3612. log := models.ExportLog{
  3613. LogType: 6,
  3614. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3615. TotalNum: int64(len(total_goods)),
  3616. FailNum: int64(len(errLogs)),
  3617. SuccessNum: int64(len(projectList)),
  3618. CreateTime: time.Now().Unix(),
  3619. UpdateTime: time.Now().Unix(),
  3620. ExportTime: export_time,
  3621. Status: 1,
  3622. }
  3623. service.CreateExportLog(&log)
  3624. c.ServeSuccessJSON(map[string]interface{}{
  3625. "msg": "导入成功",
  3626. "total_num": len(total_goods),
  3627. "success_num": len(projectList),
  3628. "fail_num": int64(len(errLogs)),
  3629. })
  3630. }
  3631. } else {
  3632. log := models.ExportLog{
  3633. LogType: 6,
  3634. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3635. TotalNum: int64(len(total_goods)),
  3636. FailNum: int64(len(errLogs)),
  3637. SuccessNum: int64(len(projectList)),
  3638. CreateTime: time.Now().Unix(),
  3639. UpdateTime: time.Now().Unix(),
  3640. ExportTime: export_time,
  3641. Status: 1,
  3642. }
  3643. service.CreateExportLog(&log)
  3644. c.ServeSuccessJSON(map[string]interface{}{
  3645. "msg": "导入成功",
  3646. "total_num": len(total_goods),
  3647. "success_num": len(projectList),
  3648. "fail_num": int64(len(errLogs)),
  3649. })
  3650. }
  3651. }
  3652. //func (this *HisApiController) EditProjectInformation(){
  3653. //
  3654. // id, _ := this.GetInt64("id")
  3655. // project_team := this.GetString("project_team")
  3656. // price := this.GetString("price")
  3657. // price_float, _ := strconv.ParseFloat(price, 64)
  3658. // pinyin := this.GetString("pinyin")
  3659. // wubi := this.GetString("wubi")
  3660. // tube_color, _ := this.GetInt64("tube_color")
  3661. // team_type, _ := this.GetInt64("team_type")
  3662. // remark := this.GetString("remark")
  3663. // ids := this.GetString("ids")
  3664. // item_id := this.GetString("item_id")
  3665. // projectTeam := models.XtHisProjectTeam{
  3666. // ProjectTeam: project_team,
  3667. // Price: price_float,
  3668. // Pinyin: pinyin,
  3669. // Wubi: wubi,
  3670. // TubeColor: tube_color,
  3671. // TeamType: team_type,
  3672. // Remark: remark,
  3673. // ProjectId: ids,
  3674. // ItemId: item_id,
  3675. // }
  3676. //
  3677. //
  3678. // dataBody := make(map[string]interface{}, 0)
  3679. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3680. // if err != nil {
  3681. // utils.ErrorLog(err.Error())
  3682. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3683. // return
  3684. // }
  3685. //
  3686. // err = service.UpdatedProjectTeam(id, &projectTeam)
  3687. //
  3688. //
  3689. // if err != nil {
  3690. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3691. // return
  3692. // }
  3693. //
  3694. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  3695. // infos, _ := dataBody["info"].([]interface{})
  3696. // if len(infos) > 0 {
  3697. // var ids []string
  3698. //
  3699. // for _, item := range infos {
  3700. // items := item.(map[string]interface{})
  3701. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3702. // utils.ErrorLog("id")
  3703. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3704. // return
  3705. // }
  3706. // id := int64(items["id"].(float64))
  3707. //
  3708. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3709. // utils.ErrorLog("type")
  3710. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3711. // return
  3712. // }
  3713. // types := int64(items["type"].(float64))
  3714. //
  3715. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  3716. // utils.ErrorLog("number")
  3717. // }
  3718. //
  3719. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  3720. //
  3721. // projectList := models.XtHisProjectList{
  3722. // Number: number,
  3723. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3724. // ProjectId: id,
  3725. // Status: 1,
  3726. // CreatedTime: time.Now().Unix(),
  3727. // UpdatedTime: time.Now().Unix(),
  3728. // TeamId: projectTeam.ID,
  3729. // Type: types,
  3730. // }
  3731. // list := projectList
  3732. //
  3733. // service.CreateProjectList(&list)
  3734. //
  3735. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  3736. //
  3737. // }
  3738. // ids_str := strings.Join(ids, ",")
  3739. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  3740. // service.SaveProjectTeam(&projectTeam)
  3741. // this.ServeSuccessJSON(map[string]interface{}{
  3742. // "projectTeam": projectTeam,
  3743. // })
  3744. // }
  3745. // }
  3746. //}
  3747. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  3748. name := c.GetString("name")
  3749. mode_id, _ := c.GetInt64("mode", 0)
  3750. types, _ := c.GetInt64("type", 0)
  3751. patient_id, _ := c.GetInt64("patient_id", 0)
  3752. types = 1
  3753. adminInfo := c.GetAdminUserInfo()
  3754. template := &models.HisPrescriptionTemplate{
  3755. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3756. PatientId: patient_id,
  3757. Type: types,
  3758. Status: 1,
  3759. Ctime: time.Now().Unix(),
  3760. Mtime: time.Now().Unix(),
  3761. Name: name,
  3762. Mode: mode_id,
  3763. }
  3764. dataBody := make(map[string]interface{}, 0)
  3765. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3766. if err != nil {
  3767. utils.ErrorLog(err.Error())
  3768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3769. return
  3770. }
  3771. err = service.CreateHisPrescriptionTemplate(template)
  3772. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3773. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3774. if len(prescriptions) > 0 {
  3775. for _, item := range prescriptions {
  3776. items := item.(map[string]interface{})
  3777. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3778. utils.ErrorLog("type")
  3779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3780. return
  3781. }
  3782. types := int64(items["type"].(float64))
  3783. ctime := time.Now().Unix()
  3784. prescription := &models.HisPrescriptionInfoTemplate{
  3785. PatientId: patient_id,
  3786. UserOrgId: adminInfo.CurrentOrgId,
  3787. Ctime: ctime,
  3788. Mtime: ctime,
  3789. Type: types,
  3790. Modifier: adminInfo.AdminUser.Id,
  3791. Creator: adminInfo.AdminUser.Id,
  3792. Status: 1,
  3793. PTemplateId: template.ID,
  3794. }
  3795. service.CreateHisPrescriptionInfoTemplate(prescription)
  3796. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3797. advices := items["advices"].([]interface{})
  3798. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3799. groupNo := int64(0)
  3800. ctime := time.Now().Unix()
  3801. mtime := ctime
  3802. if len(advices) > 0 {
  3803. for _, advice := range advices {
  3804. var s models.HisPrescriptionAdviceTemplate
  3805. s.PrescriptionId = prescription.ID
  3806. s.AdviceType = 2
  3807. s.StopState = 2
  3808. s.ExecutionState = 2
  3809. s.Status = 1
  3810. s.UserOrgId = adminInfo.CurrentOrgId
  3811. s.Groupno = groupNo
  3812. s.CreatedTime = ctime
  3813. s.UpdatedTime = mtime
  3814. s.PatientId = patient_id
  3815. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  3816. if errcode > 0 {
  3817. c.ServeFailJSONWithSGJErrorCode(errcode)
  3818. return
  3819. }
  3820. service.CreateHisPrescriptionAdviceTemplate(&s)
  3821. }
  3822. }
  3823. }
  3824. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3825. projects := items["project"].([]interface{})
  3826. if len(projects) > 0 {
  3827. for _, project := range projects {
  3828. var p models.HisPrescriptionProjectTemplate
  3829. p.PrescriptionId = prescription.ID
  3830. p.Ctime = time.Now().Unix()
  3831. p.Mtime = time.Now().Unix()
  3832. p.PatientId = patient_id
  3833. p.UserOrgId = adminInfo.CurrentOrgId
  3834. p.Status = 1
  3835. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  3836. if errcode > 0 {
  3837. c.ServeFailJSONWithSGJErrorCode(errcode)
  3838. return
  3839. }
  3840. service.CreateHisPrescriptionProjectTemplate(&p)
  3841. }
  3842. }
  3843. }
  3844. }
  3845. c.ServeSuccessJSON(map[string]interface{}{
  3846. "msg": "创建成功",
  3847. })
  3848. }
  3849. }
  3850. }