예제 #1
0
 private void bindColType(
     ims.RefMan.forms.daycaseadmissiondialog.GenForm.grdIdentifiersRow row, boolean isNew) {
   row.getcolIdType().clear();
   PatIdTypeCollection collTypes = LookupHelper.getPatIdType(domain.getLookupService());
   for (int i = 0; i < collTypes.size(); i++) {
     if (ConfigFlag.DOM.HEARTS_REPLICATE_PATIENTS.getValue()) {
       if (isNew) {
         if (collTypes.get(i).equals(PatIdType.HOSPNUM) || collTypes.get(i).equals(PatIdType.PKEY))
           continue;
       }
     }
     row.getcolIdType().newRow(collTypes.get(i), collTypes.get(i).getText());
   }
 }
  private synchronized IAddress searchForAddress(
      IAddress searchCriteria, String searchTypeText, String listItem, String searchStatus)
      throws PresentationLogicException {
    // LOG.info("getAddressByPostcode:");

    if (searchCriteria == null) throw new PresentationLogicException("No Search Criteria given.");

    // select
    // AMBIGLIST,ORGANISATION,SUBBUILDING,BUILDINGNAME,BUILDINGNUMBER,DEPSTREET,STREET,DEPLOCALITY,LOCALITY,POSTTOWN,COUNTY,POSTCODE,ADDR,ADDKEY,ORGKEY,LISTTYPE,SEARCHSTATUS,LISTCOUNT,AMBIGLIST,BARCODE,ADEPOS,ADESCORE,ADPNRLOC,MSCORE,FFLAG,RESCODE,ERRNO,ERRTEXT,COUNTRY,COUNTRYCODE,MATCHLVL,PCLVL,INPCLVL,PCCHGLVL,PCCHGTYP,VANITYFLAGS,ELEMS_UNMATCHED,ELEMS_MATCHED,ELEMS_CORRECT,ELEMS_MISSPELLED,ELEMS_MISSING,FIELDSTATUS,OUTPUTSTATUS,ADDFMT_ABBR,ADDFMT_CONC,ADDFMT_TRUN,ADDFMT_ELIM,ADMINNUMBER,TRADNUMBER,LONLOCOUT,ADMINCOUNTY,TRADCOUNTY from PCLOOKUP where POSTCODE=

    StringBuilder l_query = new StringBuilder();
    StringBuilder l_restQuery = new StringBuilder();
    StringBuilder l_queryType = new StringBuilder();

    l_query.append(
        "AMBIGLIST,ORGANISATION,SUBBUILDING,BUILDINGNAME,BUILDINGNUMBER,"
            + "DEPSTREET,STREET,DEPLOCALITY,LOCALITY,POSTTOWN,COUNTY,"
            + "POSTCODE(PP=16),ADDR,ADDKEY,ORGKEY,LISTTYPE,SEARCHSTATUS,"
            + "LISTCOUNT,AMBIGLIST,BARCODE,ADEPOS,ADESCORE,ADPNRLOC,"
            + "MSCORE,FFLAG,RESCODE,ERRNO,ERRTEXT,COUNTRY,COUNTRYCODE,"
            + "MATCHLVL,PCLVL,INPCLVL,PCCHGLVL,PCCHGTYP,VANITYFLAGS,"
            + "ELEMS_UNMATCHED,ELEMS_MATCHED,ELEMS_CORRECT,"
            + "ELEMS_MISSPELLED,ELEMS_MISSING,FIELDSTATUS,"
            + "OUTPUTSTATUS,ADDFMT_ABBR,ADDFMT_CONC,ADDFMT_TRUN,"
            + "ADDFMT_ELIM,ADMINNUMBER,TRADNUMBER,LONLOCOUT,ADMINCOUNTY,"
            + "TRADCOUNTY,PCG,DHA,OLDPCG,OLDDHA from "); // WDEV-14455

    String postcode = "";
    String Addr = "";
    String buildingNumber = "";
    String street = "";
    String postTown = "";
    String county = "";

    l_restQuery.append("");

    if (searchTypeText.equals("SEARCH")) {
      if (searchCriteria.getAddressSearchText() != null
          && searchCriteria.getAddressSearchText() != "") {
        Addr = searchCriteria.getAddressSearchText();
        if (l_restQuery.length() == 0) l_restQuery.append(" WHERE ADDR=" + "\"" + Addr + "\"");
      }
    } else if (searchTypeText.equals("SELECT")) {
      if (searchCriteria.getAddressPostCode() != null) {
        postcode = searchCriteria.getAddressPostCode().toString();
        l_restQuery.append(" WHERE POSTCODE=" + "\"" + postcode + "\"");
      }

      if (searchStatus != null && !searchStatus.equals("")) {
        if (l_restQuery.length() == 0)
          l_restQuery.append(" WHERE SEARCHSTATUS=" + "\"" + searchStatus + "\"");
        else l_restQuery.append(",SEARCHSTATUS=" + "\"" + searchStatus + "\"");
      }

      if (searchCriteria.getAddressBuildingNumber() != null
          && searchCriteria.getAddressBuildingNumber() != "") {
        buildingNumber = searchCriteria.getAddressBuildingNumber().toString();
        if (l_restQuery.length() == 0)
          l_restQuery.append(" WHERE BUILDINGNUMBER=" + "\"" + buildingNumber + "\"");
        else l_restQuery.append(",BUILDINGNUMBER=" + "\"" + buildingNumber + "\"");
      }
      if (searchCriteria.getAddressStreet() != null && searchCriteria.getAddressStreet() != "") {
        street = searchCriteria.getAddressStreet().toString();
        if (l_restQuery.length() == 0) l_restQuery.append(" WHERE STREET=" + "\"" + street + "\"");
        else l_restQuery.append(",STREET=" + "\"" + street + "\"");
      }

      if (searchCriteria.getAddressPostTown() != null
          && searchCriteria.getAddressPostTown() != "") {
        postTown = searchCriteria.getAddressPostTown().toString();
        if (l_restQuery.length() == 0)
          l_restQuery.append(" WHERE POSTTOWN=" + "\"" + postTown + "\"");
        else l_restQuery.append(",POSTTOWN=" + "\"" + postTown + "\"");
      }
      if (searchCriteria.getAddressCounty() != null && searchCriteria.getAddressCounty() != "") {
        county = searchCriteria.getAddressCounty().toString();
        if (l_restQuery.length() == 0) l_restQuery.append(" WHERE COUNTY=" + "\"" + county + "\"");
        else l_restQuery.append(",COUNTY=" + "\"" + county + "\"");
      }

      // ListItem for Ambiguity selection
      if (listItem != null && listItem != "") {
        if (l_restQuery.length() == 0)
          l_restQuery.append(" WHERE LISTITEM=" + "\"" + listItem + "\"");
        else l_restQuery.append(",LISTITEM=" + "\"" + listItem + "\"");
      }
    } else if (searchTypeText.equals("PCLOOKUP")) {
      if (searchCriteria.getAddressPostCode() != null) {
        postcode = searchCriteria.getAddressPostCode().toString();
        l_restQuery.append(" WHERE POSTCODE=" + "\"" + postcode + "\"");
      }
    }

    l_queryType.append(searchTypeText);

    l_query.append(l_queryType);
    l_query.append(l_restQuery);

    try {
      parseQuery(l_query.toString());
      LOG.info("CAPSCAN Query: " + l_query.toString());
    } catch (Exception e) {
      LOG.error(e.getMessage());
      return null;
    }

    capscan.client.McConnection addressManagerConnection = null;

    try {
      // WDEV-17607
      addressManagerConnection = AddressManager.getConnection();
      if (addressManagerConnection == null
          || (addressManagerConnection != null && addressManagerConnection.errno() != 0)
          || (addressManagerConnection != null && addressManagerConnection.errno() != 1)) {
        AddressManager.connect(
            EnvironmentConfig.getCapscanServerName(),
            EnvironmentConfig.getCapscanPool(),
            McConnection.STATELESS);
        addressManagerConnection = AddressManager.getConnection();
      }
      // WDEV-17607
    } catch (Exception e) {
      LOG.error(e.getMessage());
      return null;
    }

    if (addressManagerConnection == null) {
      LOG.error(
          "Error getting Address Manager connection. Please see server logs for more information.");
      return null;
    }

    // WDEV-19795
    int EventId =
        createSystemLogEntry(
                SystemLogType.PostCodeLookup,
                SystemLogLevel.INFORMATION,
                "Postcode lookup:"
                    + select.toString()
                    + " "
                    + where.toString()
                    + " "
                    + data.toString())
            .getSystemLogEventId();
    // WDEV-19795

    resultsSearch = addressManagerConnection.search(searchType, select, where, data, 15);

    if (resultsSearch != null
        && addressManagerConnection != null
        && addressManagerConnection.errno() == capscan.client.McConnection.OK) {
      // Display results
      // int count = results.length;

      //
      // use for logging search query at level ERROR

      String pools[] = addressManagerConnection.pools();
      LOG.info("QUERY RESULTS");
      pools = addressManagerConnection.pools();
      String column;
      int count = 0;
      int i;
      int k;
      int j;
      count = resultsSearch.length;

      for (j = k = 0; j < pools.length; j++) {
        if (pools.length > 1) {
          LOG.info("Pool " + pools[j] + ":\r\n");
        }

        for (i = 0; k < count && i < select.size(); i++, k++) {
          column = (String) select.elementAt(i);
          LOG.info(column + ":\r\n");
          if (column.equals("AMBIGLIST")) {
            printAmbigList(resultsSearch[k]);
          } else {
            LOG.info("\t" + resultsSearch[k] + "\r\n");
          }
        }
      }

      if (select.size() > 1) {
        String strSubBuildingName = getColumnValue("SUBBUILDING");
        boolean displaystrSubBuildingName = false;

        String strBuildingName = getColumnValue("BUILDINGNAME");
        if (strSubBuildingName != null && !strSubBuildingName.equals("")) {
          if (!strBuildingName.equals("")) {
            // WDEV-17696
            if (ConfigFlag.DOM.HEARTS_REPLICATE_PATIENTS.getValue()) {
              if (strSubBuildingName != null
                  && strBuildingName != null
                  && ConfigFlag.DOM.HEARTS_ADDRESS_LINE_MAXLEN != null) {
                if (strSubBuildingName.length() + strBuildingName.length()
                    <= ConfigFlag.DOM.HEARTS_ADDRESS_LINE_MAXLEN.getValue()) {
                  searchCriteria.setAddressBuildingName(
                      strSubBuildingName + ", " + strBuildingName);
                  displaystrSubBuildingName = true;
                } else searchCriteria.setAddressBuildingName(strBuildingName);
              } else searchCriteria.setAddressBuildingName(strBuildingName);
            } else searchCriteria.setAddressBuildingName(strBuildingName);
          } else searchCriteria.setAddressBuildingName(strSubBuildingName);
        } else {
          searchCriteria.setAddressBuildingName(strBuildingName);
        }

        searchCriteria.setAddressBuildingNumber(getColumnValue("BUILDINGNUMBER"));
        searchCriteria.setAddressLocality(getColumnValue("LOCALITY"));
        // WDEV-15963
        // support for DEPSTREET
        if (getColumnValue("DEPSTREET") != null && !getColumnValue("DEPSTREET").equals(""))
          searchCriteria.setAddressStreet(
              getColumnValue("DEPSTREET") + "," + getColumnValue("STREET"));
        else searchCriteria.setAddressStreet(getColumnValue("STREET"));

        // WDEV-17553
        searchCriteria.setAddressPostTown(getColumnValue("POSTTOWN"));
        if (getColumnValue("POSTTOWN") != null
            && !getColumnValue("POSTTOWN").equals(getColumnValue("COUNTY")))
          searchCriteria.setAddressCounty(getColumnValue("COUNTY"));
        else searchCriteria.setAddressCounty("");

        // WDEV-15963
        searchCriteria.setAddressPostCode(getColumnValue("POSTCODE(PP=16)"));
        searchCriteria.setAddressSearchText(getColumnValue("SEARCHSTATUS"));

        // WDEV-17696
        if (displaystrSubBuildingName)
          searchCriteria.setAddressOrganisation(getColumnValue("ORGANISATION"));
        else if (getColumnValue("ORGANISATION") != null) {

          String strSubBuildingNameNoComma =
              strSubBuildingName != null && strSubBuildingName.length() > 0
                  ? "," + strSubBuildingName
                  : ""; // WDEV-19643
          searchCriteria.setAddressOrganisation(
              !getColumnValue("ORGANISATION").equals("")
                  ? getColumnValue("ORGANISATION") + strSubBuildingNameNoComma
                  : strSubBuildingName);
        }
        // WDEV-14455
        if (ConfigFlag.UI.CAPSCAN_USE_OLDPCT_CODE.getValue()) {
          searchCriteria.setPCTcode(stripspaces(getColumnValue("OLDPCG")));
        } else {
          searchCriteria.setPCTcode(stripspaces(getColumnValue("PCG")));
        }
      }
    } else {
      if (addressManagerConnection != null) {
        LOG.error("error: " + addressManagerConnection.strerror(addressManagerConnection.errno()));
        return null;
      } else {
        LOG.error("error: connection null");
        return null;
      }
    }

    return searchCriteria;
  }