浏览代码

设备首绑更新发放医生;康复计划代码优化

zd_123 7 年之前
父节点
当前提交
1e89f87f44

+ 195 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/specialist/rehabilitation/RehabilitationPlanService.java

@ -0,0 +1,195 @@
package com.yihu.wlyy.service.specialist.rehabilitation;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.specialist.SpecialistEvaluateSevice;
import com.yihu.wlyy.util.http.HttpResponse;
import com.yihu.wlyy.util.http.HttpUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
/**
 * Created by humingfen on 2018/8/22.
 */
@Service
@Transactional
public class RehabilitationPlanService extends BaseService {
    @Value("${specialist.url}")
    private String specialistUrl;
    @Autowired
    private AdminTeamService teamService;
    @Autowired
    private SpecialistEvaluateSevice specialistEvaluateSevice;
    public JSONArray findTemplateInfo(String doctor, String patient) throws Exception {
        Map<String, Object> param = new HashedMap();
        Long adminTeamId = null;
        AdminTeam team = teamService.findByLeaderCode(doctor);
        if(StringUtils.isBlank(patient)){
            adminTeamId = team.getId();
            param.put("adminTeamCode", adminTeamId);
        }else {
            param.put("doctor", doctor);
            param.put("patient", patient);
        }
        HttpResponse response = null;
        try {
            response = HttpUtils.doGet(specialistUrl + "svr-specialist/findRehabilitationPlanTemplate", param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject rs = new JSONObject(response.getContent());
        if ("success".equals(rs.getString("message"))) {
            return rs.getJSONArray("detailModelList");
        }
        throw new Exception("请求获取模板列表失败!");
    }
    public JSONArray findTemplateDetailInfo(String templateId) throws Exception {
        Map<String, Object> param = new HashedMap();
        param.put("templateId", templateId);
        HttpResponse response = null;
        try {
            response = HttpUtils.doGet(specialistUrl + "svr-specialist/findTemplateDetailByTemplateId", param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject rs = new JSONObject(response.getContent());
        if (rs.getInt("status") == 200) {
            return rs.getJSONArray("detailModelList");
        }
        throw new Exception("请求获取模板明细列表失败!");
    }
    public String createTemplate(String title, Doctor doctor, Long teamId) throws Exception {
        JSONObject json = new JSONObject();
        json.put("title", title);
        json.put("adminTeamCode", teamId);
        json.put("hospital", doctor.getHospital());
        json.put("hospitalName", doctor.getHospitalName());
        json.put("createUser", doctor.getCode());
        json.put("createUserName", doctor.getName());
        Map<String, Object> param = new HashedMap();
        param.put("rehabilitationTemplate", json.toString());
        HttpResponse response = null;
        try {
            response = HttpUtils.doPost(specialistUrl + "svr-specialist/createRehabilitationPlanTemplate", param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject rs = new JSONObject(response.getContent());
        if ("success".equals(rs.getString("message"))) {
            return rs.getString("obj");
        }
        return rs.getString("message");
    }
    public String createTemplateDetail(String json, String type, Doctor doctor) {
        JSONObject object = new JSONObject(json);
        JSONArray details = new JSONArray();
        String templateId = object.get("templateId").toString();
        String hospitalServiceItemIds = object.get("hospitalServiceItemId").toString();
        if(hospitalServiceItemIds.contains(",")) {
            String [] itemIds = hospitalServiceItemIds.split(",");
            int len = itemIds.length;
            while (len > 0){
                len --;
                JSONObject j = new JSONObject();
                j.put("templateId", templateId);
                j.put("hospitalServiceItemId", itemIds[len]);
                j.put("createUser", doctor.getCode());
                j.put("createUserName", doctor.getName());
                details.put(len, j);
            }
        }else {
            object.put("createUser", doctor.getCode());
            object.put("createUserName", doctor.getName());
            details.put(object);
        }
        Map<String, Object> param = new HashedMap();
        param.put("rehabilitationTemplateDetail", details.toString());
        HttpResponse response = null;
        try {
            if(type.equals("create")) {
                response = HttpUtils.doPost(specialistUrl + "svr-specialist/createRehabilitationTemplateDetail", param);
            }else if(type.equals("edit")) {
                response = HttpUtils.doPost(specialistUrl + "svr-specialist/updateRehabilitationTemplateDetail", param);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject rs = new JSONObject(response.getContent());
        return rs.getString("message");
    }
    public String createRehabilitationPlan(String json, Doctor doctor) {
        JSONObject object = new JSONObject(json);
        String patient = object.getString("patient");
        object.put("createUser", doctor.getCode());
        object.put("createUserName", doctor.getName());
        Map<String, Object> param = new HashedMap();
        param.put("rehabilitationPlan", object.toString());
        HttpResponse response = null;
        try {
            response = HttpUtils.doPost(specialistUrl + "svr-specialist/createPatientRehabilitationPlan", param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject rs = new JSONObject(response.getContent());
        JSONArray detailModelList = (JSONArray) rs.get("detailModelList");
        //康复计划创建完给执行者发送消息
        for (Object obj : detailModelList){
            JSONObject detail = (JSONObject) obj;
            Message message = new Message();
            message.setSender(doctor.getCode());
            message.setType(19);
            message.setRelationCode(detail.getString("planId"));
            message.setReceiver(detail.getString("doctor"));
            specialistEvaluateSevice.sendMessage(message, detail.getString("hospital"), patient,null);
        }
        return rs.getString("message");
    }
    public String deleteTemplate(String templateId) {
        Map<String, Object> param = new HashedMap();
        param.put("id", templateId);
        HttpResponse response = null;
        try {
            response = HttpUtils.doPost(specialistUrl + "svr-specialist/deleteRehabilitationPlanTemplate", param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject rs = new JSONObject(response.getContent());
        return rs.getString("message");
    }
    /**
     * 更新计划的状态
     * @param planId
     * @param status
     * @throws Exception
     */
    public void updatePlanStatusById(String planId, Integer status) throws Exception{
        Map<String, Object> param = new HashedMap();
        param.put("planId", planId);
        param.put("status", status);
        HttpResponse response = HttpUtils.doPost(specialistUrl + "svr-specialist/updatePlanStatusById", param);
        JSONObject result = new JSONObject(response.getContent());
        if(result.getInt("status")!=200){
            throw new Exception("请求微服务失败!");
        }
    }
}

+ 133 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/specialist/rehabilitation/DoctorRehabilitationPlanController.java

@ -0,0 +1,133 @@
package com.yihu.wlyy.web.doctor.specialist.rehabilitation;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.common.account.DoctorService;
import com.yihu.wlyy.service.specialist.rehabilitation.RehabilitationPlanService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by humingfen on 2018/8/22.
 */
@RestController
@RequestMapping(value = "/doctor/specialist/rehabilitationPlan",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "医生端-康复服务套餐管理")
public class DoctorRehabilitationPlanController extends BaseController {
    @Autowired
    private RehabilitationPlanService rehabilitationPlanService;
    @Autowired
    private AdminTeamService teamService;
    @Autowired
    private DoctorService doctorService;
    @RequestMapping(value = "/findTemplateList", method = RequestMethod.GET)
    @ApiOperation(value = "获取康复服务套餐模板列表")
    public String templateList(@ApiParam(name = "doctor", value = "医生标识")
                               @RequestParam(required = false)String doctor,
                               @ApiParam(name = "patient", value = "居民标识")
                               @RequestParam(required = false)String patient){
        try {
            if(!StringUtils.isNotBlank(doctor)){
                doctor = getUID();
            }
            return write(200, "获取成功", "data", rehabilitationPlanService.findTemplateInfo(doctor, patient));
        } catch (Exception e) {
            error(e);
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "/findTemplateDetail", method = RequestMethod.GET)
    @ApiOperation(value = "获取康复服务套餐模板明细")
    public String findTemplateDetail(@ApiParam(name = "templateId", value = "模板id")
                                     @RequestParam(required = true)String templateId){
        try {
            return write(200, "获取成功", "data", rehabilitationPlanService.findTemplateDetailInfo(templateId));
        } catch (Exception e) {
            error(e);
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "/createTemplate", method = RequestMethod.POST)
    @ApiOperation(value = "创建康复服务套餐模板")
    public String createTemplate(@ApiParam(name = "doctor", value = "医生标识")
                                 @RequestParam(required = false)String doctor,
                                 @ApiParam(name = "title", value = "康复服务模板名称")
                                 @RequestParam(required = true) String title){
        try {
            if(!StringUtils.isNotBlank(doctor)){
                doctor = getUID();
            }
            AdminTeam team = teamService.findByLeaderCode(doctor);
            Doctor d = doctorService.findDoctorByCode(doctor);
            return write(200, "获取成功", "data", rehabilitationPlanService.createTemplate(title,d,team.getId()));
        } catch (Exception e) {
            error(e);
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "/createTemplateDetail", method = RequestMethod.POST)
    @ApiOperation(value = "创建康复服务套餐模板明细")
    public String createTemplateDetail(@ApiParam(name = "doctor", value = "医生标识")
                                       @RequestParam(required = false)String doctor,
                                       @ApiParam(name = "json", value = "康复服务模板明细")
                                       @RequestParam(required = true) String json,
                                       @ApiParam(name = "type", value = "create或者edit")
                                       @RequestParam(required = true) String type){
        try {
            if(!StringUtils.isNotBlank(doctor)){
                doctor = getUID();
            }
            Doctor d = doctorService.findDoctorByCode(doctor);
            return write(200, "获取成功", "data", rehabilitationPlanService.createTemplateDetail(json, type, d));
        } catch (Exception e) {
            error(e);
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "/deleteTemplate", method = RequestMethod.POST)
    @ApiOperation(value = "删除康复服务套餐模板")
    public String deleteTemplate(@ApiParam(name = "templateId", value = "模板id")
                                 @RequestParam(required = true)String templateId){
        try {
            return write(200, "获取成功", "data", rehabilitationPlanService.deleteTemplate(templateId));
        } catch (Exception e) {
            error(e);
            return error(-1, "请求失败");
        }
    }
    @RequestMapping(value = "/createRehabilitationPlan", method = RequestMethod.POST)
    @ApiOperation(value = "创建居民康复计划")
    public String createRehabilitationPlan(@ApiParam(name = "doctor", value = "医生标识")
                                           @RequestParam(required = false)String doctor,
                                           @ApiParam(name = "json", value = "康复计划json")
                                           @RequestParam(required = true) String json){
        try {
            if(!StringUtils.isNotBlank(doctor)){
                doctor = getUID();
            }
            Doctor d = doctorService.findDoctorByCode(doctor);
            return write(200, "获取成功", "data", rehabilitationPlanService.createRehabilitationPlan(json,d));
        } catch (Exception e) {
            error(e);
            return error(-1, "请求失败");
        }
    }
}