his_api_controller.go 164KB

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