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