Пример #1
0
 /**
  * 按条件查询出单个对象
  *
  * @param tableName
  * @param timeValue
  * @param appId
  * @param appVersion
  * @param appChannel
  * @param appPlatform
  * @param tenantId
  * @param network
  * @param carrier
  * @return
  */
 public Document findOneBy(
     String tableName,
     String timeValue,
     String appId,
     String appVersion,
     String appChannel,
     String appPlatform,
     String network,
     String carrier,
     String tenantId) {
   MongoDatabase db = mongoClient.getDatabase(appId);
   Document matchFields = new Document();
   matchFields.put("timeValue", timeValue);
   matchFields.put("appVersion", appVersion);
   matchFields.put("appChannel", appChannel);
   matchFields.put("appPlatform", appPlatform);
   matchFields.put("network", network);
   matchFields.put("carrier", carrier);
   if (tenantId != null && !tenantId.trim().isEmpty()) {
     matchFields.put("tenantId", tenantId);
   } else { // 当相同的条件下有tenantId对应一条数据,无tenantId对应一条数据,所以要加上matchFields.put("tenantId",
            // null);,以免查询出两条数据,会照成结果错误
     matchFields.put("tenantId", null);
   }
   FindIterable<Document> iterable = db.getCollection(tableName).find(matchFields);
   if (iterable.iterator().hasNext()) {
     return iterable.first();
   } else {
     return null;
   }
 }
 /**
  * 取得指定住院号的记录
  *
  * @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;
   }
 }
 /**
  * 取得已出院未回访的用户
  *
  * @return
  */
 public List<record> GetleavehospitalRecords() {
   try {
     List<record> list = new ArrayList<record>();
     MongoDAO dao = MongoDAO.GetInstance();
     BasicDBObject cond = new BasicDBObject();
     cond.append("leaveHospital", new BasicDBObject("$eq", true));
     cond.append("followup", 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.setLeaveTime(doc.getDate("leaveTime"));
       fol.setDisease(doc.getString("disease"));
       list.add(fol);
     }
     return list;
   } catch (Exception e) {
     e.printStackTrace();
     logger.error(e.toString());
     return null;
   }
 }
Пример #4
0
 public Document findBy(String appId, String deviceId) {
   MongoDatabase db = mongoClient.getDatabase(appId);
   FindIterable<Document> iterable =
       db.getCollection("Widget").find(new Document("deviceId", deviceId));
   if (iterable.iterator().hasNext()) {
     return iterable.first();
   } else {
     return null;
   }
 }
 /**
  * 是否有同名记录
  *
  * @param name 患儿姓名
  * @return 住院记录
  */
 public boolean isRecordNameExists(String name) {
   try {
     MongoDAO dao = MongoDAO.GetInstance();
     BasicDBObject cond = new BasicDBObject();
     cond.append("name", new BasicDBObject("$eq", name));
     FindIterable<Document> result = dao.GetCollection("records").find(cond);
     MongoCursor<Document> it = result.iterator();
     if (it.hasNext()) {
       return true;
     }
     return false;
   } catch (Exception e) {
     e.printStackTrace();
     logger.error(e.toString());
     return false;
   }
 }