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 java.util.List; 024 025import org.hl7.fhir.instance.model.api.IBaseResource; 026 027import ca.uhn.fhir.context.FhirContext; 028 029public interface IContextValidationSupport<EVS_IN, EVS_OUT, SDT, CST, CDCT, IST> { 030 031 /** 032 * Expands the given portion of a ValueSet 033 * 034 * @param theInclude 035 * The portion to include 036 * @return The expansion 037 */ 038 EVS_OUT expandValueSet(FhirContext theContext, EVS_IN theInclude); 039 040 /** 041 * Load and return all possible structure definitions 042 */ 043 List<SDT> fetchAllStructureDefinitions(FhirContext theContext); 044 045 046 /** 047 * Fetch a code system by ID 048 * 049 * @param theSystem 050 * The code system 051 * @return The valueset (must not be null, but can be an empty ValueSet) 052 */ 053 CST fetchCodeSystem(FhirContext theContext, String theSystem); 054 055 /** 056 * Loads a resource needed by the validation (a StructureDefinition, or a 057 * ValueSet) 058 * 059 * @param theContext 060 * The HAPI FHIR Context object current in use by the validator 061 * @param theClass 062 * The type of the resource to load 063 * @param theUri 064 * 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 077 * The URI for the code system, e.g. <code>"http://loinc.org"</code> 078 * @return Returns <code>true</code> if codes in the given code system can be 079 * validated 080 */ 081 boolean isCodeSystemSupported(FhirContext theContext, String theSystem); 082 083/** 084 * Validates that the given code exists and if possible returns a display 085 * name. This method is called to check codes which are found in "example" 086 * binding fields (e.g. <code>Observation.code</code> in the default profile. 087 * 088 * @param theCodeSystem 089 * The code system, e.g. "<code>http://loinc.org</code>" 090 * @param theCode 091 * The code, e.g. "<code>1234-5</code>" 092 * @param theDisplay 093 * The display name, if it should also be validated 094 * @return Returns a validation result object 095 */ 096 CodeValidationResult<CDCT, IST> validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay); 097 098 public class CodeValidationResult<CDCT, IST> { 099 private CDCT definition; 100 private String message; 101 private IST severity; 102 103 public CodeValidationResult(CDCT theNext) { 104 this.definition = theNext; 105 } 106 107 public CodeValidationResult(IST severity, String message) { 108 this.severity = severity; 109 this.message = message; 110 } 111 112 public CodeValidationResult(IST severity, String message, CDCT definition) { 113 this.severity = severity; 114 this.message = message; 115 this.definition = definition; 116 } 117 118 public CDCT asConceptDefinition() { 119 return definition; 120 } 121 122 public String getMessage() { 123 return message; 124 } 125 126 public IST getSeverity() { 127 return severity; 128 } 129 130 public boolean isOk() { 131 return definition != null; 132 } 133 134 } 135 136}