his_api_controller.go 163KB

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