his_service.go 132KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140
  1. package service
  2. import (
  3. "fmt"
  4. "gdyb/models"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "time"
  8. )
  9. type HisPatient struct {
  10. ID int64 `gorm:"column:id" json:"id" form:"id"`
  11. Name string `gorm:"column:name" json:"name" form:"name"`
  12. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  13. Total float64 `gorm:"column:total" json:"total" form:"total"`
  14. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  15. Status int64 `gorm:"column:status" json:"status" form:"status"`
  16. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  17. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  18. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  19. Number string `gorm:"column:number" json:"number" form:"number"`
  20. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  21. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  22. }
  23. func (HisPatient) TableName() string {
  24. return "his_patient"
  25. }
  26. type Schedule struct {
  27. ID int64 `gorm:"column:id" json:"id" form:"id"`
  28. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  29. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  30. Status int64 `gorm:"column:status" json:"status" form:"status"`
  31. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  32. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  33. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  34. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  35. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  36. }
  37. func (Schedule) TableName() string {
  38. return "xt_schedule"
  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 Patients 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. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  70. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  71. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  72. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  73. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  74. Source int64 `gorm:"column:source" json:"source" form:"source"`
  75. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  76. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  77. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  78. Name string `gorm:"column:name" json:"name" form:"name"`
  79. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  80. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  81. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  82. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  83. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  84. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  85. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  86. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  87. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  88. Height int64 `gorm:"column:height" json:"height" form:"height"`
  89. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  90. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  91. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  92. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  93. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  94. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  95. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  96. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  97. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  98. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  99. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  100. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  101. Children int64 `gorm:"column:children" json:"children" form:"children"`
  102. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  103. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  104. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  105. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  106. PredialysisCondition string `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
  107. PreHospitalDialysisFrequency string `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
  108. PreHospitalDialysisTimes int64 `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
  109. HospitalFirstDialysisDate int64 `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
  110. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  111. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  112. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  113. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  114. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  115. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  116. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  117. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  118. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  119. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  120. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  121. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  122. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
  123. PresentHistory string `gorm:"column:present_history" json:"present_history" form:"present_history"`
  124. PastHistory string `gorm:"column:past_history" json:"past_history" form:"past_history"`
  125. Temperature float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
  126. Pulse int64 `gorm:"column:pulse" json:"pulse" form:"pulse"`
  127. Respiratory int64 `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
  128. Sbp int64 `gorm:"column:sbp" json:"sbp" form:"sbp"`
  129. Dbp int64 `gorm:"column:dbp" json:"dbp" form:"dbp"`
  130. Status int64 `gorm:"column:status" json:"status" form:"status"`
  131. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  132. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  133. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  134. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  135. Age int64 `gorm:"column:age" json:"age" form:"age"`
  136. InfectiousNextRecordTime int64 `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
  137. IsInfectious int64 `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
  138. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
  139. RemindCycle int64 `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
  140. ResponseResult string `gorm:"column:response_result" json:"response_result" form:"response_result"`
  141. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  142. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  143. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  144. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  145. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  146. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  147. IsExcelExport int64 `gorm:"column:is_excel_export" json:"is_excel_export" form:"is_excel_export"`
  148. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  149. OutReason string `gorm:"column:out_reason" json:"out_reason" form:"out_reason"`
  150. InsuplcAdmdvs string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
  151. }
  152. func (Patients) TableName() string {
  153. return "xt_patients"
  154. }
  155. type HisPrescription struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  159. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  160. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  161. Status int64 `gorm:"column:status" json:"status" form:"status"`
  162. }
  163. func (HisPrescription) TableName() string {
  164. return "his_prescription"
  165. }
  166. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  167. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  168. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  169. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  170. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  171. return
  172. }
  173. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  174. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  175. return
  176. }
  177. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  178. 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
  179. return
  180. }
  181. func GetNewHisPatientInfo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  182. 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
  183. return
  184. }
  185. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  186. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  187. return
  188. }
  189. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  190. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  191. return
  192. }
  193. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  194. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  195. err = db.Find(&caseHistorys).Error
  196. return
  197. }
  198. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  199. likekey := "%" + keyword + "%"
  200. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  201. if startime > 0 {
  202. db = db.Where("record_date>=?", startime)
  203. }
  204. if endtime > 0 {
  205. db = db.Where("record_date<=?", endtime)
  206. }
  207. if len(keyword) > 0 {
  208. db = db.Where("template_name like ? ", likekey)
  209. }
  210. err = db.Find(&caseHistorys).Error
  211. return
  212. }
  213. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  214. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  215. return caseHistory, err
  216. }
  217. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  218. err = writeDb.Create(&template).Error
  219. return
  220. }
  221. func GetHisPatientCaseHistoryById(hispatientid int64) (*models.HisPatientCaseHistory, error) {
  222. history := models.HisPatientCaseHistory{}
  223. err := XTReadDB().Model(&history).Where("his_patient_id = ? and status = 1", hispatientid).Find(&history).Error
  224. if err != nil {
  225. if err == gorm.ErrRecordNotFound {
  226. return nil, err
  227. } else {
  228. return nil, err
  229. }
  230. }
  231. return &history, nil
  232. }
  233. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  234. err := writeDb.Create(&caseHistory).Error
  235. return err
  236. }
  237. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  238. err = writeDb.Save(&prescription).Error
  239. return
  240. }
  241. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  242. 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
  243. 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
  244. 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
  245. return
  246. }
  247. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  248. 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
  249. return
  250. }
  251. func DelelteProject(id int64, user_org_id int64) (err error) {
  252. 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
  253. return
  254. }
  255. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  256. err = readDb.Model(&models.HisPrescription{}).
  257. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  258. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  259. }).
  260. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  261. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  262. }).
  263. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  264. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  265. }).
  266. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1", org_id, record_date, patient_id).
  267. Find(&prescription).Error
  268. return
  269. }
  270. func GetNewHisPrescription(org_id int64, his_patient_id int64, record_date int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  271. err = readDb.Model(&models.HisPrescription{}).
  272. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  273. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  274. }).
  275. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  276. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  277. }).
  278. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  279. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  280. }).
  281. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, reg_type).
  282. Find(&prescription).Error
  283. return
  284. }
  285. type OtherDrugWarehouseInfo struct {
  286. ID int64 `gorm:"column:id" json:"id" form:"id"`
  287. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  288. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  289. Status int64 `gorm:"column:status" json:"status" form:"status"`
  290. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  291. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  292. }
  293. func (OtherDrugWarehouseInfo) TableName() string {
  294. return "xt_drug_warehouse_info"
  295. }
  296. type VMDrugSalesReturnInfo struct {
  297. ID int64 `gorm:"column:id" json:"id" form:"id"`
  298. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  299. Count int64 `gorm:"column:count" json:"count" form:"count"`
  300. Status int64 `gorm:"column:status" json:"status" form:"status"`
  301. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  302. }
  303. func (VMDrugSalesReturnInfo) TableName() string {
  304. return "xt_drug_sales_return_info"
  305. }
  306. type VMDrugWarehouseOutInfo struct {
  307. ID int64 `gorm:"column:id" json:"id" form:"id"`
  308. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  309. Count int64 `gorm:"column:count" json:"count" form:"count"`
  310. Status int64 `gorm:"column:status" json:"status" form:"status"`
  311. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  312. }
  313. func (VMDrugWarehouseOutInfo) TableName() string {
  314. return "xt_drug_warehouse_out_info"
  315. }
  316. type VMDrugCancelStockInfo struct {
  317. ID int64 `gorm:"column:id" json:"id" form:"id"`
  318. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  319. Count int64 `gorm:"column:count" json:"count" form:"count"`
  320. Status int64 `gorm:"column:status" json:"status" form:"status"`
  321. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  322. }
  323. func (VMDrugCancelStockInfo) TableName() string {
  324. return "xt_drug_cancel_stock_info"
  325. }
  326. type BaseDrugLib struct {
  327. ID int64 `gorm:"column:id" json:"id" form:"id"`
  328. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  329. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  330. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  331. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  332. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  333. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  334. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  335. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  336. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  337. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  338. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  339. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  340. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  341. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  342. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  343. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  344. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  345. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  346. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  347. Number string `gorm:"column:number" json:"number" form:"number"`
  348. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  349. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  350. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  351. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  352. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  353. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  354. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  355. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  356. Code string `gorm:"column:code" json:"code" form:"code"`
  357. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  358. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  359. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  360. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  361. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  362. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  363. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  364. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  365. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  366. Label int64 `gorm:"column:label" json:"label" form:"label"`
  367. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  368. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  369. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  370. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  371. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  372. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  373. Status int64 `gorm:"column:status" json:"status" form:"status"`
  374. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  375. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  376. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  377. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  378. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  379. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  380. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  381. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  382. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  383. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  384. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  385. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  386. }
  387. func (BaseDrugLib) TableName() string {
  388. return "xt_base_drug"
  389. }
  390. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  391. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  392. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  393. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  394. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  395. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  396. return
  397. }
  398. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  399. err = writeDb.Create(&charge).Error
  400. return
  401. }
  402. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  403. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  404. 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")
  405. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  406. return
  407. }
  408. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  409. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  410. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  411. }).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  412. return
  413. }
  414. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  415. err = writeDb.Save(s).Error
  416. return
  417. }
  418. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  419. err = writeDb.Save(project).Error
  420. return
  421. }
  422. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  423. 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
  424. return
  425. }
  426. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  427. err := writeDb.Create(&patient).Error
  428. return err
  429. }
  430. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  431. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  432. return
  433. }
  434. func GetNewVMHisPatientInfo(org_id int64, his_patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  435. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, his_patient_id).First(&info).Error
  436. return
  437. }
  438. func GetNewHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  439. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, id).First(&info).Error
  440. return
  441. }
  442. func GetHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  443. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  444. return
  445. }
  446. func CreateOrder(order *models.HisOrder) (err error) {
  447. err = writeDb.Create(&order).Error
  448. return
  449. }
  450. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  451. err = writeDb.Create(&order).Error
  452. return
  453. }
  454. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  455. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  456. return
  457. }
  458. func FindHisPatientPrescriptionInfo(org_id int64, his_patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  459. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ?", org_id, record_date, his_patient_id).First(&info).Error
  460. return
  461. }
  462. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  463. 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
  464. return
  465. }
  466. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  467. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, patient_id).Last(&info).Error
  468. return
  469. }
  470. func FindLastPatientPrescriptionInfoTwo1(org_id int64, patient_id int64) (info models.HisPrescriptionInfo, err error) {
  471. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1", org_id, patient_id).Last(&info).Error
  472. return
  473. }
  474. func FindLastPatientPrescriptionInfoTwo2(org_id int64, patient_id int64, start_time string, end_time string) (info []models.HisPrescriptionInfo, err error) {
  475. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1 and FROM_UNIXTIME(record_date) >= ? and FROM_UNIXTIME(record_date) <= ?", org_id, patient_id, start_time, end_time).Find(&info).Error
  476. return
  477. }
  478. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  479. err = writeDb.Save(&info).Error
  480. return
  481. }
  482. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string) (order []*models.HisOrder, err error, total int64) {
  483. offset := (page - 1) * limit
  484. db := readDb.Model(&models.HisOrder{})
  485. if doctor_id > 0 {
  486. 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)
  487. }
  488. if len(keywords) > 0 {
  489. keywords = "%" + keywords + "%"
  490. 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)
  491. }
  492. if start_time != 0 {
  493. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  494. }
  495. if end_time != 0 {
  496. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  497. }
  498. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
  499. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  500. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  501. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  502. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  503. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  504. })
  505. db = db.Count(&total)
  506. err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
  507. return
  508. }
  509. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  510. 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
  511. return
  512. }
  513. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  514. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  515. return
  516. }
  517. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  518. 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": 2, "mtime": time.Now().Unix()}).Error
  519. return
  520. }
  521. func UpDateHisPrescriptionInfoNumber(user_org_id int64, his_patient_id int64, number string, record_time int64) (err error) {
  522. 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": 2, "mtime": time.Now().Unix()}).Error
  523. return
  524. }
  525. type HisOrder struct {
  526. ID int64 `gorm:"column:id" json:"id" form:"id"`
  527. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  528. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  529. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  530. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  531. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  532. Status int64 `gorm:"column:status" json:"status" form:"status"`
  533. Number string `gorm:"column:number" json:"number" form:"number"`
  534. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  535. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  536. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  537. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  538. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  539. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  540. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  541. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  542. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  543. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  544. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  545. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  546. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  547. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  548. MedType int64 `gorm:"column:med_type" json:"med_type" form:"med_type"`
  549. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  550. SzChargeInfo string `gorm:"column:sz_charge_info" json:"sz_charge_info" form:"sz_charge_info"`
  551. SzProjectInfo string `gorm:"column:sz_project_info" json:"sz_project_info" form:"sz_project_info"`
  552. SzMedicineInsuranceInfo string `gorm:"column:sz_medicine_insurance_info" json:"sz_medicine_insurance_info" form:"sz_medicine_insurance_info"`
  553. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  554. OrgSetlNumber string `gorm:"column:org_setl_number" json:"org_setl_number" form:"org_setl_number"`
  555. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  556. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  557. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  558. FaPiaoSn string `gorm:"column:fa_piao_sn" json:"fa_piao_sn" form:"fa_piao_sn"`
  559. //FaPiaoSn string `gorm:"column:fa_piao_sn" json:"fa_piao_sn" form:"fa_piao_sn"`
  560. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  561. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  562. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  563. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  564. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  565. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  566. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  567. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  568. }
  569. func (HisOrder) TableName() string {
  570. return "his_order"
  571. }
  572. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  573. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  574. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  575. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  576. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  577. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  578. Order("ctime desc").
  579. Find(&order).Error
  580. return
  581. }
  582. func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  583. err = readDb.Model(&models.HisPrescription{}).
  584. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  585. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  586. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  587. }).
  588. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  589. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
  590. Find(&prescription).Error
  591. return
  592. }
  593. type HisPrescriptionInfo struct {
  594. ID int64 `gorm:"column:id" json:"id" form:"id"`
  595. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  596. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  597. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  598. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  599. Status int64 `gorm:"column:status" json:"status" form:"status"`
  600. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  601. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  602. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  603. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  604. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  605. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  606. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  607. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  608. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  609. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  610. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  611. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  612. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  613. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  614. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  615. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  616. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  617. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  618. }
  619. func (HisPrescriptionInfo) TableName() string {
  620. return "his_prescription_info"
  621. }
  622. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  623. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  624. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  625. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  626. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  627. Order("ctime desc").Find(&prescriptionOrder).Error
  628. return
  629. }
  630. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  631. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
  632. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  633. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  634. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  635. return
  636. }
  637. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  638. err = readDb.Model(&models.HisPrescription{}).
  639. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  640. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  641. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  642. }).
  643. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  644. Find(&prescription).Error
  645. return
  646. }
  647. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  648. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  649. return
  650. }
  651. func UpdataOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  652. 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(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  653. 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
  654. 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
  655. return
  656. }
  657. func UpdataOrderStatusThree(id int64, number string, user_org_id int64, log string, result string) (err error) {
  658. 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(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  659. 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
  660. 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
  661. return
  662. }
  663. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  664. 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()})
  665. //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
  666. //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
  667. }
  668. func UpdataRegStatusTwo(his_patient_id int64, record_time int64, org_id int64) {
  669. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", record_time, org_id, his_patient_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  670. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  671. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  672. }
  673. func UpdataRegStatus2(id int64) error {
  674. err := writeDb.Model(&models.HisPatient{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  675. return err
  676. }
  677. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  678. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  679. return
  680. }
  681. func GetAdminUserInfo(org_id int64) (role models.UserAdminRole, err error) {
  682. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1", org_id).First(&role).Error
  683. return
  684. }
  685. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  686. err = readDb.Model(&HisOrder{}).Where("user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  687. First(&order).Error
  688. return
  689. }
  690. func UpDateOrder(order models.HisOrder) (err error) {
  691. err = writeDb.Save(&order).Error
  692. return
  693. }
  694. func UpDateOrderTwo(order *models.HisOrder) (err error) {
  695. err = writeDb.Save(&order).Error
  696. return
  697. }
  698. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  699. 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
  700. 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
  701. return
  702. }
  703. func CreateErrMsgLog(log *models.HisOrderError) {
  704. writeDb.Model(&models.HisOrderError{}).Create(&log)
  705. }
  706. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  707. 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
  708. return
  709. }
  710. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  711. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  712. return
  713. }
  714. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  715. db := readDb.Model(&models.OutpatientServiceSick{})
  716. db = db.Where("user_org_id = ? AND status = 1", orgId)
  717. err = db.Order("ctime desc").Find(&list).Error
  718. return
  719. }
  720. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  721. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  722. db = db.Where("user_org_id = ? AND status = 1", orgId)
  723. err = db.Order("ctime desc").Find(&list).Error
  724. return
  725. }
  726. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  727. db := readDb.Model(&models.XtHisAddtionConfig{})
  728. db = db.Where("user_org_id = ? AND status = 1", orgId)
  729. err = db.Order("ctime desc").Find(&list).Error
  730. return
  731. }
  732. type XtHisOrder struct {
  733. ID int64 `gorm:"column:id" json:"id" form:"id"`
  734. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  735. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  736. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  737. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  738. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  739. Status int64 `gorm:"column:status" json:"status" form:"status"`
  740. Number string `gorm:"column:number" json:"number" form:"number"`
  741. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  742. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  743. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  744. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  745. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  746. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  747. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  748. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  749. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  750. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  751. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  752. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  753. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  754. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  755. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  756. }
  757. func (XtHisOrder) TableName() string {
  758. return "his_order"
  759. }
  760. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  761. err = readDb.Model(&models.HisPrescription{}).
  762. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  763. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  764. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  765. }).
  766. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  767. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  768. Find(&prescription).Error
  769. return
  770. }
  771. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  772. 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
  773. return
  774. }
  775. func DelelteAddition(id int64, user_org_id int64) (err error) {
  776. 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
  777. return
  778. }
  779. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
  780. offset := (page - 1) * limit
  781. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  782. if len(keywords) > 0 {
  783. keywords = "%" + keywords + "%"
  784. 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)
  785. 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 ?", org_id, record_date, keywords)
  786. }
  787. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  788. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  789. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).
  790. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id)
  791. db = db.Count(&total)
  792. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  793. return
  794. }
  795. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  796. patient := models.VMHisPatient{}
  797. 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
  798. return patient, err
  799. }
  800. type VMOtherHisPrescriptionInfo struct {
  801. ID int64 `gorm:"column:id" json:"id" form:"id"`
  802. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  803. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  804. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  805. Status int64 `gorm:"column:status" json:"status" form:"status"`
  806. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  807. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  808. }
  809. func (VMOtherHisPrescriptionInfo) TableName() string {
  810. return "his_prescription_info"
  811. }
  812. type VMHisPrescription struct {
  813. ID int64 `gorm:"column:id" json:"id" form:"id"`
  814. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  815. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  816. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  817. Status int64 `gorm:"column:status" json:"status" form:"status"`
  818. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  819. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  820. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  821. Type int64 `gorm:"column:type" json:"type" form:"type"`
  822. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  823. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  824. }
  825. func (VMHisPrescription) TableName() string {
  826. return "his_prescription"
  827. }
  828. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  829. 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).
  830. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  831. return db.Where("status = 1 AND user_org_id = ?", org_id).
  832. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  833. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  834. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  835. })
  836. }).Find(&advice).Error
  837. return
  838. }
  839. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  840. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  841. return
  842. }
  843. func GetFaPiaoHisOrderByID(order_id int64) (order models.HisFaPiaoOrder, err error) {
  844. str := strconv.FormatInt(order_id, 10)
  845. key := "%" + str + "%"
  846. err = readDb.Model(&models.HisFaPiaoOrder{}).Where("order_ids like ? and status = 1", key).First(&order).Error
  847. return
  848. }
  849. func GetHisOrderByIDTwo(order_id int64) (order models.HisOrder, err error) {
  850. err = readDb.Model(&models.HisOrder{}).Preload("HisOrderInfo", "status = 1").Preload("HisPatient", "status = 1").Where("id = ? AND status = 1", order_id).First(&order).Error
  851. return
  852. }
  853. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  854. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  855. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  856. })
  857. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  858. return
  859. }
  860. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfo, err error) {
  861. db := readDb.Model(&models.HisOrderInfo{})
  862. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  863. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  864. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  865. })
  866. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  867. return
  868. }
  869. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfo, err error) {
  870. db := readDb.Model(&models.HisOrderInfo{})
  871. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  872. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  873. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  874. })
  875. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  876. return
  877. }
  878. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  879. db := readDb.Model(&models.HisOrder{})
  880. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  881. if len(clr_org) > 0 {
  882. db = db.Where("clr_optins = ?", clr_org)
  883. }
  884. if len(clr_type) > 0 {
  885. if mdtrtareaAdmvs == "150499" {
  886. if clr_type == "11" {
  887. db = db.Where("clr_type = ?", clr_type)
  888. }
  889. } else {
  890. db = db.Where("clr_type = ?", clr_type)
  891. }
  892. } else {
  893. if len(clr_type) == 0 {
  894. db = db.Where("clr_type = ?", "")
  895. } else {
  896. db = db.Where("clr_type = ?", "9903")
  897. }
  898. }
  899. err = db.Find(&orders).Error
  900. return
  901. }
  902. func GetOrderByTimeFive(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  903. db := readDb.Model(&models.HisOrder{})
  904. db = db.Where("user_org_id = ? AND order_status = 3 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  905. if len(clr_org) > 0 {
  906. db = db.Where("clr_optins = ?", clr_org)
  907. }
  908. if len(clr_type) > 0 {
  909. if mdtrtareaAdmvs == "150499" {
  910. if clr_type == "11" {
  911. db = db.Where("clr_type = ?", clr_type)
  912. }
  913. } else {
  914. db = db.Where("clr_type = ?", clr_type)
  915. }
  916. }
  917. err = db.Find(&orders).Error
  918. return
  919. }
  920. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  921. db := readDb.Model(&models.HisOrder{})
  922. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org_id, end_time, start_time)
  923. err = db.Find(&orders).Error
  924. return
  925. }
  926. func GetOrderByTimeTenaaa(start_time int64, end_time int64, org_id int64, org string) (orders []*models.HisOrder, err error) {
  927. db := readDb.Model(&models.HisOrder{})
  928. db = db.Where("clr_options = ? and user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org, org_id, end_time, start_time)
  929. err = db.Find(&orders).Error
  930. return
  931. }
  932. func GetOrderByTime11222(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  933. db := readDb.Model(&models.HisOrder{})
  934. db = db.Where("psn_name = '付云芳' and user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time)
  935. err = db.Find(&orders).Error
  936. return
  937. }
  938. func GetOrderByTimeFourfor11(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  939. db := readDb.Model(&models.HisOrder{})
  940. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? and med_type = 11", org_id, end_time, start_time)
  941. err = db.Find(&orders).Error
  942. return
  943. }
  944. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  945. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype).Find(&orders).Error
  946. return
  947. }
  948. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  949. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time).Find(&orders).Error
  950. return
  951. }
  952. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  953. var patient models.Patients
  954. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  955. if err != nil {
  956. if err == gorm.ErrRecordNotFound {
  957. return nil, nil
  958. } else {
  959. return nil, err
  960. }
  961. }
  962. return &patient, nil
  963. }
  964. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  965. dealer := models.HisXtDiagnoseConfig{}
  966. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  967. return dealer, err
  968. }
  969. func FindDiagnoseByIdtwo(id string) (models.HisXtDiagnoseConfig, error) {
  970. dealer := models.HisXtDiagnoseConfig{}
  971. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  972. return dealer, err
  973. }
  974. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  975. dealer := []*models.HisXtDiagnoseConfig{}
  976. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  977. return dealer, err
  978. }
  979. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  980. outPatient := &models.OutpatientServiceSick{}
  981. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  982. return outPatient, err
  983. }
  984. //
  985. //type MonthHisPrescription struct {
  986. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  987. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  988. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  989. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  990. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  991. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  992. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  993. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  994. // Number string `gorm:"column:number" json:"number" form:"number"`
  995. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  996. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  997. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  998. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  999. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1000. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1001. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1002. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1003. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  1004. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1005. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1006. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  1007. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  1008. //}
  1009. //
  1010. //func (MonthHisPrescription) TableName() string {
  1011. // return "his_prescription"
  1012. //}
  1013. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  1014. err = readDb.Model(&models.HisPrescription{}).
  1015. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1016. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1017. }).
  1018. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1019. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1020. }).
  1021. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1022. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1023. }).
  1024. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, reg_type).
  1025. Find(&prescription).Error
  1026. return
  1027. }
  1028. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  1029. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  1030. return
  1031. }
  1032. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1033. err = readDb.Model(&Patients{}).Where("(health_care_no = ? or id_card_no = ?) AND user_org_id = ?", id_card_no, id_card_no, user_org_id).First(&patient).Error
  1034. return
  1035. }
  1036. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1037. 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
  1038. return
  1039. }
  1040. func GetAppRole(orgID int64) (models.App_Role, error) {
  1041. var appRole models.App_Role
  1042. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  1043. return appRole, err
  1044. }
  1045. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1046. var patient Patients
  1047. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1048. return patient, err
  1049. }
  1050. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  1051. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1052. table := XTReadDB().Table("xt_manufacturer as m")
  1053. fmt.Print(table)
  1054. if orgID > 0 {
  1055. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  1056. }
  1057. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1058. return drug, err
  1059. }
  1060. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  1061. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  1062. return dataconfig, err
  1063. }
  1064. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1065. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  1066. //return role, err
  1067. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1068. table := UserReadDB().Table("sgj_user_admin as a")
  1069. fmt.Println(table)
  1070. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1071. return role, err
  1072. }
  1073. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1074. err = readDb.Model(&models.HisPrescription{}).
  1075. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1076. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1077. }).
  1078. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1079. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1080. }).
  1081. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1082. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1083. }).
  1084. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1085. Find(&prescription).Error
  1086. return
  1087. }
  1088. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1089. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1090. //table := UserReadDB().Table("sgj_user_admin as a")
  1091. //fmt.Println(table)
  1092. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1093. return role, err
  1094. }
  1095. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1096. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1097. return role, err
  1098. }
  1099. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1100. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1101. table := XTReadDB().Table("xt_manufacturer as m")
  1102. fmt.Print(table)
  1103. if orgID > 0 {
  1104. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1105. }
  1106. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1107. return drug, err
  1108. }
  1109. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1110. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1111. table := XTReadDB().Table("xt_manufacturer as m")
  1112. fmt.Println(table)
  1113. if orgid > 0 {
  1114. db = db.Where("x.org_id = ?", orgid)
  1115. }
  1116. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1117. return good, err
  1118. }
  1119. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1120. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1121. table := XTReadDB().Table("xt_manufacturer as m")
  1122. fmt.Println(table)
  1123. if orgid > 0 {
  1124. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1125. }
  1126. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1127. return good, err
  1128. }
  1129. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1130. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1131. table := UserReadDB().Table("sgj_user_admin as a")
  1132. fmt.Println(table)
  1133. if id > 0 {
  1134. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1135. }
  1136. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1137. return role, err
  1138. }
  1139. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1140. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1141. return project, err
  1142. }
  1143. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1144. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1145. return project, err
  1146. }
  1147. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1148. db := XTReadDB().Table("xt_his_project")
  1149. if len(idss) == 1 {
  1150. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1151. } else {
  1152. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1153. }
  1154. return project, err
  1155. }
  1156. func GetBathchMyPorjecgListtwo(org_id int64) (project []*models.MyHisProject, err error) {
  1157. db := XTReadDB().Table("xt_his_project")
  1158. err = db.Where("status = 1 and user_org_id = ?", org_id).Find(&project).Error
  1159. return project, err
  1160. }
  1161. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1162. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1163. table := UserReadDB().Table("sgj_user_admin as a")
  1164. fmt.Println(table)
  1165. if len(idss) == 1 {
  1166. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1167. } else {
  1168. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1169. }
  1170. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1171. return role, err
  1172. }
  1173. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1174. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1175. return
  1176. }
  1177. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1178. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1179. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1180. return
  1181. }
  1182. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1183. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date <= ? AND record_date >= ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1184. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1185. return
  1186. }
  1187. func UpdateHisPrescriptionHisID1111(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1188. //XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1189. //XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1190. return
  1191. }
  1192. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1193. 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
  1194. return
  1195. }
  1196. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1197. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1198. return
  1199. }
  1200. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1201. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1202. return
  1203. }
  1204. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1205. err = writeDb.Create(&result).Error
  1206. return
  1207. }
  1208. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1209. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1210. return
  1211. }
  1212. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1213. err = writeDb.Save(&result).Error
  1214. return
  1215. }
  1216. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1217. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1218. return
  1219. }
  1220. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1221. writeDb.Save(&his)
  1222. }
  1223. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1224. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code <> '' AND fa_piao_number <> ''", org_id).Last(&his).Error
  1225. return
  1226. }
  1227. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1228. 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
  1229. return
  1230. }
  1231. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1232. 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
  1233. return
  1234. }
  1235. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1236. 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).
  1237. Order("ctime desc").
  1238. Find(&order).Error
  1239. return
  1240. }
  1241. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1242. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1243. return
  1244. }
  1245. func UpdateHisPatientThree(his *models.HisPatient) {
  1246. writeDb.Save(&his)
  1247. }
  1248. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1249. err = readDb.Model(&models.HisPrescription{}).
  1250. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1251. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1252. }).
  1253. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1254. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1255. }).
  1256. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1257. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1258. }).
  1259. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, med_type).
  1260. Find(&prescription).Error
  1261. return
  1262. }
  1263. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1264. err = readDb.Model(&models.HisPrescription{}).
  1265. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1266. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1267. }).
  1268. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1269. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1270. }).
  1271. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1272. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1273. }).
  1274. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, med_type).
  1275. Find(&prescription).Error
  1276. return
  1277. }
  1278. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1279. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1280. return
  1281. }
  1282. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1283. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 1 AND mdtrt_id = ?", org_id, patient_id, record_time, number).First(&order).Error
  1284. return
  1285. }
  1286. func GetLastFundList(org_id int64) (order models.HisFundSettleListResult, err error) {
  1287. err = readDb.Model(&models.HisFundSettleListResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Last(&order).Error
  1288. return
  1289. }
  1290. func GetOrderError(org_id int64) (order []*models.HisOrderError, err error) {
  1291. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 10106 ", org_id).Find(&order).Error
  1292. return
  1293. }
  1294. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1295. 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
  1296. return
  1297. }
  1298. func CreateHisPsn(psn *models.HisPsn) {
  1299. writeDb.Save(&psn)
  1300. }
  1301. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1302. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1303. return
  1304. }
  1305. func GetPsnByPatientIdtWO(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1306. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ?", patient_id, record_date).Last(&psn).Error
  1307. return
  1308. }
  1309. //func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1310. // err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1311. // return
  1312. //}
  1313. func GetPsnByPatientIdTwo(patient_id int64) (psn models.HisPsn, err error) {
  1314. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1315. return
  1316. }
  1317. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1318. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2022-12-15 00:00:00'", org_id).Order("setl_time asc").Find(&his).Error
  1319. fmt.Println(err)
  1320. return
  1321. }
  1322. func GetAllHisOrderTwo(org_id int64) (his []*models.HisOrder, err error) {
  1323. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND id >= 247903", org_id).Order("setl_time asc").Find(&his).Error
  1324. fmt.Println(err)
  1325. return
  1326. }
  1327. func GetAllHisOrder10106(org_id int64) (his []*models.HisOrder, err error) {
  1328. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2023-08-01 00:00:00' AND setl_time <= '2023-08-31 23:59:00'").Order("setl_time asc").Find(&his).Error
  1329. fmt.Println(err)
  1330. return
  1331. }
  1332. func GetAllHisOrder10138() (his []*models.HisOrder, err error) {
  1333. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10138 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-04-01 00:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1334. fmt.Println(err)
  1335. return
  1336. }
  1337. func GetOrderError10138() (order []*models.HisOrderError, err error) {
  1338. err = readDb.Model(&models.HisOrderError{}).Where("status = 1 AND stage = 10138500").Find(&order).Error
  1339. return
  1340. }
  1341. func GetAllHisOrder10278() (his []*models.HisOrder, err error) {
  1342. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10278 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-04-01 00:00:00' AND setl_time <= '2024-09-30 23:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1343. fmt.Println(err)
  1344. return
  1345. }
  1346. func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1347. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-09-01 00:00:00' AND setl_time <= '2024-09-30 23:59:00'").Order("setl_time asc").Find(&his).Error
  1348. fmt.Println(err)
  1349. return
  1350. }
  1351. //func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1352. // err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2023-09-01 00:00:00'").Order("setl_time asc").Find(&his).Error
  1353. // fmt.Println(err)
  1354. // return
  1355. //}
  1356. // func GetAllHisOrder2(org_id int64) (his []models.HisOrder, err error) {
  1357. // err = readDb.Model(&models.HisOrder{}).Where("id = 180753").Order("setl_time asc").First(&his).Error
  1358. // return
  1359. // }
  1360. func GetAllHisOrderErr10278() (his []*models.HisOrderError, err error) {
  1361. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = 10278 AND status = 1 AND stage = 10276").Find(&his).Error
  1362. return
  1363. }
  1364. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1365. db := readDb.Model(&models.HisOrderInfo{})
  1366. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1367. return
  1368. }
  1369. func UpdataOrderStatusByNumber(number string) (err error) {
  1370. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND number = ?", number).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1371. return
  1372. }
  1373. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1374. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND order_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  1375. 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
  1376. 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
  1377. return
  1378. }
  1379. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1380. db := readDb.Model(&models.HisFundSettleListResult{})
  1381. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1382. return
  1383. }
  1384. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1385. writeDb.Save(&record)
  1386. }
  1387. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1388. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1389. return
  1390. }
  1391. func UpdateOrder(order models.HisOrder) (err error) {
  1392. err = writeDb.Save(&order).Error
  1393. return
  1394. }
  1395. func UpdateOrderTwo(order models.NewHisOrder111) (err error) {
  1396. err = writeDb.Save(&order).Error
  1397. return
  1398. }
  1399. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1400. err = readDb.Model(&models.HisPrescriptionTen{}).
  1401. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1402. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1403. }).
  1404. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1405. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1406. }).
  1407. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND p_type <> 1 ", org_id, record_date, his_patient_id).
  1408. Find(&prescription).Error
  1409. return
  1410. }
  1411. func GetHisOrderByIDTwo1111(order_id int64) (order models.NewHisOrder111, err error) {
  1412. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1413. return
  1414. }
  1415. func GetHisPrescriptionForMedType(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1416. err = readDb.Model(&models.HisPrescription{}).
  1417. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1418. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1419. }).
  1420. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1421. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1422. }).
  1423. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1424. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1425. }).
  1426. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 148801) or (user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 118801)", org_id, record_date, patient_id, org_id, record_date, patient_id).
  1427. Find(&prescription).Error
  1428. return
  1429. }
  1430. func GetOrderByTimeTen(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1431. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1432. return
  1433. }
  1434. func GetOrderByTimeTentwo(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1435. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 0 and his_order.order_status = 3 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1436. return
  1437. }
  1438. func GetOrderDetailByTimeTen(start_time string, end_time string, org_id int64, fund_key string) (fund []models.FundDetail, err error) {
  1439. err = readDb.Raw("SELECT CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') end AS fund_key, his_order.`setl_detail` FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and CONCAT(his_order.insutype, '99', his_order.med_type, '555555') = ?", org_id, start_time+" 00:00:00", end_time+" 23:59:00", fund_key).Scan(&fund).Error
  1440. return
  1441. }
  1442. func Saveflow(flow models.HisPrescriptionFlow) {
  1443. writeDb.Save(&flow)
  1444. }
  1445. func Createflow(flow *models.HisPrescriptionFlow) {
  1446. writeDb.Create(&flow)
  1447. }
  1448. func GetNewHisPrescriptionTenone(org_id int64, number string) (prescription []*models.HisPrescriptionTen, err error) {
  1449. err = readDb.Model(&models.HisPrescriptionTen{}).
  1450. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1451. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1452. }).
  1453. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1454. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1455. }).
  1456. Where("user_org_id = ? AND status = 1 AND batch_number = ? and order_status = 4 ", org_id, number).
  1457. Find(&prescription).Error
  1458. return
  1459. }
  1460. func GetHisOrderByIDThree(start_time string) (his []*models.HisOrder, err error) {
  1461. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= ?", start_time).Order("setl_time asc").Find(&his).Error
  1462. fmt.Println(err)
  1463. return
  1464. }
  1465. func UpDatePrescriptionNumber111(user_org_id int64, start_time int64, end_time int64, number string, patient_id int64) (err error) {
  1466. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? and record_date <= ? and patient_id = ? and order_status = 1", user_org_id, start_time, end_time, patient_id).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1467. return
  1468. }
  1469. func UpDatePrescriptionNumber222(user_org_id int64, id int64, number string, patient_id int64) (err error) {
  1470. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id = ? and patient_id = ?", user_org_id, id, patient_id).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1471. return
  1472. }
  1473. func GetAllHisOrderTwo10485() (his []*models.HisOrder, err error) {
  1474. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10485 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-01-01 00:00:00' ").Order("setl_time asc").Find(&his).Error
  1475. fmt.Println(err)
  1476. return
  1477. }
  1478. func GetNewDrugWarehouseInfo(org_id int64, id_arr []string) (newDrugWarehouse []*models.NewDrugWarehouseInfo, err error) {
  1479. readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and id in (?) ", org_id, id_arr).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&newDrugWarehouse)
  1480. return
  1481. }
  1482. func GetNewDrugFlowInfo(org_id int64, id_arr []string) (flows []*models.DrugFlow, err error) {
  1483. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?)", org_id, id_arr).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1484. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1485. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1486. return
  1487. }
  1488. func GetNewDrugFlowInfoByPatient(patient_id int64, advice_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1489. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?) and patinet_id = ? and advice_id = ? and system_time = ?", org_id, patient_id, advice_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1490. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1491. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1492. return
  1493. }
  1494. func GetNewUploadDrugFlowInfoByPatientTwo(patient_id int64, advice_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1495. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?) and patinet_id = ? and advice_id = ? and system_time = ? and is_sale = 1 and is_bg = 1", org_id, patient_id, advice_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1496. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1497. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1498. return
  1499. }
  1500. func GetNewDrugFlowInfotwo() (flows []*models.DrugFlow, err error) {
  1501. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10188 and status = 1 and id >= ? and consumable_type = 3 and is_sale = 0", 2394762).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1502. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1503. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1504. return
  1505. }
  1506. func GetNewDrugFlowInfothree() (flows []*models.DrugFlow, err error) {
  1507. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10217 and status = 1 and id >= ? and consumable_type = 3 and is_sale = 0", 2328112).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1508. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1509. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1510. return
  1511. }
  1512. func GetNewDrugFlowInforTen() (flows []*models.DrugFlow, err error) {
  1513. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10318 and status = 1 and drug_code != '' and consumable_type = 3 and is_sale = 0").Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1514. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1515. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1516. return
  1517. }
  1518. func GetHisPrescriptionByID(id int64) (pre models.HisPrescription) {
  1519. err = readDb.Model(&models.HisPrescription{}).Where("id = ? and status = 1", id).Find(&pre).Error
  1520. return
  1521. }
  1522. func GetHisOrderByNumber(number string) (order models.HisOrder) {
  1523. err = readDb.Model(&models.HisOrder{}).Where("number = ? and status = 1", number).First(&order).Error
  1524. return
  1525. }
  1526. func SaveDF(df *models.DrugFlow) (err error) {
  1527. //err = writeDb.(&df).Error
  1528. err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
  1529. "is_sale": df.IsSale,
  1530. "sale_date": df.SaleDate,
  1531. "bchno": df.Bchno,
  1532. //"is_change"
  1533. }).Error
  1534. return
  1535. }
  1536. func SaveDF2(df *models.DrugFlow) (err error) {
  1537. //err = writeDb.(&df).Error
  1538. err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
  1539. "is_change": df.IsChange,
  1540. "bg_bchno": df.BgBchno,
  1541. //"is_change"
  1542. }).Error
  1543. return
  1544. }
  1545. func GetDrugByID(drug_id int64) (drug models.BaseDrugLib, err error) {
  1546. err = readDb.Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).First(&drug).Error
  1547. return
  1548. }
  1549. func GetBbx01ByTeamID(team_id int64) (team models.XtHisProjectTeam) {
  1550. err = readDb.Model(&models.XtHisProjectTeam{}).Where("id = ?", team_id).First(&team).Error
  1551. return
  1552. }
  1553. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1554. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1555. 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)
  1556. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1557. 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)
  1558. }).Find(&order).Error
  1559. return
  1560. }
  1561. type HisOrderInfo struct {
  1562. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1563. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1564. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1565. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1566. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1567. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1568. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1569. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1570. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1571. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1572. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1573. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1574. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1575. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1576. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1577. SelfpayProp float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
  1578. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1579. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1580. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1581. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1582. }
  1583. func (HisOrderInfo) TableName() string {
  1584. return "his_order_info"
  1585. }
  1586. type HisDoctorAdviceInfo struct {
  1587. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1588. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1589. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1590. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1591. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1592. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1593. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1594. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1595. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1596. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1597. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1598. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1599. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1600. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1601. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1602. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1603. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1604. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1605. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1606. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1607. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1608. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1609. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1610. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1611. }
  1612. type Drug struct {
  1613. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1614. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  1615. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1616. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1617. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  1618. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  1619. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  1620. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  1621. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1622. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  1623. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  1624. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  1625. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  1626. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  1627. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  1628. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  1629. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  1630. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  1631. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  1632. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  1633. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  1634. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  1635. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  1636. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  1637. Number string `gorm:"column:number" json:"number" form:"number"`
  1638. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  1639. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  1640. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  1641. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1642. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  1643. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  1644. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  1645. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  1646. Code string `gorm:"column:code" json:"code" form:"code"`
  1647. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  1648. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  1649. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  1650. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  1651. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  1652. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1653. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1654. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1655. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1656. Label int64 `gorm:"column:label" json:"label" form:"label"`
  1657. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  1658. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  1659. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  1660. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  1661. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  1662. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  1663. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1664. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1665. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1666. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1667. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  1668. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  1669. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  1670. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1671. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  1672. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  1673. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  1674. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  1675. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  1676. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  1677. Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  1678. Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  1679. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  1680. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  1681. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  1682. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1683. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1684. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  1685. Bck01b string `gorm:"column:bck01b" json:"bck01b" form:"bck01b"`
  1686. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  1687. Bbx01 string `gorm:"column:bbx01" json:"bbx01" form:"bbx01"`
  1688. }
  1689. func (Drug) TableName() string {
  1690. return "xt_base_drug"
  1691. }
  1692. type VMHisProject struct {
  1693. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1694. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1695. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1696. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1697. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1698. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1699. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1700. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1701. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1702. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1703. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1704. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1705. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1706. }
  1707. func (VMHisProject) TableName() string {
  1708. return "xt_his_project"
  1709. }
  1710. type VMGoodInfo struct {
  1711. ID int64 `gorm:"column:id" json:"id"`
  1712. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  1713. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  1714. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  1715. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  1716. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  1717. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1718. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  1719. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1720. }
  1721. func (VMGoodInfo) TableName() string {
  1722. return "xt_good_information"
  1723. }
  1724. func (HisDoctorAdviceInfo) TableName() string {
  1725. return "his_doctor_advice_info"
  1726. }
  1727. type VMHisPatient struct {
  1728. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1729. BalanceAccountsType int64 `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`
  1730. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1731. Name string `gorm:"column:name" json:"name" form:"name"`
  1732. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  1733. IdType int64 `gorm:"column:id_type" json:"id_type" form:"id_type"`
  1734. MedicalTreatmentType int64 `gorm:"column:medical_treatment_type" json:"medical_treatment_type" form:"medical_treatment_type"`
  1735. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  1736. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1737. Age float64 `gorm:"column:age" json:"age" form:"age"`
  1738. PhoneNumber string `gorm:"column:phone_number" json:"phone_number" form:"phone_number"`
  1739. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1740. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1741. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  1742. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1743. IsNeedCostOfProduction int64 `gorm:"column:is_need_cost_of_production" json:"is_need_cost_of_production" form:"is_need_cost_of_production"`
  1744. RegisterCost float64 `gorm:"column:register_cost" json:"register_cost" form:"register_cost"`
  1745. TreatmentCost float64 `gorm:"column:treatment_cost" json:"treatment_cost" form:"treatment_cost"`
  1746. CostOfProduction float64 `gorm:"column:cost_of_production" json:"cost_of_production" form:"cost_of_production"`
  1747. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1748. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1749. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1750. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1751. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1752. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1753. Number string `gorm:"column:number" json:"number" form:"number"`
  1754. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1755. IsReturn int64 `gorm:"column:is_return" json:"is_return" form:"is_return"`
  1756. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1757. PsnCertType string `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
  1758. Certno string `gorm:"column:certno" json:"certno" form:"certno"`
  1759. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1760. Gend string `gorm:"column:gend" json:"gend" form:"gend"`
  1761. Naty string `gorm:"column:naty" json:"naty" form:"naty"`
  1762. Brdy string `gorm:"column:brdy" json:"brdy" form:"brdy"`
  1763. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1764. Idetinfo string `gorm:"column:idetinfo" json:"idetinfo" form:"idetinfo"`
  1765. IptOtpNo string `gorm:"column:ipt_otp_no" json:"ipt_otp_no" form:"ipt_otp_no"`
  1766. PType string `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1767. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1768. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1769. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  1770. }
  1771. func (VMHisPatient) TableName() string {
  1772. return "his_patient"
  1773. }
  1774. type HisPrescriptionProject struct {
  1775. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1776. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1777. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1778. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1779. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1780. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1781. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1782. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1783. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1784. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1785. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1786. Count string `gorm:"column:count" json:"count" form:"count"`
  1787. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1788. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1789. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1790. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1791. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1792. Day string `gorm:"column:day" json:"day" form:"day"`
  1793. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1794. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1795. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1796. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1797. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1798. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1799. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1800. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1801. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1802. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1803. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1804. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1805. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1806. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1807. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1808. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1809. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1810. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1811. }
  1812. func (HisPrescriptionProject) TableName() string {
  1813. return "his_prescription_project"
  1814. }
  1815. func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1816. db := XTReadDB().Model(&advice).Where("status= 1 and is_medicine = 0")
  1817. if orgid > 0 {
  1818. db = db.Where("user_org_id = ?", orgid)
  1819. }
  1820. if patient_id > 0 {
  1821. db = db.Where("patient_id = ?", patient_id)
  1822. }
  1823. if stime > 0 {
  1824. db = db.Where("advice_date >=?", stime)
  1825. }
  1826. if etime > 0 {
  1827. db = db.Where("advice_date<=?", etime)
  1828. }
  1829. err = db.Find(&advice).Error
  1830. return advice, err
  1831. }
  1832. func FindUploadHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1833. db := XTReadDB().Model(&advice).Where("status= 1 and is_medicine = 0")
  1834. if orgid > 0 {
  1835. db = db.Where("user_org_id = ?", orgid)
  1836. }
  1837. if patient_id > 0 {
  1838. db = db.Where("patient_id = ?", patient_id)
  1839. }
  1840. if stime > 0 {
  1841. db = db.Where("advice_date >=?", stime)
  1842. }
  1843. if etime > 0 {
  1844. db = db.Where("advice_date<=?", etime)
  1845. }
  1846. db = db.Where("is_upload = 1")
  1847. err = db.Find(&advice).Error
  1848. return advice, err
  1849. }