浏览代码

增加团队医生删除逻辑判断

Sand 8 年之前
父节点
当前提交
23f91a7703

+ 2 - 0
src/main/java/com/yihu/wlyy/repository/doctor/DoctorAdminTeamDao.java

@ -69,4 +69,6 @@ public interface DoctorAdminTeamDao extends
    @Query("SELECT t.id from AdminTeam t WHERE t.leaderCode = :leaderCode")
    Long findIdByLeaderCode(@Param("leaderCode") String leaderCode);
}

+ 12 - 1
src/main/java/com/yihu/wlyy/repository/doctor/DoctorTeamMemberDao.java

@ -5,8 +5,10 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.function.BooleanSupplier;
/**
 * Created by Administrator on 2016/7/30.
@ -44,7 +46,16 @@ public interface DoctorTeamMemberDao extends PagingAndSortingRepository<DoctorTe
    List<DoctorTeamMember> findByTeamAndDel(String team, String del);
    @Query(" FROM DoctorTeamMember a WHERE a.team =?1 and  a.del='1' and  a.signType='2' and  a.memberCode=?2 ")
    DoctorTeamMember findMemberByTeamAndCode(String teamCode, String oldDoctorCode);
    /**
     * 判断医生是否为三师签团队的成员。
     *
     * @param doctorCode
     * @return
     */
    @Query("SELECT case when count(a) > 0 THEN true else false END FROM DoctorTeamMember a WHERE a.signType = 1 AND a" +
            ".memberCode = :memberCode")
    Boolean isSanShiSigning(@Param(":memberCode") String doctorCode);
}

+ 0 - 3
src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -30,7 +30,6 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
	@Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status >= 1")
	SignFamily findByPatientAndType(String patient,int type);
	SignFamily findByCode(String code);
	SignFamily findByFamilyCode(String familyCode);
@ -59,14 +58,12 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
	@Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status >= 0")
	SignFamily findByIdcard(String idcard);
	@Query("select a from SignFamily a where a.idcard = ?1 and a.type =1 and a.status >= 0")
	SignFamily findSSByIdcard(String idcard);
	@Query("select a from SignFamily a where a.idcard = ?1 ")
	List<SignFamily> findAllByIdcard(String idcard);
	@Query("select a from SignFamily a where a.idcard = ?1 and a.status >= 0")
	List<SignFamily> findSSandJTByIdcard(String idcard);

+ 35 - 4
src/main/java/com/yihu/wlyy/service/app/team/AdminTeamService.java

@ -6,7 +6,10 @@ import com.yihu.wlyy.entity.doctor.team.admin.AdminTeamMember;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
import com.yihu.wlyy.repository.doctor.DoctorAdminTeamMemberDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.DoctorTeamMemberDao;
import com.yihu.wlyy.service.BaseService;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
@ -26,12 +29,18 @@ import java.util.*;
@Component
@Transactional
public class AdminTeamService extends BaseService {
    @Autowired
    DoctorDao doctorDao;
    @Autowired
    DoctorAdminTeamDao teamDao;
    @Autowired
    DoctorAdminTeamMemberDao memberDao;
    @Autowired
    DoctorTeamMemberDao signingTeamMemberDao;
    /**
     * 获取团队数量。
     *
@ -150,18 +159,40 @@ public class AdminTeamService extends BaseService {
    }
    /**
     * 移除成员。
     * <p>
     * 如果成员已经有跟团队内的某医生合作与患者签约,那么不能移除,必须等签约患者交接后才可以。
     * 移除成员逻辑:
     * 1、判断团队内是否有三师签约关系,如果有不能删除。
     * 2、若没有三师签约关系,判断是否为专科医生,如果是,直接删除
     * 3、若不是,则判断健康管理师或全科医生是否有签约人,有的话提示先转移居民。
     *
     * @param teamId
     * @param doctorCode
     */
    public Pair<Integer, String> removeMember(long teamId, String doctorCode) {
        if(signingTeamMemberDao.isSanShiSigning(doctorCode)){
            return new ImmutablePair<>(403, "三师签约医生,不能删除");
        }
        Doctor doctor = doctorDao.findByCode(doctorCode);
        if (!doctor.isProfessionalDoctor()){
            if (doctor.isGeneralDoctor()){
                List<Doctor> doctorList = new ArrayList<>();
                doctorList.add(doctor);
                Integer count = getMemberSigningCount(teamId, doctorList).get(doctorCode);
                if (count != null || count > 0){
                    if (doctor.isGeneralDoctor()){
                        return new ImmutablePair<>(403, "全科医生有签约关系,不可删除");
                    } else if (doctor.isHealthDoctor()){
                        return new ImmutablePair<>(403, "健康管理师仍有签约居民,请先转移签约居民");
                    }
                }
            }
        }
        AdminTeamMember member = memberDao.findByTeamIdAndDoctorCodeOrderByDoctorCodeAsc(teamId, doctorCode);
        if (member != null) memberDao.delete(member);
        return null;
        return new ImmutablePair<>(200, "OK");
    }
    public List<Doctor> getMembers(long teamId) {