Преглед на файлове

更新分词显示效果,添加既往史信息

MarkHuang преди 6 години
родител
ревизия
2f82b1297c

+ 124 - 37
nlp/src/main/java/org/diagbot/nlp/relation/analyze/StructureAnalyze.java

@@ -13,6 +13,7 @@ import org.diagbot.nlp.relation.module.cell.*;
 import org.diagbot.nlp.relation.util.LemmaUtil;
 import org.diagbot.nlp.relation.util.OutputInfo;
 import org.diagbot.nlp.util.Constants;
+import org.omg.Messaging.SYNC_WITH_TRANSPORT;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -33,8 +34,10 @@ public class StructureAnalyze {
     private List<OutputInfo> outputInfos = new ArrayList<>();
     private static boolean updated = false;
     private static Object current = null;
+    private static Object current_treat = null;
     private static String num = "";
     private static List<String> diag_con = Arrays.asList("门诊","诊断");
+    private static List<String> past_con = Arrays.asList("既往");
 
     /**
      * 分词,提取词性,封装
@@ -101,6 +104,7 @@ public class StructureAnalyze {
         Pacs pacs = null;
         Vital vital = null;
         Treat treat = null;
+        Past past = null;
         PD pd1 = null;
 
         try {
@@ -118,6 +122,18 @@ public class StructureAnalyze {
                     current = updateClinicalInfo(outputInfo, lexeme.getText(), lexeme.getProperty());
                     updated = true;
                     break;
+                case Constants.word_property_vital_value:
+                    if (current instanceof Vital) {
+                        vital = (Vital) current;
+                        if (vital.getPd() == null) {
+                            vital.setPd(new PD());
+                        }
+                        pd1 = vital.getPd();
+                        pd1.setValue(lexeme.getText());
+                        pd1.setUnit("");
+                        updated = true;
+                    }
+                    break;
                 case Constants.word_property_LIS:
                 case Constants.word_property_LIS_Detail:
                     lis = new Lis();
@@ -162,6 +178,16 @@ public class StructureAnalyze {
                         ((Pacs) current).setBodypart(((Pacs)current).getBodypart()+lexeme.getText() + ", ");
                         updated = true;
                     }
+                    else if (current instanceof Symptom) {
+                        PD pd = new PD();
+                        pd.setValue(lexeme.getText());
+                        pd.setUnit("");
+                        if (((Symptom)current).getPds() == null) {
+                            ((Symptom)current).setPds(new ArrayList<>());
+                        }
+                        ((Symptom)current).getPds().add(pd);
+                        updated = true;
+                    }
                     break;
                 case Constants.word_property_neg:
                     Negative negative = new Negative();
@@ -221,6 +247,14 @@ public class StructureAnalyze {
                                 lis.setPd(new PD());
                             }
                             pd1 = lis.getPd();
+                        } else if (current instanceof Past) {
+                            past = (Past)current;
+                            if (past.getPds() == null) {
+                                List<PD> pds1 = new ArrayList<>();
+                                pds1.add(new PD());
+                                past.setPds(pds1);
+                            }
+                            pd1 = past.getPds().get(0);
                         }
                     }
                     pd1.setValue(num);
@@ -244,39 +278,18 @@ public class StructureAnalyze {
                     }
                     break;
                 case Constants.word_property_diagnose:
-                    current = updateClinicalInfo(outputInfo, lexeme.getText(), lexeme.getProperty());
-                    updated = true;
-                    break;
                 case Constants.word_property_med:
-                    if (!(current instanceof Treat)) {
-                        current = updateClinicalInfo(outputInfo, "", Constants.word_property_diagnose);
-                    }
-                    treat = (Treat) current;
-
-                    if (treat.getTreatName() == null || treat.getTreatName().trim().length() == 0) {
-                        treat.setTreatName(lexeme.getText());
-                    }
-                    else {
-                        treat.setTreatName(treat.getTreatName() + "," + lexeme.getText());
-                    }
-                    updated = true;
-                    break;
                 case Constants.word_property_treat:
-                    if (current instanceof Treat) {
-                        treat = (Treat)current;
-                        if (treat.getValue() == null || treat.getValue().trim().length() == 0) {
-                            treat.setValue(lexeme.getText());
-                        }
-                        else {
-                            treat.setValue(treat.getValue() + "," + lexeme.getText());
-                        }
-                        updated = true;
-                    }
+                    current = updateClinicalInfo(outputInfo, lexeme.getText(), lexeme.getProperty());
+                    updated = true;
                     break;
                 case Constants.word_property_other:
                     if (diag_con.indexOf(lexeme.getText()) >= 0) {
                         current = new Treat();
                     }
+                    else if (past_con.indexOf(lexeme.getText()) >= 0) {
+                        current = new Past();
+                    }
                     break;
             }
         }
@@ -294,6 +307,8 @@ public class StructureAnalyze {
 
         outputInfo.setVitals(new ArrayList<>());
 
+        outputInfo.setPasts(new ArrayList<>());
+
         outputInfo.setLises(new ArrayList<>());
 
         outputInfo.setPacses(new ArrayList<>());
@@ -304,8 +319,9 @@ public class StructureAnalyze {
     }
 
     public int getPropsize(OutputInfo outputInfo) {
-        int size = outputInfo.getSymptoms().size() + outputInfo.getLises().size() + outputInfo.getTreats().size()
-                + outputInfo.getVitals().size() + outputInfo.getPacses().size();
+        int size = outputInfo.getSymptoms().size() + outputInfo.getVitals().size() +
+                outputInfo.getPasts().size() + outputInfo.getLises().size() +
+                outputInfo.getPacses().size() + outputInfo.getTreats().size();
 
         return size;
     }
@@ -315,6 +331,8 @@ public class StructureAnalyze {
 
         Object obj = null;
         Symptom symptom = null;
+        Treat treat = null;
+        Past past = null;
 
         switch (type) {
             case Constants.word_property_symptom:
@@ -347,19 +365,34 @@ public class StructureAnalyze {
                 obj = vital;
                 break;
             case Constants.word_property_diagnose:
-                if (outputInfo.getTreats().size() == 0) {
-                    outputInfo.getTreats().add(new Treat());
-                }
-
-                Treat treat = outputInfo.getTreats().get(outputInfo.getTreats().size()-1);
+                if (current instanceof Past) {
+                    past = (Past)current;
 
-                if (treat.getDiagnose() == null || treat.getDiagnose().trim().length() == 0) {
-                    treat.setDiagnose(name);
+                    if (past.getDiagnose() == null || past.getDiagnose().trim().length() == 0) {
+                        past.setDiagnose(name);
+                    } else {
+                        past.setDiagnose(past.getDiagnose() + "," + name);
+                    }
+                    outputInfo.getPasts().add(past);
+                    obj = past;
+                    current_treat = past;
                 }
                 else {
-                    treat.setDiagnose(treat.getDiagnose() + "," + name);
+                    if (current instanceof Treat) {
+                        treat = (Treat) current;
+                    } else if (outputInfo.getTreats().size() == 0) {
+                        outputInfo.getTreats().add(new Treat());
+                        treat = outputInfo.getTreats().get(outputInfo.getTreats().size() - 1);
+                    }
+
+                    if (treat.getDiagnose() == null || treat.getDiagnose().trim().length() == 0) {
+                        treat.setDiagnose(name);
+                    } else {
+                        treat.setDiagnose(treat.getDiagnose() + "," + name);
+                    }
+                    obj = treat;
+                    current_treat = treat;
                 }
-                obj = treat;
                 break;
             case Constants.word_property_cause:
                 Cause cause = new Cause();
@@ -425,6 +458,60 @@ public class StructureAnalyze {
                 symptom.setProperty(property);
                 obj = symptom;
                 break;
+            case Constants.word_property_treat:
+                if (current instanceof Treat) {
+                    treat = (Treat)current;
+                    if (treat.getValue() == null || treat.getValue().trim().length() == 0) {
+                        treat.setValue(name);
+                    }
+                    else {
+                        treat.setValue(treat.getValue() + "," + name);
+                    }
+                    current_treat = treat;
+                    obj = treat;
+                }
+                else if (current_treat instanceof Past) {
+                    past = (Past)current_treat;
+                    if (past.getValue() == null || past.getValue().trim().length() == 0) {
+                        past.setValue(name);
+                    }
+                    else {
+                        past.setValue(past.getValue() + "," + name);
+                    }
+
+                    obj = past;
+                }
+                break;
+            case Constants.word_property_med:
+                if (current_treat instanceof Past) {
+                    past = (Past)current_treat;
+
+                    if (past.getTreatName() == null || past.getTreatName().trim().length() == 0) {
+                        past.setTreatName(name);
+                    } else {
+                        past.setTreatName(past.getTreatName() + "," + name);
+                    }
+
+                    obj = past;
+                }
+                else {
+                    if (!(current instanceof Treat)) {
+                        if (current_treat != null && current_treat instanceof Treat) {
+                            current = current_treat;
+                        } else {
+                            current = updateClinicalInfo(outputInfo, "", Constants.word_property_diagnose);
+                        }
+                    }
+                    treat = (Treat) current;
+
+                    if (treat.getTreatName() == null || treat.getTreatName().trim().length() == 0) {
+                        treat.setTreatName(name);
+                    } else {
+                        treat.setTreatName(treat.getTreatName() + "," + name);
+                    }
+                    obj = treat;
+                }
+                break;
         }
 
         return obj;

+ 43 - 0
nlp/src/main/java/org/diagbot/nlp/relation/module/Past.java

@@ -0,0 +1,43 @@
+package org.diagbot.nlp.relation.module;
+
+import org.diagbot.nlp.relation.module.cell.PD;
+
+import java.util.List;
+
+/**
+ * @ClassName org.diagbot.nlp.relation.module.Past
+ * @Description 既往史
+ * @Author Mark Huang
+ * @Date 2019/5/5 14:57
+ * @Version 1.0
+ **/
+public class Past {
+    private String diagnose;
+    private String treatName;
+    private String value;
+    private List<PD> pds;
+
+    public String getDiagnose() { return diagnose; }
+
+    public void setDiagnose(String diagname) { this.diagnose = diagname; }
+
+    public String getTreatName() {
+        return treatName;
+    }
+
+    public void setTreatName(String treatName) {
+        this.treatName = treatName;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public List<PD> getPds() { return pds; }
+
+    public void setPds(List<PD> pds) { this.pds = pds; }
+}

+ 5 - 0
nlp/src/main/java/org/diagbot/nlp/relation/util/OutputInfo.java

@@ -19,6 +19,7 @@ public class OutputInfo {
     List<Lis> lises = new ArrayList<>();
     List<Pacs> pacses = new ArrayList<>();
     List<Treat> treats = new ArrayList<>();
+    List<Past> pasts = new ArrayList<>();
 
     public List<Symptom> getSymptoms() {
         return symptoms;
@@ -59,4 +60,8 @@ public class OutputInfo {
     public void setTreats(List<Treat> treats) {
         this.treats = treats;
     }
+
+    public List<Past> getPasts() { return pasts; }
+
+    public void setPasts(List<Past> pasts) { this.pasts = pasts; }
 }

+ 1 - 0
nlp/src/main/java/org/diagbot/nlp/util/Constants.java

@@ -65,6 +65,7 @@ public class Constants {
     public final static String word_property_direction = "21";
     public final static String word_property_freq = "33";
     public final static String word_property_vital_idx = "60";
+    public final static String word_property_vital_value = "61";
     public final static String word_property_vital_result = "62";
     public final static String word_property_degree_quan = "80";
     public final static String word_property_other = "99";

+ 64 - 0
push-web/src/main/resources/static/pages/relation/sample.html

@@ -211,6 +211,37 @@
                     </div>
                     <!-- /.box -->
 
+                    <!-- TABLE: LATEST ORDERS -->
+                    <div class="box box-info">
+                        <div class="box-header with-border">
+                            <h3 class="box-title">既往信息</h3>
+                            <div class="box-tools pull-right">
+                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
+                                </button>
+                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
+                            </div>
+                        </div>
+                        <!-- /.box-header -->
+                        <div class="box-body">
+                            <div class="table-responsive">
+                                <table class="table no-margin">
+                                    <thead>
+                                    <tr>
+                                        <th width="20%">诊断</th>
+                                        <th width="20%">用药</th>
+                                        <th width="20%">结果</th>
+                                        <th width="40%">其他</th>
+                                    </tr>
+                                    </thead>
+                                    <tbody id="past_extract_id">
+                                    </tbody>
+                                </table>
+                            </div>
+                            <!-- /.table-responsive -->
+                        </div>
+                    </div>
+                    <!-- /.box -->
+
                     <!-- TABLE: LATEST ORDERS -->
                     <div class="box box-info">
                         <div class="box-header with-border">
@@ -330,6 +361,7 @@
                             var outputInfos = data.data;
                             var h = "";
                             var vital_h = "";
+                            var past_h = "";
                             var lis_h = "";
                             var pacs_h = "";
                             var treat_h = "";
@@ -438,6 +470,37 @@
                                     });
                                 }
 
+                                var pasts = outputInfo.pasts;
+                                if (pasts != null) {
+                                    $.each(pasts, function (past_index, past) {
+                                        past_h += "<tr><td>";
+                                        if (past.diagnose != null) {
+                                            past_h += past.diagnose;
+                                        }
+                                        past_h += "</td>";
+
+                                        past_h += "<td>";
+                                        if (past.treatName != null) {
+                                            past_h += past.treatName;
+                                        }
+                                        past_h += "</td>";
+
+                                        past_h += "<td>";
+                                        if (past.value != null) {
+                                            past_h += past.value;
+                                        }
+                                        past_h += "</td>";
+
+                                        past_h += "<td>";
+                                        if (past.pds != null) {
+                                            $.each(past.pds, function (pd_index, pd) {
+                                                past_h += pd.value + pd.unit + " ";
+                                            });
+                                        }
+                                        past_h += "</td></tr>";
+                                    });
+                                }
+
                                 var lises = outputInfo.lises;
                                 if (lises != null) {
                                     $.each(lises, function (lis_index, lis) {
@@ -519,6 +582,7 @@
 
                             $("#symptom_extract_id").html(h);
                             $("#vital_extract_id").html(vital_h);
+                            $("#past_extract_id").html(past_h);
                             $("#lis_extract_id").html(lis_h);
                             $("#pacs_extract_id").html(pacs_h);
                             $("#treat_extract_id").html(treat_h);