Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.med.pbm.ampl.fhir.unmarshall.dstu2.unbundle;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import ca.uhn.fhir.model.dstu2.composite.AddressDt;
import ca.uhn.fhir.model.primitive.StringDt;
import gov.va.med.pbm.ampl.constant.AmplConstants;
import gov.va.med.pbm.ampl.model.address.Address;
import gov.va.med.pbm.ampl.model.address.ConfidentialAddress;
import gov.va.med.pbm.ampl.model.address.PermanentAddress;
import gov.va.med.pbm.ampl.model.address.TemporaryAddress;
/**
* The UnbundleSignature class marshals a {@link AddressDt} resource to a client readable JSON format.
*
* @author Ian Meinert
*/
public class UnbundleAddress {
private List<AddressDt> addresses;
/**
* Overloaded constructor accepting a List of {@list AddressDt}.
*
* @param addresses List of {@link AddressDt}
*/
public UnbundleAddress(List<AddressDt> addresses) {
this.addresses = addresses;
}
/**
* Overloaded constructor accepting a {@list AddressDt}.
* <p>
* The address will be added to the addresses class property.
*
* @param address {@link AddressDt}
*/
public UnbundleAddress(AddressDt address) {
addresses = new ArrayList<AddressDt>();
addresses.add(address);
}
/**
* This method finds and returns an address using the given class type.
*
* @return an address which inherits from {@link ConfidentialAddress}
*/
public ConfidentialAddress getAddressAsConfidential() {
ConfidentialAddress address = new ConfidentialAddress();
address.setAddress(this.doSelectAddressByTypeCode("Home")); // FIXME Need the code for this
return address;
}
/**
* This method finds and returns an address using the given class type.
*
* @return an address which inherits from {@link PermanentAddress}
*/
public PermanentAddress getAddressAsPermanent() {
PermanentAddress address = new PermanentAddress();
address.setAddress(this.doSelectAddressByTypeCode("Home"));
return address;
}
/**
* This method finds and returns an address using the given class type.
*
* @return an address which inherits from {@link TemporaryAddress}
*/
public TemporaryAddress getAddressAsTemporary() {
TemporaryAddress address = new TemporaryAddress();
address.setAddress(this.doSelectAddressByTypeCode("Temporary"));
return address;
}
/**
* This method finds and returns an address using the given class type.
*
* @return {@link Address}
*/
public Address getAddressAsWork() {
return this.doSelectAddressByTypeCode("Work");
}
/**
* This method selects an address by given FHIR type.
*
* @param use FHIR {@link AddressDt} use
* @return {@link Address}
*/
private Address doSelectAddressByTypeCode(String use) {
Address address = new Address();
if (!addresses.isEmpty()) {
List<AddressDt> addressDts = new ArrayList<AddressDt>();
addressDts = addresses.stream().filter(s -> {
Optional<String> optUse = Optional.ofNullable(s.getUse());
if (optUse.isPresent()) {
return use.equalsIgnoreCase(optUse.get());
}
return false;
}).collect(Collectors.toList());
if (!addressDts.isEmpty()) {
AddressDt addressDt = addressDts.get(0);
if (!addressDt.getLine().isEmpty()) {
int lineCount = addressDt.getLine().size();
if (lineCount >= AmplConstants.NUMBER_ONE) {
Optional<StringDt> line1 = Optional.of(addressDt.getLine().get(0));
address.setStreet(line1.isPresent() ? line1.get().toString() : new String());
if (lineCount >= AmplConstants.NUMBER_TWO) {
Optional<StringDt> line2 = Optional.of(addressDt.getLine().get(1));
address.setStreetLine2(line2.isPresent() ? line1.get().toString() : new String());
if (lineCount >= AmplConstants.NUMBER_THREE) {
Optional<StringDt> line3 = Optional.of(addressDt.getLine().get(2));
address.setStreetLine3(line3.isPresent() ? line1.get().toString() : new String());
}
}
}
}
address.setCity(addressDt.getCity());
address.setCounty(addressDt.getDistrict());
address.setState(addressDt.getState());
address.setZip(addressDt.getPostalCode());
address.setCountry(addressDt.getCountry());
}
}
return address;
}
}