package new_mobile_api_controllers

import (
	"Xcx_New/controllers/mobile_api_controllers"
	"Xcx_New/enums"
	"Xcx_New/service"
	"fmt"
)

type NewDrugApiController struct {
	mobile_api_controllers.MobileBaseAPIAuthController
}

func (this *NewDrugApiController) GetSelfMedicalList() {

	patient_id, _ := this.GetInt64("patient_id")
	fmt.Println("222222222", patient_id)
	adminUserInfo := this.GetMobileAdminUserInfo()
	orgId := adminUserInfo.Org.Id
	medical, _ := service.GetSetSelfMedical(orgId)
	//开启
	if medical.DrugStart == 1 {
		list, err := service.GetSelfMedicalList(patient_id)
		if err != nil {
			this.ServeFailJsonSend(enums.ErrorCodeDataException, "获取自备药失败")
			return
		}
		this.ServeSuccessJSON(map[string]interface{}{
			"medicalList": list,
		})
	}
}

func (this *NewDrugApiController) GetDrugDescByDrugName() {

	drug_name := this.GetString("drug_name")
	fmt.Println("drug_name", drug_name)
	patient_id, _ := this.GetInt64("patient_id")
	fmt.Println("patient_id", patient_id)
	adminUserInfo := this.GetMobileAdminUserInfo()
	orgId := adminUserInfo.Org.Id
	drugspec, err := service.GetDrugDescByDrugName(drug_name, patient_id, orgId)
	if err != nil {
		this.ServeFailJsonSend(enums.ErrorCodeDataException, "更新设备失败")
		return
	}
	this.ServeSuccessJSON(map[string]interface{}{
		"drugspec": drugspec,
	})
}
