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 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 Uri 036 * 037 * @param uri Canonical Uri of the code system 038 * @return The valueset (must not be null, but can be an empty ValueSet) 039 */ 040 @Override 041 CodeSystem fetchCodeSystem(FhirContext theContext, String uri); 042 043 /** 044 * Fetch a valueset by Uri 045 * 046 * @param uri Canonical Uri of the ValueSet 047 * @return The valueset (must not be null, but can be an empty ValueSet) 048 */ 049 ValueSet fetchValueSet(FhirContext theContext, String uri); 050 051 /** 052 * Loads a resource needed by the validation (a StructureDefinition, or a 053 * ValueSet) 054 * 055 * @param theContext The HAPI FHIR Context object current in use by the validator 056 * @param theClass The type of the resource to load 057 * @param theUri The resource URI 058 * @return Returns the resource, or <code>null</code> if no resource with the 059 * given URI can be found 060 */ 061 @Override 062 <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri); 063 064 @Override 065 StructureDefinition fetchStructureDefinition(FhirContext theCtx, String theUrl); 066 067 /** 068 * Returns <code>true</code> if codes in the given code system can be expanded 069 * or validated 070 * 071 * @param theSystem The URI for the code system, e.g. <code>"http://loinc.org"</code> 072 * @return Returns <code>true</code> if codes in the given code system can be 073 * validated 074 */ 075 @Override 076 boolean isCodeSystemSupported(FhirContext theContext, String theSystem); 077 078 /** 079 * Generate a snapshot from the given differential profile. 080 * 081 * @return Returns null if this module does not know how to handle this request 082 */ 083 StructureDefinition generateSnapshot(StructureDefinition theInput, String theUrl, String theWebUrl, String theProfileName); 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 The code system, e.g. "<code>http://loinc.org</code>" 091 * @param theCode The code, e.g. "<code>1234-5</code>" 092 * @param theDisplay The display name, if it should also be validated 093 * @return Returns a validation result object 094 */ 095 @Override 096 CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay); 097 098 class CodeValidationResult extends IContextValidationSupport.CodeValidationResult<ConceptDefinitionComponent, IssueSeverity> { 099 100 public CodeValidationResult(ConceptDefinitionComponent theNext) { 101 super(theNext); 102 } 103 104 public CodeValidationResult(IssueSeverity theSeverity, String theMessage) { 105 super(theSeverity, theMessage); 106 } 107 108 public CodeValidationResult(IssueSeverity severity, String message, ConceptDefinitionComponent definition) { 109 super(severity, message, definition); 110 } 111 112 @Override 113 protected String getDisplay() { 114 String retVal = null; 115 if (isOk()) { 116 retVal = asConceptDefinition().getDisplay(); 117 } 118 return retVal; 119 } 120 121 } 122 123}