/*******************************************************************************
 * Copyright © 2004 VHA. All rights reserved
 ******************************************************************************/
package gov.va.med.esr.common.builder.entity.metaData;

// Java Classes

// Library Classes

// Framework Classes
import gov.va.med.fw.hl7.segment.OBX;
import gov.va.med.fw.hl7.segment.PD1;
import gov.va.med.fw.hl7.segment.ZEL;

import gov.va.med.esr.common.builder.datatype.metadata.CE;
import gov.va.med.esr.common.builder.datatype.metadata.XON;
import gov.va.med.esr.common.builder.entity.BeneficiaryMetaData;
import gov.va.med.esr.common.model.person.Person;

public class BeneficiaryMetaDataFromZEL
    extends AbstractMetaData
    implements BeneficiaryMetaData
{
	private Person entity;

    private OBX obx;
	private ZEL zel;
    
    private CE sensitiveRecord;
    private XON cmor;
    private String claimFolderLocation;
    private String sendingFacility;

    public BeneficiaryMetaDataFromZEL(ZEL zel, PD1 pd1, OBX obx, String sendingFacility)
    {
        super();

        this.zel = zel;
        this.obx = obx;

        this.cmor = (pd1 == null) ? null : XON.create(pd1.getCIRN(), pd1
            .getComponentDelimiter(), pd1.getSubComponentDelimiter());
        this.sensitiveRecord = (obx == null) ? null : CE.create(obx
            .getObservationValue(), obx.getComponentDelimiter());

        String unprocessedLocation = (this.zel == null) ? null : this.zel
            .getClaimFolderLocation();
        this.claimFolderLocation = ((unprocessedLocation == null) || (unprocessedLocation
            .length() < 3)) ? unprocessedLocation : unprocessedLocation
            .substring(0, 3);
        
        this.sendingFacility = sendingFacility;
    }

    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#getEntity()
     */
    public Person getEntity()
    {
        return this.entity;
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#setEntity(gov.va.med.esr.common.model.person.Beneficiary)
     */
    public void setEntity(Person entity)
    {
        this.entity = entity;
    }
    

    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#getClaimFolderLocation()
     */
    public String getClaimFolderLocation()
    {
        return this.claimFolderLocation;
    }

    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#getClaimFolderNumber()
     */
    public String getClaimFolderNumber()
    {
        return (this.zel == null) ? null : this.zel.getClaimFolderNumber();
    }

    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#getCMOR()
     */
    public String getCMOR()
    {
        return (this.cmor == null) ? null : super.getValue(this.cmor
            .getOrganizationName());
    }

    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#getSensitiveRecord()
     */
    public String getSensitiveRecord()
    {
        return (this.sensitiveRecord == null) ? null : super
            .getValue(this.sensitiveRecord.getID());
    }

    public String getSensitivityChangeDate()
    {
        return (obx == null) ? null : obx.getObservationDate();
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#getUserEnrolleeSite()
     */
    public String getUserEnrolleeSite()
    {
        return (this.zel == null) ? null : this.zel.getUserEnrolleeSite();
    }

    /*
     * (non-Javadoc)
     * 
     * @see gov.va.med.esr.messaging.builder.entity.BeneficiaryMetaData#getUserEnrolleeValidThrough()
     */
    public String getUserEnrolleeValidThrough()
    {
        return (this.zel == null) ? null : this.zel
            .getUserEnrolleeValidThrough();
    }
    
    public String getSensitivityChangeSite()
    {
        return sendingFacility;
    }
    
}