private static PatientName extractName(PNExplicit name) {
    String nameString = "";
    Boolean hasName = false;
    PatientName result = new PatientName();
    List<Serializable> choice = name.getContent();
    Iterator<Serializable> iterSerialObjects = choice.iterator();

    EnExplicitFamily familyName = new EnExplicitFamily();
    EnExplicitGiven givenName = new EnExplicitGiven();

    while (iterSerialObjects.hasNext()) {
      Serializable contentItem = iterSerialObjects.next();

      if (contentItem instanceof JAXBElement) {
        JAXBElement oJAXBElement = (JAXBElement) contentItem;
        if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
          familyName = (EnExplicitFamily) oJAXBElement.getValue();
          result.LastName = familyName.getContent();
          hasName = true;
        } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
          givenName = (EnExplicitGiven) oJAXBElement.getValue();
          if (result.FirstName == "") {
            result.FirstName = givenName.getContent();
            ;
          } else {
            result.MiddleName = givenName.getContent();
            ;
          }
          hasName = true;
        } else if (oJAXBElement.getValue() instanceof EnExplicitPrefix) {
          EnExplicitPrefix prefix = (EnExplicitPrefix) oJAXBElement.getValue();
          result.Title = prefix.getContent();
        } else if (oJAXBElement.getValue() instanceof EnExplicitSuffix) {
          EnExplicitSuffix suffix = (EnExplicitSuffix) oJAXBElement.getValue();
          result.Suffix = suffix.getContent();
        }
      }
    }

    if (hasName == true) {
      nameString = familyName.getContent();
      System.out.println(nameString);
    }

    return result;
  }
  public static PersonName ExtractPersonName(PRPAMT201306UV02ParameterList params) {
    log.debug("Entering HL7Parser201305.ExtractPersonName method...");

    PersonName personname = new PersonName();

    // Extract the name from the query parameters - Assume only one was specified
    if (params.getLivingSubjectName() != null
        && params.getLivingSubjectName().size() > 0
        && params.getLivingSubjectName().get(0) != null) {
      PRPAMT201306UV02LivingSubjectName name = params.getLivingSubjectName().get(0);

      if (name.getValue() != null && name.getValue().size() > 0 && name.getValue().get(0) != null) {
        List<Serializable> choice = name.getValue().get(0).getContent();

        log.info("choice.size()=" + choice.size());

        Iterator<Serializable> iterSerialObjects = choice.iterator();

        String nameString = "";
        EnExplicitFamily lastname = null;
        EnExplicitGiven firstname = null;

        while (iterSerialObjects.hasNext()) {
          log.info("in iterSerialObjects.hasNext() loop");

          Serializable contentItem = iterSerialObjects.next();

          if (contentItem instanceof String) {
            log.info("contentItem is string");
            String strValue = (String) contentItem;

            if (nameString != null) {
              nameString += strValue;
            } else {
              nameString = strValue;
            }
            log.info("nameString=" + nameString);
          } else if (contentItem instanceof JAXBElement) {
            log.info("contentItem is JAXBElement");

            JAXBElement oJAXBElement = (JAXBElement) contentItem;

            if (oJAXBElement.getValue() instanceof EnExplicitFamily) {
              lastname = new EnExplicitFamily();
              lastname = (EnExplicitFamily) oJAXBElement.getValue();
              log.info("found lastname element; content=" + lastname.getContent());
            } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) {
              if (firstname == null) {
                firstname = new EnExplicitGiven();
                firstname = (EnExplicitGiven) oJAXBElement.getValue();
                log.info("found firstname element; content=" + firstname.getContent());
              } else {
                // this would be where to add handle for middlename
              }
            } else {
              log.info("other name part=" + (ENXPExplicit) oJAXBElement.getValue());
            }
          } else {
            log.info("contentItem is other");
          }
        }

        // If text string in patient name, then set in name
        // else set in element.
        boolean namefound = false;
        if (lastname != null && lastname.getContent() != null) {
          personname.setLastName(lastname.getContent());
          log.info("FamilyName : " + personname.getLastName());
          namefound = true;
        }

        if (firstname != null && firstname.getContent() != null) {
          personname.setFirstName(firstname.getContent());
          log.info("GivenName : " + personname.getFirstName());
          namefound = true;
        }

        if (!namefound && !nameString.trim().contentEquals("")) {
          log.info("setting name by nameString " + nameString);
          personname.setLastName(nameString);
        }
      } else {
        log.info("message does not contain a subject name");
      }
    } else {
      log.info("message does not contain a subject name");
    }

    log.debug("Exiting HL7Parser201305.ExtractPersonName method...");
    return personname;
  }