his_api_controller.go 161KB

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