| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.model.TCrmClinic; |
| | | import com.ruoyi.system.model.TSysAppUser; |
| | | import com.ruoyi.system.model.TSysInspection; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TCrmClinicService; |
| | | import com.ruoyi.system.service.TSysAppUserService; |
| | | import com.ruoyi.system.service.TSysInspectionService; |
| | | import com.ruoyi.web.controller.tool.WordUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public class TSysInspectionController { |
| | | |
| | | private final TSysInspectionService sysInspectionService; |
| | | private final TokenService tokenService; |
| | | private final TCrmClinicService crmClinicService; |
| | | private final ISysUserService sysUserService; |
| | | private final TSysAppUserService sysAppUserService; |
| | | private final WordUtil wordUtil; |
| | | @Autowired |
| | | public TSysInspectionController(TSysInspectionService sysInspectionService) { |
| | | public TSysInspectionController(TSysInspectionService sysInspectionService, TokenService tokenService, TCrmClinicService crmClinicService, ISysUserService sysUserService, TSysAppUserService sysAppUserService, WordUtil wordUtil) { |
| | | this.sysInspectionService = sysInspectionService; |
| | | this.tokenService = tokenService; |
| | | this.crmClinicService = crmClinicService; |
| | | this.sysUserService = sysUserService; |
| | | this.sysAppUserService = sysAppUserService; |
| | | this.wordUtil = wordUtil; |
| | | } |
| | | |
| | | // /** |
| | |
| | | @PostMapping(value = "/add") |
| | | public R<Boolean> add(@Validated @RequestBody TSysInspection dto) { |
| | | dto.setIsPay(1); |
| | | String checkTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
| | | dto.setCheckTime(checkTime); |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | TCrmClinic crmClinic = crmClinicService.getOne(Wrappers.lambdaQuery(TCrmClinic.class) |
| | | .eq(TCrmClinic::getUserId, userId) |
| | | .last("LIMIT 1")); |
| | | if(Objects.isNull(crmClinic)){ |
| | | SysUser sysUser = sysUserService.selectUserById(userId); |
| | | crmClinic = crmClinicService.getById(sysUser.getObjectId()); |
| | | } |
| | | dto.setClinicId(crmClinic.getId()); |
| | | // 查询该诊所最新的一条检测记录 |
| | | TSysInspection sysInspection = sysInspectionService.getOne(Wrappers.lambdaQuery(TSysInspection.class) |
| | | .eq(TSysInspection::getClinicId, crmClinic.getId()) |
| | | .orderByDesc(TSysInspection::getCreateTime) |
| | | .last("LIMIT 1")); |
| | | if(StringUtils.hasLength(sysInspection.getPrescriptionNumber())){ |
| | | // 生成处方编号 总共六位数字,不满6位前面补0 |
| | | String prescriptionNumber = sysInspection.getPrescriptionNumber(); |
| | | prescriptionNumber = prescriptionNumber.substring(prescriptionNumber.length() - 6); |
| | | prescriptionNumber = String.format("%06d", Integer.parseInt(prescriptionNumber) + 1); |
| | | dto.setPrescriptionNumber(prescriptionNumber); |
| | | }else{ |
| | | dto.setPrescriptionNumber("000001"); |
| | | } |
| | | dto.setInspectionType(1); |
| | | return R.ok(sysInspectionService.save(dto)); |
| | | } |
| | | |
| | |
| | | return R.ok(sysInspectionService.removeByIds(ids)); |
| | | } |
| | | |
| | | @Log(title = "用户检测信息管理信息-导出检测信息", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "导出检测信息") |
| | | @GetMapping(value = "/exportInspection") |
| | | public R<String> exportInspection(@RequestParam String id) { |
| | | TSysInspection sysInspection = sysInspectionService.getById(id); |
| | | // 查询诊所信息 |
| | | TCrmClinic crmClinic = crmClinicService.getById(sysInspection.getClinicId()); |
| | | if(Objects.isNull(crmClinic)){ |
| | | return R.fail("诊所信息不存在"); |
| | | } |
| | | Map<String, Object> templateParam = new HashMap<>(); |
| | | fill(templateParam, "clinicName", crmClinic.getClinicName()); |
| | | // 住院次数 |
| | | if(StringUtils.hasLength(sysInspection.getHospitalizationCount())){ |
| | | fill(templateParam, "hospitalizationCount", sysInspection.getHospitalizationCount()); |
| | | } |
| | | // 住院编号 |
| | | if(StringUtils.hasLength(sysInspection.getHospitalizationNumber())){ |
| | | fill(templateParam, "hospitalizationNumber", sysInspection.getHospitalizationNumber()); |
| | | } |
| | | // 姓名 |
| | | if(StringUtils.hasLength(sysInspection.getNickName())){ |
| | | fill(templateParam, "nickName", sysInspection.getNickName()); |
| | | } |
| | | // 出生地 |
| | | if(StringUtils.hasLength(sysInspection.getBirthplace())){ |
| | | fill(templateParam, "birthplace", sysInspection.getBirthplace()); |
| | | } |
| | | // 性别 |
| | | if(Objects.nonNull(sysInspection.getSex())){ |
| | | if(sysInspection.getSex() == 1){ |
| | | fill(templateParam, "sex", "男"); |
| | | }else{ |
| | | fill(templateParam, "sex", "女"); |
| | | } |
| | | } |
| | | // 民族 |
| | | if(StringUtils.hasLength(sysInspection.getNation())){ |
| | | fill(templateParam, "nation", sysInspection.getNation()); |
| | | } |
| | | // 年龄 |
| | | if(Objects.nonNull(sysInspection.getAge())){ |
| | | fill(templateParam, "age", sysInspection.getAge()); |
| | | } |
| | | // 入院日期 |
| | | if(StringUtils.hasLength(sysInspection.getAdmissionDate())){ |
| | | fill(templateParam, "admissionDate", sysInspection.getAdmissionDate()); |
| | | } |
| | | // 婚姻状况 |
| | | if(Objects.nonNull(sysInspection.getMaritalStatus())){ |
| | | fill(templateParam, "maritalStatus", sysInspection.getMaritalStatus()); |
| | | } |
| | | // 记录日期 |
| | | if(StringUtils.hasLength(sysInspection.getRecordDate())){ |
| | | fill(templateParam, "recordDate", sysInspection.getRecordDate()); |
| | | } |
| | | // 职业 |
| | | if(StringUtils.hasLength(sysInspection.getOccupation())){ |
| | | fill(templateParam, "occupation", sysInspection.getOccupation()); |
| | | } |
| | | // 病史陈述者 |
| | | if(StringUtils.hasLength(sysInspection.getHistoryNarrator())){ |
| | | fill(templateParam, "historyNarrator", sysInspection.getHistoryNarrator()); |
| | | } |
| | | // 主诉 |
| | | if(StringUtils.hasLength(sysInspection.getChiefComplaint())){ |
| | | fill(templateParam, "chiefComplaint", sysInspection.getChiefComplaint()); |
| | | } |
| | | // 现病史 |
| | | if(StringUtils.hasLength(sysInspection.getPresentHistory())){ |
| | | fill(templateParam, "presentHistory", sysInspection.getPresentHistory()); |
| | | } |
| | | // 既往史 |
| | | if(StringUtils.hasLength(sysInspection.getPastMedicalHistory())){ |
| | | fill(templateParam, "pastMedicalHistory", sysInspection.getPastMedicalHistory()); |
| | | } |
| | | // 月经史 |
| | | if(StringUtils.hasLength(sysInspection.getMenstrualHistory())){ |
| | | fill(templateParam, "menstrualHistory", sysInspection.getMenstrualHistory()); |
| | | } |
| | | // 婚育史 |
| | | if(StringUtils.hasLength(sysInspection.getObstetricHistory())){ |
| | | fill(templateParam, "obstetricHistory", sysInspection.getObstetricHistory()); |
| | | } |
| | | // 家族史 |
| | | if(StringUtils.hasLength(sysInspection.getFamilyHistory())){ |
| | | fill(templateParam, "familyHistory", sysInspection.getFamilyHistory()); |
| | | } |
| | | // 体温 |
| | | if(StringUtils.hasLength(sysInspection.getBodyTemperature())){ |
| | | fill(templateParam, "bodyTemperature", sysInspection.getBodyTemperature()); |
| | | } |
| | | // 脉搏 |
| | | if(StringUtils.hasLength(sysInspection.getPulse())){ |
| | | fill(templateParam, "pulse", sysInspection.getPulse()); |
| | | } |
| | | // 呼吸 |
| | | if(StringUtils.hasLength(sysInspection.getBreathe())){ |
| | | fill(templateParam, "breathe", sysInspection.getBreathe()); |
| | | } |
| | | // 血压 |
| | | if(StringUtils.hasLength(sysInspection.getBloodPressure())){ |
| | | fill(templateParam, "bloodPressure", sysInspection.getBloodPressure()); |
| | | } |
| | | // 一般情况 |
| | | if(StringUtils.hasLength(sysInspection.getGeneralSituation())){ |
| | | fill(templateParam, "generalSituation", sysInspection.getGeneralSituation()); |
| | | } |
| | | |
| | | String url = wordUtil.generatePdf( |
| | | "/usr/local/project/template/", |
| | | "病历-样例.docx", |
| | | templateParam, |
| | | "病历-"+sysInspection.getNickName(), |
| | | "/usr/local/project/template/"); |
| | | // windows |
| | | // String url = wordUtil.generatePdf( |
| | | // "E:\\WXWork\\1688857451467088\\Cache\\File\\2026-01\\", |
| | | // "病历-样例.docx", |
| | | // templateParam, |
| | | // "病历-样例-temp", |
| | | // "E:\\WXWork\\1688857451467088\\Cache\\File\\2026-01\\"); |
| | | return R.ok(url); |
| | | } |
| | | |
| | | @Log(title = "用户检测信息管理信息-导出处方信息", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "导出处方信息") |
| | | @GetMapping(value = "/exportPrescription") |
| | | public R<String> exportPrescription(@RequestParam String id) { |
| | | TSysInspection sysInspection = sysInspectionService.getById(id); |
| | | // 查询诊所信息 |
| | | TCrmClinic crmClinic = crmClinicService.getById(sysInspection.getClinicId()); |
| | | if(Objects.isNull(crmClinic)){ |
| | | return R.fail("诊所信息不存在"); |
| | | } |
| | | Map<String, Object> templateParam = new HashMap<>(); |
| | | fill(templateParam, "clinicName", crmClinic.getClinicName()); |
| | | // 住院编号 |
| | | if(StringUtils.hasLength(sysInspection.getPrescriptionNumber())){ |
| | | fill(templateParam, "prescriptionNumber", sysInspection.getPrescriptionNumber()); |
| | | } |
| | | // 科室 |
| | | if(StringUtils.hasLength(sysInspection.getDepartmentName())){ |
| | | fill(templateParam, "departmentName", sysInspection.getDepartmentName()); |
| | | } |
| | | // 处方时间 |
| | | if(StringUtils.hasLength(sysInspection.getPrescriptionTime())){ |
| | | fill(templateParam, "prescriptionTime", sysInspection.getPrescriptionTime()); |
| | | } |
| | | // 姓名 |
| | | if(StringUtils.hasLength(sysInspection.getNickName())){ |
| | | fill(templateParam, "nickName", sysInspection.getNickName()); |
| | | } |
| | | // 性别 |
| | | if(Objects.nonNull(sysInspection.getSex())){ |
| | | if(sysInspection.getSex() == 1){ |
| | | fill(templateParam, "sex", "男"); |
| | | }else{ |
| | | fill(templateParam, "sex", "女"); |
| | | } |
| | | } |
| | | // 年龄 |
| | | if(Objects.nonNull(sysInspection.getAge())){ |
| | | fill(templateParam, "age", sysInspection.getAge()); |
| | | } |
| | | // 门诊病历号 |
| | | if(StringUtils.hasLength(sysInspection.getId())){ |
| | | fill(templateParam, "id", sysInspection.getId()); |
| | | } |
| | | // 单位或家庭住址 |
| | | if(Objects.nonNull(sysInspection.getHomeAddress())){ |
| | | fill(templateParam, "homeAddress", sysInspection.getHomeAddress()); |
| | | } |
| | | // 临床诊断及证型 |
| | | if(StringUtils.hasLength(sysInspection.getClinicalDiagnosis())){ |
| | | fill(templateParam, "clinicalDiagnosis", sysInspection.getClinicalDiagnosis()); |
| | | } |
| | | // 处方内容 |
| | | if(StringUtils.hasLength(sysInspection.getPrescriptionContent())){ |
| | | fill(templateParam, "prescriptionContent", sysInspection.getPrescriptionContent()); |
| | | } |
| | | // 备注 |
| | | if(StringUtils.hasLength(sysInspection.getRemarks())){ |
| | | fill(templateParam, "remarks", sysInspection.getRemarks()); |
| | | } |
| | | |
| | | String url = wordUtil.generatePdf( |
| | | "/usr/local/project/template/", |
| | | "处方单-样例.docx", |
| | | templateParam, |
| | | "处方单-"+sysInspection.getNickName(), |
| | | "/usr/local/project/template/"); |
| | | // windows |
| | | // String url = wordUtil.generatePdf( |
| | | // "E:\\WXWork\\1688857451467088\\Cache\\File\\2026-01\\", |
| | | // "处方单-样例.docx", |
| | | // templateParam, |
| | | // "处方单-样例-temp", |
| | | // "E:\\WXWork\\1688857451467088\\Cache\\File\\2026-01\\"); |
| | | return R.ok(url); |
| | | } |
| | | |
| | | private void fill(Map<String, Object> templateParam, String key, Object value) { |
| | | if (com.ruoyi.common.utils.StringUtils.isEmpty(key)){ |
| | | throw new RuntimeException("key不能为空"); |
| | | } |
| | | templateParam.put("${"+key+"}", value != null ? value : ""); |
| | | } |
| | | |
| | | } |
| | | |