コード例 #1
0
  /**
   * 更新用户信息
   *
   * @return 是否更新成功
   */
  private boolean updateRecord(record exist_record, record new_record) {
    try {
      System.out.print("update record");
      MongoDAO dao = MongoDAO.GetInstance();
      System.out.print("update record1");
      Document existing = new Document();
      existing.append("admission_number", exist_record.getAdmission_number());

      long num = dao.GetCollection("records").deleteMany(existing).getDeletedCount();
      System.out.print("remove record number = " + num);

      try {
        Map<String, Object> docMap = new_record.getDocMap();
        docMap.put("inHospital", true);
        docMap.put("leaveHospital", false);
        docMap.put("followup", false);
        dao.GetCollection("records").insertOne(new Document(docMap));
      } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.toString());
        return false;
      }

      System.out.print("update record2");
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.toString());
      return false;
    }
    return true;
  }
コード例 #2
0
  /**
   * 取得正在住院的用户
   *
   * @return
   */
  public List<record> GetInhospitalRecords() {
    try {
      List<record> list = new ArrayList<record>();
      MongoDAO dao = MongoDAO.GetInstance();
      BasicDBObject cond = new BasicDBObject();
      cond.append("inHospital", new BasicDBObject("$eq", true));
      cond.append("leaveHospital", new BasicDBObject("$eq", false));
      FindIterable<Document> result = dao.GetCollection("records").find(cond);
      MongoCursor<Document> it = result.iterator();
      while (it.hasNext()) {
        Document doc = it.next();
        record fol = new record();
        fol.setAdmission_number(doc.getString("admission_number"));
        fol.setName(doc.getString("name"));
        fol.setWeixin_openid(doc.getString("weixin_openid"));
        fol.setInTime(doc.getDate("inTime"));

        System.out.print("\nname             = " + fol.getName());
        System.out.print("\nadmission_number = " + fol.getAdmission_number());
        System.out.print("\nweixin_openid    = " + fol.getWeixin_openid());
        System.out.print("\nintime           = " + fol.getInTime());
        list.add(fol);
        System.out.print("add to list finished");
      }
      System.out.print("list ready");
      return list;
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.toString());
      return null;
    }
  }
コード例 #3
0
 /**
  * 取得指定住院号的记录
  *
  * @param admissionNum 住院号
  * @return 住院记录
  */
 public record GetRecord(String admissionNum) {
   try {
     MongoDAO dao = MongoDAO.GetInstance();
     BasicDBObject cond = new BasicDBObject();
     cond.append("admission_number", new BasicDBObject("$eq", admissionNum));
     FindIterable<Document> result = dao.GetCollection("records").find(cond);
     MongoCursor<Document> it = result.iterator();
     if (it.hasNext()) {
       Document doc = it.next();
       record fol = new record();
       fol.setAdmission_number(doc.getString("admission_number"));
       fol.setName(doc.getString("name"));
       fol.setWeixin_openid(doc.getString("weixin_openid"));
       fol.setLeaveTime(doc.getDate("leaveTime"));
       fol.setInTime(doc.getDate("inTime"));
       fol.setDisease(doc.getString("disease"));
       return fol;
     }
     return null;
   } catch (Exception e) {
     e.printStackTrace();
     logger.error(e.toString());
     return null;
   }
 }
コード例 #4
0
  /**
   * 新用户注册
   *
   * @return
   */
  public boolean addNewRecord(record rec) {
    try {
      System.out.print("add new record begin");

      record exist_record = this.GetRecord(rec.getAdmission_number());
      if (exist_record != null) {
        System.out.print("has record with same id");
        return this.updateRecord(exist_record, rec);
      }
      return this.insertRecord(rec);
    } catch (Exception e) {
      e.printStackTrace();
      logger.error(e.toString());
      return false;
    }
  }
コード例 #5
0
 /** 插入新用户 */
 private boolean insertRecord(record rec) {
   System.out.print("insertRecord begin");
   try {
     MongoDAO dao = MongoDAO.GetInstance();
     System.out.print("insertRecord : insertOne record");
     Map<String, Object> docMap = rec.getDocMap();
     docMap.put("inHospital", true);
     docMap.put("leaveHospital", false);
     docMap.put("followup", false);
     dao.GetCollection("records").insertOne(new Document(docMap));
   } catch (Exception e) {
     e.printStackTrace();
     logger.error(e.toString());
     return false;
   }
   return true;
 }