his_service.go 103KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  1. package service
  2. import (
  3. "fmt"
  4. "gdyb/models"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. type HisPatient struct {
  9. ID int64 `gorm:"column:id" json:"id" form:"id"`
  10. Name string `gorm:"column:name" json:"name" form:"name"`
  11. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  12. Total float64 `gorm:"column:total" json:"total" form:"total"`
  13. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  14. Status int64 `gorm:"column:status" json:"status" form:"status"`
  15. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  16. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  17. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  18. Number string `gorm:"column:number" json:"number" form:"number"`
  19. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  20. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  21. }
  22. func (HisPatient) TableName() string {
  23. return "his_patient"
  24. }
  25. type Schedule struct {
  26. ID int64 `gorm:"column:id" json:"id" form:"id"`
  27. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  28. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  29. Status int64 `gorm:"column:status" json:"status" form:"status"`
  30. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  31. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  32. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  33. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  34. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  35. }
  36. func (Schedule) TableName() string {
  37. return "xt_schedule"
  38. }
  39. type VMHisPrescriptionInfo struct {
  40. ID int64 `gorm:"column:id" json:"id" form:"id"`
  41. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  42. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  43. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  44. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  45. Status int64 `gorm:"column:status" json:"status" form:"status"`
  46. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  47. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  48. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  49. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  50. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  51. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  52. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  53. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  54. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  55. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  56. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  57. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  58. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  59. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  60. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  61. }
  62. func (VMHisPrescriptionInfo) TableName() string {
  63. return "his_prescription_info"
  64. }
  65. type Patients struct {
  66. ID int64 `gorm:"column:id" json:"id" form:"id"`
  67. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  68. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  69. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  70. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  71. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  72. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  73. Source int64 `gorm:"column:source" json:"source" form:"source"`
  74. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  75. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  76. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  77. Name string `gorm:"column:name" json:"name" form:"name"`
  78. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  79. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  80. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  81. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  82. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  83. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  84. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  85. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  86. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  87. Height int64 `gorm:"column:height" json:"height" form:"height"`
  88. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  89. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  90. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  91. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  92. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  93. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  94. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  95. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  96. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  97. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  98. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  99. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  100. Children int64 `gorm:"column:children" json:"children" form:"children"`
  101. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  102. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  103. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  104. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  105. PredialysisCondition string `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
  106. PreHospitalDialysisFrequency string `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
  107. PreHospitalDialysisTimes int64 `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
  108. HospitalFirstDialysisDate int64 `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
  109. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  110. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  111. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  112. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  113. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  114. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  115. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  116. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  117. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  118. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  119. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  120. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  121. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
  122. PresentHistory string `gorm:"column:present_history" json:"present_history" form:"present_history"`
  123. PastHistory string `gorm:"column:past_history" json:"past_history" form:"past_history"`
  124. Temperature float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
  125. Pulse int64 `gorm:"column:pulse" json:"pulse" form:"pulse"`
  126. Respiratory int64 `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
  127. Sbp int64 `gorm:"column:sbp" json:"sbp" form:"sbp"`
  128. Dbp int64 `gorm:"column:dbp" json:"dbp" form:"dbp"`
  129. Status int64 `gorm:"column:status" json:"status" form:"status"`
  130. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  131. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  132. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  133. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  134. Age int64 `gorm:"column:age" json:"age" form:"age"`
  135. InfectiousNextRecordTime int64 `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
  136. IsInfectious int64 `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
  137. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
  138. RemindCycle int64 `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
  139. ResponseResult string `gorm:"column:response_result" json:"response_result" form:"response_result"`
  140. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  141. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  142. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  143. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  144. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  145. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  146. IsExcelExport int64 `gorm:"column:is_excel_export" json:"is_excel_export" form:"is_excel_export"`
  147. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  148. OutReason string `gorm:"column:out_reason" json:"out_reason" form:"out_reason"`
  149. InsuplcAdmdvs string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
  150. }
  151. func (Patients) TableName() string {
  152. return "xt_patients"
  153. }
  154. type HisPrescription struct {
  155. ID int64 `gorm:"column:id" json:"id" form:"id"`
  156. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  157. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  158. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  159. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  160. Status int64 `gorm:"column:status" json:"status" form:"status"`
  161. }
  162. func (HisPrescription) TableName() string {
  163. return "his_prescription"
  164. }
  165. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  166. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  167. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  168. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  169. 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
  170. return
  171. }
  172. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  173. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  174. return
  175. }
  176. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  177. 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
  178. return
  179. }
  180. func GetNewHisPatientInfo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  181. 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
  182. return
  183. }
  184. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  185. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  186. return
  187. }
  188. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  189. 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
  190. return
  191. }
  192. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  193. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  194. err = db.Find(&caseHistorys).Error
  195. return
  196. }
  197. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  198. likekey := "%" + keyword + "%"
  199. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  200. if startime > 0 {
  201. db = db.Where("record_date>=?", startime)
  202. }
  203. if endtime > 0 {
  204. db = db.Where("record_date<=?", endtime)
  205. }
  206. if len(keyword) > 0 {
  207. db = db.Where("template_name like ? ", likekey)
  208. }
  209. err = db.Find(&caseHistorys).Error
  210. return
  211. }
  212. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  213. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  214. return caseHistory, err
  215. }
  216. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  217. err = writeDb.Create(&template).Error
  218. return
  219. }
  220. func GetHisPatientCaseHistoryById(hispatientid int64) (*models.HisPatientCaseHistory, error) {
  221. history := models.HisPatientCaseHistory{}
  222. err := XTReadDB().Model(&history).Where("his_patient_id = ? and status = 1", hispatientid).Find(&history).Error
  223. if err != nil {
  224. if err == gorm.ErrRecordNotFound {
  225. return nil, err
  226. } else {
  227. return nil, err
  228. }
  229. }
  230. return &history, nil
  231. }
  232. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  233. err := writeDb.Create(&caseHistory).Error
  234. return err
  235. }
  236. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  237. err = writeDb.Save(&prescription).Error
  238. return
  239. }
  240. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  241. 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
  242. 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
  243. 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
  244. return
  245. }
  246. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  247. 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
  248. return
  249. }
  250. func DelelteProject(id int64, user_org_id int64) (err error) {
  251. 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
  252. return
  253. }
  254. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  255. err = readDb.Model(&models.HisPrescription{}).
  256. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  257. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  258. }).
  259. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  260. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  261. }).
  262. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  263. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  264. }).
  265. 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).
  266. Find(&prescription).Error
  267. return
  268. }
  269. func GetNewHisPrescription(org_id int64, his_patient_id int64, record_date int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  270. err = readDb.Model(&models.HisPrescription{}).
  271. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  272. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  273. }).
  274. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  275. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  276. }).
  277. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  278. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  279. }).
  280. 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).
  281. Find(&prescription).Error
  282. return
  283. }
  284. type OtherDrugWarehouseInfo struct {
  285. ID int64 `gorm:"column:id" json:"id" form:"id"`
  286. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  287. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  288. Status int64 `gorm:"column:status" json:"status" form:"status"`
  289. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  290. }
  291. func (OtherDrugWarehouseInfo) TableName() string {
  292. return "xt_drug_warehouse_info"
  293. }
  294. type VMDrugSalesReturnInfo struct {
  295. ID int64 `gorm:"column:id" json:"id" form:"id"`
  296. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  297. Count int64 `gorm:"column:count" json:"count" form:"count"`
  298. Status int64 `gorm:"column:status" json:"status" form:"status"`
  299. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  300. }
  301. func (VMDrugSalesReturnInfo) TableName() string {
  302. return "xt_drug_sales_return_info"
  303. }
  304. type VMDrugWarehouseOutInfo struct {
  305. ID int64 `gorm:"column:id" json:"id" form:"id"`
  306. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  307. Count int64 `gorm:"column:count" json:"count" form:"count"`
  308. Status int64 `gorm:"column:status" json:"status" form:"status"`
  309. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  310. }
  311. func (VMDrugWarehouseOutInfo) TableName() string {
  312. return "xt_drug_warehouse_out_info"
  313. }
  314. type VMDrugCancelStockInfo struct {
  315. ID int64 `gorm:"column:id" json:"id" form:"id"`
  316. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  317. Count int64 `gorm:"column:count" json:"count" form:"count"`
  318. Status int64 `gorm:"column:status" json:"status" form:"status"`
  319. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  320. }
  321. func (VMDrugCancelStockInfo) TableName() string {
  322. return "xt_drug_cancel_stock_info"
  323. }
  324. type BaseDrugLib struct {
  325. ID int64 `gorm:"column:id" json:"id" form:"id"`
  326. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  327. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  328. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  329. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  330. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  331. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  332. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  333. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  334. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  335. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  336. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  337. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  338. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  339. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  340. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  341. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  342. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  343. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  344. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  345. Number string `gorm:"column:number" json:"number" form:"number"`
  346. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  347. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  348. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  349. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  350. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  351. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  352. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  353. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  354. Code string `gorm:"column:code" json:"code" form:"code"`
  355. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  356. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  357. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  358. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  359. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  360. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  361. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  362. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  363. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  364. Label int64 `gorm:"column:label" json:"label" form:"label"`
  365. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  366. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  367. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  368. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  369. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  370. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  371. Status int64 `gorm:"column:status" json:"status" form:"status"`
  372. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  373. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  374. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  375. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  376. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  377. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  378. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  379. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  380. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  381. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  382. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  383. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  384. }
  385. func (BaseDrugLib) TableName() string {
  386. return "xt_base_drug"
  387. }
  388. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  389. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  390. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  391. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  392. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  393. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  394. return
  395. }
  396. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  397. err = writeDb.Create(&charge).Error
  398. return
  399. }
  400. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  401. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  402. 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")
  403. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  404. return
  405. }
  406. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  407. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  408. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  409. }).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  410. return
  411. }
  412. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  413. err = writeDb.Save(s).Error
  414. return
  415. }
  416. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  417. err = writeDb.Save(project).Error
  418. return
  419. }
  420. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  421. 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
  422. return
  423. }
  424. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  425. err := writeDb.Create(&patient).Error
  426. return err
  427. }
  428. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  429. 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
  430. return
  431. }
  432. func GetNewVMHisPatientInfo(org_id int64, his_patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  433. 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
  434. return
  435. }
  436. func GetNewHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  437. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, id).First(&info).Error
  438. return
  439. }
  440. func GetHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  441. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  442. return
  443. }
  444. func CreateOrder(order *models.HisOrder) (err error) {
  445. err = writeDb.Create(&order).Error
  446. return
  447. }
  448. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  449. err = writeDb.Create(&order).Error
  450. return
  451. }
  452. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  453. 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
  454. return
  455. }
  456. func FindHisPatientPrescriptionInfo(org_id int64, his_patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  457. 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
  458. return
  459. }
  460. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  461. 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
  462. return
  463. }
  464. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  465. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, patient_id).Last(&info).Error
  466. return
  467. }
  468. func FindLastPatientPrescriptionInfoTwo1(org_id int64, patient_id int64) (info models.HisPrescriptionInfo, err error) {
  469. 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
  470. return
  471. }
  472. func FindLastPatientPrescriptionInfoTwo2(org_id int64, patient_id int64, start_time string, end_time string) (info []models.HisPrescriptionInfo, err error) {
  473. 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
  474. return
  475. }
  476. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  477. err = writeDb.Save(&info).Error
  478. return
  479. }
  480. 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) {
  481. offset := (page - 1) * limit
  482. db := readDb.Model(&models.HisOrder{})
  483. if doctor_id > 0 {
  484. 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)
  485. }
  486. if len(keywords) > 0 {
  487. keywords = "%" + keywords + "%"
  488. 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)
  489. }
  490. if start_time != 0 {
  491. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  492. }
  493. if end_time != 0 {
  494. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  495. }
  496. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
  497. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  498. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  499. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  500. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  501. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  502. })
  503. db = db.Count(&total)
  504. err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
  505. return
  506. }
  507. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  508. 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
  509. return
  510. }
  511. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  512. 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
  513. return
  514. }
  515. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  516. 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
  517. return
  518. }
  519. func UpDateHisPrescriptionInfoNumber(user_org_id int64, his_patient_id int64, number string, record_time int64) (err error) {
  520. 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
  521. return
  522. }
  523. type HisOrder struct {
  524. ID int64 `gorm:"column:id" json:"id" form:"id"`
  525. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  526. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  527. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  528. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  529. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  530. Status int64 `gorm:"column:status" json:"status" form:"status"`
  531. Number string `gorm:"column:number" json:"number" form:"number"`
  532. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  533. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  534. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  535. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  536. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  537. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  538. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  539. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  540. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  541. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  542. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  543. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  544. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  545. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  546. MedType int64 `gorm:"column:med_type" json:"med_type" form:"med_type"`
  547. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  548. SzChargeInfo string `gorm:"column:sz_charge_info" json:"sz_charge_info" form:"sz_charge_info"`
  549. SzProjectInfo string `gorm:"column:sz_project_info" json:"sz_project_info" form:"sz_project_info"`
  550. SzMedicineInsuranceInfo string `gorm:"column:sz_medicine_insurance_info" json:"sz_medicine_insurance_info" form:"sz_medicine_insurance_info"`
  551. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  552. OrgSetlNumber string `gorm:"column:org_setl_number" json:"org_setl_number" form:"org_setl_number"`
  553. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  554. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  555. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  556. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  557. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  558. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  559. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  560. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  561. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  562. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  563. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  564. }
  565. func (HisOrder) TableName() string {
  566. return "his_order"
  567. }
  568. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  569. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  570. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  571. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  572. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  573. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  574. Order("ctime desc").
  575. Find(&order).Error
  576. return
  577. }
  578. func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  579. err = readDb.Model(&models.HisPrescription{}).
  580. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  581. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  582. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  583. }).
  584. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  585. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
  586. Find(&prescription).Error
  587. return
  588. }
  589. type HisPrescriptionInfo struct {
  590. ID int64 `gorm:"column:id" json:"id" form:"id"`
  591. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  592. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  593. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  594. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  595. Status int64 `gorm:"column:status" json:"status" form:"status"`
  596. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  597. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  598. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  599. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  600. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  601. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  602. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  603. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  604. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  605. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  606. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  607. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  608. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  609. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  610. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  611. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  612. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  613. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  614. }
  615. func (HisPrescriptionInfo) TableName() string {
  616. return "his_prescription_info"
  617. }
  618. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  619. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  620. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  621. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  622. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  623. Order("ctime desc").Find(&prescriptionOrder).Error
  624. return
  625. }
  626. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  627. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
  628. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  629. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  630. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  631. return
  632. }
  633. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  634. err = readDb.Model(&models.HisPrescription{}).
  635. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  636. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  637. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  638. }).
  639. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  640. Find(&prescription).Error
  641. return
  642. }
  643. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  644. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  645. return
  646. }
  647. func UpdataOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  648. 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
  649. 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
  650. 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
  651. return
  652. }
  653. func UpdataOrderStatusThree(id int64, number string, user_org_id int64, log string, result string) (err error) {
  654. 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
  655. 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
  656. 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
  657. return
  658. }
  659. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  660. 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()})
  661. //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
  662. //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
  663. }
  664. func UpdataRegStatusTwo(his_patient_id int64, record_time int64, org_id int64) {
  665. 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()})
  666. 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()})
  667. 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()})
  668. }
  669. func UpdataRegStatus2(id int64) error {
  670. err := writeDb.Model(&models.HisPatient{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  671. return err
  672. }
  673. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  674. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  675. return
  676. }
  677. func GetAdminUserInfo(org_id int64) (role models.UserAdminRole, err error) {
  678. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1", org_id).First(&role).Error
  679. return
  680. }
  681. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  682. err = readDb.Model(&HisOrder{}).Where("user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  683. First(&order).Error
  684. return
  685. }
  686. func UpDateOrder(order models.HisOrder) (err error) {
  687. err = writeDb.Save(&order).Error
  688. return
  689. }
  690. func UpDateOrderTwo(order *models.HisOrder) (err error) {
  691. err = writeDb.Save(&order).Error
  692. return
  693. }
  694. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  695. 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
  696. 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
  697. return
  698. }
  699. func CreateErrMsgLog(log *models.HisOrderError) {
  700. writeDb.Model(&models.HisOrderError{}).Create(&log)
  701. }
  702. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  703. 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
  704. return
  705. }
  706. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  707. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  708. return
  709. }
  710. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  711. db := readDb.Model(&models.OutpatientServiceSick{})
  712. db = db.Where("user_org_id = ? AND status = 1", orgId)
  713. err = db.Order("ctime desc").Find(&list).Error
  714. return
  715. }
  716. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  717. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  718. db = db.Where("user_org_id = ? AND status = 1", orgId)
  719. err = db.Order("ctime desc").Find(&list).Error
  720. return
  721. }
  722. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  723. db := readDb.Model(&models.XtHisAddtionConfig{})
  724. db = db.Where("user_org_id = ? AND status = 1", orgId)
  725. err = db.Order("ctime desc").Find(&list).Error
  726. return
  727. }
  728. type XtHisOrder struct {
  729. ID int64 `gorm:"column:id" json:"id" form:"id"`
  730. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  731. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  732. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  733. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  734. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  735. Status int64 `gorm:"column:status" json:"status" form:"status"`
  736. Number string `gorm:"column:number" json:"number" form:"number"`
  737. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  738. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  739. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  740. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  741. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  742. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  743. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  744. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  745. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  746. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  747. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  748. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  749. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  750. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  751. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  752. }
  753. func (XtHisOrder) TableName() string {
  754. return "his_order"
  755. }
  756. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  757. err = readDb.Model(&models.HisPrescription{}).
  758. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  759. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  760. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  761. }).
  762. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  763. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  764. Find(&prescription).Error
  765. return
  766. }
  767. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  768. 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
  769. return
  770. }
  771. func DelelteAddition(id int64, user_org_id int64) (err error) {
  772. 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
  773. return
  774. }
  775. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
  776. offset := (page - 1) * limit
  777. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  778. if len(keywords) > 0 {
  779. keywords = "%" + keywords + "%"
  780. 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)
  781. 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)
  782. }
  783. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  784. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  785. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).
  786. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id)
  787. db = db.Count(&total)
  788. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  789. return
  790. }
  791. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  792. patient := models.VMHisPatient{}
  793. 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
  794. return patient, err
  795. }
  796. type VMOtherHisPrescriptionInfo struct {
  797. ID int64 `gorm:"column:id" json:"id" form:"id"`
  798. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  799. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  800. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  801. Status int64 `gorm:"column:status" json:"status" form:"status"`
  802. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  803. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  804. }
  805. func (VMOtherHisPrescriptionInfo) TableName() string {
  806. return "his_prescription_info"
  807. }
  808. type VMHisPrescription struct {
  809. ID int64 `gorm:"column:id" json:"id" form:"id"`
  810. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  811. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  812. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  813. Status int64 `gorm:"column:status" json:"status" form:"status"`
  814. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  815. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  816. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  817. Type int64 `gorm:"column:type" json:"type" form:"type"`
  818. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  819. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  820. }
  821. func (VMHisPrescription) TableName() string {
  822. return "his_prescription"
  823. }
  824. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  825. 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).
  826. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  827. return db.Where("status = 1 AND user_org_id = ?", org_id).
  828. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  829. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  830. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  831. })
  832. }).Find(&advice).Error
  833. return
  834. }
  835. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  836. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  837. return
  838. }
  839. func GetHisOrderByIDTwo(order_id int64) (order models.HisOrder, err error) {
  840. err = readDb.Model(&models.HisOrder{}).Preload("HisOrderInfo", "status = 1").Preload("HisPatient", "status = 1").Where("id = ? AND status = 1", order_id).First(&order).Error
  841. return
  842. }
  843. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  844. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  845. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  846. })
  847. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  848. return
  849. }
  850. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfo, err error) {
  851. db := readDb.Model(&models.HisOrderInfo{})
  852. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  853. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  854. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  855. })
  856. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  857. return
  858. }
  859. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfo, err error) {
  860. db := readDb.Model(&models.HisOrderInfo{})
  861. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  862. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  863. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  864. })
  865. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  866. return
  867. }
  868. 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) {
  869. db := readDb.Model(&models.HisOrder{})
  870. 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)
  871. if len(clr_org) > 0 {
  872. db = db.Where("clr_optins = ?", clr_org)
  873. }
  874. if len(clr_type) > 0 {
  875. if mdtrtareaAdmvs == "150499" {
  876. if clr_type == "11" {
  877. db = db.Where("clr_type = ?", clr_type)
  878. }
  879. } else {
  880. db = db.Where("clr_type = ?", clr_type)
  881. }
  882. } else {
  883. if len(clr_type) == 0 {
  884. db = db.Where("clr_type = ?", "")
  885. } else {
  886. db = db.Where("clr_type = ?", "9903")
  887. }
  888. }
  889. err = db.Find(&orders).Error
  890. return
  891. }
  892. 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) {
  893. db := readDb.Model(&models.HisOrder{})
  894. 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)
  895. if len(clr_org) > 0 {
  896. db = db.Where("clr_optins = ?", clr_org)
  897. }
  898. if len(clr_type) > 0 {
  899. if mdtrtareaAdmvs == "150499" {
  900. if clr_type == "11" {
  901. db = db.Where("clr_type = ?", clr_type)
  902. }
  903. } else {
  904. db = db.Where("clr_type = ?", clr_type)
  905. }
  906. }
  907. err = db.Find(&orders).Error
  908. return
  909. }
  910. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  911. db := readDb.Model(&models.HisOrder{})
  912. 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)
  913. err = db.Find(&orders).Error
  914. return
  915. }
  916. func GetOrderByTime11222(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  917. db := readDb.Model(&models.HisOrder{})
  918. 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)
  919. err = db.Find(&orders).Error
  920. return
  921. }
  922. func GetOrderByTimeFourfor11(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  923. db := readDb.Model(&models.HisOrder{})
  924. 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)
  925. err = db.Find(&orders).Error
  926. return
  927. }
  928. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  929. 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
  930. return
  931. }
  932. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  933. 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
  934. return
  935. }
  936. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  937. var patient models.Patients
  938. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  939. if err != nil {
  940. if err == gorm.ErrRecordNotFound {
  941. return nil, nil
  942. } else {
  943. return nil, err
  944. }
  945. }
  946. return &patient, nil
  947. }
  948. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  949. dealer := models.HisXtDiagnoseConfig{}
  950. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  951. return dealer, err
  952. }
  953. func FindDiagnoseByIdtwo(id string) (models.HisXtDiagnoseConfig, error) {
  954. dealer := models.HisXtDiagnoseConfig{}
  955. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  956. return dealer, err
  957. }
  958. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  959. dealer := []*models.HisXtDiagnoseConfig{}
  960. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  961. return dealer, err
  962. }
  963. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  964. outPatient := &models.OutpatientServiceSick{}
  965. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  966. return outPatient, err
  967. }
  968. //
  969. //type MonthHisPrescription struct {
  970. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  971. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  972. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  973. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  974. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  975. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  976. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  977. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  978. // Number string `gorm:"column:number" json:"number" form:"number"`
  979. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  980. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  981. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  982. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  983. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  984. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  985. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  986. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  987. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  988. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  989. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  990. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  991. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  992. //}
  993. //
  994. //func (MonthHisPrescription) TableName() string {
  995. // return "his_prescription"
  996. //}
  997. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  998. err = readDb.Model(&models.HisPrescription{}).
  999. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1000. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1001. }).
  1002. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1003. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1004. }).
  1005. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1006. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1007. }).
  1008. 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).
  1009. Find(&prescription).Error
  1010. return
  1011. }
  1012. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  1013. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  1014. return
  1015. }
  1016. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1017. 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
  1018. return
  1019. }
  1020. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1021. 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
  1022. return
  1023. }
  1024. func GetAppRole(orgID int64) (models.App_Role, error) {
  1025. var appRole models.App_Role
  1026. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  1027. return appRole, err
  1028. }
  1029. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1030. var patient Patients
  1031. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1032. return patient, err
  1033. }
  1034. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  1035. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1036. table := XTReadDB().Table("xt_manufacturer as m")
  1037. fmt.Print(table)
  1038. if orgID > 0 {
  1039. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  1040. }
  1041. 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
  1042. return drug, err
  1043. }
  1044. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  1045. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  1046. return dataconfig, err
  1047. }
  1048. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1049. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  1050. //return role, err
  1051. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1052. table := UserReadDB().Table("sgj_user_admin as a")
  1053. fmt.Println(table)
  1054. 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
  1055. return role, err
  1056. }
  1057. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1058. err = readDb.Model(&models.HisPrescription{}).
  1059. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1060. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1061. }).
  1062. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1063. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1064. }).
  1065. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1066. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1067. }).
  1068. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1069. Find(&prescription).Error
  1070. return
  1071. }
  1072. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1073. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1074. //table := UserReadDB().Table("sgj_user_admin as a")
  1075. //fmt.Println(table)
  1076. 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
  1077. return role, err
  1078. }
  1079. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1080. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1081. return role, err
  1082. }
  1083. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1084. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1085. table := XTReadDB().Table("xt_manufacturer as m")
  1086. fmt.Print(table)
  1087. if orgID > 0 {
  1088. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1089. }
  1090. 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
  1091. return drug, err
  1092. }
  1093. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1094. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1095. table := XTReadDB().Table("xt_manufacturer as m")
  1096. fmt.Println(table)
  1097. if orgid > 0 {
  1098. db = db.Where("x.org_id = ?", orgid)
  1099. }
  1100. 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
  1101. return good, err
  1102. }
  1103. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1104. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1105. table := XTReadDB().Table("xt_manufacturer as m")
  1106. fmt.Println(table)
  1107. if orgid > 0 {
  1108. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1109. }
  1110. 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
  1111. return good, err
  1112. }
  1113. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1114. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1115. table := UserReadDB().Table("sgj_user_admin as a")
  1116. fmt.Println(table)
  1117. if id > 0 {
  1118. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1119. }
  1120. 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
  1121. return role, err
  1122. }
  1123. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1124. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1125. return project, err
  1126. }
  1127. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1128. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1129. return project, err
  1130. }
  1131. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1132. db := XTReadDB().Table("xt_his_project")
  1133. if len(idss) == 1 {
  1134. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1135. } else {
  1136. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1137. }
  1138. return project, err
  1139. }
  1140. func GetBathchMyPorjecgListtwo(org_id int64) (project []*models.MyHisProject, err error) {
  1141. db := XTReadDB().Table("xt_his_project")
  1142. err = db.Where("status = 1 and user_org_id = ?", org_id).Find(&project).Error
  1143. return project, err
  1144. }
  1145. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1146. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1147. table := UserReadDB().Table("sgj_user_admin as a")
  1148. fmt.Println(table)
  1149. if len(idss) == 1 {
  1150. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1151. } else {
  1152. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1153. }
  1154. 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
  1155. return role, err
  1156. }
  1157. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1158. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1159. return
  1160. }
  1161. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1162. 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})
  1163. 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})
  1164. return
  1165. }
  1166. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1167. 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})
  1168. 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})
  1169. return
  1170. }
  1171. func UpdateHisPrescriptionHisID1111(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1172. //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})
  1173. //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})
  1174. return
  1175. }
  1176. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1177. 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
  1178. return
  1179. }
  1180. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1181. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1182. return
  1183. }
  1184. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1185. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1186. return
  1187. }
  1188. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1189. err = writeDb.Create(&result).Error
  1190. return
  1191. }
  1192. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1193. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1194. return
  1195. }
  1196. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1197. err = writeDb.Save(&result).Error
  1198. return
  1199. }
  1200. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1201. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1202. return
  1203. }
  1204. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1205. writeDb.Save(&his)
  1206. }
  1207. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1208. 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
  1209. return
  1210. }
  1211. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1212. 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
  1213. return
  1214. }
  1215. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1216. 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
  1217. return
  1218. }
  1219. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1220. 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).
  1221. Order("ctime desc").
  1222. Find(&order).Error
  1223. return
  1224. }
  1225. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1226. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1227. return
  1228. }
  1229. func UpdateHisPatientThree(his *models.HisPatient) {
  1230. writeDb.Save(&his)
  1231. }
  1232. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1233. err = readDb.Model(&models.HisPrescription{}).
  1234. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1235. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1236. }).
  1237. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1238. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1239. }).
  1240. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1241. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1242. }).
  1243. 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).
  1244. Find(&prescription).Error
  1245. return
  1246. }
  1247. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1248. err = readDb.Model(&models.HisPrescription{}).
  1249. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1250. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1251. }).
  1252. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1253. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1254. }).
  1255. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1256. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1257. }).
  1258. 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).
  1259. Find(&prescription).Error
  1260. return
  1261. }
  1262. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1263. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1264. return
  1265. }
  1266. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1267. 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
  1268. return
  1269. }
  1270. func GetLastFundList(org_id int64) (order models.HisFundSettleListResult, err error) {
  1271. err = readDb.Model(&models.HisFundSettleListResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Last(&order).Error
  1272. return
  1273. }
  1274. func GetOrderError(org_id int64) (order []*models.HisOrderError, err error) {
  1275. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 10106 ", org_id).Find(&order).Error
  1276. return
  1277. }
  1278. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1279. 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
  1280. return
  1281. }
  1282. func CreateHisPsn(psn *models.HisPsn) {
  1283. writeDb.Save(&psn)
  1284. }
  1285. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1286. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1287. return
  1288. }
  1289. func GetPsnByPatientIdtWO(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1290. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ?", patient_id, record_date).Last(&psn).Error
  1291. return
  1292. }
  1293. //func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1294. // err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1295. // return
  1296. //}
  1297. func GetPsnByPatientIdTwo(patient_id int64) (psn models.HisPsn, err error) {
  1298. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1299. return
  1300. }
  1301. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1302. 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
  1303. fmt.Println(err)
  1304. return
  1305. }
  1306. func GetAllHisOrderTwo(org_id int64) (his []*models.HisOrder, err error) {
  1307. 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
  1308. fmt.Println(err)
  1309. return
  1310. }
  1311. func GetAllHisOrder10106(org_id int64) (his []*models.HisOrder, err error) {
  1312. 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
  1313. fmt.Println(err)
  1314. return
  1315. }
  1316. func GetAllHisOrder10138() (his []*models.HisOrder, err error) {
  1317. 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 setl_time <= '2024-04-30 23:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1318. fmt.Println(err)
  1319. return
  1320. }
  1321. func GetOrderError10138() (order []*models.HisOrderError, err error) {
  1322. err = readDb.Model(&models.HisOrderError{}).Where("status = 1 AND stage = 10138500").Find(&order).Error
  1323. return
  1324. }
  1325. func GetAllHisOrder10278() (his []*models.HisOrder, err error) {
  1326. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10278 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-01-01 00:00:00' AND setl_time <= '2024-03-31 23:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1327. fmt.Println(err)
  1328. return
  1329. }
  1330. func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1331. 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
  1332. fmt.Println(err)
  1333. return
  1334. }
  1335. // func GetAllHisOrder2(org_id int64) (his []models.HisOrder, err error) {
  1336. // err = readDb.Model(&models.HisOrder{}).Where("id = 180753").Order("setl_time asc").First(&his).Error
  1337. // return
  1338. // }
  1339. func GetAllHisOrderErr10278() (his []*models.HisOrderError, err error) {
  1340. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = 10278 AND status = 1 AND stage = 10276").Find(&his).Error
  1341. return
  1342. }
  1343. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1344. db := readDb.Model(&models.HisOrderInfo{})
  1345. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1346. return
  1347. }
  1348. func UpdataOrderStatusByNumber(number string) (err error) {
  1349. 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
  1350. return
  1351. }
  1352. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1353. 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
  1354. 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
  1355. 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
  1356. return
  1357. }
  1358. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1359. db := readDb.Model(&models.HisFundSettleListResult{})
  1360. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1361. return
  1362. }
  1363. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1364. writeDb.Save(&record)
  1365. }
  1366. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1367. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1368. return
  1369. }
  1370. func UpdateOrder(order models.HisOrder) (err error) {
  1371. err = writeDb.Save(&order).Error
  1372. return
  1373. }
  1374. func UpdateOrderTwo(order models.NewHisOrder111) (err error) {
  1375. err = writeDb.Save(&order).Error
  1376. return
  1377. }
  1378. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1379. err = readDb.Model(&models.HisPrescriptionTen{}).
  1380. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1381. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1382. }).
  1383. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1384. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1385. }).
  1386. 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).
  1387. Find(&prescription).Error
  1388. return
  1389. }
  1390. func GetHisOrderByIDTwo1111(order_id int64) (order models.NewHisOrder111, err error) {
  1391. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1392. return
  1393. }
  1394. func GetHisPrescriptionForMedType(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1395. err = readDb.Model(&models.HisPrescription{}).
  1396. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1397. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1398. }).
  1399. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1400. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1401. }).
  1402. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1403. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1404. }).
  1405. 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).
  1406. Find(&prescription).Error
  1407. return
  1408. }
  1409. func GetOrderByTimeTen(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1410. 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
  1411. return
  1412. }
  1413. func GetOrderByTimeTentwo(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1414. 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
  1415. return
  1416. }
  1417. func GetOrderDetailByTimeTen(start_time string, end_time string, org_id int64, fund_key string) (fund []models.FundDetail, err error) {
  1418. 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
  1419. return
  1420. }
  1421. func Saveflow(flow models.HisPrescriptionFlow) {
  1422. writeDb.Save(&flow)
  1423. }
  1424. func Createflow(flow *models.HisPrescriptionFlow) {
  1425. writeDb.Create(&flow)
  1426. }
  1427. func GetNewHisPrescriptionTenone(org_id int64, number string) (prescription []*models.HisPrescriptionTen, err error) {
  1428. err = readDb.Model(&models.HisPrescriptionTen{}).
  1429. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1430. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1431. }).
  1432. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1433. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1434. }).
  1435. Where("user_org_id = ? AND status = 1 AND batch_number = ? and order_status = 4 ", org_id, number).
  1436. Find(&prescription).Error
  1437. return
  1438. }
  1439. func GetHisOrderByIDThree(start_time string) (his []*models.HisOrder, err error) {
  1440. 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
  1441. fmt.Println(err)
  1442. return
  1443. }
  1444. func UpDatePrescriptionNumber111(user_org_id int64, start_time int64, end_time int64, number string, patient_id int64) (err error) {
  1445. 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
  1446. return
  1447. }
  1448. func UpDatePrescriptionNumber222(user_org_id int64, id int64, number string, patient_id int64) (err error) {
  1449. 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
  1450. return
  1451. }
  1452. func GetAllHisOrderTwo10485() (his []*models.HisOrder, err error) {
  1453. 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
  1454. fmt.Println(err)
  1455. return
  1456. }
  1457. func GetNewDrugWarehouseInfo(id_arr []string) (newDrugWarehouse []*models.NewDrugWarehouseInfo, err error) {
  1458. readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and id in (?) ", 10191, id_arr).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", 10191).Preload("Dealers", "status = 1 AND org_id = ?", 10191).Find(&newDrugWarehouse)
  1459. return
  1460. }
  1461. func GetNewDrugFlowInfo(id_arr []string) (flows []*models.DrugFlow, err error) {
  1462. err = readDb.Model(&models.DrugFlow{}).Where("org_id = ? and status = 1 and id in (?)", 10191, id_arr).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1463. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1464. }).Find(&flows).Error
  1465. return
  1466. }
  1467. func GetHisPrescriptionByID(id int64) (pre models.HisPrescription) {
  1468. err = readDb.Model(&models.HisPrescription{}).Where("id = ? and status = 1", id).Find(&pre).Error
  1469. return
  1470. }
  1471. func GetHisOrderByNumber(number string) (order models.HisOrder) {
  1472. err = readDb.Model(&models.HisOrder{}).Where("number = ? and status = 1", number).First(&order).Error
  1473. return
  1474. }