his_api_controller.go 190KB

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