001package org.hl7.fhir.r4.hapi.ctx;
002
003import ca.uhn.fhir.context.FhirContext;
004import ca.uhn.fhir.context.support.IContextValidationSupport;
005import org.hl7.fhir.instance.model.api.IBaseResource;
006import org.hl7.fhir.r4.model.CodeSystem;
007import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
008import org.hl7.fhir.r4.model.StructureDefinition;
009import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent;
010import org.hl7.fhir.r4.terminologies.ValueSetExpander;
011import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
012
013import java.util.List;
014
015public interface IValidationSupport
016                extends ca.uhn.fhir.context.support.IContextValidationSupport<ConceptSetComponent, ValueSetExpander.ValueSetExpansionOutcome, StructureDefinition, CodeSystem, ConceptDefinitionComponent, IssueSeverity> {
017
018        /**
019         * Expands the given portion of a ValueSet
020         * 
021         * @param theInclude
022         *           The portion to include
023         * @return The expansion
024         */
025        @Override
026   ValueSetExpander.ValueSetExpansionOutcome expandValueSet(FhirContext theContext, ConceptSetComponent theInclude);
027
028        /**
029         * Load and return all possible structure definitions
030         */
031        @Override
032        List<StructureDefinition> fetchAllStructureDefinitions(FhirContext theContext);
033
034        /**
035         * Fetch a code system by ID
036         * 
037         * @param theSystem
038         *           The code system
039         * @return The valueset (must not be null, but can be an empty ValueSet)
040         */
041        @Override
042        CodeSystem fetchCodeSystem(FhirContext theContext, String theSystem);
043
044        /**
045         * Loads a resource needed by the validation (a StructureDefinition, or a
046         * ValueSet)
047         * 
048         * @param theContext
049         *           The HAPI FHIR Context object current in use by the validator
050         * @param theClass
051         *           The type of the resource to load
052         * @param theUri
053         *           The resource URI
054         * @return Returns the resource, or <code>null</code> if no resource with the
055         *         given URI can be found
056         */
057        @Override
058        <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri);
059
060        @Override
061        StructureDefinition fetchStructureDefinition(FhirContext theCtx, String theUrl);
062
063        /**
064         * Returns <code>true</code> if codes in the given code system can be expanded
065         * or validated
066         * 
067         * @param theSystem
068         *           The URI for the code system, e.g. <code>"http://loinc.org"</code>
069         * @return Returns <code>true</code> if codes in the given code system can be
070         *         validated
071         */
072        @Override
073        boolean isCodeSystemSupported(FhirContext theContext, String theSystem);
074
075        /**
076         * Validates that the given code exists and if possible returns a display
077         * name. This method is called to check codes which are found in "example"
078         * binding fields (e.g. <code>Observation.code</code> in the default profile.
079         * 
080         * @param theCodeSystem
081         *           The code system, e.g. "<code>http://loinc.org</code>"
082         * @param theCode
083         *           The code, e.g. "<code>1234-5</code>"
084         * @param theDisplay
085         *           The display name, if it should also be validated
086         * @return Returns a validation result object
087         */
088        @Override
089        CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay);
090
091        class CodeValidationResult extends IContextValidationSupport.CodeValidationResult<ConceptDefinitionComponent, IssueSeverity> {
092
093                public CodeValidationResult(ConceptDefinitionComponent theNext) {
094                        super(theNext);
095                }
096
097                public CodeValidationResult(IssueSeverity theSeverity, String theMessage) {
098                        super(theSeverity, theMessage);
099                }
100
101                public CodeValidationResult(IssueSeverity severity, String message, ConceptDefinitionComponent definition) {
102                        super(severity, message, definition);
103                }
104
105        }
106
107}