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.time.OffsetDateTime;
import java.util.Date;
import java.util.Optional;

import ca.uhn.fhir.model.api.IDatatype;
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
import ca.uhn.fhir.model.dstu2.resource.RelatedPerson;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import gov.va.med.pbm.ampl.constant.MockDataConstants;
import gov.va.med.pbm.ampl.model.Provider;
import gov.va.med.pbm.ampl.model.Signature;
import gov.va.med.pbm.ampl.model.patientdemographics.Person;
import gov.va.med.pbm.ampl.utility.DateUtility;

/**
* The UnbundleSignature class marshals a {@link ResourceReferenceDt} resource to a client readable JSON format.
*
* @author Ian Meinert
*
*/
public class UnbundleSignature {

/**
* This method marshals a given resource of {@link Practitioner}, {@link RelatedPerson}, or a {@link Patient} from a
* {@link ResourceReferenceDt}.
*
* @param optResourceReference The {@link Optional} {@link ResourceReferenceDt} containing the fields to be marshalled
* @param optDateElement The {@link Optional} {@link DateTimeDt} containing the fields to be marshalled
* @return {@link Signature} object
*/
public Signature getSignatureFromResourceReference(Optional<ResourceReferenceDt> optResourceReference,
Optional<OffsetDateTime> optDateElement) {
Signature signature = new Signature();

if (optResourceReference.isPresent()) {
ResourceReferenceDt resourceReference = optResourceReference.get();

if (!resourceReference.getDisplayElement().isEmpty()) {
String resourceType = resourceReference.getReference().getResourceType();
UnbundlePerson unbundledPerson = new UnbundlePerson(resourceReference.getResource());

switch (resourceType) {
case "Practitioner":
Provider practitioner = unbundledPerson.getPractitionerAsProvider();
signature.setBlockName(practitioner.getName());
signature.setBlockTitle(practitioner.getRole());
break;
case "RelatedPerson":
Person relatedPerson = unbundledPerson.getRelatedPersonAsPerson();
signature.setBlockName(relatedPerson.getName());
break;
case "Patient":
Person patient = unbundledPerson.getResourceAsPerson();
signature.setBlockName(patient.getName());
break;
default:
signature.setBlockName(resourceReference.getDisplayElement().getValue());
break;
}

if (optDateElement.isPresent()) {
signature.setSignDate(optDateElement.get());
}
}
} else {
signature.setSignator(MockDataConstants.NOT_MAPPED);
}

return signature;
}

/**
* This method marshals an author and date into a {@link Signature}.
*
* @param optAuthor the author
* @param optDate the date
* @return {@link Signature}
*/
public Signature getSignatureFromIDataType(Optional<IDatatype> optAuthor, Optional<Date> optDate) {
Signature signature = new Signature();

if (optAuthor.isPresent()) {
UnbundlePerson unbundledPerson = new UnbundlePerson(optAuthor.get());
Person author = (Person) unbundledPerson.getIDatatypeAsPerson();
OffsetDateTime offsetDateTime = optDate.isPresent() ? DateUtility.offsetDateTimeValueOf(optDate.get()) : null;

// signature.setSignator(this.buildSignatureFromAnnotation(optAuthor, optDate));
signature.setSignDate(offsetDateTime);
signature.setBlockName(author.getName());
}

return signature;
}
}