/*
 * NIST HL7 Web Service
 * Hl7MessageValidationInterface.java Oct 11, 2007
 *
 * This code was produced by the National Institute of Standards and
 * Technology (NIST). See the "nist.disclaimer" file given in the distribution
 * for information on the use and redistribution of this software.
 */
package gov.nist.hl7.ws.messagevalidation;

/**
 * NIST HL7 V2 Message Validation Web Service
 * <p>
 * This service provides an interface for validating HL7 version 2 (V2) message instances
 * against a message profile and a validation context. The interface is designed
 * for use in a web-service environment. The method are intended to be simple and in many cases
 * atomic calls. Parameters and return values are intentionally made to be simple objects. This
 * provides for a flexible interface for building a user specific interface.
 * <p>
 * This service supports validation for HL7 Version 2.3.1, 2.4, 2.5, and 2.5.1. The version that is
 * used for validation is indicated in the message profile.
 * <p>
 * @author Robert Snelick (NIST)
 *
 */
public interface Hl7MessageValidationInterface {

    /**
     * Load the message to be validated. This is an HL7 V2 message instance. The interface
     * supports the native HL7 V2 ER7 encoding and HL7 V2 XML encoding.
     *
     * @param message an HL7 V2 ER7 encoded message instance or an HL7 V2 XML encoded message
     * instance
     * <p>
     * @return true if the message instance is valid with respect to the profile and the validation
     * context; false otherwise.
     */
    boolean loadMessage(String message) throws Exception;

    /**
     * Use the handle identified by the OID. A handle represents a package of resources (e.g., a profile and a table file).
     * The repository is searched using the OID, if the handle is located all of the artifacts linked with handle
     * is used when performing message validation.
     * @param oid referencing a handle
     * @return true if handle was located in the repository and processed successfully; false otherwise.
     */
    boolean useHandle(String oid) throws Exception;

    /**
     * Load an HL7 version 2 message profile. The profile is an XML document
     * that follows the rules given in the HL7 version 2 profile schema.
     * <p>
     * @param xmlProfile an HL7 version 2 message profile.
     * <p>
     * @return true if profile was loaded and processed successfully; false otherwise.
     */
    boolean loadProfile(String xmlProfile) throws Exception;

    /**
     * Use the profile identified by the OID. The repository is searched using the OID, if the profile
     * is located it is use for performing message validation.
     * <p>
     * @param oid referencing an HL7 version message profile.
     * <p>
     * @return true if profile was located in the repository and processed successfully; false
     * otherwise.
     */
    boolean useProfile(String oid) throws Exception;

    /**
     * The loadResource method allows a user to load additional resources that can be used in the
     * validation process. This may be a table that specifies local codes. Each resource type defines
     * the format of the given resource. More than one resource can be associated to a validation process.
     * <p>
     * TBD-what are the resource types and their formats.
     * <p>
     * @param xmlResource a resource that is used in the validation process.
     * <p>
     * @param resourceType a document that describes the type of the xmlResource; for example, an XML
     * schema.
     * <p>
     * @return true if the resource has been successfully loaded and processed; false otherwise.
     */
    boolean loadResource(java.lang.String xmlResource, java.lang.String resourceType) throws Exception;

    /**
     * The useResource method allows a user to access a resource that can be used in the
     * validation process. This may be a table that specifies local codes. More than one
     * resource can be associated to a validation process. Resource files are stored in the
     * repository.
     * <p>
     * TBD-what are the resource types and their formats.
     * <p>
     * @param oid an object identifier to reference the resource
     * <p>
     * @return true if the resource was located in the repository and processed successfully; false otherwise.
     */
    boolean useResource(java.lang.String oid) throws Exception;

    /**
     * The validation context describes the circumstances in which the message instance is validated. It
     * may reference the profile and resources, it may describe how to interpret flagged items, and it may
     * specify specific tests. The validation context is encoded in an XML document that adheres to the
     * validation context schema. For details of the format see...
     * <p>
     * @param xmlValidationContext the message validation context describes the circumstances the message
     * instance will be validated against.
     * <p>
     * @return true is the validation context has been successfully loaded and processed; false otherwise.
     */
    boolean setValidationContext(java.lang.String xmlValidationContext) throws Exception;

    /**
     * Perform the message validation.
     * <p>
     * @return true if the message is valid with respect to the message profile and the message validation context. The
     * method returns false if the message is not valid with respect to the message profile and message validation context
     * or if an error occurred during the validation process (e.g., a profile was not located).
     */
    boolean validate() throws Exception;

    /**
     * Get the status of the service.
     * <p>
     * @return true if the service is available; false if the service unavailable (e.g., running but too busy).
     */
    boolean getServiceStatus() throws Exception;

    /**
     *  Get a detailed report of the message validation results in an XML document. The results are
     *  described in the results schema (see .... for details).
     * <p>
     * @return an XML document with a detailed of the message validation results.
     */
    String getValidationReport() throws Exception;

    /**
     * Get the message of the last exception caught.
     * <p>
     * @return a description of the last exception.
     */
    String getLastExceptionMessage() throws Exception;
}
