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.List;
import java.util.Optional;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.HealthcareService;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
import ca.uhn.fhir.model.dstu2.resource.Practitioner.PractitionerRole;
import ca.uhn.fhir.model.dstu2.resource.RelatedPerson;
import gov.va.med.pbm.ampl.model.Provider;
import gov.va.med.pbm.ampl.model.patientdemographics.Person;
/**
* The UnbundlePerson class marshals a {@link Person} resource to a client readable JSON format.
*
* @author Ian Meinert
*/
public class UnbundlePerson {
private IBaseResource resource;
private IDatatype iDatatype;
/**
* The overloaded constructor accepting a list of {@link ResourceReferenceDt}.
*
* @param resourceReferences list of {@link ResourceReferenceDt}
*/
public UnbundlePerson(List<ResourceReferenceDt> resourceReferences) {
if (!resourceReferences.isEmpty()) {
this.resource = resourceReferences.get(0).getResource();
}
}
/**
* The overloaded constructor accepting a {@link IBaseResource}.
*
* @param resource {@link IBaseResource}
*/
public UnbundlePerson(IBaseResource resource) {
this.resource = resource;
}
/**
* The overloaded constructor accepting a {@link IDatatype}.
*
* @param iDatatype {@link IDatatype}
*/
public UnbundlePerson(IDatatype iDatatype) {
this.iDatatype = iDatatype;
}
/**
* This method unbundles the {@link IBaseResource} casted to a {@link Practitioner} as a {@link Provider}.
*
* @return {@link Provider}.
*/
public Provider getPractitionerAsProvider() {
Provider provider = new Provider();
if (resource != null) {
Practitioner practitioner = (Practitioner) resource;
UnbundleContact contact = new UnbundleContact();
PractitionerRole role = practitioner.getPractitionerRoleFirstRep();
UnbundleFacility facility = new UnbundleFacility(role.getManagingOrganization());
HealthcareService healthcareService = role.getHealthcareService().size() > 0
? (HealthcareService) role.getHealthcareService().get(0).getResource()
: null;
Optional<HealthcareService> optStatus = Optional.ofNullable(healthcareService);
provider.setContactDetails(contact.getContact(practitioner.getTelecom()));
provider.setFacility(facility.getResourceAsOrganization());
provider.setName(practitioner.getName().getNameAsSingleString());
provider.setRole(role.getRole().getText());
provider.setStatus(optStatus.isPresent() ? optStatus.get().getServiceName() : new String());
}
return provider;
}
/**
* This method unbundles the {@link IBaseResource} casted to a {@link Practitioner} as a {@link Person}.
*
* @return {@link Person}.
*/
public Person getPractitionerAsPerson() {
Person person = new Person();
if (resource != null) {
Practitioner practitioner = (Practitioner) resource;
UnbundleContact contact = new UnbundleContact();
PractitionerRole role = practitioner.getPractitionerRoleFirstRep();
UnbundleFacility facility = new UnbundleFacility(role.getManagingOrganization());
person.setAddress(facility.getResourceAsOrganization().getLocation());
person.setContactDetails(contact.getContact(practitioner.getTelecom()));
person.setName(practitioner.getName().getNameAsSingleString());
person.setRelationship(role.getRole().getText());
}
return person;
}
/**
* This method unbundles the {@link IBaseResource} casted to a {@link RelatedPerson} as a {@link Person}.
*
* @return {@link Person}.
*/
public Person getRelatedPersonAsPerson() {
Person person = new Person();
if (resource != null) {
RelatedPerson relatedPerson = (RelatedPerson) resource;
UnbundleContact contact = new UnbundleContact();
UnbundleAddress address = new UnbundleAddress(relatedPerson.getAddress());
person.setAddress(address.getAddressAsWork());
person.setContactDetails(contact.getContact(relatedPerson.getTelecom()));
person.setName(relatedPerson.getName().getNameAsSingleString());
person.setRelationship(relatedPerson.getRelationship().getText());
}
return person;
}
/**
* This method unbundles the {@link IBaseResource} casted to a {@link Patient} as a {@link Person}.
*
* @return {@link Person}.
*/
public Person getPatientAsPerson() {
Person person = new Person();
if (resource != null) {
Patient patient = (Patient) resource;
UnbundleContact contact = new UnbundleContact();
UnbundleAddress address = new UnbundleAddress(patient.getAddress());
person.setAddress(address.getAddressAsWork());
person.setContactDetails(contact.getContact(patient.getTelecom()));
person.setName(patient.getNameFirstRep().getNameAsSingleString());
}
return person;
}
/**
* This method unbundles the {@link IBaseResource} casted to a {@link ca.uhn.fhir.model.dstu2.resource.Person} as a
* {@link Person}.
*
* @return {@link Person}.
*/
public Person getResourceAsPerson() {
return this.setFromFhirPerson((ca.uhn.fhir.model.dstu2.resource.Person) resource);
}
/**
* This method unbundles the {@link IDatatype} casted to a {@link ca.uhn.fhir.model.dstu2.resource.Person} as a
* {@link Person}.
*
* @return {@link Person}.
*/
public Person getIDatatypeAsPerson() {
return this.setFromFhirPerson((ca.uhn.fhir.model.dstu2.resource.Person) iDatatype);
}
/**
* This method unbundles a {@link ca.uhn.fhir.model.dstu2.resource.Person} as a {@link Person}.
*
* @param fhirPerson {@link ca.uhn.fhir.model.dstu2.resource.Person}
* @return {@link Person}.
*/
private Person setFromFhirPerson(ca.uhn.fhir.model.dstu2.resource.Person fhirPerson) {
Person person = new Person();
if (fhirPerson != null) {
UnbundleContact contact = new UnbundleContact();
UnbundleAddress address = new UnbundleAddress(fhirPerson.getAddress());
person.setAddress(address.getAddressAsWork());
person.setContactDetails(contact.getContact(fhirPerson.getTelecom()));
person.setName(fhirPerson.getNameFirstRep().getNameAsSingleString());
}
return person;
}
}