001package ca.uhn.fhir.context.support;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2017 University Health Network
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.context.FhirContext;
024import org.hl7.fhir.instance.model.api.IBaseResource;
025
026import java.util.List;
027
028public interface IContextValidationSupport<EVS_IN, EVS_OUT, SDT, CST, CDCT, IST> {
029
030        /**
031         * Expands the given portion of a ValueSet
032         *
033         * @param theInclude The portion to include
034         * @return The expansion
035         */
036        EVS_OUT expandValueSet(FhirContext theContext, EVS_IN theInclude);
037
038        /**
039         * Load and return all conformance resources associated with this
040         * validation support module. This method may return null if it doesn't
041         * make sense for a given module.
042         */
043        List<IBaseResource> fetchAllConformanceResources(FhirContext theContext);
044
045        /**
046         * Load and return all possible structure definitions
047         */
048        List<SDT> fetchAllStructureDefinitions(FhirContext theContext);
049
050        /**
051         * Fetch a code system by ID
052         *
053         * @param theSystem The code system
054         * @return The valueset (must not be null, but can be an empty ValueSet)
055         */
056        CST fetchCodeSystem(FhirContext theContext, String theSystem);
057
058        /**
059         * Loads a resource needed by the validation (a StructureDefinition, or a
060         * ValueSet)
061         *
062         * @param theContext The HAPI FHIR Context object current in use by the validator
063         * @param theClass   The type of the resource to load
064         * @param theUri     The resource URI
065         * @return Returns the resource, or <code>null</code> if no resource with the
066         * given URI can be found
067         */
068        <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri);
069
070        SDT fetchStructureDefinition(FhirContext theCtx, String theUrl);
071
072        /**
073         * Returns <code>true</code> if codes in the given code system can be expanded
074         * or validated
075         *
076         * @param theSystem The URI for the code system, e.g. <code>"http://loinc.org"</code>
077         * @return Returns <code>true</code> if codes in the given code system can be
078         * validated
079         */
080        boolean isCodeSystemSupported(FhirContext theContext, String theSystem);
081
082        /**
083         * Validates that the given code exists and if possible returns a display
084         * name. This method is called to check codes which are found in "example"
085         * binding fields (e.g. <code>Observation.code</code> in the default profile.
086         *
087         * @param theCodeSystem The code system, e.g. "<code>http://loinc.org</code>"
088         * @param theCode       The code, e.g. "<code>1234-5</code>"
089         * @param theDisplay    The display name, if it should also be validated
090         * @return Returns a validation result object
091         */
092        CodeValidationResult<CDCT, IST> validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay);
093
094        public class CodeValidationResult<CDCT, IST> {
095                private CDCT definition;
096                private String message;
097                private IST severity;
098
099                public CodeValidationResult(CDCT theNext) {
100                        this.definition = theNext;
101                }
102
103                public CodeValidationResult(IST severity, String message) {
104                        this.severity = severity;
105                        this.message = message;
106                }
107
108                public CodeValidationResult(IST severity, String message, CDCT definition) {
109                        this.severity = severity;
110                        this.message = message;
111                        this.definition = definition;
112                }
113
114                public CDCT asConceptDefinition() {
115                        return definition;
116                }
117
118                public String getMessage() {
119                        return message;
120                }
121
122                public IST getSeverity() {
123                        return severity;
124                }
125
126                public boolean isOk() {
127                        return definition != null;
128                }
129
130        }
131
132}