001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2025 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.api.model.json; 011 012import com.fasterxml.jackson.annotation.JsonProperty; 013import io.swagger.v3.oas.annotations.media.Schema; 014import jakarta.annotation.Nullable; 015 016import java.util.Objects; 017 018@SuppressWarnings("UnusedReturnValue") 019@Schema(name = "TokenizationRule", description = "Defines a single rule for FHIR Repository Tokenization") 020public class TokenizationRuleJson implements IModelJson, Cloneable { 021 022 @Schema( 023 description = 024 "An optional description of this rule. This field does not affect the functionality of the rule, but can be used as documentation.") 025 @JsonProperty(value = "description", required = false) 026 private String myDescription; 027 028 @Schema( 029 description = 030 "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`.") 031 @JsonProperty(value = "path", required = true) 032 private String myPath; 033 034 @JsonProperty(value = "searchParameter", required = false) 035 @Schema( 036 description = 037 "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).") 038 private String mySearchParameter; 039 040 @JsonProperty(value = "searchValueNormalization", required = false) 041 @Schema( 042 description = 043 "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.") 044 private TokenizationValueNormalizationEnum mySearchValueNormalization; 045 046 @JsonProperty(value = "neverDetokenize", required = false) 047 @Schema( 048 description = 049 "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.") 050 private boolean myNeverDetokenize; 051 052 /** 053 * Constructor 054 */ 055 public TokenizationRuleJson() { 056 super(); 057 } 058 059 /** 060 * Copy Constructor 061 */ 062 public TokenizationRuleJson(TokenizationRuleJson theTokenizationRuleJson) { 063 myDescription = theTokenizationRuleJson.myDescription; 064 myPath = theTokenizationRuleJson.myPath; 065 mySearchParameter = theTokenizationRuleJson.mySearchParameter; 066 mySearchValueNormalization = theTokenizationRuleJson.mySearchValueNormalization; 067 myNeverDetokenize = theTokenizationRuleJson.myNeverDetokenize; 068 } 069 070 public String getDescription() { 071 return myDescription; 072 } 073 074 public TokenizationRuleJson setDescription(String theDescription) { 075 myDescription = theDescription; 076 return this; 077 } 078 079 public String getPath() { 080 return myPath; 081 } 082 083 public TokenizationRuleJson setPath(String thePath) { 084 myPath = thePath; 085 return this; 086 } 087 088 public String getSearchParameter() { 089 return mySearchParameter; 090 } 091 092 public TokenizationRuleJson setSearchParameter(String theSearchParameter) { 093 mySearchParameter = theSearchParameter; 094 return this; 095 } 096 097 @Nullable 098 public TokenizationValueNormalizationEnum getSearchValueNormalization() { 099 return mySearchValueNormalization; 100 } 101 102 public TokenizationRuleJson setSearchValueNormalization( 103 TokenizationValueNormalizationEnum theSearchValueNormalization) { 104 mySearchValueNormalization = theSearchValueNormalization; 105 return this; 106 } 107 108 @Nullable 109 public String getResourceType() { 110 int dotIdx = myPath.indexOf('.'); 111 if (dotIdx != -1) { 112 return myPath.substring(0, dotIdx); 113 } 114 return null; 115 } 116 117 public boolean isNeverDetokenize() { 118 return myNeverDetokenize; 119 } 120 121 public TokenizationRuleJson setNeverDetokenize(boolean theNeverDetokenize) { 122 myNeverDetokenize = theNeverDetokenize; 123 return this; 124 } 125 126 @SuppressWarnings("MethodDoesntCallSuperMethod") 127 @Override 128 public TokenizationRuleJson clone() { 129 return new TokenizationRuleJson(this); 130 } 131 132 @Override 133 public boolean equals(Object theO) { 134 if (!(theO instanceof TokenizationRuleJson that)) { 135 return false; 136 } 137 return myNeverDetokenize == that.myNeverDetokenize 138 && Objects.equals(myDescription, that.myDescription) 139 && Objects.equals(myPath, that.myPath) 140 && Objects.equals(mySearchParameter, that.mySearchParameter) 141 && mySearchValueNormalization == that.mySearchValueNormalization; 142 } 143 144 @Override 145 public int hashCode() { 146 return Objects.hash(myDescription, myPath, mySearchParameter, mySearchValueNormalization, myNeverDetokenize); 147 } 148}