@ -7,6 +7,8 @@ import com.xinelu.common.constant.RouteNodeNameConstants;
import com.xinelu.common.constant.TaskContentConstants ;
import com.xinelu.common.constant.TaskCreateTypeConstant ;
import com.xinelu.common.constant.TemplateTypeConstants ;
import com.xinelu.common.constant.TriggerConditionOperatorConstants ;
import com.xinelu.common.constant.TriggerLogicConstants ;
import com.xinelu.common.constant.VisitMethodConstants ;
import com.xinelu.common.enums.NodeExecuteStatusEnum ;
import com.xinelu.common.enums.RouteCheckStatusEnum ;
@ -14,6 +16,7 @@ import com.xinelu.common.exception.ServiceException;
import com.xinelu.common.utils.SecurityUtils ;
import com.xinelu.common.utils.StringUtils ;
import com.xinelu.common.utils.bean.BeanUtils ;
import com.xinelu.manage.domain.patientinfo.PatientAllInfoViewUppercase ;
import com.xinelu.manage.domain.patientinfo.PatientInfo ;
import com.xinelu.manage.domain.patientnodeparamscurrent.PatientNodeParamsCurrent ;
import com.xinelu.manage.domain.patientvisitrecord.PatientVisitRecord ;
@ -22,6 +25,7 @@ import com.xinelu.manage.domain.signpatientmanageroute.SignPatientManageRoute;
import com.xinelu.manage.domain.signpatientmanageroutenode.SignPatientManageRouteNode ;
import com.xinelu.manage.domain.signpatientrecord.SignPatientRecord ;
import com.xinelu.manage.domain.specialdiseasenode.SpecialDiseaseNode ;
import com.xinelu.manage.domain.specialdiseaseroute.SpecialDiseaseRoute ;
import com.xinelu.manage.domain.specialdiseasetriggercondition.SpecialDiseaseTriggerCondition ;
import com.xinelu.manage.domain.textmessage.TextMessage ;
import com.xinelu.manage.domain.wechattemplate.WechatTemplate ;
@ -31,6 +35,7 @@ import com.xinelu.manage.dto.signpatientmanageroutenode.PatientTaskDto;
import com.xinelu.manage.dto.signpatientmanageroutenode.RouteNodeCheckDto ;
import com.xinelu.manage.dto.signpatientmanageroutenode.SignPatientManageRouteNodeDto ;
import com.xinelu.manage.mapper.labelfieldcontent.LabelFieldContentMapper ;
import com.xinelu.manage.mapper.patientinfo.PatientAllInfoViewMapper ;
import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper ;
import com.xinelu.manage.mapper.patientvisitrecord.PatientVisitRecordMapper ;
import com.xinelu.manage.mapper.scriptInfo.ScriptInfoMapper ;
@ -38,6 +43,7 @@ import com.xinelu.manage.mapper.signpatientmanageroute.SignPatientManageRouteMap
import com.xinelu.manage.mapper.signpatientmanageroutenode.SignPatientManageRouteNodeMapper ;
import com.xinelu.manage.mapper.signpatientrecord.SignPatientRecordMapper ;
import com.xinelu.manage.mapper.specialdiseasenode.SpecialDiseaseNodeMapper ;
import com.xinelu.manage.mapper.specialdiseaseroute.SpecialDiseaseRouteMapper ;
import com.xinelu.manage.mapper.specialdiseasetriggercondition.SpecialDiseaseTriggerConditionMapper ;
import com.xinelu.manage.mapper.textmessage.TextMessageMapper ;
import com.xinelu.manage.mapper.wechattemplate.WechatTemplateMapper ;
@ -56,6 +62,8 @@ import com.xinelu.manage.vo.signpatientmanageroutenode.SignPatientManageRouteNod
import com.xinelu.manage.vo.signpatientmanageroutenode.SignPatientManageRouteNodeVo ;
import com.xinelu.manage.vo.specialdiseasenode.PatientSpecialDiseaseNodeVo ;
import com.xinelu.manage.vo.specialdiseaseroute.SpecialDiseaseRouteVO ;
import java.lang.reflect.Field ;
import java.math.BigDecimal ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.util.ArrayList ;
@ -113,6 +121,10 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
private LabelFieldContentMapper labelFieldContentMapper ;
@Resource
private WechatTemplateMapper wechatTemplateMapper ;
@Resource
private PatientAllInfoViewMapper patientAllInfoViewMapper ;
@Resource
private SpecialDiseaseRouteMapper specialDiseaseRouteMapper ;
/ * *
* 查询签约患者管理任务路径节点
@ -596,7 +608,7 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
}
@Override public void generateMainRouteTask ( Long signRecordId ) {
List < SignPatientManageRouteNode > nodeSaveList = new ArrayList < > ( ) ;
/ / 查询专病路径节点和手动创建的任务节点
SignPatientRecord signPatientRecord = signPatientRecordMapper . selectByPrimaryKey ( signRecordId ) ;
if ( ObjectUtils . isEmpty ( signPatientRecord ) ) {
@ -610,12 +622,163 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
throw new ServiceException ( " 未找到签约管理路径 " ) ;
}
SignPatientManageRoute signPatientManageRoute = manageRouteList . get ( 0 ) ;
generateByManageRoute ( signPatientManageRoute , signPatientRecord . getPatientId ( ) ) ;
}
@Override
public void manualCreateTaskLabelReplace ( Long signRecordId ) {
SignPatientManageRoute manageRouteQuery = new SignPatientManageRoute ( ) ;
manageRouteQuery . setSignPatientRecordId ( signRecordId ) ;
manageRouteQuery . setTaskCreateType ( TaskCreateTypeConstant . MANUAL_CREATE ) ;
List < SignPatientManageRoute > manageRouteList = signRouteMapper . selectSignPatientManageRouteList ( manageRouteQuery ) ;
if ( CollectionUtils . isNotEmpty ( manageRouteList ) ) {
/ / 查询患者画像信息
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( manageRouteList . get ( 0 ) . getPatientId ( ) ) ;
if ( CollectionUtils . isEmpty ( labelFieldContentList ) ) {
throw new ServiceException ( " 请先维护画像信息 " ) ;
}
List < Long > manageRouteIds = manageRouteList . stream ( ) . map ( SignPatientManageRoute : : getId ) . collect ( Collectors . toList ( ) ) ;
List < SignPatientManageRouteNode > manageNodeList = signPatientManageRouteNodeMapper . selectNodesByManageIds ( manageRouteIds ) ;
/ / 根据node去替换模板信息
manageNodeList . forEach ( manageNode - > {
switch ( manageNode . getTaskType ( ) ) {
/ / 电话外呼 - - 话术
case TaskContentConstants . PHONE_OUTBOUND :
ScriptInfo scriptInfo = scriptInfoMapper . selectScriptInfoById ( manageNode . getPhoneId ( ) ) ;
if ( ObjectUtils . isNotEmpty ( scriptInfo ) ) {
/ / 话术库json内容替换
manageNode . setPhoneNodeContent ( getFlowScheme ( scriptInfo . getFlowScheme ( ) , labelFieldContentList ) ) ;
/ / 电话短信内容
if ( manageNode . getPhoneMessageTemplateId ( ) ! = null ) {
/ / 查询短信库
manageNode . setPhoneMessageTemplateContent ( replaceMessageInfo ( manageNode . getPhoneMessageTemplateId ( ) , labelFieldContentList ) ) ;
}
}
break ;
/ / 问卷
case TaskContentConstants . QUESTIONNAIRE_SCALE :
/ / 宣教
case TaskContentConstants . PROPAGANDA_ARTICLE :
/ / 文字提醒
case TaskContentConstants . TEXT_REMIND :
/ / 人工随访
case TaskContentConstants . ARTIFICIAL_FOLLOW_UP :
break ;
}
signPatientManageRouteNodeMapper . updateSignPatientManageRouteNode ( manageNode ) ;
} ) ;
}
}
/ * *
* 生成子路径任务
* @param patientId 患者主键
* @param signPatientRecordId 签约记录主键
* @param specialDiseaseRouteId 专病管理路径路径id
* /
@Transactional ( rollbackFor = Exception . class )
public void generateChildRouteTask ( Long patientId , Long signPatientRecordId , Long specialDiseaseRouteId ) {
boolean generateTask = false ;
/ / 查询患者信息
PatientAllInfoViewUppercase patientAllInfo = null ;
List < PatientAllInfoViewUppercase > patientAllInfoViewList = patientAllInfoViewMapper . selectPatientAllInfoListViewByPatientId ( patientId ) ;
if ( CollectionUtils . isNotEmpty ( patientAllInfoViewList ) ) {
patientAllInfo = patientAllInfoViewList . get ( 0 ) ;
}
/ / 查询画像信息
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( patientId ) ;
/ / 查询子路径触发条件
SpecialDiseaseTriggerCondition triggerConditionQuery = new SpecialDiseaseTriggerCondition ( ) ;
triggerConditionQuery . setRouteId ( specialDiseaseRouteId ) ;
List < SpecialDiseaseTriggerCondition > triggerConditionList = triggerConditionMapper . selectSpecialDiseaseTriggerConditionList ( triggerConditionQuery ) ;
/ / 判断触发条件是否成立
if ( CollectionUtils . isNotEmpty ( triggerConditionList ) ) {
boolean condition1 = judgeTriggerCondition ( triggerConditionList . get ( 0 ) , patientAllInfo , labelFieldContentList ) ;
if ( condition1 ) {
/ / 条件1成立 , 继续判断条件2 , 3
if ( triggerConditionList . size ( ) > 1 ) {
boolean condition2 = judgeTriggerCondition ( triggerConditionList . get ( 1 ) , patientAllInfo , labelFieldContentList ) ;
if ( condition2 ) {
/ / 条件2成立 , 判断2 、 3的逻辑连接符 , or : 则不判断3 , and : 需要判断3
if ( triggerConditionList . size ( ) > 2 ) {
boolean judgetCondition3 = true ;
switch ( triggerConditionList . get ( 2 ) . getTriggerLogic ( ) ) {
case TriggerLogicConstants . AND :
judgetCondition3 = true ;
break ;
case TriggerLogicConstants . OR :
judgetCondition3 = false ;
break ;
}
if ( judgetCondition3 ) {
boolean condition3 = judgeTriggerCondition ( triggerConditionList . get ( 2 ) , patientAllInfo , labelFieldContentList ) ;
if ( condition3 ) {
/ / 3成立 , 则生成任务
generateTask = true ;
}
}
}
} else {
/ / 条件2不成立 , 判断2 、 3的逻辑连接符 , or : 判断3 , and : 不判断3
if ( triggerConditionList . size ( ) > 2 ) {
boolean judgetCondition3 = false ;
switch ( triggerConditionList . get ( 2 ) . getTriggerLogic ( ) ) {
case TriggerLogicConstants . AND :
judgetCondition3 = false ;
break ;
case TriggerLogicConstants . OR :
judgetCondition3 = true ;
break ;
}
if ( judgetCondition3 ) {
boolean condition3 = judgeTriggerCondition ( triggerConditionList . get ( 2 ) , patientAllInfo , labelFieldContentList ) ;
if ( condition3 ) {
/ / 3成立 , 则生成任务
generateTask = true ;
}
}
}
}
} else {
/ / 只有1个条件且成立 , 生成任务
generateTask = true ;
}
}
}
if ( generateTask ) {
/ / 保存sign_patient_manage_route表
SpecialDiseaseRoute specialDiseaseRoute = specialDiseaseRouteMapper . selectSpecialDiseaseRouteById ( specialDiseaseRouteId ) ;
SignPatientManageRoute signPatientManageRoute = new SignPatientManageRoute ( ) ;
BeanUtils . copyBeanProp ( signPatientManageRoute , specialDiseaseRoute ) ;
signPatientManageRoute . setSignPatientRecordId ( signPatientRecordId ) ;
signPatientManageRoute . setPatientId ( patientId ) ;
signPatientManageRoute . setId ( null ) ;
signPatientManageRoute . setRouteId ( specialDiseaseRoute . getId ( ) ) ;
signPatientManageRoute . setTaskCreateType ( TaskCreateTypeConstant . MANUAL_MATCHE ) ;
signPatientManageRoute . setCreateTime ( LocalDateTime . now ( ) ) ;
signPatientManageRoute . setCreateBy ( SecurityUtils . getLoginUser ( ) . getUser ( ) . getNickName ( ) ) ;
signRouteMapper . insertSignPatientManageRoute ( signPatientManageRoute ) ;
/ / 保存任务
generateByManageRoute ( signPatientManageRoute , patientId ) ;
}
}
/ * *
* 根据管理路径生成任务
* @param signPatientManageRoute 签约管理路径
* @param patientId 患者主键
* /
private void generateByManageRoute ( SignPatientManageRoute signPatientManageRoute , Long patientId ) {
List < SignPatientManageRouteNode > nodeSaveList = new ArrayList < > ( ) ;
/ / 查询路径节点
SpecialDiseaseNode specialDiseaseNodeQuery = new SpecialDiseaseNode ( ) ;
specialDiseaseNodeQuery . setRouteId ( signPatientManageRoute . getRouteId ( ) ) ;
List < SpecialDiseaseNode > nodeList = specialDiseaseNodeMapper . selectSpecialDiseaseNodeList ( specialDiseaseNodeQuery ) ;
/ / 查询患者画像信息
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( signPatientRecord . getPatientId ( ) ) ;
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( patientId ) ;
if ( CollectionUtils . isEmpty ( labelFieldContentList ) ) {
throw new ServiceException ( " 请先维护画像信息 " ) ;
}
@ -675,66 +838,6 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
} ) ;
}
@Override
public void manualCreateTaskLabelReplace ( Long signRecordId ) {
SignPatientManageRoute manageRouteQuery = new SignPatientManageRoute ( ) ;
manageRouteQuery . setSignPatientRecordId ( signRecordId ) ;
manageRouteQuery . setTaskCreateType ( TaskCreateTypeConstant . MANUAL_CREATE ) ;
List < SignPatientManageRoute > manageRouteList = signRouteMapper . selectSignPatientManageRouteList ( manageRouteQuery ) ;
if ( CollectionUtils . isNotEmpty ( manageRouteList ) ) {
/ / 查询患者画像信息
List < LabelFieldInfoContentVo > labelFieldContentList = labelFieldContentMapper . selectByPatientId ( manageRouteList . get ( 0 ) . getPatientId ( ) ) ;
if ( CollectionUtils . isEmpty ( labelFieldContentList ) ) {
throw new ServiceException ( " 请先维护画像信息 " ) ;
}
List < Long > manageRouteIds = manageRouteList . stream ( ) . map ( SignPatientManageRoute : : getId ) . collect ( Collectors . toList ( ) ) ;
List < SignPatientManageRouteNode > manageNodeList = signPatientManageRouteNodeMapper . selectNodesByManageIds ( manageRouteIds ) ;
/ / 根据node去替换模板信息
manageNodeList . forEach ( manageNode - > {
switch ( manageNode . getTaskType ( ) ) {
/ / 电话外呼 - - 话术
case TaskContentConstants . PHONE_OUTBOUND :
ScriptInfo scriptInfo = scriptInfoMapper . selectScriptInfoById ( manageNode . getPhoneId ( ) ) ;
if ( ObjectUtils . isNotEmpty ( scriptInfo ) ) {
/ / 话术库json内容替换
manageNode . setPhoneNodeContent ( getFlowScheme ( scriptInfo . getFlowScheme ( ) , labelFieldContentList ) ) ;
/ / 电话短信内容
if ( manageNode . getPhoneMessageTemplateId ( ) ! = null ) {
/ / 查询短信库
manageNode . setPhoneMessageTemplateContent ( replaceMessageInfo ( manageNode . getPhoneMessageTemplateId ( ) , labelFieldContentList ) ) ;
}
}
break ;
/ / 问卷
case TaskContentConstants . QUESTIONNAIRE_SCALE :
/ / 宣教
case TaskContentConstants . PROPAGANDA_ARTICLE :
/ / 文字提醒
case TaskContentConstants . TEXT_REMIND :
/ / 人工随访
case TaskContentConstants . ARTIFICIAL_FOLLOW_UP :
break ;
}
signPatientManageRouteNodeMapper . updateSignPatientManageRouteNode ( manageNode ) ;
} ) ;
}
}
/ * *
* 生成子路径任务
* @param patientId 患者主键
* @param routeId 子路径id
* @param routeNodeId 节点id
* /
private void generateChildRouteTask ( Long patientId , Long routeId , Long routeNodeId ) {
/ / 查询子路径触发条件
SpecialDiseaseTriggerCondition triggerConditionQuery = new SpecialDiseaseTriggerCondition ( ) ;
triggerConditionQuery . setRouteId ( routeId ) ;
List < SpecialDiseaseTriggerCondition > triggerConditionList = triggerConditionMapper . selectSpecialDiseaseTriggerConditionList ( triggerConditionQuery ) ;
}
private String replaceNodeContent ( String nodeContent , List < PatientNodeParamsCurrent > paramsList ) {
Map < String , String > map = paramsList . stream ( ) . collect ( Collectors . toMap ( PatientNodeParamsCurrent : : getParamKey , PatientNodeParamsCurrent : : getParamValue , ( key1 , key2 ) - > key2 ) ) ;
Document document = Jsoup . parse ( nodeContent ) ;
@ -874,4 +977,65 @@ public class SignPatientManageRouteNodeServiceImpl implements ISignPatientManage
return manageNodeList ;
}
private boolean judgeTriggerCondition ( SpecialDiseaseTriggerCondition triggerCondition , PatientAllInfoViewUppercase patientAllInfo , List < LabelFieldInfoContentVo > labelFieldContentList ) {
List < String > labelValueList = new ArrayList < > ( ) ;
if ( ObjectUtils . isNotEmpty ( patientAllInfo ) ) {
try {
Class < ? > clazz = patientAllInfo . getClass ( ) ;
Field field = clazz . getDeclaredField ( triggerCondition . getTriggerConditionCode ( ) ) ;
field . setAccessible ( true ) ;
/ / 获取字段的值
Object value = field . get ( patientAllInfo ) ;
if ( ObjectUtils . isNotEmpty ( value ) ) {
labelValueList . add ( String . valueOf ( value ) ) ;
}
} catch ( NoSuchFieldException | IllegalAccessException e ) {
throw new RuntimeException ( e ) ;
}
}
/ / 查询画像中的信息
if ( CollectionUtils . isNotEmpty ( labelFieldContentList ) ) {
labelValueList . addAll ( labelFieldContentList . stream ( )
. filter ( content - > StringUtils . equals ( content . getFieldCode ( ) , triggerCondition . getTriggerConditionCode ( ) ) )
. map ( LabelFieldInfoContentVo : : getFieldValue )
. collect ( Collectors . toList ( ) ) ) ;
}
boolean retBoolean = false ;
if ( CollectionUtils . isNotEmpty ( labelValueList ) ) {
switch ( triggerCondition . getTriggerConditionOperator ( ) ) {
case ( TriggerConditionOperatorConstants . CONTAIN ) :
/ / 判断labelValue中的内容是否包含triggerConditionValue
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > StringUtils . containsIgnoreCase ( labelValue , triggerCondition . getTriggerConditionValue ( ) ) ) ;
break ;
case ( TriggerConditionOperatorConstants . NOT_CONTAIN ) :
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > ! StringUtils . containsIgnoreCase ( labelValue , triggerCondition . getTriggerConditionValue ( ) ) ) ;
break ;
case ( TriggerConditionOperatorConstants . EQUAL_TO ) :
case ( TriggerConditionOperatorConstants . EQUAL ) :
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > StringUtils . equalsIgnoreCase ( labelValue , triggerCondition . getTriggerConditionValue ( ) ) ) ;
break ;
case ( TriggerConditionOperatorConstants . NOT_EQUAL_TO ) :
case ( TriggerConditionOperatorConstants . NOT_EQUAL ) :
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > ! StringUtils . equalsIgnoreCase ( labelValue , triggerCondition . getTriggerConditionValue ( ) ) ) ;
break ;
case ( TriggerConditionOperatorConstants . GREATER_THAN_OR_EQUAL ) :
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > new BigDecimal ( labelValue ) . compareTo ( new BigDecimal ( triggerCondition . getTriggerConditionValue ( ) ) ) > = 0 ) ;
break ;
case ( TriggerConditionOperatorConstants . GREATER_THAN ) :
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > new BigDecimal ( labelValue ) . compareTo ( new BigDecimal ( triggerCondition . getTriggerConditionValue ( ) ) ) > 0 ) ;
break ;
case ( TriggerConditionOperatorConstants . LESS_THAN ) :
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > new BigDecimal ( labelValue ) . compareTo ( new BigDecimal ( triggerCondition . getTriggerConditionValue ( ) ) ) < 0 ) ;
break ;
case ( TriggerConditionOperatorConstants . LESS_THAN_OR_EQUAL ) :
retBoolean = labelValueList . stream ( ) . anyMatch ( labelValue - > new BigDecimal ( labelValue ) . compareTo ( new BigDecimal ( triggerCondition . getTriggerConditionValue ( ) ) ) < = 0 ) ;
break ;
}
}
return retBoolean ;
}
}