his_api_controller.go 188KB

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