|
@@ -11,10 +11,15 @@ import com.lantone.qc.pub.Content;
|
|
|
import com.lantone.qc.pub.model.InputInfo;
|
|
|
import com.lantone.qc.pub.model.doc.BeHospitalizedDoc;
|
|
|
import com.lantone.qc.pub.model.entity.Annotation;
|
|
|
+import com.lantone.qc.pub.model.entity.Clinical;
|
|
|
+import com.lantone.qc.pub.model.entity.Diag;
|
|
|
import com.lantone.qc.pub.model.entity.Lis;
|
|
|
+import com.lantone.qc.pub.model.label.ChiefLabel;
|
|
|
import com.lantone.qc.pub.model.vo.CRFVo;
|
|
|
import com.lantone.qc.pub.util.StringUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -37,7 +42,7 @@ public class BeHospitalizedAI {
|
|
|
public static String entityRelationObject = "entity_relation_object";
|
|
|
public static String outputs = "outputs";
|
|
|
|
|
|
- public Map<String,List<CrfOut>> medrec(InputInfo inputInfo,CRFServiceClient crfServiceClient){
|
|
|
+ public void medrec(InputInfo inputInfo,CRFServiceClient crfServiceClient){
|
|
|
|
|
|
Map<String,List<CrfOut>> crfOut = new HashMap<>();//主诉-->
|
|
|
JSONArray crfContent = new JSONArray();
|
|
@@ -74,32 +79,107 @@ public class BeHospitalizedAI {
|
|
|
//获取CRF模型返回数据
|
|
|
JSONArray data = getAnnotation(crfServiceClient, crfVo).getData();
|
|
|
JSONObject midData = getOutputs(data);
|
|
|
+ EntityProcessMethod entityProcessMethod = new EntityProcessMethod();
|
|
|
+ putChiefCrfData(midData.getJSONObject(Content.chief),inputInfo,entityProcessMethod);
|
|
|
//处理主诉
|
|
|
- putAllCrfData(midData.getJSONObject(Content.chief),crfOut);
|
|
|
- putAllCrfData(midData.getJSONObject(Content.present), crfOut);
|
|
|
- putAllCrfData(midData.getJSONObject(Content.special_exam), crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.chief),crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.present), crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.special_exam), crfOut);
|
|
|
+//
|
|
|
+// //存放CRF模型既往史、家族史返回数据
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.past), crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.family), crfOut);
|
|
|
+// //存放CRF模型一般查体(体格检查(一))返回数据
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.phys_exam), crfOut);
|
|
|
+// //存放CRF模型个人史、月经史、婚育史返回数据
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.personal), crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.menses), crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.marriage), crfOut);
|
|
|
+// //存放CRF模型病历特点、初步诊断、诊断依据返回数据
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.case_feature), crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.pridiag), crfOut);
|
|
|
+// putAllCrfData(midData.getJSONObject(Content.diag_basis), crfOut);
|
|
|
+// return crfOut;
|
|
|
+ }
|
|
|
+ public void putChiefCrfData(JSONObject jsonObject,InputInfo inputInfo,EntityProcessMethod entityProcessMethod){
|
|
|
+ if (jsonObject == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject outputs = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
|
|
|
+ List<Clinical> clinicals = entityProcessMethod.extractClinicalEntity(outputs);
|
|
|
+ List<Diag> diags = entityProcessMethod.extractDiagEntity(outputs);
|
|
|
+ ChiefLabel chiefLabel = inputInfo.getBeHospitalizedDoc().getChiefLabel();
|
|
|
+ chiefLabel.setClinicals(clinicals);
|
|
|
+ chiefLabel.setDiags(diags);
|
|
|
|
|
|
- //存放CRF模型既往史、家族史返回数据
|
|
|
- putAllCrfData(midData.getJSONObject(Content.past), crfOut);
|
|
|
- putAllCrfData(midData.getJSONObject(Content.family), crfOut);
|
|
|
- //存放CRF模型一般查体(体格检查(一))返回数据
|
|
|
- putAllCrfData(midData.getJSONObject(Content.phys_exam), crfOut);
|
|
|
- //存放CRF模型个人史、月经史、婚育史返回数据
|
|
|
- putAllCrfData(midData.getJSONObject(Content.personal), crfOut);
|
|
|
- putAllCrfData(midData.getJSONObject(Content.menses), crfOut);
|
|
|
- putAllCrfData(midData.getJSONObject(Content.marriage), crfOut);
|
|
|
- //存放CRF模型病历特点、初步诊断、诊断依据返回数据
|
|
|
- putAllCrfData(midData.getJSONObject(Content.case_feature), crfOut);
|
|
|
- putAllCrfData(midData.getJSONObject(Content.pridiag), crfOut);
|
|
|
- putAllCrfData(midData.getJSONObject(Content.diag_basis), crfOut);
|
|
|
+ }
|
|
|
+ public Map<String,CrfOut> medrec_new(InputInfo inputInfo,CRFServiceClient crfServiceClient) {
|
|
|
+ Map<String, CrfOut> crfOut = new HashMap<>();//主诉-->
|
|
|
+ JSONArray crfContent = new JSONArray();
|
|
|
+ BeHospitalizedDoc beHospitalizedDoc = inputInfo.getBeHospitalizedDoc();
|
|
|
+ String chief_text = beHospitalizedDoc.getChiefLabel().getText();
|
|
|
+ String Personal_text = beHospitalizedDoc.getPersonalLabel().getText();
|
|
|
+ String family_text = beHospitalizedDoc.getFamilyLabel().getText();
|
|
|
+ String past_text = beHospitalizedDoc.getPastLabel().getText();
|
|
|
+ String present_text = beHospitalizedDoc.getPresentLabel().getText();
|
|
|
+ //月经史
|
|
|
+ String menstrual_text = beHospitalizedDoc.getMenstrualLabel().getText();
|
|
|
+ //婚育史
|
|
|
+ String marital_text = beHospitalizedDoc.getMaritalLabel().getText();
|
|
|
+ //一般体格检查
|
|
|
+ String vital_text = beHospitalizedDoc.getVitalLabel().getText();
|
|
|
+ //专科体格检查
|
|
|
+ String vitalSpecial_text = beHospitalizedDoc.getVitalLabelSpecial().getText();
|
|
|
+ //存放主诉、现病史、专科查体(体格检查(二))
|
|
|
+ putContent(crfContent,medicalTextType.get(3), chief_text,Content.chief);
|
|
|
+ putContent(crfContent,medicalTextType.get(3), present_text,Content.present);
|
|
|
+ putContent(crfContent,medicalTextType.get(3), vitalSpecial_text,Content.special_exam);
|
|
|
+ //存放既往史、家族史
|
|
|
+ putContent(crfContent,medicalTextType.get(3), past_text,Content.past);
|
|
|
+ putContent(crfContent,medicalTextType.get(3), family_text,Content.family);
|
|
|
+ //存放一般查体
|
|
|
+ putContent(crfContent,medicalTextType.get(3), vital_text,Content.phys_exam);
|
|
|
+ //存放个人史、月经史、婚育史
|
|
|
+ putContent(crfContent,medicalTextType.get(3), Personal_text,Content.personal);
|
|
|
+ putContent(crfContent,medicalTextType.get(3), menstrual_text,Content.menses);
|
|
|
+ putContent(crfContent,medicalTextType.get(3), marital_text,Content.marriage);
|
|
|
+ //存储CRF完整所需结构数据
|
|
|
+ CRFVo crfVo = new CRFVo();
|
|
|
+ crfVo.setData(crfContent);
|
|
|
+ //获取CRF模型返回数据
|
|
|
+ JSONArray data = getAnnotation(crfServiceClient, crfVo).getData();
|
|
|
+ JSONObject midData = getOutputs(data);
|
|
|
+ //处理主诉
|
|
|
+ putAllCrfData_new(midData.getJSONObject(Content.chief),crfOut);
|
|
|
+ putAllCrfData_new(midData.getJSONObject(Content.present),crfOut);
|
|
|
return crfOut;
|
|
|
}
|
|
|
+ public void putAllCrfData_new(JSONObject jsonObject,Map<String,CrfOut> crfOut){
|
|
|
+ if (jsonObject == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject outputs = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
|
|
|
+ Map<String, Map<String, String>> chiefMap = annsiys_tr(outputs);
|
|
|
+ System.out.println();
|
|
|
|
|
|
+ }
|
|
|
+ public void packageData(Map<String, Map<String, String>> chiefMap){
|
|
|
+ if(chiefMap.size()>0){
|
|
|
+ for (Map.Entry<String, Map<String, String>> data:chiefMap.entrySet()) {
|
|
|
+ String key = data.getKey();
|
|
|
+ Map<String, String> value = data.getValue();
|
|
|
+ if(value.size()>0){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
public void putAllCrfData(JSONObject jsonObject,Map<String,List<CrfOut>> crfOut){
|
|
|
if (jsonObject == null) {
|
|
|
return;
|
|
|
}
|
|
|
JSONObject outputs = jsonObject.getJSONObject(entityRelationObject).getJSONObject(BeHospitalizedAI.outputs);
|
|
|
+ Map<String, Map<String, String>> stringMapMap = annsiys_tr(outputs);
|
|
|
List<CrfOut> medOut = new ArrayList<>();
|
|
|
CrfOut outputInfo = new CrfOut();
|
|
|
add2Output(new EntityProcessSymptom(), outputs, outputInfo);//临床表现
|
|
@@ -113,6 +193,72 @@ public class BeHospitalizedAI {
|
|
|
medOut.add(outputInfo);
|
|
|
crfOut.put(jsonObject.getString("detail_title"),medOut);
|
|
|
}
|
|
|
+ public Map<String,Map<String,String>> annsiys_tr(JSONObject outputs){
|
|
|
+ Map<String,Map<String,String>> result_map = new HashMap<>();
|
|
|
+ Map<Integer,List<Integer>> id_map = new HashMap<>();
|
|
|
+ JSONObject annotation = outputs.getJSONObject("annotation");
|
|
|
+ JSONArray entitys = annotation.getJSONArray("T");
|
|
|
+ JSONArray relations = annotation.getJSONArray("R");
|
|
|
+ if(relations.size()>0){
|
|
|
+ for(int i = 0;i<relations.size();i++){
|
|
|
+ if (StringUtils.isEmpty(relations.get(i).toString())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = relations.getJSONObject(i);
|
|
|
+ if(!jsonObject.isEmpty()){
|
|
|
+ Integer from_id = jsonObject.getInteger("from");
|
|
|
+ Integer to_id = jsonObject.getInteger("to");
|
|
|
+ if(id_map.containsKey(from_id)){
|
|
|
+ List<Integer> integers = id_map.get(from_id);
|
|
|
+ integers.add(to_id);
|
|
|
+ id_map.put(from_id,integers);
|
|
|
+ }else {
|
|
|
+ List<Integer> ids = new ArrayList<>();
|
|
|
+ ids.add(to_id);
|
|
|
+ id_map.put(from_id,ids);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(id_map.size()>0 && entitys.size()>0){
|
|
|
+ for(int i = 0;i<entitys.size();i++){
|
|
|
+ if (StringUtils.isEmpty(entitys.get(i).toString())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = entitys.getJSONObject(i);
|
|
|
+ if(!jsonObject.isEmpty()){
|
|
|
+ String name = jsonObject.getString("name");
|
|
|
+ Integer id = jsonObject.getInteger("id");
|
|
|
+ String value = jsonObject.getString("value");
|
|
|
+ if(id_map.keySet().contains(id)){
|
|
|
+ Map<String,String> rMap = new HashMap<>();
|
|
|
+ rMap.put("type",name);
|
|
|
+ List<Integer> ids = id_map.get(id);
|
|
|
+ if(ids.size()>0){
|
|
|
+ for (Integer id_n:ids) {
|
|
|
+ if(entitys.size()>0){
|
|
|
+ for(int h = 0;h<entitys.size();h++){
|
|
|
+ if (StringUtils.isEmpty(entitys.get(h).toString())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject jsonObject_h = entitys.getJSONObject(h);
|
|
|
+ if(!jsonObject_h.isEmpty()){
|
|
|
+ Integer id1 = jsonObject_h.getInteger("id");
|
|
|
+ if(id_n.equals(id1)){
|
|
|
+ rMap.put(jsonObject_h.getString("name"),jsonObject_h.getString("value"));
|
|
|
+ result_map.put(value,rMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result_map;
|
|
|
+ }
|
|
|
public void add2Output(EntityProcess entityProcess, JSONObject outputs, CrfOut outputInfo){
|
|
|
entityProcess.extractEntity(outputs, outputInfo);
|
|
|
}
|