|
@@ -3,107 +3,158 @@ package com.lantone.qc.kernel.structure.ai.process;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.lantone.qc.kernel.structure.ai.model.CrfOut;
|
|
import com.lantone.qc.kernel.structure.ai.model.CrfOut;
|
|
import com.lantone.qc.kernel.structure.ai.model.EntityEnum;
|
|
import com.lantone.qc.kernel.structure.ai.model.EntityEnum;
|
|
|
|
+import com.lantone.qc.kernel.structure.ai.model.Lemma;
|
|
import com.lantone.qc.pub.model.entity.*;
|
|
import com.lantone.qc.pub.model.entity.*;
|
|
import com.lantone.qc.pub.model.label.PastLabel;
|
|
import com.lantone.qc.pub.model.label.PastLabel;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @ClassName : EntityProcessPast
|
|
|
|
+ * @Description : 既往史
|
|
|
|
+ * @Author : 楼辉荣
|
|
|
|
+ * @Date: 2020-03-10 10:20
|
|
|
|
+ */
|
|
public class EntityProcessPast extends EntityProcess {
|
|
public class EntityProcessPast extends EntityProcess {
|
|
- public static String allergy_history = "过敏史";
|
|
|
|
- public static String disease_history = "疾病史";
|
|
|
|
- public static String surgery_history = "手术史";
|
|
|
|
- public static String injury_history = "外伤史";
|
|
|
|
- public static String blood_history = "输血史";
|
|
|
|
- public static String vaccination_history = "预防接种史";
|
|
|
|
- public static String infect_history = "传染病史";
|
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(EntityProcessPast.class);
|
|
|
|
|
|
public PastLabel extractEntity(JSONObject aiOut) {
|
|
public PastLabel extractEntity(JSONObject aiOut) {
|
|
PastLabel pastLabel = new PastLabel();
|
|
PastLabel pastLabel = new PastLabel();
|
|
-
|
|
|
|
try {
|
|
try {
|
|
- List<Diag> diags = addEntity(aiOut, EntityEnum.DIEASE, Diag.class);
|
|
|
|
|
|
+ //读取疾病信息
|
|
|
|
+ List<Lemma> diagLemmas = createEntityTree(aiOut, EntityEnum.DIEASE.toString());
|
|
|
|
+ for (Lemma lemma : diagLemmas) {
|
|
|
|
+ Diag diag = new Diag();
|
|
|
|
+ diag.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ //阴性
|
|
|
|
+ diag.setNegative(findNegative(lemma));
|
|
|
|
+ //可能的
|
|
|
|
+ for (Lemma relationLemma : lemma.getRelationLemmas()) {
|
|
|
|
+ if (relationLemma.getProperty().equals(EntityEnum.POSSIBLE.toString())) {
|
|
|
|
+ Possible possible = new Possible();
|
|
|
|
+ possible.setName(relationLemma.getText());
|
|
|
|
+ diag.setPossible(possible);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ pastLabel.addDiag(diag);
|
|
|
|
+ }
|
|
//手术史
|
|
//手术史
|
|
- List<Operation> operations = addEntity(aiOut, EntityEnum.OPERATION, Operation.class);
|
|
|
|
|
|
+ List<Lemma> operationLemmas = createEntityTree(aiOut, EntityEnum.OPERATION.toString());
|
|
|
|
+ for (Lemma lemma : operationLemmas) {
|
|
|
|
+ Operation operation = new Operation();
|
|
|
|
+ operation.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ //阴性
|
|
|
|
+ operation.setNegative(findNegative(lemma));
|
|
|
|
+ //时间
|
|
|
|
+ operation.setPd(findPD(lemma));
|
|
|
|
+ //手术结果
|
|
|
|
+ for (Lemma relationLemma : lemma.getRelationLemmas()) {
|
|
|
|
+ if (relationLemma.getProperty().equals(EntityEnum.OPERATION_RESULT.toString())) {
|
|
|
|
+ OperationResult operationResult = new OperationResult();
|
|
|
|
+ operationResult.setName(relationLemma.getText());
|
|
|
|
+ operation.setOperationResult(operationResult);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //手术原因
|
|
|
|
+ for (Lemma relationLemma : lemma.getRelationLemmas()) {
|
|
|
|
+ if (relationLemma.getProperty().equals(EntityEnum.DIEASE.toString())) {
|
|
|
|
+ Diag diag = new Diag();
|
|
|
|
+ diag.setName(relationLemma.getText());
|
|
|
|
+ operation.setDiag(diag);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ pastLabel.addOperation(operation);
|
|
|
|
+ }
|
|
//外伤史
|
|
//外伤史
|
|
- List<Wound> wounds = addEntity(aiOut, EntityEnum.INJURY, Wound.class);
|
|
|
|
|
|
+ List<Lemma> woundLemmas = createEntityTree(aiOut, EntityEnum.INJURY.toString());
|
|
|
|
+ for (Lemma lemma : woundLemmas) {
|
|
|
|
+ Wound wound = new Wound();
|
|
|
|
+ wound.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ wound.setNegative(findNegative(lemma));//阴性
|
|
|
|
+ wound.setPd(findPD(lemma));//时间
|
|
|
|
+ wound.setBodyPart(findT(lemma, new BodyPart(), EntityEnum.BODY.toString()));//部位
|
|
|
|
+ wound.setDegree(findT(lemma, new Degree(), EntityEnum.TREND.toString()));//程度
|
|
|
|
+ wound.setTreat(findT(lemma, new Treat(), EntityEnum.CURE.toString()));//治疗
|
|
|
|
+ wound.setOperation(findT(lemma, new Operation(), EntityEnum.OPERATION.toString()));//手术
|
|
|
|
+ }
|
|
|
|
+ pastLabel.addWound(wound);
|
|
|
|
+ }
|
|
//过敏史
|
|
//过敏史
|
|
- List<Allergy> allergies = addEntity(aiOut, EntityEnum.ALLERGY, Allergy.class);
|
|
|
|
- List<AllergyFood> allergyFoods = addEntity(aiOut, EntityEnum.FOOD_ALLERGY, AllergyFood.class);
|
|
|
|
- List<AllergyMedicine> allergyMedicines = addEntity(aiOut, EntityEnum.DRUG_ALLERGY, AllergyMedicine.class);
|
|
|
|
- List<AllergyDesc> allergyDescs = addEntity(aiOut, EntityEnum.ALLERGY_SYMPTOM, AllergyDesc.class);
|
|
|
|
-
|
|
|
|
|
|
+ List<Lemma> allergyLemmas = createEntityTree(aiOut, EntityEnum.ALLERGY.toString());
|
|
|
|
+ for (Lemma lemma : allergyLemmas) {
|
|
|
|
+ Allergy allergy = new Allergy();
|
|
|
|
+ allergy.setName(lemma.getText());
|
|
|
|
+ allergy.setNegative(findNegative(lemma));
|
|
|
|
+ pastLabel.addAllergy(allergy);
|
|
|
|
+ }
|
|
|
|
+ //食物过敏史
|
|
|
|
+ List<Lemma> allergyFoodLemmas = createEntityTree(aiOut, EntityEnum.FOOD_ALLERGY.toString());
|
|
|
|
+ for (Lemma lemma : allergyFoodLemmas) {
|
|
|
|
+ AllergyFood allergyFood = new AllergyFood();
|
|
|
|
+ allergyFood.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ allergyFood.setNegative(findNegative(lemma));
|
|
|
|
+ allergyFood.setPd(findPD(lemma));//时间
|
|
|
|
+ allergyFood.setDegree(findT(lemma, new Degree(), EntityEnum.TREND.toString()));//程度
|
|
|
|
+ }
|
|
|
|
+ pastLabel.addAllergyFood(allergyFood);
|
|
|
|
+ }
|
|
|
|
+ //药物过敏史
|
|
|
|
+ List<Lemma> allergyMedicineLemmas = createEntityTree(aiOut, EntityEnum.DRUG_ALLERGY.toString());
|
|
|
|
+ for (Lemma lemma : allergyMedicineLemmas) {
|
|
|
|
+ AllergyMedicine allergyMedicine = new AllergyMedicine();
|
|
|
|
+ allergyMedicine.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ allergyMedicine.setNegative(findNegative(lemma));
|
|
|
|
+ allergyMedicine.setPd(findPD(lemma));//时间
|
|
|
|
+ allergyMedicine.setDegree(findT(lemma, new Degree(), EntityEnum.TREND.toString()));//程度
|
|
|
|
+ }
|
|
|
|
+ pastLabel.addAllergyMedicine(allergyMedicine);
|
|
|
|
+ }
|
|
//输血史
|
|
//输血史
|
|
- List<BloodTransfusion> bloodTransfusions = addEntity(aiOut, EntityEnum.BLOOD_TRANSFUSION, BloodTransfusion.class);
|
|
|
|
- //预防接种史
|
|
|
|
- List<Vaccinate> vaccinates = addEntity(aiOut, EntityEnum.VACCINATION, Vaccinate.class);
|
|
|
|
- //传染病史
|
|
|
|
- List<DiagInfectious> diagInfectious = addEntity(aiOut, EntityEnum.INFECTIOUS_KEYWORD, DiagInfectious.class);
|
|
|
|
- pastLabel.setDiags(diags);
|
|
|
|
- pastLabel.setAllergies(allergies);
|
|
|
|
- pastLabel.setAllergyFoods(allergyFoods);
|
|
|
|
- pastLabel.setAllergyMedicines(allergyMedicines);
|
|
|
|
- pastLabel.setAllergyDescs(allergyDescs);
|
|
|
|
- pastLabel.setBloodTransfusions(bloodTransfusions);
|
|
|
|
- pastLabel.setDiagInfectiouses(diagInfectious);
|
|
|
|
- pastLabel.setOperations(operations);
|
|
|
|
- pastLabel.setVaccinates(vaccinates);
|
|
|
|
- pastLabel.setWounds(wounds);
|
|
|
|
- }catch (Exception e){
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- return pastLabel;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- private void addPast(JSONObject outputs, List<Past> pasts) {
|
|
|
|
- Past past = null;
|
|
|
|
- List<Map<String, String>> pastEntityList = processJson(outputs, EntityEnum.DIEASE.toString());
|
|
|
|
- for (Map<String, String> pastEntityMap : pastEntityList) {
|
|
|
|
- if (StringUtils.isEmpty(pastEntityMap.get(EntityEnum.DIEASE.toString()))) {
|
|
|
|
- continue;
|
|
|
|
|
|
+ List<Lemma> bloodTransfusionLemmas = createEntityTree(aiOut, EntityEnum.BLOOD_TRANSFUSION.toString());
|
|
|
|
+ for (Lemma lemma : bloodTransfusionLemmas) {
|
|
|
|
+ BloodTransfusion bloodTransfusion = new BloodTransfusion();
|
|
|
|
+ bloodTransfusion.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ bloodTransfusion.setNegative(findNegative(lemma));
|
|
|
|
+ }
|
|
|
|
+ pastLabel.addBloodTransfusion(bloodTransfusion);
|
|
|
|
+ }
|
|
|
|
+ //预防接种史
|
|
|
|
+ List<Lemma> vaccinateLemmas = createEntityTree(aiOut, EntityEnum.VACCINATION.toString());
|
|
|
|
+ for (Lemma lemma : vaccinateLemmas) {
|
|
|
|
+ Vaccinate vaccinate = new Vaccinate();
|
|
|
|
+ vaccinate.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ vaccinate.setNegative(findNegative(lemma));
|
|
|
|
+ }
|
|
|
|
+ pastLabel.addVaccinate(vaccinate);
|
|
}
|
|
}
|
|
- past = new Past();
|
|
|
|
- String cureValue = "";
|
|
|
|
- for (String key : pastEntityMap.keySet()) {
|
|
|
|
- switch (EntityEnum.parseOfValue(key)) {
|
|
|
|
- case DIEASE:
|
|
|
|
- past.setType(6);
|
|
|
|
- past.setTitle(EntityProcessPast.disease_history);
|
|
|
|
- past.setValue(pastEntityMap.get(key));
|
|
|
|
- break;
|
|
|
|
- case CURE:
|
|
|
|
- past.setTreat(pastEntityMap.get(key));
|
|
|
|
- break;
|
|
|
|
- case CURE_AIM:
|
|
|
|
- cureValue += "," + pastEntityMap.get(key);
|
|
|
|
- break;
|
|
|
|
- case TREND:
|
|
|
|
- cureValue += "," + pastEntityMap.get(key);
|
|
|
|
- break;
|
|
|
|
- case TIME:
|
|
|
|
- cureValue += "," + pastEntityMap.get(key);
|
|
|
|
- break;
|
|
|
|
- case FREQUENCY:
|
|
|
|
- cureValue += "," + pastEntityMap.get(key);
|
|
|
|
- break;
|
|
|
|
- case MODIFICATION:
|
|
|
|
- cureValue += "," + pastEntityMap.get(key);
|
|
|
|
- break;
|
|
|
|
- case NEGATIVE:
|
|
|
|
- Negative negative = new Negative();
|
|
|
|
- negative.setName(StringUtils.isEmpty(pastEntityMap.get(key)) ? "" : pastEntityMap.get(key));
|
|
|
|
- past.setNegative(negative);
|
|
|
|
- break;
|
|
|
|
- //TODO PD
|
|
|
|
|
|
+ //传染病史
|
|
|
|
+ List<Lemma> diagInfectiousLemmas = createEntityTree(aiOut, EntityEnum.INFECTIOUS_KEYWORD.toString());
|
|
|
|
+ for (Lemma lemma : diagInfectiousLemmas) {
|
|
|
|
+ DiagInfectious diagInfectious = new DiagInfectious();
|
|
|
|
+ diagInfectious.setName(lemma.getText());
|
|
|
|
+ if (lemma.isHaveChildren()) {
|
|
|
|
+ diagInfectious.setNegative(findNegative(lemma));
|
|
}
|
|
}
|
|
|
|
+ pastLabel.addDiagInfectious(diagInfectious);
|
|
}
|
|
}
|
|
- past.setDescribe(cureValue.startsWith(",") ? cureValue.substring(1, cureValue.length()) : cureValue);
|
|
|
|
- pasts.add(past);
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.error(e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
+ return pastLabel;
|
|
}
|
|
}
|
|
}
|
|
}
|