Ejemplo n.º 1
0
  /**
   * ラボモジュールを検索する。
   *
   * @param patientId 対象患者のID
   * @param firstResult 取得結果リストの最初の番号
   * @param maxResult 取得する件数の最大値
   * @return ラボモジュールのリスト
   */
  @Override
  public List<NLaboModule> getLaboTest(String fidPid, int firstResult, int maxResult) {

    // String fidPid = SessionHelper.getQualifiedPid(ctx, patientId);

    //
    // 検体採取日の降順で返す
    //
    List<NLaboModule> ret =
        (List<NLaboModule>)
            em.createQuery(QUERY_MODULE_BY_FIDPID)
                .setParameter(FIDPID, fidPid)
                .setFirstResult(firstResult)
                .setMaxResults(maxResult)
                .getResultList();

    for (NLaboModule m : ret) {

      if (m.getReportFormat() != null && m.getReportFormat().equals(WOLF)) {
        List<NLaboItem> items =
            (List<NLaboItem>)
                em.createQuery(QUERY_ITEM_BY_MID_ORDERBY_SORTKEY)
                    .setParameter(MID, m.getId())
                    .getResultList();
        m.setItems(items);

      } else {
        List<NLaboItem> items =
            (List<NLaboItem>)
                em.createQuery(QUERY_ITEM_BY_MID).setParameter(MID, m.getId()).getResultList();
        m.setItems(items);
      }
    }
    return ret;
  }
Ejemplo n.º 2
0
  @Override
  public PatientModel create(String fid, NLaboModule module) {

    String pid = module.getPatientId();

    // 施設IDと LaboModule の患者IDで 患者を取得する
    PatientModel patient =
        (PatientModel)
            em.createQuery("from PatientModel p where p.facilityId=:fid and p.patientId=:pid")
                .setParameter("fid", fid)
                .setParameter("pid", pid)
                .getSingleResult();

    // --------------------------------------------------------
    if (patient != null) {

      // 患者の健康保険を取得する
      List<HealthInsuranceModel> insurances =
          (List<HealthInsuranceModel>)
              em.createQuery(QUERY_INSURANCE_BY_PATIENT_PK)
                  .setParameter(PK, patient.getId())
                  .getResultList();
      patient.setHealthInsurances(insurances);
    }
    // --------------------------------------------------------

    String fidPid = fid + ":" + pid;
    module.setPatientId(fidPid);

    // item の patientId を変更する
    Collection<NLaboItem> items = module.getItems();
    for (NLaboItem item : items) {
      item.setPatientId(fidPid);
    }

    // --------------------------------------------------------
    // patientId & 検体採取日 & ラボコード で key
    // これが一致しているモジュールは再報告として削除してから登録する。
    // --------------------------------------------------------
    String sampleDate = module.getSampleDate();
    String laboCode = module.getLaboCenterCode();
    String moduleKey = module.getModuleKey();
    if (moduleKey != null) {
      StringBuilder sb = new StringBuilder();
      sb.append(pid).append(".").append(sampleDate).append(".").append(laboCode);
      String test = sb.toString();
      if (test.equals(moduleKey)) {
        sb = new StringBuilder();
        sb.append(fid);
        sb.append(":");
        sb.append(moduleKey);
        moduleKey = sb.toString();
        module.setModuleKey(moduleKey);
        System.err.println("corrected moduke key=" + module.getModuleKey());
      }
    }

    NLaboModule exist = null;

    try {
      if (moduleKey != null) {
        exist =
            (NLaboModule)
                em.createQuery(QUERY_MODULE_BY_MODULE_KEY)
                    .setParameter(MODULEKEY, moduleKey)
                    .getSingleResult();
        System.err.println("module did exist");

      } else {
        exist =
            (NLaboModule)
                em.createQuery(QUERY_MODULE_BY_PID_SAMPLEDATE_LABCODE)
                    .setParameter(FIDPID, fidPid)
                    .setParameter(SAMPLEDATE, sampleDate)
                    .setParameter(LABOCODE, laboCode)
                    .getSingleResult();
      }

    } catch (Exception e) {
      exist = null;
    }

    // Cascade.TYPE=ALL
    if (exist != null) {
      em.remove(exist);
      System.err.println("module did remove");
    }

    // 永続化する
    em.persist(module);

    return patient;
  }