123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "fmt"
- "github.com/astaxie/beego"
- "os"
- "strings"
- "time"
- )
-
- const (
- key = "4a6617a4409c48dc836152e80e18febd"
- )
-
- type HisPrintApiController struct {
- BaseAuthAPIController
- }
-
- func HisPrintApiRegistRouters() {
- beego.Router("/api/his/prescription/print", &HisPrintApiController{}, "get:GetBatchHisPrescriptionData")
- beego.Router("/api/his/prescription/list", &HisPrintApiController{}, "get:GetUnChargePrescriptionList")
- beego.Router("/api/his/prescription/summary", &HisPrintApiController{}, "get:GetUnChargePrescriptionSummary")
- beego.Router("/api/his/label/create", &HisPrintApiController{}, "get:CreateLablePrint")
- beego.Router("/api/his/label/get", &HisPrintApiController{}, "get:GetLablePrint")
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- func (c *HisPrintApiController) GetLablePrint() {
- patient_id, _ := c.GetInt64("patient_id")
- ids := c.GetString("ids")
- record_date := c.GetString("record_date")
- labels, _ := service.GetLabelPrint(ids, c.GetAdminUserInfo().CurrentOrgId, record_date, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "labels": labels,
- })
- return
- }
-
- func (c *HisPrintApiController) CreateLablePrint() {
- patient_id, _ := c.GetInt64("patient_id")
- isCombinationPrint, _ := c.GetBool("is_combination_print")
- team_ids := c.GetString("team_ids")
- ids := c.GetString("ids")
- record_date := c.GetString("record_date")
- doctor_id, _ := c.GetInt64("doctor_id")
- project_ids := c.GetString("project_ids")
- is_team, _ := c.GetInt64("is_team")
-
- var hlpsi models.HisLabelPrintStatusInfo
- hlpsi.Status = 1
- hlpsi.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
- hlpsi.PatientId = patient_id
- hlpsi.RecordDate = record_date
- hlpsi.Mtime = time.Now().Unix()
- hlpsi.Ctime = time.Now().Unix()
- hlpsi.ItemIds = team_ids
- hlpsi.ProjectIds = project_ids
- hlpsi.Ids = ids
- hlpsi.DoctorId = doctor_id
- hlpsi.IsTeam = is_team
- hlpsi.IsPrint = 1
- if isCombinationPrint == true {
- hlpsi.IsCombinationPrint = 1
- } else {
- hlpsi.IsCombinationPrint = 0
- }
- service.CreateLabelPrint(&hlpsi)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "保存成功",
- "hlpsi": hlpsi,
- })
- return
- }
-
- func (c *HisPrintApiController) GetUnChargePrescriptionList() {
- patient_id, _ := c.GetInt64("patient_id")
- recordDateTime, _ := c.GetInt64("record_date")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- p_type, _ := c.GetInt64("p_type", 0)
- admin := c.GetAdminUserInfo()
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
- record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
- var prescriptions []*models.HisPrescription
- prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
- admin_info, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "record": record,
- "admin_info": admin_info,
- })
- return
- }
- func (c *HisPrintApiController) GetUnChargePrescriptionSummary() {
- patient_id, _ := c.GetInt64("patient_id")
- record_date, _ := c.GetInt64("record_date")
- admin_user_id, _ := c.GetInt64("admin_user_id")
- p_type, _ := c.GetInt64("p_type", 0)
-
-
-
-
-
-
-
-
- admin := c.GetAdminUserInfo()
- xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
- record, _ := service.GetLastInHospitalRecord(patient_id, c.GetAdminUserInfo().CurrentOrgId)
- var prescriptions []*models.HisPrescription
- prescriptions, _ = service.GetUnChargeHisPrescriptionTen(admin.CurrentOrgId, patient_id, record_date, p_type)
-
- service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "xt_info": xt_patient_info,
- "prescription": prescriptions,
- "record": record,
- "admin_info": admin_user_id,
- })
- return
- }
- func (c *HisPrintApiController) GetBatchHisPrescriptionData() {
- record_date := c.GetString("record_date")
- patient_ids := c.GetString("patient_ids")
- print_type, _ := c.GetInt64("type")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordDateTime := theTime.Unix()
- adminInfo := c.GetAdminUserInfo()
- ids := strings.Split(patient_ids, ",")
- switch print_type {
- case 1:
- patients, _ := service.GetBatchDrugHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- break
- case 2:
-
-
- patients, _ := service.GetBatchProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
-
-
-
-
-
-
-
-
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- })
- break
- case 3:
- var newPatients []*models.PrintPatient
- var newPatientsTwo []*models.PrintPatient
-
- patients, _ := service.GetBatchInspectionProjectHisPrescription(ids, recordDateTime, adminInfo.CurrentOrgId)
- for _, item := range patients {
- var newPatient *models.PrintPatient
- newPatient = item
- for index, subItem := range item.HisPrintPrescription {
- if index > 0 {
- item.HisPrintPrescription[0].HisPrescriptionProject = append(item.HisPrintPrescription[0].HisPrescriptionProject, subItem.HisPrescriptionProject...)
- }
- }
- newPatients = append(newPatients, newPatient)
- }
-
- for _, item := range patients {
- var newPatient *models.PrintPatient
- newPatient = item
- if len(item.HisPrintPrescription) > 0 {
- newPatient.NewHisPrintPrescription = append(newPatient.NewHisPrintPrescription, item.HisPrintPrescription[0])
- newPatientsTwo = append(newPatientsTwo, newPatient)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": newPatientsTwo,
- })
- break
- }
- }
-
- func GetAge(idCard string) (int, error) {
- birthDate, err := getBirthDateFromIDCard(idCard)
- if err != nil {
- return 0, err
- }
-
- age := calculateAge(birthDate)
- return age, nil
- }
-
- func getBirthDateFromIDCard(idCard string) (time.Time, error) {
- birthDateStr := idCard[6:14]
- birthDate, err := time.Parse("20060102", birthDateStr)
- if err != nil {
- return time.Time{}, err
- }
-
- return birthDate, nil
- }
-
- func calculateAge(birthDate time.Time) int {
- now := time.Now()
- age := now.Year() - birthDate.Year()
-
-
- if now.Month() < birthDate.Month() || (now.Month() == birthDate.Month() && now.Day() < birthDate.Day()) {
- age--
- }
-
- return age
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- func SaveErrorLog(result string, request string, infno string, desc string) {
-
-
- dir := "faild"
- utils.Mkdir(dir)
- month := time.Unix(1557042972, 0).Format("1")
- year := time.Now().Format("2006")
- month = time.Now().Format("01")
- day := time.Now().Format("02")
- hour := time.Now().Format("15")
- min := time.Now().Format("04")
- sec := time.Now().Format("05")
-
- result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
-
- file := "failed" + "_" + year + month + day + "_log"
- file_name := file + ".txt"
- file_path := "faild" + "/" + file_name
- exist, _ := utils.PathExists(file_path)
- if exist {
- fmt.Println("存在")
- f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
- if err != nil {
- fmt.Println("read fail")
- }
- content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
- n, _ := f.Seek(0, 2)
- _, err = f.WriteAt([]byte(content), n)
-
- } else {
- fmt.Println("文件不存在,创建文件")
- f, err := os.Create("faild" + "/" + file_name)
- defer f.Close()
- if err != nil {
- } else {
- _, err = f.Write([]byte("记录日志"))
- }
- }
-
- }
- func saveSuccessLog(result string, request string, infno string, desc string) {
-
-
-
-
-
- month := time.Unix(1557042972, 0).Format("1")
- year := time.Now().Format("2006")
- month = time.Now().Format("01")
- day := time.Now().Format("02")
- hour := time.Now().Format("15")
- min := time.Now().Format("04")
- sec := time.Now().Format("05")
-
- result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
-
- file := "success" + "_" + year + month + day + "_log"
- file_name := file + ".txt"
- file_path := file_name
- exist, _ := utils.PathExists(file_path)
- if exist {
- fmt.Println("存在")
- f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
- if err != nil {
- fmt.Println("read fail")
- }
- content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
- n, _ := f.Seek(0, 2)
- _, err = f.WriteAt([]byte(content), n)
-
- } else {
- fmt.Println("文件不存在,创建文件")
- f, err := os.Create(file_name)
- defer f.Close()
- if err != nil {
- } else {
- _, err = f.Write([]byte("记录日志"))
- }
- }
-
- }
|