his_service.go 179KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strings"
  7. "time"
  8. )
  9. type VMSchedule struct {
  10. ID int64 `gorm:"column:id" json:"id" form:"id"`
  11. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  12. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  13. Status int64 `gorm:"column:status" json:"status" form:"status"`
  14. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  15. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  16. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  17. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  18. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  19. }
  20. func (VMSchedule) TableName() string {
  21. return "xt_schedule"
  22. }
  23. type HisPatient struct {
  24. ID int64 `gorm:"column:id" json:"id" form:"id"`
  25. Name string `gorm:"column:name" json:"name" form:"name"`
  26. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  27. Total float64 `gorm:"column:total" json:"total" form:"total"`
  28. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  29. Status int64 `gorm:"column:status" json:"status" form:"status"`
  30. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  31. HisPrescription []*HisPrescription `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  32. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  33. Number string `gorm:"column:number" json:"number" form:"number"`
  34. VMHisOrders []*VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"orders"`
  35. VMHisOrder VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"order"`
  36. }
  37. func (HisPatient) TableName() string {
  38. return "his_patient"
  39. }
  40. type VMHisPrescriptionInfo struct {
  41. ID int64 `gorm:"column:id" json:"id" form:"id"`
  42. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  43. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  44. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  45. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  46. Status int64 `gorm:"column:status" json:"status" form:"status"`
  47. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  48. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  49. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  50. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  51. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  52. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  53. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  54. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  55. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  56. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  57. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  58. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  59. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  60. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  61. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  62. }
  63. func (VMHisPrescriptionInfo) TableName() string {
  64. return "his_prescription_info"
  65. }
  66. type VMHisOrder struct {
  67. ID int64 `gorm:"column:id" json:"id" form:"id"`
  68. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  69. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  70. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  71. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  72. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  73. Status int64 `gorm:"column:status" json:"status" form:"status"`
  74. Number string `gorm:"column:number" json:"number" form:"number"`
  75. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  76. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  77. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  78. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  79. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  80. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  81. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  82. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  83. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  84. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  85. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  86. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  87. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  88. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  89. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  90. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  91. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  92. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  93. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  94. }
  95. func (VMHisOrder) TableName() string {
  96. return "his_order"
  97. }
  98. type Patients struct {
  99. ID int64 `gorm:"column:id" json:"id" form:"id"`
  100. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  101. Name string `gorm:"column:name" json:"name" form:"name"`
  102. Status int64 `gorm:"column:status" json:"status" form:"status"`
  103. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  104. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  105. Phone int64 `gorm:"column:phone" json:"phone" form:"phone"`
  106. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  107. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  108. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  109. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  110. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  111. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  112. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  113. }
  114. func (Patients) TableName() string {
  115. return "xt_patients"
  116. }
  117. type HisPrescription struct {
  118. ID int64 `gorm:"column:id" json:"id" form:"id"`
  119. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  120. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  121. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  122. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  123. Status int64 `gorm:"column:status" json:"status" form:"status"`
  124. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  125. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  126. }
  127. func (HisPrescription) TableName() string {
  128. return "his_prescription"
  129. }
  130. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  131. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,xt_patients.first_letter,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  132. if sch_type != 0 {
  133. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  134. } else {
  135. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  136. }
  137. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  138. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  139. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  140. return
  141. }
  142. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  143. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  144. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  145. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  146. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  147. return
  148. }
  149. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  150. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  151. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  152. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  153. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  154. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  155. return
  156. }
  157. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  158. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  159. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  160. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  161. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  162. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  163. return
  164. }
  165. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  166. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  167. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  168. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  169. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  170. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  171. return
  172. }
  173. type PatientTwo struct {
  174. ID int64 `gorm:"column:id" json:"id" form:"id"`
  175. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  176. Name string `gorm:"column:name" json:"name" form:"name"`
  177. Status int64 `gorm:"column:status" json:"status" form:"status"`
  178. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  179. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  180. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  181. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  182. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  183. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  184. }
  185. func (PatientTwo) TableName() string {
  186. return "xt_patients"
  187. }
  188. type HisPatientTwo struct {
  189. ID int64 `gorm:"column:id" json:"id" form:"id"`
  190. Name string `gorm:"column:name" json:"name" form:"name"`
  191. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  192. Total float64 `gorm:"column:total" json:"total" form:"total"`
  193. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  194. Status int64 `gorm:"column:status" json:"status" form:"status"`
  195. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  196. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  197. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  198. Number string `gorm:"column:number" json:"number" form:"number"`
  199. }
  200. func (HisPatientTwo) TableName() string {
  201. return "his_patient"
  202. }
  203. type HisPrescriptionTwo struct {
  204. ID int64 `gorm:"column:id" json:"id" form:"id"`
  205. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  206. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  207. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  208. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  209. Status int64 `gorm:"column:status" json:"status" form:"status"`
  210. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  211. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  212. Number string `gorm:"column:number" json:"number" form:"number"`
  213. Type int64 `gorm:"column:type" json:"type" form:"type"`
  214. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  215. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  216. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  217. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  218. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  219. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  220. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  221. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  222. }
  223. func (HisPrescriptionTwo) TableName() string {
  224. return "his_prescription"
  225. }
  226. func GetNewHisPatientList(org_id int64, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  227. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  228. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  229. if sch_type > 0 {
  230. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND schedule_type = ?", record_date, org_id, sch_type)
  231. }
  232. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  233. return db.Preload("HisPrescriptionTwo", "status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Where("user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  234. })
  235. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  236. return
  237. }
  238. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  239. db := readDb.Model(&PatientTwo{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  240. if sch_type != 0 {
  241. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  242. } else {
  243. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  244. }
  245. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  246. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  247. return
  248. }
  249. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  250. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
  251. return
  252. }
  253. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  254. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  255. return
  256. }
  257. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  258. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  259. return
  260. }
  261. func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient, err error) {
  262. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND number = ?", org_id, number).First(&info).Error
  263. return
  264. }
  265. func GetHisPatientInfoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  266. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  267. return
  268. }
  269. func GetHisPatientInfoFour(org_id int64, patient_id int64, record_date int64, his_patient_id int64) (info models.HisPatient, err error) {
  270. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND id = ?", org_id, record_date, patient_id, his_patient_id).First(&info).Error
  271. return
  272. }
  273. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  274. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  275. return
  276. }
  277. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  278. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  279. return
  280. }
  281. func GetNewHisHosptialRecordTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  282. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  283. return
  284. }
  285. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  286. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Count(&total).Error
  287. return
  288. }
  289. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  290. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  291. return
  292. }
  293. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  294. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  295. return
  296. }
  297. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  298. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  299. err = db.Find(&caseHistorys).Error
  300. return
  301. }
  302. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  303. likekey := "%" + keyword + "%"
  304. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  305. if startime > 0 {
  306. db = db.Where("record_date>=?", startime)
  307. }
  308. if endtime > 0 {
  309. db = db.Where("record_date<=?", endtime)
  310. }
  311. if len(keyword) > 0 {
  312. db = db.Where("template_name like ? ", likekey)
  313. }
  314. err = db.Find(&caseHistorys).Error
  315. return
  316. }
  317. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  318. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  319. return caseHistory, err
  320. }
  321. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  322. err = writeDb.Create(&template).Error
  323. return
  324. }
  325. func GetHisPatientCaseHistoryById(patient_id int64, record_date int64, user_org_id int64) (*models.HisPatientCaseHistory, error) {
  326. history := models.HisPatientCaseHistory{}
  327. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1 and user_org_id = ? and record_date = ?", patient_id, user_org_id, record_date).Find(&history).Error
  328. if err != nil {
  329. if err == gorm.ErrRecordNotFound {
  330. return nil, err
  331. } else {
  332. return nil, err
  333. }
  334. }
  335. return &history, nil
  336. }
  337. func GetLastHisPatientCaseHistoryById(patient_id int64) (models.HisPatientCaseHistory, error) {
  338. history := models.HisPatientCaseHistory{}
  339. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patient_id).Last(&history).Error
  340. return history, err
  341. }
  342. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  343. err := writeDb.Create(&caseHistory).Error
  344. return err
  345. }
  346. func UpdatePatientCaseHistory(patient_id int64, record_date int64, user_org_id int64, his *models.HisPatientCaseHistory) error {
  347. err := XTWriteDB().Model(&his).Where("patient_id = ? and record_date = ? and user_org_id = ? and status =1", patient_id, record_date, user_org_id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.Pulse, "allergic_history": his.AllergicHistory, "diagnose": his.AllergicHistory, "sick": his.Sick, "remark": his.Remark, "doctor_advice": his.DoctorAdvice, "breathing": his.Breathing, "delivery_way": his.DeliveryWay, "diagnostic": his.Diagnostic, "family_history": his.FamilyHistory, "personal_history": his.PersonalHistory, "chief_conplaint": his.ChiefConplaint, "doctor": his.Doctor, "past_history": his.PastHistory, "history_of_present_illness": his.HistoryOfPresentIllness, "is_infect": his.IsInfect, "sick_date": his.SickDate, "symptom": his.Symptom, "sick_type": his.SickType, "blood_fat": his.BloodFat, "sbp": his.Sbp, "dbp": his.Dbp, "primary_disease": his.PrimaryDisease, "confirm_failure_date": his.ConfirmFailureDate, "drug_allergy_history": his.DrugAllergyHistory, "physical_examination": his.PhysicalExamination, "special_inspection": his.SpecialInspection, "lab_apparatus": his.LabApparatus}).Error
  348. return err
  349. }
  350. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  351. tx := writeDb.Begin()
  352. if err = tx.Model(&models.HisPrescription{}).Save(prescription).Error; err != nil {
  353. tx.Rollback()
  354. return
  355. }
  356. tx.Commit()
  357. return
  358. }
  359. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  360. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  361. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  362. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  363. return
  364. }
  365. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  366. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  367. return
  368. }
  369. func DelelteProject(id int64, user_org_id int64) (err error) {
  370. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  371. return
  372. }
  373. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  374. err = readDb.Model(&models.HisPrescription{}).
  375. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  376. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  377. }).
  378. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  379. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  380. }).
  381. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  382. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  383. }).
  384. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  385. Find(&prescription).Error
  386. return
  387. }
  388. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  389. err = readDb.Model(&models.HisPrescription{}).
  390. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  391. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  392. }).
  393. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  394. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  395. }).
  396. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  397. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  398. }).
  399. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, his_patient_id, p_type).
  400. Find(&prescription).Error
  401. return
  402. }
  403. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  404. err = readDb.Model(&models.HisPrescription{}).
  405. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  406. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  407. }).
  408. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  409. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  410. }).
  411. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  412. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  413. }).
  414. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 AND his_patient_id = ? AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
  415. Find(&prescription).Error
  416. return
  417. }
  418. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  419. err = readDb.Model(&models.HisPrescription{}).
  420. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  421. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  422. }).
  423. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  424. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  425. }).
  426. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  427. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  428. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  429. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  430. }).
  431. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?) AND (his_patient_id = ? OR his_patient_id = 0)", org_id, record_date, patient_id, p_type, his_patient_id).
  432. Find(&prescription).Error
  433. return
  434. }
  435. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  436. err = readDb.Model(&models.HisPrescription{}).
  437. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  438. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  439. }).
  440. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  441. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  442. }).
  443. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  444. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  445. }).
  446. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  447. Find(&prescription).Error
  448. return
  449. }
  450. func GetSettleHisPrescriptionTX(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  451. err = tx.Model(&models.HisPrescription{}).
  452. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  453. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  454. }).
  455. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  456. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  457. }).
  458. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  459. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  460. }).
  461. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  462. Find(&prescription).Error
  463. return
  464. }
  465. func GetSettleHisPrescriptionTXOne(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  466. err = tx.Model(&models.HisPrescription{}).
  467. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  468. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  469. }).
  470. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  471. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  472. }).
  473. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  474. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  475. }).
  476. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  477. Find(&prescription).Error
  478. return
  479. }
  480. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  481. err = readDb.Model(&models.HisPrescription{}).
  482. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  483. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  484. }).
  485. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  486. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  487. }).
  488. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  489. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  490. }).
  491. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  492. Find(&prescription).Error
  493. return
  494. }
  495. func GetMonthHisPrescriptionTX(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  496. err = tx.Model(&models.HisPrescription{}).
  497. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  498. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  499. }).
  500. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  501. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  502. }).
  503. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  504. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  505. }).
  506. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  507. Find(&prescription).Error
  508. return
  509. }
  510. func GetMonthHisPrescriptionTXOne(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  511. err = tx.Model(&models.HisPrescription{}).
  512. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  513. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  514. }).
  515. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  516. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  517. }).
  518. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  519. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  520. }).
  521. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  522. Find(&prescription).Error
  523. return
  524. }
  525. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  526. err = readDb.Model(&models.HisPrescription{}).
  527. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  528. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  529. }).
  530. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  531. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  532. }).
  533. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  534. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  535. }).
  536. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  537. Find(&prescription).Error
  538. return
  539. }
  540. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  541. err = readDb.Model(&models.HisPrescription{}).
  542. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  543. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  544. }).
  545. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  546. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  547. }).
  548. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  549. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  550. }).
  551. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? ", org_id, start_date, end_date, patient_id, p_type).
  552. Find(&prescription).Error
  553. return
  554. }
  555. // 未收费
  556. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  557. err = readDb.Model(&models.HisPrescription{}).
  558. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  559. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  560. }).
  561. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  562. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  563. }).
  564. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  565. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  566. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  567. return db.Where("status = 1 AND user_org_id = ?", org_id)
  568. }).
  569. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status <> 4 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  570. Find(&prescription).Error
  571. return
  572. }
  573. // 已收费
  574. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  575. err = readDb.Model(&models.HisPrescription{}).
  576. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  577. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  578. }).
  579. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  580. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  581. }).
  582. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  583. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  584. }).
  585. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  586. Find(&prescription).Error
  587. return
  588. }
  589. func GetUnChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  590. err = readDb.Model(&models.HisPrescription{}).
  591. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  592. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  593. }).
  594. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  595. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  596. }).
  597. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  598. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  599. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  600. return db.Where("status = 1 AND user_org_id = ?", org_id)
  601. }).
  602. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status <> 4", org_id, start_date, end_date, patient_id).
  603. Find(&prescription).Error
  604. return
  605. }
  606. type OtherDrugWarehouseInfo struct {
  607. ID int64 `gorm:"column:id" json:"id" form:"id"`
  608. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  609. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  610. Status int64 `gorm:"column:status" json:"status" form:"status"`
  611. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  612. StockMaxNumber int64 `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
  613. StockMinNumber int64 `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
  614. Price float64 `gorm:"column:price" json:"price" form:"price"`
  615. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  616. }
  617. func (OtherDrugWarehouseInfo) TableName() string {
  618. return "xt_drug_warehouse_info"
  619. }
  620. type VMDrugSalesReturnInfo struct {
  621. ID int64 `gorm:"column:id" json:"id" form:"id"`
  622. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  623. Count int64 `gorm:"column:count" json:"count" form:"count"`
  624. Status int64 `gorm:"column:status" json:"status" form:"status"`
  625. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  626. }
  627. func (VMDrugSalesReturnInfo) TableName() string {
  628. return "xt_drug_sales_return_info"
  629. }
  630. type VMDrugWarehouseOutInfo struct {
  631. ID int64 `gorm:"column:id" json:"id" form:"id"`
  632. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  633. Count int64 `gorm:"column:count" json:"count" form:"count"`
  634. Status int64 `gorm:"column:status" json:"status" form:"status"`
  635. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  636. }
  637. func (VMDrugWarehouseOutInfo) TableName() string {
  638. return "xt_drug_warehouse_out_info"
  639. }
  640. type VMDrugCancelStockInfo struct {
  641. ID int64 `gorm:"column:id" json:"id" form:"id"`
  642. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  643. Count int64 `gorm:"column:count" json:"count" form:"count"`
  644. Status int64 `gorm:"column:status" json:"status" form:"status"`
  645. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  646. }
  647. func (VMDrugCancelStockInfo) TableName() string {
  648. return "xt_drug_cancel_stock_info"
  649. }
  650. type BaseDrugLib struct {
  651. ID int64 `gorm:"column:id" json:"id" form:"id"`
  652. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  653. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  654. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  655. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  656. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  657. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  658. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  659. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  660. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  661. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  662. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  663. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  664. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  665. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  666. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  667. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  668. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  669. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  670. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  671. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  672. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  673. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  674. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  675. Number string `gorm:"column:number" json:"number" form:"number"`
  676. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  677. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  678. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  679. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  680. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  681. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  682. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  683. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  684. Code string `gorm:"column:code" json:"code" form:"code"`
  685. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  686. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  687. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  688. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  689. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  690. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  691. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  692. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  693. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  694. Label int64 `gorm:"column:label" json:"label" form:"label"`
  695. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  696. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  697. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  698. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  699. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  700. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  701. Status int64 `gorm:"column:status" json:"status" form:"status"`
  702. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  703. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  704. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  705. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  706. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  707. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  708. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  709. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  710. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  711. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  712. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  713. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  714. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  715. //Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  716. //Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  717. //PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  718. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  719. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  720. Total float64 `gorm:"column:total" json:"total" form:"total"`
  721. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  722. BatchRetaiPrice float64 `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
  723. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  724. SumCount int64 `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
  725. SumInCount int64 `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
  726. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  727. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  728. IsProject int64 `gorm:"column:is_project" json:"is_project" form:"is_project"`
  729. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  730. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  731. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  732. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  733. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  734. }
  735. func (BaseDrugLib) TableName() string {
  736. return "xt_base_drug"
  737. }
  738. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  739. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  740. return db.Where("(status = 1 and stock_max_number > 0) or (status = 1 AND stock_min_number >0)")
  741. }).Find(&list).Error
  742. //err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
  743. return
  744. }
  745. func GetAllDrugLibListSix(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  746. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  747. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  748. }).Find(&list).Error
  749. return
  750. }
  751. func GetAllDrugLibListSeven(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  752. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  753. return db.Where("(status = 1 and storehouse_id = ? ) or (status = 1 and storehouse_id = ?)", storehouse_id, storehouse_id)
  754. }).Find(&list).Error
  755. return
  756. }
  757. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  758. db := readDb.Model(&models.BaseDrugLib{}).Preload("Drugs", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Group("drug_name")
  759. err = db.Find(&drugs).Error
  760. return
  761. }
  762. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  763. if len(keyword) != 0 {
  764. key := "%" + keyword + "%"
  765. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ? ", org_id, key).Find(&list).Error
  766. } else {
  767. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  768. }
  769. return
  770. }
  771. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  772. err = writeDb.Create(&charge).Error
  773. return
  774. }
  775. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  776. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  777. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  778. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  779. return
  780. }
  781. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  782. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  783. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  784. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  785. return
  786. }
  787. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  788. tx := writeDb.Begin()
  789. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  790. tx.Rollback()
  791. return
  792. }
  793. tx.Commit()
  794. return
  795. }
  796. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  797. tx := writeDb.Begin()
  798. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  799. tx.Rollback()
  800. return
  801. }
  802. tx.Commit()
  803. return
  804. }
  805. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  806. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
  807. return
  808. }
  809. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  810. err := writeDb.Create(&patient).Error
  811. return err
  812. }
  813. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  814. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  815. return
  816. }
  817. func CreateOrder(order *models.HisOrder) (err error) {
  818. err = writeDb.Create(&order).Error
  819. return
  820. }
  821. func CreateOrderTX(order *models.HisOrder, tx *gorm.DB) (err error) {
  822. err = tx.Create(&order).Error
  823. return
  824. }
  825. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  826. err = writeDb.Create(&order).Error
  827. return
  828. }
  829. func CreateOrderInfoTX(order *models.HisOrderInfo, tx *gorm.DB) (err error) {
  830. err = tx.Create(&order).Error
  831. return
  832. }
  833. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  834. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  835. return
  836. }
  837. func FindPatientPrescriptionInfoTen(org_id int64, patient_id int64, start_time int64, end_time int64, p_type int64) (info []models.HisPrescriptionInfo, err error) {
  838. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? and record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_time, end_time, patient_id, p_type).First(&info).Error
  839. return
  840. }
  841. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  842. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
  843. return
  844. }
  845. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  846. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).Last(&info).Error
  847. return
  848. }
  849. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  850. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  851. return
  852. }
  853. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  854. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ?", org_id, record_date, patient_id).Order("record_date desc").First(&info).Error
  855. return
  856. }
  857. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  858. tx := writeDb.Begin()
  859. if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
  860. tx.Rollback()
  861. return
  862. }
  863. tx.Commit()
  864. return
  865. }
  866. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64, doctor_id int64, keywords string, p_type int64, sort_type int64, start_time string, end_time string, charge_type int64, sch_type int64, zone_type int64, med_type int64) (order []*models.HisOrder, err error, total int64) {
  867. offset := (page - 1) * limit
  868. db := readDb.Model(&models.HisOrder{})
  869. if doctor_id > 0 {
  870. db = db.Joins("join his_prescription_info as info on info.patient_id = his_order.patient_id AND info.record_date = his_order.settle_accounts_date AND info.doctor_id = ? AND info.user_org_id = ?", doctor_id, user_org_id)
  871. }
  872. if len(keywords) > 0 {
  873. keywords = "%" + keywords + "%"
  874. db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id AND patient.name like ? AND patient.user_org_id = ?", keywords, user_org_id)
  875. }
  876. if sch_type > 0 && zone_type > 0 {
  877. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp, zone_type)
  878. }
  879. if sch_type > 0 && zone_type == 0 {
  880. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp)
  881. }
  882. if sch_type == 0 && zone_type > 0 {
  883. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", start_time_timestamp, end_time_timestamp, zone_type)
  884. }
  885. if med_type > 0 {
  886. db = db.Where("his_order.med_type = ?", med_type)
  887. }
  888. //if zone_type > 0 {
  889. // db = db.Joins("join xt_schedule sch_two on sch_two.schedule_date = his_order.settle_accounts_date AND sch_two.patient_id = his_order.patient_id AND sch_two.partition_id = ?", zone_type)
  890. //}
  891. if sort_type == 1 {
  892. if start_time_timestamp != 0 {
  893. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  894. }
  895. if end_time_timestamp != 0 {
  896. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  897. }
  898. } else {
  899. if len(start_time) != 0 {
  900. db = db.Where("his_order.setl_time>=?", start_time+" 00:00:00")
  901. }
  902. if len(end_time) != 0 {
  903. db = db.Where("his_order.setl_time<=?", end_time+" 23:59:59")
  904. }
  905. }
  906. if p_type > 0 {
  907. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.p_type = ? AND his_order.order_status = 2", user_org_id, p_type)
  908. } else {
  909. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  910. }
  911. if charge_type > 0 {
  912. if charge_type == 2 {
  913. db = db.Where("his_order.is_medicine_insurance = 0")
  914. } else {
  915. db = db.Where("his_order.is_medicine_insurance = ?", charge_type)
  916. }
  917. }
  918. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  919. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  920. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  921. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  922. db = db.Preload("HisFundSettleListResult", "status = 1")
  923. db = db.Count(&total)
  924. db = db.Limit(limit).Offset(offset)
  925. if user_org_id == 10215 {
  926. if sort_type == 1 {
  927. err = db.Order("settle_accounts_date asc,ctime asc").Group("his_order.id").Find(&order).Error
  928. }
  929. if sort_type == 2 {
  930. err = db.Order("setl_time asc,ctime asc").Group("his_order.id").Find(&order).Error
  931. }
  932. } else {
  933. if sort_type == 1 {
  934. err = db.Order("settle_accounts_date desc,ctime desc").Group("his_order.id").Find(&order).Error
  935. }
  936. if sort_type == 2 {
  937. err = db.Order("setl_time desc,ctime desc").Group("his_order.id").Find(&order).Error
  938. }
  939. }
  940. return
  941. }
  942. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  943. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  944. return
  945. }
  946. func UpDatePrescriptionNumberTX(user_org_id int64, ids []int64, number string, tx *gorm.DB) (err error) {
  947. err = tx.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  948. return
  949. }
  950. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  951. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  952. return
  953. }
  954. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  955. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date = ?", user_org_id, id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  956. return
  957. }
  958. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  959. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  960. return
  961. }
  962. func UpDateHisPrescriptionInfoNumberTX(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64, tx *gorm.DB) (err error) {
  963. err = tx.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  964. return
  965. }
  966. func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
  967. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date <= ? AND record_date >= ? ", user_org_id, end_time, start_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  968. return
  969. }
  970. type HisOrder struct {
  971. ID int64 `gorm:"column:id" json:"id" form:"id"`
  972. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  973. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  974. Number string `gorm:"column:number" json:"number" form:"number"`
  975. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  976. Status int64 `gorm:"column:status" json:"status" form:"status"`
  977. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  978. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  979. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  980. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  981. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  982. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  983. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  984. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  985. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  986. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  987. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  988. PsnType string `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
  989. CvlservFlag string `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
  990. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  991. MdtrtCertType string `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
  992. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  993. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  994. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  995. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  996. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  997. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  998. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  999. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1000. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1001. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  1002. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1003. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1004. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1005. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1006. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  1007. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1008. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  1009. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1010. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1011. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  1012. Balc float64 `gorm:"column:balc" json:"balc" form:"balc"`
  1013. AcctMulaidPay float64 `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
  1014. MedinsSetlId string `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
  1015. ClrOptins string `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
  1016. ClrWay string `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
  1017. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1018. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1019. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  1020. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1021. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  1022. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1023. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1024. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1025. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1026. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1027. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1028. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1029. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1030. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1031. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1032. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1033. }
  1034. func (HisOrder) TableName() string {
  1035. return "his_order"
  1036. }
  1037. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  1038. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1039. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1040. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1041. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1042. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1043. Order("ctime desc").
  1044. Find(&order).Error
  1045. return
  1046. }
  1047. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  1048. err = readDb.Model(&models.HisPrescription{}).
  1049. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1050. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1051. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1052. }).
  1053. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1054. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  1055. Find(&prescription).Error
  1056. return
  1057. }
  1058. type HisPrescriptionInfo struct {
  1059. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1060. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1061. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1062. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1063. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1064. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1065. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1066. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1067. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1068. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1069. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1070. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1071. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1072. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1073. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  1074. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1075. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  1076. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  1077. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1078. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1079. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  1080. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1081. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1082. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1083. }
  1084. func (HisPrescriptionInfo) TableName() string {
  1085. return "his_prescription_info"
  1086. }
  1087. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  1088. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  1089. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1090. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1091. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  1092. Order("ctime desc").Find(&prescriptionOrder).Error
  1093. return
  1094. }
  1095. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  1096. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  1097. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1098. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1099. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  1100. return
  1101. }
  1102. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  1103. err = readDb.Model(&models.HisPrescription{}).
  1104. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1105. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1106. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  1107. }).
  1108. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  1109. Find(&prescription).Error
  1110. return
  1111. }
  1112. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  1113. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  1114. return
  1115. }
  1116. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  1117. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1118. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  1119. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1120. return
  1121. }
  1122. func UpdataOrderStatusten(id int64, number string, user_org_id int64) (err error) {
  1123. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1124. //err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1125. return
  1126. }
  1127. func UpdataHospitalOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  1128. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 1}).Error
  1129. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  1130. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 4, "mtime": time.Now().Unix()}).Error
  1131. return
  1132. }
  1133. func UpdataOrderStatusTen(id int64, number string, user_org_id int64) (err error) {
  1134. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  1135. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1136. return
  1137. }
  1138. func UpdataOrderInfoStatus(id int64, number string, user_org_id int64) {
  1139. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1140. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND user_org_id = ? AND order_number = ?", user_org_id, number).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1141. return
  1142. }
  1143. func SaveHisPatient(his models.HisPatient) (err error) {
  1144. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", his.RecordDate, his.UserOrgId, his.ID).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  1145. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1146. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1147. return
  1148. }
  1149. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  1150. writeDb.Model(&models.HisPatient{}).Where("patient_id = ? AND status = 1 AND record_date =? AND user_org_id = ?", patient_id, record_time, org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  1151. }
  1152. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  1153. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  1154. return
  1155. }
  1156. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  1157. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1158. First(&order).Error
  1159. return
  1160. }
  1161. func UpDateOrder(order models.HisOrder) (err error) {
  1162. err = writeDb.Save(&order).Error
  1163. return
  1164. }
  1165. func UpDateOrderTX(order models.HisOrder, tx *gorm.DB) (err error) {
  1166. err = writeDb.Save(&order).Error
  1167. return
  1168. }
  1169. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  1170. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  1171. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1172. return
  1173. }
  1174. func UpdataOrderStatusTwoTX(number string, user_org_id int64, tx *gorm.DB) (err error) {
  1175. err = tx.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  1176. err = tx.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1177. return
  1178. }
  1179. func CreateErrMsgLog(log *models.HisOrderError) {
  1180. writeDb.Model(&models.HisOrderError{}).Create(&log)
  1181. }
  1182. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  1183. err = readDb.Model(&models.VMHisPatient{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Count(&total).Error
  1184. return
  1185. }
  1186. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  1187. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  1188. return
  1189. }
  1190. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  1191. db := readDb.Model(&models.OutpatientServiceSick{})
  1192. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1193. err = db.Order("ctime desc").Find(&list).Error
  1194. return
  1195. }
  1196. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  1197. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  1198. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1199. err = db.Order("ctime desc").Find(&list).Error
  1200. return
  1201. }
  1202. func FindPatientDianose(orgId int64) (list []*models.XtPatientDiagnose, err error) {
  1203. err = readDb.Where("user_org_id =?", orgId).Find(&list).Error
  1204. return list, err
  1205. }
  1206. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  1207. db := readDb.Model(&models.XtHisAddtionConfig{})
  1208. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1209. err = db.Order("ctime desc").Find(&list).Error
  1210. return
  1211. }
  1212. type XtHisOrder struct {
  1213. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1214. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1215. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1216. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1217. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1218. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1219. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1220. Number string `gorm:"column:number" json:"number" form:"number"`
  1221. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1222. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1223. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1224. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1225. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1226. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1227. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1228. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1229. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1230. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1231. }
  1232. func (XtHisOrder) TableName() string {
  1233. return "his_order"
  1234. }
  1235. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  1236. err = readDb.Model(&models.HisPrescription{}).
  1237. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  1238. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1239. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1240. }).
  1241. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1242. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  1243. Find(&prescription).Error
  1244. return
  1245. }
  1246. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  1247. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Find(&addition).Error
  1248. return
  1249. }
  1250. func DelelteAddition(id int64, user_org_id int64) (err error) {
  1251. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1252. return
  1253. }
  1254. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64, sch_type int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  1255. offset := (page - 1) * limit
  1256. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("his_prescription_info.user_org_id = ? AND his_prescription_info.status = 1 AND his_prescription_info.record_date = ? AND his_prescription_info.p_type <> 1 ", org_id, record_date)
  1257. if len(keywords) > 0 {
  1258. keywords = "%" + keywords + "%"
  1259. db = db.Joins("JOIN xt_patients On his_prescription_info.patient_id = xt_patients.id AND xt_patients.name like ?", keywords)
  1260. }
  1261. if sch_type > 0 {
  1262. db = db.Joins("JOIN xt_schedule On xt_schedule.status = 1 AND his_prescription_info.patient_id = xt_schedule.patient_id AND xt_schedule.schedule_date = ? AND xt_schedule.schedule_type = ?", record_date, sch_type)
  1263. }
  1264. db = db.Preload("Patients", "xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1265. db = db.Preload("HisPrescription", "his_prescription.user_org_id = ? AND his_prescription.status = 1 AND his_prescription.p_type <> 1", org_id)
  1266. db = db.Count(&total)
  1267. err = db.Limit(limit).Offset(offset).Group("his_prescription_info.id").Find(&patients).Error
  1268. return
  1269. }
  1270. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  1271. offset := (page - 1) * limit
  1272. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  1273. if len(keywords) > 0 {
  1274. keywords = "%" + keywords + "%"
  1275. db = db.Joins("JOIN xt_patients as p On xt_schedule.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  1276. db = db.Joins("JOIN his_prescription_info as info On xt_schedule.patient_id = info.patient_id AND info.user_org_id = ? AND info.record_date = ? AND info.prescription_number like ? AND info.p_type <> 1", org_id, record_date, keywords)
  1277. }
  1278. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1279. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1280. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1281. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1282. db = db.Count(&total)
  1283. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1284. return
  1285. }
  1286. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1287. patient := models.VMHisPatient{}
  1288. err := XTWriteDB().Model(&patient).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patientid, recorddate, orgid).Updates(map[string]interface{}{"is_return": 3}).Error
  1289. return patient, err
  1290. }
  1291. type VMOtherHisPrescriptionInfo struct {
  1292. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1293. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1294. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1295. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1296. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1297. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1298. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1299. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1300. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1301. }
  1302. func (VMOtherHisPrescriptionInfo) TableName() string {
  1303. return "his_prescription_info"
  1304. }
  1305. type VMHisPrescription struct {
  1306. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1307. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1308. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1309. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1310. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1311. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1312. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1313. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1314. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1315. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1316. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1317. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1318. }
  1319. func (VMHisPrescription) TableName() string {
  1320. return "his_prescription"
  1321. }
  1322. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1323. if change_type == 1 { //根据日期取出上一方数据
  1324. var Id AdviceDate
  1325. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  1326. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1327. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1328. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1329. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1330. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1331. }).
  1332. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1333. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1334. })
  1335. }).Find(&advice).Error
  1336. } else if change_type == 2 {
  1337. var Id AdviceDate
  1338. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date > ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date desc").Scan(&Id).Error
  1339. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1340. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1341. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1342. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1343. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1344. }).
  1345. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1346. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1347. })
  1348. }).Find(&advice).Error
  1349. }
  1350. return
  1351. }
  1352. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1353. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ?", patient_id, org_id, start_time, end_time, p_type).
  1354. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1355. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1356. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1357. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1358. }).
  1359. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1360. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1361. })
  1362. }).Order("record_date desc").Find(&advice).Error
  1363. return
  1364. }
  1365. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1366. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
  1367. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1368. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1369. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1370. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1371. }).
  1372. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1373. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1374. })
  1375. }).Find(&advice).Error
  1376. return
  1377. }
  1378. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1379. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1380. return
  1381. }
  1382. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1383. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1384. return
  1385. }
  1386. func GetHisOrderByIDTX(order_id int64, tx *gorm.DB) (order models.HisOrder, err error) {
  1387. err = tx.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1388. return
  1389. }
  1390. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1391. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1392. return
  1393. }
  1394. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1395. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? AND insutype = ? AND clr_type = ? ", org_id, end_time, start_time, insutype, clr_type).Find(&orders).Error
  1396. return
  1397. }
  1398. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1399. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? ", org_id, end_time, start_time).Find(&orders).Error
  1400. return
  1401. }
  1402. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1403. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1404. return
  1405. }
  1406. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1407. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1408. return
  1409. }
  1410. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1411. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1412. return
  1413. }
  1414. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1415. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1416. return
  1417. }
  1418. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1419. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1420. return
  1421. }
  1422. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1423. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1424. return
  1425. }
  1426. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1427. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1428. return
  1429. }
  1430. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1431. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
  1432. return
  1433. }
  1434. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1435. var patient Patients
  1436. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1437. return patient, err
  1438. }
  1439. func GetPatientByIDTenTwo(orgID int64, patientID int64) (models.PatientTwos, error) {
  1440. var patient models.PatientTwos
  1441. err := readDb.Model(&models.PatientTwos{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1442. return patient, err
  1443. }
  1444. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1445. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1446. return
  1447. }
  1448. type VMHisProjectTeam struct {
  1449. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1450. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1451. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1452. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1453. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1454. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1455. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1456. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1457. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1458. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1459. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1460. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1461. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1462. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1463. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1464. }
  1465. func (VMHisProjectTeam) TableName() string {
  1466. return "xt_his_project_team"
  1467. }
  1468. type VMHisProject struct {
  1469. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1470. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1471. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1472. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1473. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1474. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1475. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1476. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1477. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1478. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1479. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1480. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1481. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1482. }
  1483. func (VMHisProject) TableName() string {
  1484. return "xt_his_project"
  1485. }
  1486. type VMItemProjectList struct {
  1487. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1488. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1489. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1490. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1491. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1492. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1493. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1494. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1495. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1496. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1497. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1498. }
  1499. func (VMItemProjectList) TableName() string {
  1500. return "xt_his_project_list"
  1501. }
  1502. type VMHisPrescriptionTwo struct {
  1503. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1504. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1505. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1506. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1507. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1508. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1509. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1510. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1511. }
  1512. func (VMHisPrescriptionTwo) TableName() string {
  1513. return "his_prescription"
  1514. }
  1515. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1516. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1517. for _, item := range project {
  1518. var project_item []*VMItemProjectList
  1519. ids := strings.Split(item.ItemId, ",")
  1520. XTReadDB().Model(&VMItemProjectList{}).Where("status = 1 AND id IN (?)", ids).Preload("VMHisProject", "status = 1 AND user_org_id = ?", orgid).Preload("GoodInfo", "status = 1 AND org_id = ?", orgid).Find(&project_item)
  1521. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1522. }
  1523. return
  1524. }
  1525. type HisDoctorAdviceInfo struct {
  1526. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1527. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1528. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1529. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1530. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1531. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1532. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1533. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1534. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1535. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1536. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1537. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1538. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1539. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1540. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1541. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1542. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1543. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1544. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1545. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1546. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1547. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1548. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1549. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1550. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1551. }
  1552. func (HisDoctorAdviceInfo) TableName() string {
  1553. return "his_doctor_advice_info"
  1554. }
  1555. type HisPrescriptionProject struct {
  1556. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1557. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1558. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1559. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1560. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1561. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1562. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1563. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1564. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1565. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1566. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1567. Count string `gorm:"column:count" json:"count" form:"count"`
  1568. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1569. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1570. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1571. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1572. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1573. Day string `gorm:"column:day" json:"day" form:"day"`
  1574. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1575. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1576. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1577. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1578. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1579. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1580. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1581. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1582. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1583. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1584. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1585. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1586. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1587. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1588. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1589. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1590. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1591. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1592. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1593. }
  1594. func (HisPrescriptionProject) TableName() string {
  1595. return "his_prescription_project"
  1596. }
  1597. type HisOrderInfo struct {
  1598. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1599. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1600. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1601. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1602. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1603. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1604. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1605. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1606. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1607. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1608. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1609. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1610. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1611. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1612. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1613. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1614. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1615. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1616. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1617. }
  1618. func (HisOrderInfo) TableName() string {
  1619. return "his_order_info"
  1620. }
  1621. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1622. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1623. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  1624. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1625. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  1626. }).Find(&order).Error
  1627. return
  1628. }
  1629. //func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1630. // db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1631. // return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  1632. // })
  1633. // err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1634. // return
  1635. //}
  1636. func GetHisOrderInfoByNumberOne(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1637. db := readDb.Model(&models.HisOrderInfoTwo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1638. return db.Preload("Drug", "status = 1").Where("status = 1")
  1639. })
  1640. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1641. return
  1642. }
  1643. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1644. db := readDb.Model(&models.HisOrderInfoTwo{})
  1645. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  1646. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1647. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1648. })
  1649. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0 ", order_number).Find(&order).Error
  1650. return
  1651. }
  1652. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1653. db := readDb.Model(&models.HisOrderInfoTwo{})
  1654. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  1655. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1656. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1657. })
  1658. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0", order_number).Find(&order).Error
  1659. return
  1660. }
  1661. type MedicalInsuranceCostCompare struct {
  1662. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1663. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1664. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1665. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1666. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1667. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1668. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1669. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1670. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1671. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1672. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1673. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1674. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1675. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1676. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1677. }
  1678. func (MedicalInsuranceCostCompare) TableName() string {
  1679. return "medical_insurance_cost_compare"
  1680. }
  1681. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1682. offset := (page - 1) * limit
  1683. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1684. if len(keywords) == 0 {
  1685. db = db.Where("status=1")
  1686. if len(insutype) != 0 {
  1687. db = db.Where("insutype = ?", insutype)
  1688. }
  1689. if start_time != 0 {
  1690. db = db.Where("ctime >= ? ", start_time)
  1691. }
  1692. if end_time != 0 {
  1693. db = db.Where("ctime <= ? ", end_time)
  1694. }
  1695. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1696. } else {
  1697. keywords = "%" + keywords + "%"
  1698. db = db.Joins("join sgj_users.sgj_user_admin_role role on role.admin_user_id = medical_insurance_cost_compare.creator and role.user_name Like ?", keywords)
  1699. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1700. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1701. }
  1702. return
  1703. }
  1704. type TempPatients struct {
  1705. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1706. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1707. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1708. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1709. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1710. Name string `gorm:"column:name" json:"name" form:"name"`
  1711. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1712. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1713. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1714. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1715. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1716. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1717. }
  1718. func (TempPatients) TableName() string {
  1719. return "xt_patients"
  1720. }
  1721. type GdybPsnNcdsRecord struct {
  1722. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1723. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1724. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1725. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1726. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1727. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1728. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1729. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1730. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1731. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1732. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1733. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1734. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1735. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1736. }
  1737. func (GdybPsnNcdsRecord) TableName() string {
  1738. return "gdyb_psn_ncds_record"
  1739. }
  1740. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1741. offset := (page - 1) * limit
  1742. db := readDb.Model(&TempPatients{})
  1743. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1744. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1745. })
  1746. fmt.Println(is_cancel)
  1747. if len(keywords) == 0 {
  1748. if is_cancel == 1 {
  1749. db = db.Joins("JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND gdyb_psn_ncds_record.is_cancel = ?", is_cancel)
  1750. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1751. } else if is_cancel == 0 {
  1752. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1753. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1754. } else if is_cancel == 2 {
  1755. db = db.Joins("LEFT JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND (gdyb_psn_ncds_record.is_cancel <> 1 OR gdyb_psn_ncds_record.is_cancel is null)")
  1756. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1757. }
  1758. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1759. } else {
  1760. keywords = "%" + keywords + "%"
  1761. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1 AND xt_patients.name LIKE ?", orgID, keywords)
  1762. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1763. }
  1764. return
  1765. }
  1766. type CustomAccountFormData struct {
  1767. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1768. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1769. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1770. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1771. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1772. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1773. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1774. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1775. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1776. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1777. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1778. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1779. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1780. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1781. DiagnosisId string `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1782. DialysisCount int64 `gorm:"-"`
  1783. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1784. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1785. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1786. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1787. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1788. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1789. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1790. }
  1791. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (cus []*CustomAccountFormData, err error) {
  1792. if clr_type == "9903" {
  1793. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt,o.hifp_pay as hifp_pay from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND o.insutype = ? AND o.clr_type = ? Group by o.id", org_id, start_time, end_time, insutype, clr_type).Scan(&cus).Error
  1794. } else {
  1795. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt,o.hifp_pay as hifp_pay from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND o.insutype = ? AND o.clr_type <> 9903 Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
  1796. }
  1797. for _, item := range cus {
  1798. var total int64
  1799. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, end_time, start_time).Count(&total)
  1800. fmt.Println(total)
  1801. item.DialysisCount = total
  1802. fmt.Println(item.DialysisCount)
  1803. }
  1804. return
  1805. }
  1806. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1807. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1808. return
  1809. }
  1810. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order models.HisOrder, err error) {
  1811. err = readDb.Model(&models.HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
  1812. Last(&order).Error
  1813. return
  1814. }
  1815. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1816. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? AND settle_accounts_date = ? ", user_org_id, patient_id, mdtrt_id, record_time).
  1817. Order("ctime desc").
  1818. Find(&order).Error
  1819. return
  1820. }
  1821. type NewCustomPatients struct {
  1822. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1823. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1824. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1825. Number string `gorm:"column:number" json:"number" form:"number"`
  1826. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1827. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1828. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1829. }
  1830. func (NewCustomPatients) TableName() string {
  1831. return "his_patients"
  1832. }
  1833. type NewSZCustomPatients struct {
  1834. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1835. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1836. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1837. Number string `gorm:"column:number" json:"number" form:"number"`
  1838. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1839. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1840. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1841. }
  1842. func (NewSZCustomPatients) TableName() string {
  1843. return "his_patients"
  1844. }
  1845. //
  1846. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1847. // var tempPatients []*NewSZCustomPatients
  1848. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1849. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1850. // return tempPatients, err
  1851. //}
  1852. type NewTempPatients struct {
  1853. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1854. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1855. Name string `gorm:"column:name" json:"name" form:"name"`
  1856. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1857. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1858. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  1859. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  1860. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  1861. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  1862. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  1863. }
  1864. func (NewTempPatients) TableName() string {
  1865. return "xt_patients"
  1866. }
  1867. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  1868. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  1869. db := readDb.Model(&NewTempPatients{})
  1870. if sch_type > 0 {
  1871. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  1872. }
  1873. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1874. db = db.Preload("Schedule", "status = 1")
  1875. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1876. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1877. })
  1878. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  1879. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Group("xt_patients.id").Error
  1880. for _, item := range patients {
  1881. for _, sumItem := range item.HisPatient {
  1882. if len(sumItem.VMHisOrders) > 0 {
  1883. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1884. }
  1885. }
  1886. }
  1887. return
  1888. }
  1889. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  1890. db := readDb.Model(&NewTempPatients{})
  1891. fmt.Println("sch_type")
  1892. fmt.Println(sch_type)
  1893. if sch_type > 0 {
  1894. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  1895. }
  1896. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1897. db = db.Preload("Schedule", "status = 1")
  1898. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1899. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? ", org_id, record_date)
  1900. })
  1901. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status = 2", org_id, record_date)
  1902. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Group("xt_patients.id").Error
  1903. for _, item := range patients {
  1904. for _, sumItem := range item.HisPatient {
  1905. if len(sumItem.VMHisOrders) > 0 {
  1906. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1907. }
  1908. }
  1909. }
  1910. return
  1911. }
  1912. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  1913. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  1914. return
  1915. }
  1916. type CustomInComeStatistics struct {
  1917. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1918. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1919. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1920. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1921. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1922. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1923. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1924. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1925. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1926. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1927. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1928. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  1929. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  1930. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1931. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1932. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1933. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1934. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1935. }
  1936. func (CustomInComeStatistics) TableName() string {
  1937. return "his_order"
  1938. }
  1939. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  1940. offset := (page - 1) * limit
  1941. if len(keywords) != 0 {
  1942. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1943. } else {
  1944. if start_time != 0 && end_time != 0 {
  1945. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ?", org_id, start_time, end_time).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1946. } else {
  1947. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  1948. }
  1949. }
  1950. return
  1951. }
  1952. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  1953. offset := (page - 1) * limit
  1954. if len(keywords) != 0 {
  1955. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1956. } else {
  1957. if start_time != 0 && end_time != 0 {
  1958. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ? ", org_id, start_time, end_time).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1959. } else {
  1960. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  1961. }
  1962. }
  1963. return
  1964. }
  1965. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1966. // err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  1967. // return
  1968. //}
  1969. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  1970. err = writeDb.Create(&template).Error
  1971. return
  1972. }
  1973. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  1974. err = writeDb.Save(&s).Error
  1975. return
  1976. }
  1977. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  1978. err = writeDb.Save(&s).Error
  1979. return
  1980. }
  1981. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  1982. err = writeDb.Save(&project).Error
  1983. return
  1984. }
  1985. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  1986. err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ? AND status = 1", org_id, patient_id, sch_date).First(&sch).Error
  1987. return
  1988. }
  1989. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  1990. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND status = 1 AND mode = ? AND patient_id = ?", org_id, mode_id, patient_id).Last(&prescription).Error
  1991. return
  1992. }
  1993. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  1994. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  1995. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1996. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1997. }).
  1998. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1999. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2000. }).
  2001. Where("status = 1 AND p_template_id = ? ", template_id).
  2002. Find(&prescription).Error
  2003. return
  2004. }
  2005. // 组
  2006. func GetHisPrescriptionTemplateL(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplateL, err error) {
  2007. err = readDb.Model(&models.HisPrescriptionInfoTemplateL{}).
  2008. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  2009. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2010. }).
  2011. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  2012. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2013. }).
  2014. Where("status = 1 AND p_template_id = ? ", template_id).
  2015. Find(&prescription).Error
  2016. return
  2017. }
  2018. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  2019. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND good_id = ?", orgID, patient_id, recordDate, good_id).First(&consumables).Error
  2020. return
  2021. }
  2022. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  2023. err = writeDb.Save(&consumables).Error
  2024. return
  2025. }
  2026. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  2027. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  2028. return
  2029. }
  2030. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2031. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id = 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2032. return
  2033. }
  2034. func GetHisPrescriptionTeamProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2035. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1 AND user_org_id = ?", user_org_id).Preload("HisProject", "status = 1 AND user_org_id = ?", user_org_id).Preload("GoodInfo", "status = 1 AND org_id = ?", user_org_id).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id > 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2036. return
  2037. }
  2038. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  2039. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2040. return
  2041. }
  2042. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  2043. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  2044. return
  2045. }
  2046. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  2047. err = writeDb.Save(&good_info).Error
  2048. return
  2049. }
  2050. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2051. err = readDb.Model(&models.HisPrescription{}).
  2052. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2053. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2054. }).
  2055. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2056. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2057. }).
  2058. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2059. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2060. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2061. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2062. }).
  2063. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id, p_type).
  2064. Find(&prescription).Error
  2065. return
  2066. }
  2067. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2068. err = readDb.Model(&models.HisPrescription{}).
  2069. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2070. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2071. }).
  2072. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2073. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2074. }).
  2075. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2076. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2077. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2078. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2079. }).
  2080. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status = 2 ", org_id, start_date, end_date, patient_id, p_type).
  2081. Find(&prescription).Error
  2082. return
  2083. }
  2084. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2085. err = readDb.Model(&models.HisPrescription{}).
  2086. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2087. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2088. }).
  2089. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2090. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  2091. }).
  2092. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2093. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  2094. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2095. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2096. }).
  2097. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND order_status = 2 AND batch_number = ? AND p_type = ?", org_id, patient_id, order_number, p_type).
  2098. Find(&prescription).Error
  2099. return
  2100. }
  2101. // 已收费
  2102. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2103. err = readDb.Model(&models.HisPrescription{}).
  2104. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2105. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2106. }).
  2107. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2108. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2109. }).
  2110. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2111. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2112. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2113. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2114. }).
  2115. Where("user_org_id = ? AND status = 1 AND batch_number = ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, order_number, patient_id, p_type).
  2116. Find(&prescription).Error
  2117. return
  2118. }
  2119. func UpdataHisPateint(his *models.HisPatient) {
  2120. writeDb.Save(&his)
  2121. }
  2122. func UpdataHisPateintTX(his *models.HisPatient, tx *gorm.DB) {
  2123. tx.Save(&his)
  2124. }
  2125. func SaveHisOrder(his *models.HisOrder) (err error) {
  2126. err = writeDb.Save(&his).Error
  2127. return
  2128. }
  2129. func UpdataHisPateintTwo(his *models.VMHisPatient) {
  2130. writeDb.Save(&his)
  2131. }
  2132. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  2133. err = readDb.Model(&models.HisPrescription{}).
  2134. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2135. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2136. }).
  2137. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2138. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2139. }).
  2140. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2141. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2142. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2143. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2144. }).
  2145. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2146. Find(&prescription).Error
  2147. return
  2148. }
  2149. func GetPrescriptionByIdsTX(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2150. err = tx.Model(&models.HisPrescription{}).
  2151. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2152. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2153. }).
  2154. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2155. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2156. }).
  2157. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2158. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2159. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2160. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2161. }).
  2162. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2163. Find(&prescription).Error
  2164. return
  2165. }
  2166. func GetPrescriptionByIdsTxOne(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2167. err = tx.Model(&models.HisPrescription{}).
  2168. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2169. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2170. }).
  2171. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2172. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  2173. }).
  2174. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2175. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1")
  2176. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2177. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2178. }).
  2179. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2180. Find(&prescription).Error
  2181. return
  2182. }
  2183. func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  2184. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2185. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2186. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? AND order_status <> 2", org_id, record_date)
  2187. })
  2188. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2189. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2190. for _, item := range patients {
  2191. for _, sumItem := range item.HisPatient {
  2192. if len(sumItem.VMHisOrders) > 0 {
  2193. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2194. }
  2195. }
  2196. }
  2197. return
  2198. }
  2199. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  2200. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 2 AND mdtrt_id = ?", org_id, patient_id, record_time, number).Count(&count).Error
  2201. return
  2202. }
  2203. func GetNewHisOrderList(org_id int64) (order []*models.NewHisOrder, err error) {
  2204. err = readDb.Model(&models.NewHisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Preload("HisPatient", "status = 1").Find(&order).Error
  2205. var numbers []string
  2206. for _, item := range order {
  2207. numbers = append(numbers, item.Number)
  2208. }
  2209. return
  2210. }
  2211. func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderInfo, err error) {
  2212. err = readDb.Model(&models.VMHisOrderInfo{}).Where("status = 1 AND order_number in (?)", order_numbers).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2213. return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1")
  2214. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2215. return db.Where("status = 1 ").Preload("Drug", "status =1")
  2216. }).Find(&order).Error
  2217. return
  2218. }
  2219. func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2220. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_date > ? AND advice_date <= ? AND drug_id = ? ", orgId, patient_id, end, now, drug_id).Find(&advice).Error
  2221. return
  2222. }
  2223. func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
  2224. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date > ? AND record_date <= ? AND project_id = ? ", orgId, patient_id, end, now, project_id).Find(&project).Error
  2225. return
  2226. }
  2227. func GetProjectByTeamId(user_org_id int64, team_id int64, patient_id int64, record_time int64) (label models.HisLabelPrintInfo, err error) {
  2228. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND item_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, team_id, patient_id, record_time).First(&label).Error
  2229. return
  2230. }
  2231. func GetProjectById(user_org_id int64, p_project_id int64, record_time int64, patient_id int64) (label models.HisLabelPrintInfo, err error) {
  2232. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND p_project_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, p_project_id, patient_id, record_time).First(&label).Error
  2233. return
  2234. }
  2235. func DeletePrintInfo(id int64) {
  2236. writeDb.Model(&models.HisLabelPrintInfo{}).Where("p_project_id = ?", id).Updates(map[string]interface{}{"status": 0})
  2237. }
  2238. func CreateHisLabelRecord(label *models.HisLabelPrintInfo) error {
  2239. err := writeDb.Save(&label).Error
  2240. return err
  2241. }
  2242. func DeletePsnNCDSRecordById(id int64) (err error) {
  2243. err = writeDb.Model(&models.GdybPsnNcdsRecord{}).Where("id = ?", id).Updates(map[string]interface{}{"user_org_id": 1110000}).Error
  2244. return
  2245. }
  2246. func GetBaiLinOrderData() (order []*models.NewCustomHisOrder) {
  2247. readDb.Model(&models.NewCustomHisOrder{}).Preload("Patients", "status = 1").Preload("NewCustomHisOrderInfo", func(db *gorm.DB) *gorm.DB {
  2248. return db.Where("status = 1 AND project_id > 0").Preload("NewCustomHisPrescriptionProject", "(status = 1 and project_id = 1027 AND type = 2) OR (status = 1 AND project_id = 2036 AND type = 3)")
  2249. }).Where("user_org_id = 10138 AND settle_accounts_date >= 1638288000 AND settle_accounts_date <= 1640880000 AND order_status = 2 AND status = 1 AND (medfee_sumamt = 50 OR medfee_sumamt = 40)").Find(&order)
  2250. return
  2251. }
  2252. func GetHisDoctorAdviceInfo(id int64) (models.HisDoctorAdviceInfo, error) {
  2253. info := models.HisDoctorAdviceInfo{}
  2254. err := readDb.Model(&info).Where("id = ? and status = 1", id).Preload("Drug", "status = 1").Find(&info).Error
  2255. return info, err
  2256. }
  2257. func UpdateBatchHisPrescriptionMedType(ids []string, med_type string, start_time int64, end_time int64, user_org_id int64, old_med_type string) (err error) {
  2258. tx := writeDb.Begin()
  2259. if err = tx.Model(&models.HisPrescription{}).Where("id in (?) AND status = 1 AND user_org_id=? AND med_type = ? AND record_date >= ? AND record_date <= ?", ids, user_org_id, old_med_type, start_time, end_time).Updates(map[string]interface{}{"med_type": med_type}).Error; err != nil {
  2260. tx.Rollback()
  2261. return
  2262. }
  2263. tx.Commit()
  2264. return
  2265. }
  2266. func GetWarehoseInfoByDrugId(drug_id int64, org_id int64) (info OtherDrugWarehouseInfo, err error) {
  2267. err = readDb.Model(&OtherDrugWarehouseInfo{}).Where("(drug_id = ? AND org_id = ? AND status = 1 and stock_max_number > 0) or (drug_id = ? AND org_id = ? AND status = 1 AND stock_min_number >0)", drug_id, org_id, drug_id, org_id).First(&info).Error
  2268. return
  2269. }
  2270. func GetGoodWarehoseInfoByGoodId(good_id int64, org_id int64) (info models.GoodSotckInfo, err error) {
  2271. err = readDb.Model(&models.GoodSotckInfo{}).Where("stock_count > 0 and status = 1 and good_id = ? and org_id = ?", good_id, org_id).First(&info).Error
  2272. return
  2273. }
  2274. type MonthChargePatients struct {
  2275. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2276. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2277. Name string `gorm:"column:name" json:"name" form:"name"`
  2278. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2279. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2280. Number string `gorm:"column:number" json:"number" form:"number"`
  2281. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2282. }
  2283. func (MonthChargePatients) TableName() string {
  2284. return "his_patient"
  2285. }
  2286. func GetMonthUnChargeHisPatientList(org_id int64, record_date int64, start_time int64, end_time int64) (patients []*MonthChargePatients, err error) {
  2287. db := readDb.Model(&MonthChargePatients{}).Where("his_patient.user_org_id = ? AND his_patient.status = 1 AND his_patient.record_date = ?", org_id, record_date)
  2288. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, start_time, end_time)
  2289. return
  2290. }
  2291. func UpdataOrderStatusThree(number string, user_org_id int64) (err error) {
  2292. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 5, "mtime": time.Now().Unix()}).Error
  2293. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 5, "mtime": time.Now().Unix()}).Error
  2294. return
  2295. }
  2296. func UpDateOrderTwo(order *models.HisOrder, tx *gorm.DB) (err error) {
  2297. err = tx.Save(&order).Error
  2298. return
  2299. }
  2300. type HisOrderInfoTen struct {
  2301. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2302. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2303. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2304. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2305. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2306. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2307. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2308. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2309. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2310. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2311. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2312. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2313. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2314. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2315. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2316. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2317. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2318. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2319. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2320. }
  2321. func (HisOrderInfoTen) TableName() string {
  2322. return "his_order_info"
  2323. }
  2324. func GetHisOrderDetailByNumberTen(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2325. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2326. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2327. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2328. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2329. }).Find(&order).Error
  2330. return
  2331. }
  2332. func GetHisOrderDetailByNumberEleven(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2333. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2334. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2335. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2336. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2337. }).Find(&order).Error
  2338. return
  2339. }
  2340. func GetHisOrderByIDTen(order_id int64) (order models.HisOrder, err error) {
  2341. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2342. return
  2343. }
  2344. func GetHisPrescriptonProjectById(id int64) (models.HisPrescriptionProject, error) {
  2345. project := models.HisPrescriptionProject{}
  2346. err := XTReadDB().Where("id = ? and status = 1", id).Find(&project).Error
  2347. return project, err
  2348. }
  2349. type HisOrderInfoTwo struct {
  2350. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2351. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2352. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2353. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2354. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2355. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2356. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2357. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2358. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2359. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2360. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2361. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2362. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2363. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2364. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2365. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2366. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2367. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2368. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2369. }
  2370. func (HisOrderInfoTwo) TableName() string {
  2371. return "his_order_info"
  2372. }
  2373. func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2374. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2375. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2376. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2377. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2378. }).Find(&order).Error
  2379. return
  2380. }
  2381. func GetHisOrderDetailByNumberThree(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2382. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2383. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2384. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2385. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2386. }).Find(&order).Error
  2387. return
  2388. }
  2389. func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
  2390. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2391. return
  2392. }
  2393. func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
  2394. drug := models.XtDrugStockCount{}
  2395. err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1 and storehouse_id =?", drug_id, user_org_id, storehouse_id).Find(&drug).Error
  2396. return drug, err
  2397. }
  2398. func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
  2399. stockCount := models.XtGoodStockCount{}
  2400. err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
  2401. return stockCount, err
  2402. }
  2403. func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
  2404. order := models.HisOrder{}
  2405. err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
  2406. return order, err
  2407. }
  2408. func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
  2409. err = XTReadDB().Where("user_org_id = ? and status= 1", orgid).Find(&patient).Error
  2410. return patient, err
  2411. }
  2412. func UpdatePatienPlan(id int64, trement_plan string) error {
  2413. err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
  2414. return err
  2415. }
  2416. func GetDialysisOrderList(orgid int64) (order []*models.XtDialysisOrder, err error) {
  2417. err = XTReadDB().Where("user_org_id = ? and status= 1 and url<>''", orgid).Group("patient_id").Find(&order).Error
  2418. return order, err
  2419. }
  2420. func UpdatePatientDialysisOrder(patient_id int64, url string) error {
  2421. err := XTWriteDB().Model(&models.XtPatients{}).Where("id =? and status=1", patient_id).Updates(map[string]interface{}{"url": url}).Error
  2422. return err
  2423. }
  2424. func GetHisOrderByIDTenOne(order_id string) (order models.HisOrder, err error) {
  2425. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  2426. return
  2427. }
  2428. func GetHisDoctorAdviceInfotwo(id int64) (models.HisDoctorAdviceInfo, error) {
  2429. info := models.HisDoctorAdviceInfo{}
  2430. err := readDb.Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
  2431. return info, err
  2432. }
  2433. func GetHisDoctorAdviceInfothree(org_id int64, record_date int64) (info []*models.HisDoctorAdviceInfo, err error) {
  2434. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&info).Error
  2435. return
  2436. }
  2437. func GetHisPrescriptionProjectByIDFour(org_id int64, record_date int64) (projects []*models.HisPrescriptionProject, err error) {
  2438. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&projects).Error
  2439. return
  2440. }
  2441. func GetHisPrescriptionProjectByIDThree(id int64) (projects models.HisPrescriptionProject, err error) {
  2442. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id = ? AND status = 1", id).First(&projects).Error
  2443. return
  2444. }
  2445. func GetHisPrescriptionProjectByIDTwoone(id int64) (projects models.HisPrescriptionProject, err error) {
  2446. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Preload("HisProject", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2447. return
  2448. }
  2449. func GetMonthNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, start_date int64, end_date int64) (patients []NewTempPatients, err error) {
  2450. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2451. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2452. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2453. })
  2454. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1 AND order_status <> 2 AND order_status <> 3 and record_date >= ? and record_date <= ?", org_id, start_date, end_date)
  2455. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2456. for _, item := range patients {
  2457. for _, sumItem := range item.HisPatient {
  2458. if len(sumItem.VMHisOrders) > 0 {
  2459. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2460. }
  2461. }
  2462. }
  2463. return
  2464. }
  2465. func GetChargeHisPatientList(org_id int64, record_date int64) (order []*HisOrder, err error) {
  2466. err = readDb.Model(&models.HisOrder{}).Preload("Patients", "status = 1").Where("settle_accounts_date = ? and user_org_id = ? AND status = 1 and order_status = 2", record_date, org_id).Find(&order).Error
  2467. return
  2468. }
  2469. func GetGoodByIdIsStop(good_id int64, org_id int64) (models.GoodInfoSeven, error) {
  2470. goodInfoSeven := models.GoodInfoSeven{}
  2471. err = XTReadDB().Where("org_id = ? and status = 1 and find_in_set('停用',good_status) = 0 and id =?", org_id, good_id).Find(&goodInfoSeven).Error
  2472. return goodInfoSeven, err
  2473. }
  2474. func GetHisPrescriptionByBatchNumber(org_id int64, number string) (prescription []*models.HisPrescription, err error) {
  2475. err = readDb.Model(&models.HisPrescription{}).
  2476. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2477. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2478. }).
  2479. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2480. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2481. }).
  2482. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2483. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  2484. }).
  2485. Where("user_org_id = ? AND status = 1 AND batch_number = ?", org_id, number).
  2486. Find(&prescription).Error
  2487. return
  2488. }
  2489. func GetLastHisOrderThree(org_id int64) (err error, o models.HisOrder) {
  2490. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? and status = 1 and order_status = 2", org_id).First(&o).Error
  2491. return
  2492. }
  2493. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  2494. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  2495. return
  2496. }
  2497. //func GetZuoBiaoNewAllUnChargeHisPatientList(org_id int64, record_date int64) (patients []*NewTempPatients, err error) {
  2498. // db := readDb.Model(&NewTempPatients{})
  2499. //
  2500. // db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2501. // db = db.Preload("Schedule", "status = 1")
  2502. // db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2503. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2504. // })
  2505. // db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2506. // err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2507. //
  2508. // for _, item := range patients {
  2509. // for _, sumItem := range item.HisPatient {
  2510. // if len(sumItem.VMHisOrders) > 0 {
  2511. // sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2512. // }
  2513. // }
  2514. //
  2515. // }
  2516. //
  2517. // return
  2518. //}
  2519. //func GetHisPrescriptionByHisPatientID(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  2520. // err = readDb.Model(&models.HisPrescriptionTen{}).
  2521. // Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = 2 and his_patient_id = 0", org_id, record_date, patient_id).
  2522. // Find(&prescription).Error
  2523. // return
  2524. //}
  2525. func GetHisPrescriptionByHisPatientID(record_date int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  2526. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ? and order_status = 1", patient_id, org_id, record_date, record_date, 1).
  2527. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  2528. return db.Where("status = 1 AND user_org_id = ?", org_id).
  2529. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2530. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2531. }).
  2532. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2533. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  2534. })
  2535. }).Order("record_date desc").Find(&advice).Error
  2536. return
  2537. }