Esempio n. 1
0
  /**
   * Creates an address instance via an HL7 XAD string.
   *
   * @param hl7XAD the HL7 XAD string. Can be <code>null</code>.
   * @return the created Address instance. <code>null</code> if no relevant data was found in the
   *     HL7 string.
   */
  public Address fromHL7(String hl7XAD) {
    List<String> parts = HL7.parse(HL7Delimiter.COMPONENT, hl7XAD);
    List<String> sad = HL7.parse(HL7Delimiter.SUBCOMPONENT, HL7.get(parts, 1, false));

    String streetAddress = HL7.get(sad, 1, true);
    String otherDesignation = HL7.get(parts, 2, true);
    String city = HL7.get(parts, 3, true);
    String stateOrProvince = HL7.get(parts, 4, true);
    String zipOrPostalCode = HL7.get(parts, 5, true);
    String country = HL7.get(parts, 6, true);
    String countyParishCode = HL7.get(parts, 9, true);

    if (streetAddress == null
        && otherDesignation == null
        && city == null
        && stateOrProvince == null
        && zipOrPostalCode == null
        && country == null
        && countyParishCode == null) {
      return null;
    }

    Address address = new Address();
    address.setStreetAddress(streetAddress);
    address.setOtherDesignation(otherDesignation);
    address.setCity(city);
    address.setStateOrProvince(stateOrProvince);
    address.setZipOrPostalCode(zipOrPostalCode);
    address.setCountry(country);
    address.setCountyParishCode(countyParishCode);
    return address;
  }
Esempio n. 2
0
  /**
   * Transforms an address instance into an HL7v2 XAD string.
   *
   * @param address the address to transform. Can be <code>null</code>.
   * @return the HL7 representation. <code>null</code> if the input was <code>null</code> or the
   *     resulting HL7 string would be empty.
   */
  public String toHL7(Address address) {
    if (address == null) {
      return null;
    }

    return HL7.render(
        HL7Delimiter.COMPONENT,
        HL7.escape(address.getStreetAddress()),
        HL7.escape(address.getOtherDesignation()),
        HL7.escape(address.getCity()),
        HL7.escape(address.getStateOrProvince()),
        HL7.escape(address.getZipOrPostalCode()),
        HL7.escape(address.getCountry()),
        null,
        null,
        HL7.escape(address.getCountyParishCode()));
  }