feat(health): 新增用药计划模块

- 新增用药计划(HealthMedicationPlan)和用药记录(HealthMedicationRecord)实体
- 包含完整的Controller/Service/Mapper层代码
- 支持用药计划的增删改查、暂停/恢复/结束操作
- 支持用药记录的服药/跳过操作
- 新增SQL建表脚本、字典数据和菜单权限
This commit is contained in:
bot5
2026-03-18 14:10:32 +08:00
parent eaa823a8b7
commit 77e503c460
17 changed files with 2161 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
package com.intc.health.controller;
import com.intc.common.core.utils.poi.ExcelUtil;
import com.intc.common.core.web.controller.BaseController;
import com.intc.common.core.web.domain.AjaxResult;
import com.intc.common.core.web.page.TableDataInfo;
import com.intc.common.log.annotation.Log;
import com.intc.common.log.enums.BusinessType;
import com.intc.common.security.annotation.RequiresPermissions;
import com.intc.health.domain.HealthMedicationPlan;
import com.intc.health.domain.dto.HealthMedicationPlanDto;
import com.intc.health.domain.vo.HealthMedicationPlanVo;
import com.intc.health.service.IHealthMedicationPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 用药计划Controller
*
* @author intc
* @date 2025-03-18
*/
@Api(tags = "用药计划")
@RestController
@RequestMapping("/medicationPlan")
public class HealthMedicationPlanController extends BaseController
{
@Resource
private IHealthMedicationPlanService healthMedicationPlanService;
/**
* 查询用药计划列表
*/
@ApiOperation(value = "查询用药计划列表", response = HealthMedicationPlanVo.class)
@RequiresPermissions("health:medicationPlan:list")
@GetMapping("/list")
public TableDataInfo list(HealthMedicationPlanDto dto)
{
startPage();
List<HealthMedicationPlanVo> list = healthMedicationPlanService.selectHealthMedicationPlanList(dto);
return getDataTable(list);
}
/**
* 导出用药计划列表
*/
@ApiOperation(value = "导出用药计划列表")
@RequiresPermissions("health:medicationPlan:export")
@Log(title = "用药计划", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, HealthMedicationPlanDto dto)
{
List<HealthMedicationPlanVo> list = healthMedicationPlanService.selectHealthMedicationPlanList(dto);
ExcelUtil<HealthMedicationPlanVo> util = new ExcelUtil<HealthMedicationPlanVo>(HealthMedicationPlanVo.class);
util.exportExcel(response, list, "用药计划数据");
}
/**
* 获取用药计划详细信息
*/
@ApiOperation(value = "获取用药计划详细信息")
@RequiresPermissions("health:medicationPlan:query")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(healthMedicationPlanService.selectHealthMedicationPlanById(id));
}
/**
* 新增用药计划
*/
@ApiOperation(value = "新增用药计划")
@RequiresPermissions("health:medicationPlan:add")
@Log(title = "用药计划", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody HealthMedicationPlan plan)
{
return toAjax(healthMedicationPlanService.insertHealthMedicationPlan(plan));
}
/**
* 修改用药计划
*/
@ApiOperation(value = "修改用药计划")
@RequiresPermissions("health:medicationPlan:edit")
@Log(title = "用药计划", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody HealthMedicationPlan plan)
{
return toAjax(healthMedicationPlanService.updateHealthMedicationPlan(plan));
}
/**
* 删除用药计划
*/
@ApiOperation(value = "删除用药计划")
@RequiresPermissions("health:medicationPlan:remove")
@Log(title = "用药计划", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(healthMedicationPlanService.deleteHealthMedicationPlanByIds(ids));
}
/**
* 暂停用药计划
*/
@ApiOperation(value = "暂停用药计划")
@RequiresPermissions("health:medicationPlan:edit")
@Log(title = "用药计划", businessType = BusinessType.UPDATE)
@PutMapping("/pause/{id}")
public AjaxResult pause(@PathVariable Long id)
{
return toAjax(healthMedicationPlanService.pauseHealthMedicationPlan(id));
}
/**
* 恢复用药计划
*/
@ApiOperation(value = "恢复用药计划")
@RequiresPermissions("health:medicationPlan:edit")
@Log(title = "用药计划", businessType = BusinessType.UPDATE)
@PutMapping("/resume/{id}")
public AjaxResult resume(@PathVariable Long id)
{
return toAjax(healthMedicationPlanService.resumeHealthMedicationPlan(id));
}
/**
* 结束用药计划
*/
@ApiOperation(value = "结束用药计划")
@RequiresPermissions("health:medicationPlan:edit")
@Log(title = "用药计划", businessType = BusinessType.UPDATE)
@PutMapping("/end/{id}")
public AjaxResult end(@PathVariable Long id)
{
return toAjax(healthMedicationPlanService.endHealthMedicationPlan(id));
}
}

View File

@@ -0,0 +1,160 @@
package com.intc.health.controller;
import com.intc.common.core.utils.poi.ExcelUtil;
import com.intc.common.core.web.controller.BaseController;
import com.intc.common.core.web.domain.AjaxResult;
import com.intc.common.core.web.page.TableDataInfo;
import com.intc.common.log.annotation.Log;
import com.intc.common.log.enums.BusinessType;
import com.intc.common.security.annotation.RequiresPermissions;
import com.intc.health.domain.HealthMedicationRecord;
import com.intc.health.domain.dto.HealthMedicationRecordDto;
import com.intc.health.domain.vo.HealthMedicationRecordVo;
import com.intc.health.service.IHealthMedicationRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 用药记录Controller
*
* @author intc
* @date 2025-03-18
*/
@Api(tags = "用药记录")
@RestController
@RequestMapping("/medicationRecord")
public class HealthMedicationRecordController extends BaseController
{
@Resource
private IHealthMedicationRecordService healthMedicationRecordService;
/**
* 查询用药记录列表
*/
@ApiOperation(value = "查询用药记录列表", response = HealthMedicationRecordVo.class)
@RequiresPermissions("health:medicationRecord:list")
@GetMapping("/list")
public TableDataInfo list(HealthMedicationRecordDto dto)
{
startPage();
List<HealthMedicationRecordVo> list = healthMedicationRecordService.selectHealthMedicationRecordList(dto);
return getDataTable(list);
}
/**
* 查询今日用药记录
*/
@ApiOperation(value = "查询今日用药记录")
@RequiresPermissions("health:medicationRecord:list")
@GetMapping("/today")
public AjaxResult today(@RequestParam(required = false) Long personId)
{
List<HealthMedicationRecordVo> list = healthMedicationRecordService.getTodayRecords(personId);
return success(list);
}
/**
* 查询某计划某天的用药记录
*/
@ApiOperation(value = "查询某计划某天的用药记录")
@RequiresPermissions("health:medicationRecord:list")
@GetMapping("/plan/{planId}/date/{date}")
public AjaxResult getByPlanAndDate(@PathVariable Long planId, @PathVariable String date)
{
List<HealthMedicationRecordVo> list = healthMedicationRecordService.selectRecordByPlanAndDate(planId, date);
return success(list);
}
/**
* 导出用药记录列表
*/
@ApiOperation(value = "导出用药记录列表")
@RequiresPermissions("health:medicationRecord:export")
@Log(title = "用药记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, HealthMedicationRecordDto dto)
{
List<HealthMedicationRecordVo> list = healthMedicationRecordService.selectHealthMedicationRecordList(dto);
ExcelUtil<HealthMedicationRecordVo> util = new ExcelUtil<HealthMedicationRecordVo>(HealthMedicationRecordVo.class);
util.exportExcel(response, list, "用药记录数据");
}
/**
* 获取用药记录详细信息
*/
@ApiOperation(value = "获取用药记录详细信息")
@RequiresPermissions("health:medicationRecord:query")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(healthMedicationRecordService.selectHealthMedicationRecordById(id));
}
/**
* 新增用药记录(手动记录补服)
*/
@ApiOperation(value = "新增用药记录")
@RequiresPermissions("health:medicationRecord:add")
@Log(title = "用药记录", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody HealthMedicationRecord record)
{
return toAjax(healthMedicationRecordService.insertHealthMedicationRecord(record));
}
/**
* 修改用药记录
*/
@ApiOperation(value = "修改用药记录")
@RequiresPermissions("health:medicationRecord:edit")
@Log(title = "用药记录", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody HealthMedicationRecord record)
{
return toAjax(healthMedicationRecordService.updateHealthMedicationRecord(record));
}
/**
* 删除用药记录
*/
@ApiOperation(value = "删除用药记录")
@RequiresPermissions("health:medicationRecord:remove")
@Log(title = "用药记录", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(healthMedicationRecordService.deleteHealthMedicationRecordByIds(ids));
}
/**
* 服药(标记为已服用)
*/
@ApiOperation(value = "服药(标记为已服用)")
@RequiresPermissions("health:medicationRecord:edit")
@Log(title = "用药记录", businessType = BusinessType.UPDATE)
@PutMapping("/take/{id}")
public AjaxResult take(@PathVariable Long id,
@RequestParam(required = false) Double dosage,
@RequestParam(required = false) String remark)
{
return toAjax(healthMedicationRecordService.takeMedication(id, dosage, remark));
}
/**
* 跳过服药
*/
@ApiOperation(value = "跳过服药")
@RequiresPermissions("health:medicationRecord:edit")
@Log(title = "用药记录", businessType = BusinessType.UPDATE)
@PutMapping("/skip/{id}")
public AjaxResult skip(@PathVariable Long id,
@RequestParam(required = false) String remark)
{
return toAjax(healthMedicationRecordService.skipMedication(id, remark));
}
}

View File

@@ -0,0 +1,139 @@
package com.intc.health.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.intc.common.core.annotation.Excel;
import com.intc.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* 用药计划对象 health_medication_plan
*
* @author intc
* @date 2025-03-18
*/
@ApiModel("用药计划对象")
@Data
public class HealthMedicationPlan extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 人员ID */
@ApiModelProperty(value="人员ID")
@NotNull(message="人员ID不能为空")
@Excel(name = "人员ID")
private Long personId;
/** 药品ID */
@ApiModelProperty(value="药品ID")
@NotNull(message="药品ID不能为空")
@Excel(name = "药品ID")
private Long medicineId;
/** 入库ID用于扣减库存 */
@ApiModelProperty(value="入库ID")
private Long stockInId;
/** 计划名称 */
@ApiModelProperty(value="计划名称")
@Excel(name = "计划名称")
private String planName;
/** 每次剂量 */
@ApiModelProperty(value="每次剂量")
@NotNull(message="剂量不能为空")
@Excel(name = "每次剂量")
private Double dosage;
/** 剂量单位 */
@ApiModelProperty(value="剂量单位")
@Excel(name = "剂量单位")
private String dosageUnit;
/** 服药频率(每日次数) */
@ApiModelProperty(value="服药频率")
@NotNull(message="服药频率不能为空")
@Excel(name = "服药频率")
private Integer frequency;
/** 频率类型1-每日 2-隔日 3-每周 4-自定义) */
@ApiModelProperty(value="频率类型")
@Excel(name = "频率类型", readConverterExp = "1=每日,2=隔日,3=每周,4=自定义")
private String frequencyType;
/** 服药时间点JSON格式 */
@ApiModelProperty(value="服药时间点")
private String timePoints;
/** 周几服药频率类型为每周时使用JSON格式如[1,3,5]表示周一三五) */
@ApiModelProperty(value="周几服药")
private String weekDays;
/** 开始日期 */
@ApiModelProperty(value="开始日期")
@NotNull(message="开始日期不能为空")
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "开始日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date startDate;
/** 结束日期 */
@ApiModelProperty(value="结束日期")
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "结束日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date endDate;
/** 是否启用提醒0-否 1-是) */
@ApiModelProperty(value="是否启用提醒")
@Excel(name = "是否启用提醒", readConverterExp = "0=否,1=是")
private String reminderEnabled;
/** 提前提醒时间(分钟) */
@ApiModelProperty(value="提前提醒时间")
@Excel(name = "提前提醒时间(分钟)")
private Integer reminderMinutes;
/** 状态1-进行中 2-已结束 3-已暂停) */
@ApiModelProperty(value="状态")
@Excel(name = "状态", readConverterExp = "1=进行中,2=已结束,3=已暂停")
private String status;
/** 删除标志0代表存在 1代表删除 */
private String delFlag;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("personId", getPersonId())
.append("medicineId", getMedicineId())
.append("stockInId", getStockInId())
.append("planName", getPlanName())
.append("dosage", getDosage())
.append("dosageUnit", getDosageUnit())
.append("frequency", getFrequency())
.append("frequencyType", getFrequencyType())
.append("timePoints", getTimePoints())
.append("weekDays", getWeekDays())
.append("startDate", getStartDate())
.append("endDate", getEndDate())
.append("reminderEnabled", getReminderEnabled())
.append("reminderMinutes", getReminderMinutes())
.append("status", getStatus())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("delFlag", getDelFlag())
.append("remark", getRemark())
.toString();
}
}

View File

@@ -0,0 +1,99 @@
package com.intc.health.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.intc.common.core.annotation.Excel;
import com.intc.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* 用药记录对象 health_medication_record
*
* @author intc
* @date 2025-03-18
*/
@ApiModel("用药记录对象")
@Data
public class HealthMedicationRecord extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 计划ID */
@ApiModelProperty(value="计划ID")
@NotNull(message="计划ID不能为空")
@Excel(name = "计划ID")
private Long planId;
/** 人员ID */
@ApiModelProperty(value="人员ID")
@NotNull(message="人员ID不能为空")
@Excel(name = "人员ID")
private Long personId;
/** 药品ID */
@ApiModelProperty(value="药品ID")
@NotNull(message="药品ID不能为空")
@Excel(name = "药品ID")
private Long medicineId;
/** 计划服药时间 */
@ApiModelProperty(value="计划服药时间")
@NotNull(message="计划服药时间不能为空")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "计划服药时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date scheduledTime;
/** 实际服药时间 */
@ApiModelProperty(value="实际服药时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "实际服药时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date actualTime;
/** 服用剂量 */
@ApiModelProperty(value="服用剂量")
@Excel(name = "服用剂量")
private Double dosage;
/** 剂量单位 */
@ApiModelProperty(value="剂量单位")
@Excel(name = "剂量单位")
private String dosageUnit;
/** 状态1-待服用 2-已服用 3-已跳过 4-已过期) */
@ApiModelProperty(value="状态")
@Excel(name = "状态", readConverterExp = "1=待服用,2=已服用,3=已跳过,4=已过期")
private String status;
/** 删除标志0代表存在 1代表删除 */
private String delFlag;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("planId", getPlanId())
.append("personId", getPersonId())
.append("medicineId", getMedicineId())
.append("scheduledTime", getScheduledTime())
.append("actualTime", getActualTime())
.append("dosage", getDosage())
.append("dosageUnit", getDosageUnit())
.append("status", getStatus())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("delFlag", getDelFlag())
.append("remark", getRemark())
.toString();
}
}

View File

@@ -0,0 +1,69 @@
package com.intc.health.domain.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 用药计划DTO对象 health_medication_plan
*
* @author intc
* @date 2025-03-18
*/
@ApiModel("用药计划DTO对象")
@Data
public class HealthMedicationPlanDto
{
/** 主键 */
private Long id;
/** 人员ID */
@ApiModelProperty(value="人员ID")
private Long personId;
/** 人员姓名(模糊查询) */
@ApiModelProperty(value="人员姓名")
private String personName;
/** 药品ID */
@ApiModelProperty(value="药品ID")
private Long medicineId;
/** 计划名称 */
@ApiModelProperty(value="计划名称")
private String planName;
/** 频率类型 */
@ApiModelProperty(value="频率类型")
private String frequencyType;
/** 状态 */
@ApiModelProperty(value="状态")
private String status;
/** 开始日期-起 */
@ApiModelProperty(value="开始日期-起")
private Date startDateBegin;
/** 开始日期-止 */
@ApiModelProperty(value="开始日期-止")
private Date startDateEnd;
/** 结束日期-起 */
@ApiModelProperty(value="结束日期-起")
private Date endDateBegin;
/** 结束日期-止 */
@ApiModelProperty(value="结束日期-止")
private Date endDateEnd;
/** 关键字(计划名称、药品名称) */
@ApiModelProperty(value="关键字")
private String keys;
/** 分页参数 */
private Integer pageNum;
private Integer pageSize;
}

View File

@@ -0,0 +1,65 @@
package com.intc.health.domain.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 用药记录DTO对象 health_medication_record
*
* @author intc
* @date 2025-03-18
*/
@ApiModel("用药记录DTO对象")
@Data
public class HealthMedicationRecordDto
{
/** 主键 */
private Long id;
/** 计划ID */
@ApiModelProperty(value="计划ID")
private Long planId;
/** 人员ID */
@ApiModelProperty(value="人员ID")
private Long personId;
/** 人员姓名 */
@ApiModelProperty(value="人员姓名")
private String personName;
/** 药品ID */
@ApiModelProperty(value="药品ID")
private Long medicineId;
/** 状态 */
@ApiModelProperty(value="状态")
private String status;
/** 计划服药时间-起 */
@ApiModelProperty(value="计划服药时间-起")
private Date scheduledTimeBegin;
/** 计划服药时间-止 */
@ApiModelProperty(value="计划服药时间-止")
private Date scheduledTimeEnd;
/** 实际服药时间-起 */
@ApiModelProperty(value="实际服药时间-起")
private Date actualTimeBegin;
/** 实际服药时间-止 */
@ApiModelProperty(value="实际服药时间-止")
private Date actualTimeEnd;
/** 日期(按日期查询某天所有记录) */
@ApiModelProperty(value="日期")
private Date queryDate;
/** 分页参数 */
private Integer pageNum;
private Integer pageSize;
}

View File

@@ -0,0 +1,118 @@
package com.intc.health.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.intc.common.core.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 用药计划VO对象 health_medication_plan
*
* @author intc
* @date 2025-03-18
*/
@ApiModel("用药计划VO对象")
@Data
public class HealthMedicationPlanVo
{
/** 主键 */
private Long id;
/** 人员ID */
@Excel(name = "人员ID")
private Long personId;
/** 人员姓名 */
@Excel(name = "人员姓名")
private String personName;
/** 药品ID */
@Excel(name = "药品ID")
private Long medicineId;
/** 药品名称 */
@Excel(name = "药品名称")
private String medicineName;
/** 药品简称 */
private String shortName;
/** 品牌 */
private String brand;
/** 包装 */
private String packaging;
/** 入库ID */
private Long stockInId;
/** 计划名称 */
@Excel(name = "计划名称")
private String planName;
/** 每次剂量 */
@Excel(name = "每次剂量")
private Double dosage;
/** 剂量单位 */
@Excel(name = "剂量单位")
private String dosageUnit;
/** 服药频率 */
@Excel(name = "服药频率")
private Integer frequency;
/** 频率类型 */
@Excel(name = "频率类型")
private String frequencyType;
/** 服药时间点 */
private String timePoints;
/** 周几服药 */
private String weekDays;
/** 开始日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "开始日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date startDate;
/** 结束日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "结束日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date endDate;
/** 是否启用提醒 */
@Excel(name = "是否启用提醒")
private String reminderEnabled;
/** 提前提醒时间 */
@Excel(name = "提前提醒时间(分钟)")
private Integer reminderMinutes;
/** 状态 */
@Excel(name = "状态")
private String status;
/** 备注 */
private String remark;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 药品简称-品牌(组合显示) */
private String medicineDisplayName;
/** 今日已服药次数 */
private Integer todayTakenCount;
/** 今日应服药次数 */
private Integer todayTotalCount;
/** 剩余库存 */
private Double stockLeft;
}

View File

@@ -0,0 +1,87 @@
package com.intc.health.domain.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.intc.common.core.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 用药记录VO对象 health_medication_record
*
* @author intc
* @date 2025-03-18
*/
@ApiModel("用药记录VO对象")
@Data
public class HealthMedicationRecordVo
{
/** 主键 */
private Long id;
/** 计划ID */
@Excel(name = "计划ID")
private Long planId;
/** 人员ID */
@Excel(name = "人员ID")
private Long personId;
/** 人员姓名 */
@Excel(name = "人员姓名")
private String personName;
/** 药品ID */
@Excel(name = "药品ID")
private Long medicineId;
/** 药品名称 */
@Excel(name = "药品名称")
private String medicineName;
/** 药品简称 */
private String shortName;
/** 品牌 */
private String brand;
/** 包装 */
private String packaging;
/** 计划服药时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "计划服药时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date scheduledTime;
/** 实际服药时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "实际服药时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date actualTime;
/** 服用剂量 */
@Excel(name = "服用剂量")
private Double dosage;
/** 剂量单位 */
@Excel(name = "剂量单位")
private String dosageUnit;
/** 状态 */
@Excel(name = "状态")
private String status;
/** 备注 */
private String remark;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/** 药品简称-品牌(组合显示) */
private String medicineDisplayName;
/** 计划名称 */
private String planName;
}

View File

@@ -0,0 +1,86 @@
package com.intc.health.mapper;
import java.util.List;
import com.intc.health.domain.HealthMedicationPlan;
import com.intc.health.domain.dto.HealthMedicationPlanDto;
import com.intc.health.domain.vo.HealthMedicationPlanVo;
/**
* 用药计划Mapper接口
*
* @author intc
* @date 2025-03-18
*/
public interface HealthMedicationPlanMapper
{
/**
* 查询用药计划
*
* @param id 用药计划主键
* @return 用药计划
*/
public HealthMedicationPlanVo selectHealthMedicationPlanById(Long id);
/**
* 查询用药计划列表
*
* @param dto 用药计划
* @return 用药计划集合
*/
public List<HealthMedicationPlanVo> selectHealthMedicationPlanList(HealthMedicationPlanDto dto);
/**
* 查询进行中的用药计划列表(用于生成用药记录)
*
* @return 用药计划集合
*/
public List<HealthMedicationPlanVo> selectActivePlanList();
/**
* 新增用药计划
*
* @param healthMedicationPlan 用药计划
* @return 结果
*/
public int insertHealthMedicationPlan(HealthMedicationPlan healthMedicationPlan);
/**
* 修改用药计划
*
* @param healthMedicationPlan 用药计划
* @return 结果
*/
public int updateHealthMedicationPlan(HealthMedicationPlan healthMedicationPlan);
/**
* 删除用药计划
*
* @param id 用药计划主键
* @return 结果
*/
public int deleteHealthMedicationPlanById(Long id);
/**
* 批量删除用药计划
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteHealthMedicationPlanByIds(Long[] ids);
/**
* 逻辑删除用药计划
*
* @param id 用药计划主键
* @return 结果
*/
public int removeHealthMedicationPlanById(Long id);
/**
* 批量逻辑删除用药计划
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int removeHealthMedicationPlanByIds(Long[] ids);
}

View File

@@ -0,0 +1,106 @@
package com.intc.health.mapper;
import java.util.List;
import com.intc.health.domain.HealthMedicationRecord;
import com.intc.health.domain.dto.HealthMedicationRecordDto;
import com.intc.health.domain.vo.HealthMedicationRecordVo;
import org.apache.ibatis.annotations.Param;
/**
* 用药记录Mapper接口
*
* @author intc
* @date 2025-03-18
*/
public interface HealthMedicationRecordMapper
{
/**
* 查询用药记录
*
* @param id 用药记录主键
* @return 用药记录
*/
public HealthMedicationRecordVo selectHealthMedicationRecordById(Long id);
/**
* 查询用药记录列表
*
* @param dto 用药记录
* @return 用药记录集合
*/
public List<HealthMedicationRecordVo> selectHealthMedicationRecordList(HealthMedicationRecordDto dto);
/**
* 查询某计划某天的用药记录
*
* @param planId 计划ID
* @param date 日期
* @return 用药记录集合
*/
public List<HealthMedicationRecordVo> selectRecordByPlanAndDate(@Param("planId") Long planId, @Param("date") String date);
/**
* 统计某计划某天已服药次数
*
* @param planId 计划ID
* @param date 日期
* @return 次数
*/
public int countTakenByPlanAndDate(@Param("planId") Long planId, @Param("date") String date);
/**
* 新增用药记录
*
* @param record 用药记录
* @return 结果
*/
public int insertHealthMedicationRecord(HealthMedicationRecord record);
/**
* 批量新增用药记录
*
* @param records 用药记录列表
* @return 结果
*/
public int batchInsertHealthMedicationRecord(List<HealthMedicationRecord> records);
/**
* 修改用药记录
*
* @param record 用药记录
* @return 结果
*/
public int updateHealthMedicationRecord(HealthMedicationRecord record);
/**
* 删除用药记录
*
* @param id 用药记录主键
* @return 结果
*/
public int deleteHealthMedicationRecordById(Long id);
/**
* 批量删除用药记录
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteHealthMedicationRecordByIds(Long[] ids);
/**
* 逻辑删除用药记录
*
* @param id 用药记录主键
* @return 结果
*/
public int removeHealthMedicationRecordById(Long id);
/**
* 批量逻辑删除用药记录
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int removeHealthMedicationRecordByIds(Long[] ids);
}

View File

@@ -0,0 +1,87 @@
package com.intc.health.service;
import java.util.List;
import com.intc.health.domain.HealthMedicationPlan;
import com.intc.health.domain.dto.HealthMedicationPlanDto;
import com.intc.health.domain.vo.HealthMedicationPlanVo;
/**
* 用药计划Service接口
*
* @author intc
* @date 2025-03-18
*/
public interface IHealthMedicationPlanService
{
/**
* 查询用药计划
*
* @param id 用药计划主键
* @return 用药计划
*/
public HealthMedicationPlanVo selectHealthMedicationPlanById(Long id);
/**
* 查询用药计划列表
*
* @param dto 用药计划
* @return 用药计划集合
*/
public List<HealthMedicationPlanVo> selectHealthMedicationPlanList(HealthMedicationPlanDto dto);
/**
* 新增用药计划
*
* @param plan 用药计划
* @return 结果
*/
public int insertHealthMedicationPlan(HealthMedicationPlan plan);
/**
* 修改用药计划
*
* @param plan 用药计划
* @return 结果
*/
public int updateHealthMedicationPlan(HealthMedicationPlan plan);
/**
* 批量删除用药计划
*
* @param ids 需要删除的用药计划主键集合
* @return 结果
*/
public int deleteHealthMedicationPlanByIds(Long[] ids);
/**
* 删除用药计划信息
*
* @param id 用药计划主键
* @return 结果
*/
public int deleteHealthMedicationPlanById(Long id);
/**
* 暂停用药计划
*
* @param id 用药计划主键
* @return 结果
*/
public int pauseHealthMedicationPlan(Long id);
/**
* 恢复用药计划
*
* @param id 用药计划主键
* @return 结果
*/
public int resumeHealthMedicationPlan(Long id);
/**
* 结束用药计划
*
* @param id 用药计划主键
* @return 结果
*/
public int endHealthMedicationPlan(Long id);
}

View File

@@ -0,0 +1,108 @@
package com.intc.health.service;
import java.util.List;
import com.intc.health.domain.HealthMedicationRecord;
import com.intc.health.domain.dto.HealthMedicationRecordDto;
import com.intc.health.domain.vo.HealthMedicationRecordVo;
/**
* 用药记录Service接口
*
* @author intc
* @date 2025-03-18
*/
public interface IHealthMedicationRecordService
{
/**
* 查询用药记录
*
* @param id 用药记录主键
* @return 用药记录
*/
public HealthMedicationRecordVo selectHealthMedicationRecordById(Long id);
/**
* 查询用药记录列表
*
* @param dto 用药记录
* @return 用药记录集合
*/
public List<HealthMedicationRecordVo> selectHealthMedicationRecordList(HealthMedicationRecordDto dto);
/**
* 查询某计划某天的用药记录
*
* @param planId 计划ID
* @param date 日期(yyyy-MM-dd)
* @return 用药记录集合
*/
public List<HealthMedicationRecordVo> selectRecordByPlanAndDate(Long planId, String date);
/**
* 新增用药记录
*
* @param record 用药记录
* @return 结果
*/
public int insertHealthMedicationRecord(HealthMedicationRecord record);
/**
* 修改用药记录
*
* @param record 用药记录
* @return 结果
*/
public int updateHealthMedicationRecord(HealthMedicationRecord record);
/**
* 批量删除用药记录
*
* @param ids 需要删除的用药记录主键集合
* @return 结果
*/
public int deleteHealthMedicationRecordByIds(Long[] ids);
/**
* 删除用药记录信息
*
* @param id 用药记录主键
* @return 结果
*/
public int deleteHealthMedicationRecordById(Long id);
/**
* 服药(标记为已服用)
*
* @param id 记录ID
* @param dosage 实际服用剂量
* @param remark 备注
* @return 结果
*/
public int takeMedication(Long id, Double dosage, String remark);
/**
* 跳过服药
*
* @param id 记录ID
* @param remark 原因
* @return 结果
*/
public int skipMedication(Long id, String remark);
/**
* 获取今日用药记录
*
* @param personId 人员ID可选
* @return 用药记录集合
*/
public List<HealthMedicationRecordVo> getTodayRecords(Long personId);
/**
* 统计某计划某天已服药次数
*
* @param planId 计划ID
* @param date 日期(yyyy-MM-dd)
* @return 次数
*/
public int countTakenByPlanAndDate(Long planId, String date);
}

View File

@@ -0,0 +1,188 @@
package com.intc.health.service.impl;
import com.intc.common.core.utils.DateUtils;
import com.intc.common.core.utils.IdWorker;
import com.intc.common.security.utils.SecurityUtils;
import com.intc.health.domain.HealthMedicationPlan;
import com.intc.health.domain.dto.HealthMedicationPlanDto;
import com.intc.health.domain.vo.HealthMedicationPlanVo;
import com.intc.health.mapper.HealthMedicationPlanMapper;
import com.intc.health.mapper.HealthMedicationRecordMapper;
import com.intc.health.service.IHealthMedicationPlanService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* 用药计划Service业务层处理
*
* @author intc
* @date 2025-03-18
*/
@Service
public class HealthMedicationPlanServiceImpl implements IHealthMedicationPlanService
{
@Resource
private HealthMedicationPlanMapper healthMedicationPlanMapper;
@Resource
private HealthMedicationRecordMapper healthMedicationRecordMapper;
/**
* 查询用药计划
*
* @param id 用药计划主键
* @return 用药计划
*/
@Override
public HealthMedicationPlanVo selectHealthMedicationPlanById(Long id)
{
HealthMedicationPlanVo vo = healthMedicationPlanMapper.selectHealthMedicationPlanById(id);
if (vo != null) {
// 设置药品显示名称
vo.setMedicineDisplayName(vo.getShortName() + "-" + vo.getBrand() + "(" + vo.getPackaging() + ")");
// 统计今日服药情况
String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
int takenCount = healthMedicationRecordMapper.countTakenByPlanAndDate(id, today);
vo.setTodayTakenCount(takenCount);
vo.setTodayTotalCount(vo.getFrequency());
}
return vo;
}
/**
* 查询用药计划列表
*
* @param dto 用药计划
* @return 用药计划
*/
@Override
public List<HealthMedicationPlanVo> selectHealthMedicationPlanList(HealthMedicationPlanDto dto)
{
List<HealthMedicationPlanVo> list = healthMedicationPlanMapper.selectHealthMedicationPlanList(dto);
String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
for (HealthMedicationPlanVo vo : list) {
// 设置药品显示名称
vo.setMedicineDisplayName(vo.getShortName() + "-" + vo.getBrand() + "(" + vo.getPackaging() + ")");
// 统计今日服药情况
if ("1".equals(vo.getStatus())) {
int takenCount = healthMedicationRecordMapper.countTakenByPlanAndDate(vo.getId(), today);
vo.setTodayTakenCount(takenCount);
vo.setTodayTotalCount(vo.getFrequency());
}
}
return list;
}
/**
* 新增用药计划
*
* @param plan 用药计划
* @return 结果
*/
@Override
public int insertHealthMedicationPlan(HealthMedicationPlan plan)
{
plan.setId(IdWorker.getId());
plan.setCreateBy(SecurityUtils.getUsername());
plan.setCreateTime(DateUtils.getNowDate());
plan.setDelFlag("0");
// 默认状态为进行中
if (plan.getStatus() == null) {
plan.setStatus("1");
}
return healthMedicationPlanMapper.insertHealthMedicationPlan(plan);
}
/**
* 修改用药计划
*
* @param plan 用药计划
* @return 结果
*/
@Override
public int updateHealthMedicationPlan(HealthMedicationPlan plan)
{
plan.setUpdateBy(SecurityUtils.getUsername());
plan.setUpdateTime(DateUtils.getNowDate());
return healthMedicationPlanMapper.updateHealthMedicationPlan(plan);
}
/**
* 批量删除用药计划
*
* @param ids 需要删除的用药计划主键
* @return 结果
*/
@Override
public int deleteHealthMedicationPlanByIds(Long[] ids)
{
return healthMedicationPlanMapper.removeHealthMedicationPlanByIds(ids);
}
/**
* 删除用药计划信息
*
* @param id 用药计划主键
* @return 结果
*/
@Override
public int deleteHealthMedicationPlanById(Long id)
{
return healthMedicationPlanMapper.removeHealthMedicationPlanById(id);
}
/**
* 暂停用药计划
*
* @param id 用药计划主键
* @return 结果
*/
@Override
public int pauseHealthMedicationPlan(Long id)
{
HealthMedicationPlan plan = new HealthMedicationPlan();
plan.setId(id);
plan.setStatus("3"); // 已暂停
plan.setUpdateBy(SecurityUtils.getUsername());
plan.setUpdateTime(DateUtils.getNowDate());
return healthMedicationPlanMapper.updateHealthMedicationPlan(plan);
}
/**
* 恢复用药计划
*
* @param id 用药计划主键
* @return 结果
*/
@Override
public int resumeHealthMedicationPlan(Long id)
{
HealthMedicationPlan plan = new HealthMedicationPlan();
plan.setId(id);
plan.setStatus("1"); // 进行中
plan.setUpdateBy(SecurityUtils.getUsername());
plan.setUpdateTime(DateUtils.getNowDate());
return healthMedicationPlanMapper.updateHealthMedicationPlan(plan);
}
/**
* 结束用药计划
*
* @param id 用药计划主键
* @return 结果
*/
@Override
public int endHealthMedicationPlan(Long id)
{
HealthMedicationPlan plan = new HealthMedicationPlan();
plan.setId(id);
plan.setStatus("2"); // 已结束
plan.setUpdateBy(SecurityUtils.getUsername());
plan.setUpdateTime(DateUtils.getNowDate());
return healthMedicationPlanMapper.updateHealthMedicationPlan(plan);
}
}

View File

@@ -0,0 +1,214 @@
package com.intc.health.service.impl;
import com.intc.common.core.utils.DateUtils;
import com.intc.common.core.utils.IdWorker;
import com.intc.common.security.utils.SecurityUtils;
import com.intc.health.domain.HealthMedicationRecord;
import com.intc.health.domain.dto.HealthMedicationRecordDto;
import com.intc.health.domain.vo.HealthMedicationRecordVo;
import com.intc.health.mapper.HealthMedicationRecordMapper;
import com.intc.health.service.IHealthMedicationRecordService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
/**
* 用药记录Service业务层处理
*
* @author intc
* @date 2025-03-18
*/
@Service
public class HealthMedicationRecordServiceImpl implements IHealthMedicationRecordService
{
@Resource
private HealthMedicationRecordMapper healthMedicationRecordMapper;
/**
* 查询用药记录
*
* @param id 用药记录主键
* @return 用药记录
*/
@Override
public HealthMedicationRecordVo selectHealthMedicationRecordById(Long id)
{
HealthMedicationRecordVo vo = healthMedicationRecordMapper.selectHealthMedicationRecordById(id);
if (vo != null) {
vo.setMedicineDisplayName(vo.getShortName() + "-" + vo.getBrand() + "(" + vo.getPackaging() + ")");
}
return vo;
}
/**
* 查询用药记录列表
*
* @param dto 用药记录
* @return 用药记录
*/
@Override
public List<HealthMedicationRecordVo> selectHealthMedicationRecordList(HealthMedicationRecordDto dto)
{
List<HealthMedicationRecordVo> list = healthMedicationRecordMapper.selectHealthMedicationRecordList(dto);
for (HealthMedicationRecordVo vo : list) {
vo.setMedicineDisplayName(vo.getShortName() + "-" + vo.getBrand() + "(" + vo.getPackaging() + ")");
}
return list;
}
/**
* 查询某计划某天的用药记录
*
* @param planId 计划ID
* @param date 日期(yyyy-MM-dd)
* @return 用药记录集合
*/
@Override
public List<HealthMedicationRecordVo> selectRecordByPlanAndDate(Long planId, String date)
{
List<HealthMedicationRecordVo> list = healthMedicationRecordMapper.selectRecordByPlanAndDate(planId, date);
for (HealthMedicationRecordVo vo : list) {
vo.setMedicineDisplayName(vo.getShortName() + "-" + vo.getBrand() + "(" + vo.getPackaging() + ")");
}
return list;
}
/**
* 新增用药记录
*
* @param record 用药记录
* @return 结果
*/
@Override
public int insertHealthMedicationRecord(HealthMedicationRecord record)
{
record.setId(IdWorker.getId());
record.setCreateBy(SecurityUtils.getUsername());
record.setCreateTime(DateUtils.getNowDate());
record.setDelFlag("0");
// 默认状态为待服用
if (record.getStatus() == null) {
record.setStatus("1");
}
return healthMedicationRecordMapper.insertHealthMedicationRecord(record);
}
/**
* 修改用药记录
*
* @param record 用药记录
* @return 结果
*/
@Override
public int updateHealthMedicationRecord(HealthMedicationRecord record)
{
record.setUpdateBy(SecurityUtils.getUsername());
record.setUpdateTime(DateUtils.getNowDate());
return healthMedicationRecordMapper.updateHealthMedicationRecord(record);
}
/**
* 批量删除用药记录
*
* @param ids 需要删除的用药记录主键
* @return 结果
*/
@Override
public int deleteHealthMedicationRecordByIds(Long[] ids)
{
return healthMedicationRecordMapper.removeHealthMedicationRecordByIds(ids);
}
/**
* 删除用药记录信息
*
* @param id 用药记录主键
* @return 结果
*/
@Override
public int deleteHealthMedicationRecordById(Long id)
{
return healthMedicationRecordMapper.removeHealthMedicationRecordById(id);
}
/**
* 服药(标记为已服用)
*
* @param id 记录ID
* @param dosage 实际服用剂量
* @param remark 备注
* @return 结果
*/
@Override
public int takeMedication(Long id, Double dosage, String remark)
{
HealthMedicationRecord record = new HealthMedicationRecord();
record.setId(id);
record.setStatus("2"); // 已服用
record.setActualTime(new Date());
if (dosage != null) {
record.setDosage(dosage);
}
if (remark != null) {
record.setRemark(remark);
}
record.setUpdateBy(SecurityUtils.getUsername());
record.setUpdateTime(DateUtils.getNowDate());
return healthMedicationRecordMapper.updateHealthMedicationRecord(record);
}
/**
* 跳过服药
*
* @param id 记录ID
* @param remark 原因
* @return 结果
*/
@Override
public int skipMedication(Long id, String remark)
{
HealthMedicationRecord record = new HealthMedicationRecord();
record.setId(id);
record.setStatus("3"); // 已跳过
if (remark != null) {
record.setRemark(remark);
}
record.setUpdateBy(SecurityUtils.getUsername());
record.setUpdateTime(DateUtils.getNowDate());
return healthMedicationRecordMapper.updateHealthMedicationRecord(record);
}
/**
* 获取今日用药记录
*
* @param personId 人员ID可选
* @return 用药记录集合
*/
@Override
public List<HealthMedicationRecordVo> getTodayRecords(Long personId)
{
HealthMedicationRecordDto dto = new HealthMedicationRecordDto();
dto.setQueryDate(new Date());
if (personId != null) {
dto.setPersonId(personId);
}
return selectHealthMedicationRecordList(dto);
}
/**
* 统计某计划某天已服药次数
*
* @param planId 计划ID
* @param date 日期(yyyy-MM-dd)
* @return 次数
*/
@Override
public int countTakenByPlanAndDate(Long planId, String date)
{
return healthMedicationRecordMapper.countTakenByPlanAndDate(planId, date);
}
}

View File

@@ -0,0 +1,190 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.intc.health.mapper.HealthMedicationPlanMapper">
<resultMap type="HealthMedicationPlanVo" id="HealthMedicationPlanResult">
<result property="id" column="id" />
<result property="personId" column="person_id" />
<result property="personName" column="person_name" />
<result property="medicineId" column="medicine_id" />
<result property="medicineName" column="medicine_name" />
<result property="shortName" column="short_name" />
<result property="brand" column="brand" />
<result property="packaging" column="packaging" />
<result property="stockInId" column="stock_in_id" />
<result property="planName" column="plan_name" />
<result property="dosage" column="dosage" />
<result property="dosageUnit" column="dosage_unit" />
<result property="frequency" column="frequency" />
<result property="frequencyType" column="frequency_type" />
<result property="timePoints" column="time_points" />
<result property="weekDays" column="week_days" />
<result property="startDate" column="start_date" />
<result property="endDate" column="end_date" />
<result property="reminderEnabled" column="reminder_enabled" />
<result property="reminderMinutes" column="reminder_minutes" />
<result property="status" column="status" />
<result property="remark" column="remark" />
<result property="createTime" column="create_time" />
</resultMap>
<sql id="selectHealthMedicationPlanVo">
select
a.id,
a.person_id,
p.name as person_name,
a.medicine_id,
m.name as medicine_name,
m.short_name,
m.brand,
m.packaging,
a.stock_in_id,
a.plan_name,
a.dosage,
a.dosage_unit,
a.frequency,
a.frequency_type,
a.time_points,
a.week_days,
a.start_date,
a.end_date,
a.reminder_enabled,
a.reminder_minutes,
a.status,
a.remark,
a.create_time
from
health_medication_plan a
left join health_person p on a.person_id = p.id
left join health_medicine_basic m on a.medicine_id = m.id
</sql>
<select id="selectHealthMedicationPlanList" parameterType="HealthMedicationPlanDto" resultMap="HealthMedicationPlanResult">
<include refid="selectHealthMedicationPlanVo"/>
<where>
a.del_flag='0'
<if test="personId != null"> and a.person_id = #{personId}</if>
<if test="personName != null and personName != ''"> and p.name like '%'|| #{personName}||'%'</if>
<if test="medicineId != null"> and a.medicine_id = #{medicineId}</if>
<if test="planName != null and planName != ''"> and a.plan_name like '%'|| #{planName}||'%'</if>
<if test="frequencyType != null and frequencyType != ''"> and a.frequency_type = #{frequencyType}</if>
<if test="status != null and status != ''"> and a.status = #{status}</if>
<if test="startDateBegin != null"> and a.start_date &gt;= #{startDateBegin}</if>
<if test="startDateEnd != null"> and a.start_date &lt;= #{startDateEnd}</if>
<if test="endDateBegin != null"> and a.end_date &gt;= #{endDateBegin}</if>
<if test="endDateEnd != null"> and a.end_date &lt;= #{endDateEnd}</if>
<if test="keys != null and keys != ''"> and (a.plan_name like '%'|| #{keys}||'%' or m.name like '%'|| #{keys}||'%' or m.short_name like '%'|| #{keys}||'%')</if>
</where>
order by a.create_time desc
</select>
<select id="selectHealthMedicationPlanById" parameterType="Long" resultMap="HealthMedicationPlanResult">
<include refid="selectHealthMedicationPlanVo"/>
where a.id = #{id}
</select>
<select id="selectActivePlanList" resultMap="HealthMedicationPlanResult">
<include refid="selectHealthMedicationPlanVo"/>
where a.del_flag='0' and a.status = '1'
and a.start_date &lt;= current_date
and (a.end_date is null or a.end_date &gt;= current_date)
</select>
<insert id="insertHealthMedicationPlan" parameterType="HealthMedicationPlan">
insert into health_medication_plan
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="personId != null">person_id,</if>
<if test="medicineId != null">medicine_id,</if>
<if test="stockInId != null">stock_in_id,</if>
<if test="planName != null">plan_name,</if>
<if test="dosage != null">dosage,</if>
<if test="dosageUnit != null">dosage_unit,</if>
<if test="frequency != null">frequency,</if>
<if test="frequencyType != null">frequency_type,</if>
<if test="timePoints != null">time_points,</if>
<if test="weekDays != null">week_days,</if>
<if test="startDate != null">start_date,</if>
<if test="endDate != null">end_date,</if>
<if test="reminderEnabled != null">reminder_enabled,</if>
<if test="reminderMinutes != null">reminder_minutes,</if>
<if test="status != null">status,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="delFlag != null">del_flag,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="personId != null">#{personId},</if>
<if test="medicineId != null">#{medicineId},</if>
<if test="stockInId != null">#{stockInId},</if>
<if test="planName != null">#{planName},</if>
<if test="dosage != null">#{dosage},</if>
<if test="dosageUnit != null">#{dosageUnit},</if>
<if test="frequency != null">#{frequency},</if>
<if test="frequencyType != null">#{frequencyType},</if>
<if test="timePoints != null">#{timePoints},</if>
<if test="weekDays != null">#{weekDays},</if>
<if test="startDate != null">#{startDate},</if>
<if test="endDate != null">#{endDate},</if>
<if test="reminderEnabled != null">#{reminderEnabled},</if>
<if test="reminderMinutes != null">#{reminderMinutes},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateHealthMedicationPlan" parameterType="HealthMedicationPlan">
update health_medication_plan
<trim prefix="SET" suffixOverrides=",">
<if test="personId != null">person_id = #{personId},</if>
<if test="medicineId != null">medicine_id = #{medicineId},</if>
<if test="stockInId != null">stock_in_id = #{stockInId},</if>
<if test="planName != null">plan_name = #{planName},</if>
<if test="dosage != null">dosage = #{dosage},</if>
<if test="dosageUnit != null">dosage_unit = #{dosageUnit},</if>
<if test="frequency != null">frequency = #{frequency},</if>
<if test="frequencyType != null">frequency_type = #{frequencyType},</if>
<if test="timePoints != null">time_points = #{timePoints},</if>
<if test="weekDays != null">week_days = #{weekDays},</if>
<if test="startDate != null">start_date = #{startDate},</if>
<if test="endDate != null">end_date = #{endDate},</if>
<if test="reminderEnabled != null">reminder_enabled = #{reminderEnabled},</if>
<if test="reminderMinutes != null">reminder_minutes = #{reminderMinutes},</if>
<if test="status != null">status = #{status},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteHealthMedicationPlanById" parameterType="Long">
delete from health_medication_plan where id = #{id}
</delete>
<delete id="deleteHealthMedicationPlanByIds" parameterType="String">
delete from health_medication_plan where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<update id="removeHealthMedicationPlanById" parameterType="Long">
update health_medication_plan set del_flag='1' where id = #{id}
</update>
<update id="removeHealthMedicationPlanByIds" parameterType="String">
update health_medication_plan set del_flag='1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>

View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.intc.health.mapper.HealthMedicationRecordMapper">
<resultMap type="HealthMedicationRecordVo" id="HealthMedicationRecordResult">
<result property="id" column="id" />
<result property="planId" column="plan_id" />
<result property="personId" column="person_id" />
<result property="personName" column="person_name" />
<result property="medicineId" column="medicine_id" />
<result property="medicineName" column="medicine_name" />
<result property="shortName" column="short_name" />
<result property="brand" column="brand" />
<result property="packaging" column="packaging" />
<result property="scheduledTime" column="scheduled_time" />
<result property="actualTime" column="actual_time" />
<result property="dosage" column="dosage" />
<result property="dosageUnit" column="dosage_unit" />
<result property="status" column="status" />
<result property="remark" column="remark" />
<result property="createTime" column="create_time" />
<result property="planName" column="plan_name" />
</resultMap>
<sql id="selectHealthMedicationRecordVo">
select
a.id,
a.plan_id,
a.person_id,
p.name as person_name,
a.medicine_id,
m.name as medicine_name,
m.short_name,
m.brand,
m.packaging,
a.scheduled_time,
a.actual_time,
a.dosage,
a.dosage_unit,
a.status,
a.remark,
a.create_time,
pl.plan_name
from
health_medication_record a
left join health_person p on a.person_id = p.id
left join health_medicine_basic m on a.medicine_id = m.id
left join health_medication_plan pl on a.plan_id = pl.id
</sql>
<select id="selectHealthMedicationRecordList" parameterType="HealthMedicationRecordDto" resultMap="HealthMedicationRecordResult">
<include refid="selectHealthMedicationRecordVo"/>
<where>
a.del_flag='0'
<if test="planId != null"> and a.plan_id = #{planId}</if>
<if test="personId != null"> and a.person_id = #{personId}</if>
<if test="personName != null and personName != ''"> and p.name like '%'|| #{personName}||'%'</if>
<if test="medicineId != null"> and a.medicine_id = #{medicineId}</if>
<if test="status != null and status != ''"> and a.status = #{status}</if>
<if test="scheduledTimeBegin != null"> and a.scheduled_time &gt;= #{scheduledTimeBegin}</if>
<if test="scheduledTimeEnd != null"> and a.scheduled_time &lt;= #{scheduledTimeEnd}</if>
<if test="actualTimeBegin != null"> and a.actual_time &gt;= #{actualTimeBegin}</if>
<if test="actualTimeEnd != null"> and a.actual_time &lt;= #{actualTimeEnd}</if>
<if test="queryDate != null"> and date(a.scheduled_time) = date(#{queryDate})</if>
</where>
order by a.scheduled_time desc
</select>
<select id="selectHealthMedicationRecordById" parameterType="Long" resultMap="HealthMedicationRecordResult">
<include refid="selectHealthMedicationRecordVo"/>
where a.id = #{id}
</select>
<select id="selectRecordByPlanAndDate" resultMap="HealthMedicationRecordResult">
<include refid="selectHealthMedicationRecordVo"/>
where a.del_flag='0' and a.plan_id = #{planId}
and date(a.scheduled_time) = date(#{date})
order by a.scheduled_time asc
</select>
<select id="countTakenByPlanAndDate" resultType="int">
select count(1) from health_medication_record
where del_flag='0' and plan_id = #{planId}
and date(scheduled_time) = date(#{date})
and status = '2'
</select>
<insert id="insertHealthMedicationRecord" parameterType="HealthMedicationRecord">
insert into health_medication_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="planId != null">plan_id,</if>
<if test="personId != null">person_id,</if>
<if test="medicineId != null">medicine_id,</if>
<if test="scheduledTime != null">scheduled_time,</if>
<if test="actualTime != null">actual_time,</if>
<if test="dosage != null">dosage,</if>
<if test="dosageUnit != null">dosage_unit,</if>
<if test="status != null">status,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="delFlag != null">del_flag,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="planId != null">#{planId},</if>
<if test="personId != null">#{personId},</if>
<if test="medicineId != null">#{medicineId},</if>
<if test="scheduledTime != null">#{scheduledTime},</if>
<if test="actualTime != null">#{actualTime},</if>
<if test="dosage != null">#{dosage},</if>
<if test="dosageUnit != null">#{dosageUnit},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<insert id="batchInsertHealthMedicationRecord" parameterType="java.util.List">
insert into health_medication_record (id, plan_id, person_id, medicine_id, scheduled_time, dosage, dosage_unit, status, create_time, del_flag)
values
<foreach collection="list" item="item" separator=",">
(#{item.id}, #{item.planId}, #{item.personId}, #{item.medicineId}, #{item.scheduledTime}, #{item.dosage}, #{item.dosageUnit}, #{item.status}, #{item.createTime}, '0')
</foreach>
</insert>
<update id="updateHealthMedicationRecord" parameterType="HealthMedicationRecord">
update health_medication_record
<trim prefix="SET" suffixOverrides=",">
<if test="planId != null">plan_id = #{planId},</if>
<if test="personId != null">person_id = #{personId},</if>
<if test="medicineId != null">medicine_id = #{medicineId},</if>
<if test="scheduledTime != null">scheduled_time = #{scheduledTime},</if>
<if test="actualTime != null">actual_time = #{actualTime},</if>
<if test="dosage != null">dosage = #{dosage},</if>
<if test="dosageUnit != null">dosage_unit = #{dosageUnit},</if>
<if test="status != null">status = #{status},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteHealthMedicationRecordById" parameterType="Long">
delete from health_medication_record where id = #{id}
</delete>
<delete id="deleteHealthMedicationRecordByIds" parameterType="String">
delete from health_medication_record where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<update id="removeHealthMedicationRecordById" parameterType="Long">
update health_medication_record set del_flag='1' where id = #{id}
</update>
<update id="removeHealthMedicationRecordByIds" parameterType="String">
update health_medication_record set del_flag='1' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>