/**
   * Gets the l name score.
   *
   * @param lname the lname
   * @param dbLName the db l name
   * @return the l name score
   */
  private int getLNameScore(String lname, String dbLName) {
    int score = 0;
    int lnamelen = 0;
    int lnamelendiff = 0;
    String lnamemeta = "";
    String db_lnamemeta = "";

    // Get the metaphone value of each  and compare
    Metaphone metaphone = new Metaphone();
    lnamemeta = metaphone.metaphone(lname);
    db_lnamemeta = metaphone.metaphone(dbLName);
    if (lname.length() < dbLName.length()) {
      lnamelen = lname.length() - 1;
      lnamelendiff = dbLName.length() - lname.length();
    } else {
      lnamelen = dbLName.length() - 1;
      lnamelendiff = lname.length() - dbLName.length();
    }
    haveNumber += 5;
    if (lname.compareTo(dbLName) == 0
        || (lnamelendiff == 1 && (lname.regionMatches(true, 0, dbLName, 0, lnamelen)))) {
      score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_LAST_NAME_EXACT));
      haveLname = 1;
      haveBonus += 5;
    } else if (lnamemeta.compareTo(db_lnamemeta) == 0) {
      score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_LAST_NAME_PARTIAL));
      haveLname = 1;
    }
    return score;
  }
  /**
   * Check date of birth.
   *
   * @param userBirthDate the user birth date
   * @param dbPatientBirthDate the db patient birth date
   * @return the int
   */
  private int checkDateOfBirth(Date userBirthDate, Date dbPatientBirthDate) {
    int score = 0;

    if (compareMonthYear(userBirthDate, dbPatientBirthDate)) {
      score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_DOB_PARTIAL));
    } else if (compareDateMonthYear(userBirthDate, dbPatientBirthDate)) {
      score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_DOB_PARTIAL));
    }
    /*else if (compareDateYear(userBirthDate, dbPatientBirthDate))
    {
    	score = Constants.MPI_DOB_P;
    }*/
    return score;
  }
 /**
  * Gets the mRN score.
  *
  * @param mrn the mrn
  * @param siteId the site id
  * @param dbPatientInfo the db patient info
  * @return the mRN score
  */
 private int getMRNScore(String mrn, String siteId, PatientInformation dbPatientInfo) {
   int score = 0;
   if (dbPatientInfo.getParticipantMedicalIdentifierCollection() != null
       && dbPatientInfo.getParticipantMedicalIdentifierCollection().size() > 0) {
     Iterator<String> itr = dbPatientInfo.getParticipantMedicalIdentifierCollection().iterator();
     while (itr.hasNext()) {
       String dbMRN = (String) itr.next();
       String dbSiteId = (String) itr.next();
       String dbSiteName = (String) itr.next();
       // Only MRN is considered because eMPI patients hv no siteID.
       if (mrn.equals(dbMRN)) {
         score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_PMI_EXACT));
       } else {
         score = getMRNPartialScore(mrn, dbMRN);
         if (score == 0) {
           score = processMRNAndGetScore1(mrn, dbMRN);
         }
         if (score == 0) {
           score = processMRNAndGetScore2(mrn, dbMRN);
         }
       }
     }
   }
   return score;
 }
 /**
  * Gets the f name score.
  *
  * @param fname the fname
  * @param dbLName the db l name
  * @return the f name score
  */
 private int getFNameScore(String fname, String dbLName) {
   int score = 0;
   haveNumber += 5;
   if (fname.equals(dbLName)) {
     score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_FIRST_NAME_EXACT));
     haveFname = 1;
     haveBonus += 5;
   } else {
     if (fname.charAt(0) == dbLName.charAt(0)) {
       score =
           Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_FIRST_NAME_PARTIAL));
       haveFname = 1;
     }
   }
   return score;
 }
 /**
  * Gets the sSN partial score.
  *
  * @param tempssnStr the tempssn str
  * @param dbSSN the db ssn
  * @return the sSN partial score
  */
 private int getSSNPartialScore(String tempssnStr, String dbSSN) {
   int score = 0;
   if (tempssnStr.length() == 4) {
     if (tempssnStr.regionMatches(true, 0, dbSSN, 5, tempssnStr.length())) {
       score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_SSN_PARTIAL));
       haveSSN = 1;
       haveBonus++;
     }
   } else {
     if (tempssnStr.equals(dbSSN)) {
       score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_SSN_PARTIAL));
       haveSSN = 1;
       haveBonus++;
     }
   }
   return score;
 }
 /**
  * Gets the mRN partial score.
  *
  * @param tempMRNStr the temp mrn str
  * @param dbMRN the db mrn
  * @return the mRN partial score
  */
 private int getMRNPartialScore(String tempMRNStr, String dbMRN) {
   int score = 0;
   if (tempMRNStr.equals(dbMRN)) {
     score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_PMI_PARTIAL));
     haveSSN = 1;
     haveBonus++;
   }
   return score;
 }
 /**
  * Gets the gender score.
  *
  * @param gender : user entered gender
  * @param dbGender : matched patient gender
  * @return return the score value for gender match
  */
 private int getGenderScore(String gender, String dbGender) {
   int score = 0;
   haveNumber++;
   if (gender.toUpperCase().equals(dbGender)) {
     score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_GENDER_EXACT));
     haveBonus++;
   }
   return score;
 }
 /**
  * Gets the m name partial score.
  *
  * @param mName the m name
  * @param dbLName the db l name
  * @return the m name partial score
  */
 private int getMNamePartialScore(String mName, String dbLName) {
   int score = 0;
   if (((mName.length() == 1 || dbLName.length() == 1) && (mName.charAt(0) == dbLName.charAt(0)))
       || dbLName.length() == 0) {
     score =
         Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_MIDDLE_NAME_PARTIAL));
     haveBonus++;
   }
   return score;
 }
 /**
  * Gets the m name score.
  *
  * @param mName the m name
  * @param dbLName the db l name
  * @return the m name score
  */
 private int getMNameScore(String mName, String dbLName) {
   int score = 0;
   haveNumber++;
   if (mName.equals(dbLName)) {
     score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_MIDDLE_NAME_EXACT));
     haveBonus++;
   } else {
     score = getMNamePartialScore(mName, dbLName);
   }
   return score;
 }
  /**
   * Gets the dob score.
   *
   * @param dobUser : user enterd DOB
   * @param dobDB : matched patient DOB
   * @return score value for the DOB match
   */
  private int getDOBScore(Date dobUser, Date dobDB) {
    int score = 0;
    // String dob = "";
    //		haveNumber += 5;
    // dob = dobUser.toString();
    // if (dob.compareTo(dobDB.toString()) == 0)
    //		if("1926-04-19".equals(dobDB.toString()))
    //		{
    //			System.out.println("jkjkj");
    //		}
    /*	Date date = dobDB.
    if (dobUser.compareTo(dobDB) == 0)
    {
    	score += Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_DOB_EXACT));
    	haveDob = 1;
    	haveBonus += 5;
    }
    else
    {
    	score += checkDateOfBirth(dobUser, dobDB);
    	haveDob = 1;
    }*/

    if (dobUser.getMonth() == dobDB.getMonth()
        && dobUser.getYear() == dobDB.getYear()
        && dobUser.getDate() == dobDB.getDate()) {
      score += Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_DOB_EXACT));
      haveDob = 1;
      haveBonus += 5;
    } else if (compareMonthYear(dobUser, dobDB)) {
      score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_DOB_PARTIAL));
    } else if (compareDateMonthYear(dobUser, dobDB)) {
      score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_DOB_PARTIAL));
    }

    return score;
  }
 /**
  * Gets the ssn score.
  *
  * @param ssn : user entered SSN
  * @param dbSSN : matched patient SSN
  * @return score value for SSN match
  */
 private int getSSNScore(String ssn, String dbSSN) {
   int score = 0;
   haveNumber++;
   if (ssn.equals(dbSSN)) {
     score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_SSN_EXACT));
     haveSSN = 1;
     haveBonus += 5;
   } else {
     score = getSSNPartialScore(ssn, dbSSN);
     if (score == 0) {
       score = processSSNAndGetScore1(ssn, dbSSN);
     }
     if (score == 0) {
       score = processSSNAndGetScore2(ssn, dbSSN);
     }
   }
   return score;
 }
 /**
  * Gets the r score.
  *
  * @param raceTypes :list of race names
  * @param dbRaceCollection : dbRaceCollection
  * @return race matching score
  */
 private int getRScore(String[] raceTypes, Collection dbRaceCollection) {
   boolean raceFound = false;
   int score = 0;
   String raceName = null;
   if (dbRaceCollection != null) {
     Iterator iterator = dbRaceCollection.iterator();
     while (iterator.hasNext()) {
       raceName = (String) iterator.next();
     }
   }
   if (raceTypes != null) {
     for (int k = 0; k < raceTypes.length; k++) {
       if (raceTypes[k].charAt(0) == raceName.charAt(0)) {
         score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_RACE_EXACT));
         haveBonus++;
         haveNumber++;
         break;
       }
     }
   }
   return score;
 }
  /**
   * This method will calculate the score value each patients in the matched patient list by
   * comparing it with the user entered patient information.
   *
   * @param userPatientInfo : user entered PatientInformation object
   * @param dbPatientInfo : matched patient information object
   * @return score value
   */
  public int calculateScore(
      final PatientInformation userPatientInfo, PatientInformation dbPatientInfo) {
    score = 0;
    haveLname = 0;
    haveFname = 0;
    haveBonus = 0;
    haveNumber = 0;
    haveDob = 0;
    haveSSN = 0;

    if (userPatientInfo.getParticipantMedicalIdentifierCollection() != null
        && userPatientInfo.getParticipantMedicalIdentifierCollection().size() > 0) {
      Iterator itr = userPatientInfo.getParticipantMedicalIdentifierCollection().iterator();
      while (itr.hasNext()) {
        String mrn = (String) itr.next();
        String siteId = (String) itr.next();
        String siteName = (String) itr.next();
        score = getMRNScore(mrn, siteId, dbPatientInfo);
        if (score > 0) {
          break;
        }
      }
    }
    if ((userPatientInfo.getLastName() != null && userPatientInfo.getLastName().length() > 0)
        && (dbPatientInfo.getLastName() != null && dbPatientInfo.getLastName().length() > 0)) {
      haveLname = userPatientInfo.getLastName().length();
      score +=
          getLNameScore(
              userPatientInfo.getLastName().toUpperCase(),
              dbPatientInfo.getLastName().toUpperCase());
    }

    if ((userPatientInfo.getFirstName() != null && userPatientInfo.getFirstName().length() > 0)
        && (dbPatientInfo.getFirstName() != null && dbPatientInfo.getFirstName().length() > 0)) {
      haveFname = userPatientInfo.getFirstName().length();
      score +=
          getFNameScore(
              userPatientInfo.getFirstName().toUpperCase(),
              dbPatientInfo.getFirstName().toUpperCase());
    }
    if ((userPatientInfo.getMiddleName() != null && userPatientInfo.getMiddleName().length() > 0)
        && (dbPatientInfo.getMiddleName() != null && dbPatientInfo.getMiddleName().length() > 0)) {
      score +=
          getMNameScore(
              userPatientInfo.getMiddleName().toUpperCase(),
              dbPatientInfo.getMiddleName().toUpperCase());
    }

    if ((userPatientInfo.getSsn() != null && userPatientInfo.getSsn().length() > 0)
        && (dbPatientInfo.getSsn() != null && dbPatientInfo.getSsn().length() > 0)) {
      score += getSSNScore(userPatientInfo.getSsn(), dbPatientInfo.getSsn());
    }

    if ((userPatientInfo.getDob() != null && userPatientInfo.getDob().toString().length() > 0)
        && (dbPatientInfo.getDob() != null && dbPatientInfo.getDob().toString().length() > 0)) {
      score += getDOBScore(userPatientInfo.getDob(), dbPatientInfo.getDob());
    }

    if ((userPatientInfo.getGender() != null && userPatientInfo.getGender().length() > 0)
        && (dbPatientInfo.getGender() != null && dbPatientInfo.getGender().length() > 0)) {
      score +=
          getGenderScore(
              userPatientInfo.getGender().toUpperCase(), dbPatientInfo.getGender().toUpperCase());
    }

    if ((userPatientInfo.getRaceCollection() != null
            && userPatientInfo.getRaceCollection().size() > 0)
        && (dbPatientInfo.getRaceCollection() != null
            && dbPatientInfo.getRaceCollection().size() > 0)) {
      score += getRaceScore(userPatientInfo.getRaceCollection(), dbPatientInfo.getRaceCollection());
    }

    if (haveBonus >= 15
        && (haveBonus == (haveNumber - 1) || haveBonus == haveNumber)
        && score
            < Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_LOOKUP_CUTOFF))) {
      score = Integer.valueOf(XMLPropertyHandler.getValue(Constants.PARTICIPANT_LOOKUP_CUTOFF));
    }
    return score;
  }