001package ca.cdr.api.model.json; 002 003import com.fasterxml.jackson.annotation.JsonProperty; 004import io.swagger.v3.oas.annotations.media.Schema; 005import jakarta.annotation.Nullable; 006 007import java.util.Objects; 008 009@SuppressWarnings("UnusedReturnValue") 010@Schema(name = "TokenizationRule", description = "Defines a single rule for FHIR Repository Tokenization") 011public class TokenizationRuleJson implements IModelJson, Cloneable { 012 013 @Schema( 014 description = 015 "An optional description of this rule. This field does not affect the functionality of the rule, but can be used as documentation.") 016 @JsonProperty(value = "description", required = false) 017 private String myDescription; 018 019 @Schema( 020 description = 021 "A FHIRPath expression within a resource pointing to the element to tokenize. The value must begin with a resource type, e.g. `Patient.name.family`.") 022 @JsonProperty(value = "path", required = true) 023 private String myPath; 024 025 @JsonProperty(value = "searchParameter", required = false) 026 @Schema( 027 description = 028 "The name of a SearchParameter which can be used to search for the tokenized value. If the FHIRPath expression in this rule matches the path of an existing SearchParameter, it is recommended to use the name of that SearchParameter here. This may be left empty, in which case it will not be possible to perform a search for the tokenized value (in other words, this should only be populated for rules containing paths which should be indexed for searching).") 029 private String mySearchParameter; 030 031 @JsonProperty(value = "searchValueNormalization", required = false) 032 @Schema( 033 description = 034 "If this property is set, the element value will be tokenized twice. The first value contains the original element as it was stored in the resource, and the second contains a normalized version of the element. The normalized version is used for search indexing. See [Search Normalization](/docs/fhir_repository/tokenization.html#search-normalization) for more information.") 035 private TokenizationValueNormalizationEnum mySearchValueNormalization; 036 037 @JsonProperty(value = "neverDetokenize", required = false) 038 @Schema( 039 description = 040 "If set to true, the system will never attempt to de-tokenize the value. This could be set if the configured tokenization algorithm is not reversible, or the usage scenario means that it is not desirable to reverse the tokenization on this element.") 041 private boolean myNeverDetokenize; 042 043 /** 044 * Constructor 045 */ 046 public TokenizationRuleJson() { 047 super(); 048 } 049 050 /** 051 * Copy Constructor 052 */ 053 public TokenizationRuleJson(TokenizationRuleJson theTokenizationRuleJson) { 054 myDescription = theTokenizationRuleJson.myDescription; 055 myPath = theTokenizationRuleJson.myPath; 056 mySearchParameter = theTokenizationRuleJson.mySearchParameter; 057 mySearchValueNormalization = theTokenizationRuleJson.mySearchValueNormalization; 058 myNeverDetokenize = theTokenizationRuleJson.myNeverDetokenize; 059 } 060 061 public String getDescription() { 062 return myDescription; 063 } 064 065 public TokenizationRuleJson setDescription(String theDescription) { 066 myDescription = theDescription; 067 return this; 068 } 069 070 public String getPath() { 071 return myPath; 072 } 073 074 public TokenizationRuleJson setPath(String thePath) { 075 myPath = thePath; 076 return this; 077 } 078 079 public String getSearchParameter() { 080 return mySearchParameter; 081 } 082 083 public TokenizationRuleJson setSearchParameter(String theSearchParameter) { 084 mySearchParameter = theSearchParameter; 085 return this; 086 } 087 088 @Nullable 089 public TokenizationValueNormalizationEnum getSearchValueNormalization() { 090 return mySearchValueNormalization; 091 } 092 093 public TokenizationRuleJson setSearchValueNormalization( 094 TokenizationValueNormalizationEnum theSearchValueNormalization) { 095 mySearchValueNormalization = theSearchValueNormalization; 096 return this; 097 } 098 099 @Nullable 100 public String getResourceType() { 101 int dotIdx = myPath.indexOf('.'); 102 if (dotIdx != -1) { 103 return myPath.substring(0, dotIdx); 104 } 105 return null; 106 } 107 108 public boolean isNeverDetokenize() { 109 return myNeverDetokenize; 110 } 111 112 public TokenizationRuleJson setNeverDetokenize(boolean theNeverDetokenize) { 113 myNeverDetokenize = theNeverDetokenize; 114 return this; 115 } 116 117 @SuppressWarnings("MethodDoesntCallSuperMethod") 118 @Override 119 public TokenizationRuleJson clone() { 120 return new TokenizationRuleJson(this); 121 } 122 123 @Override 124 public boolean equals(Object theO) { 125 if (!(theO instanceof TokenizationRuleJson that)) { 126 return false; 127 } 128 return myNeverDetokenize == that.myNeverDetokenize 129 && Objects.equals(myDescription, that.myDescription) 130 && Objects.equals(myPath, that.myPath) 131 && Objects.equals(mySearchParameter, that.mySearchParameter) 132 && mySearchValueNormalization == that.mySearchValueNormalization; 133 } 134 135 @Override 136 public int hashCode() { 137 return Objects.hash(myDescription, myPath, mySearchParameter, mySearchValueNormalization, myNeverDetokenize); 138 } 139}