his_api_controller.go 173KB

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