001package ca.cdr.api.model.json;
002
003import ca.uhn.fhir.model.api.annotation.ExampleSupplier;
004import com.fasterxml.jackson.annotation.JsonProperty;
005import io.swagger.v3.oas.annotations.media.Schema;
006import jakarta.annotation.Nonnull;
007import org.apache.commons.lang3.Validate;
008
009import java.util.ArrayList;
010import java.util.List;
011import java.util.function.Supplier;
012
013/**
014 * This class implements the rules used for data tokenization in the
015 * FHIR Storage module.
016 */
017@Schema(
018                name = "TokenizationRules",
019                description =
020                                "Defines a collection of rules for [FHIR Repository Tokenization](/docs/fhir_repository/tokenization.md)")
021@ExampleSupplier(TokenizationRulesJson.ExampleSupplier.class)
022public class TokenizationRulesJson implements IModelJson {
023
024        @JsonProperty("rules")
025        private List<TokenizationRuleJson> myRules;
026
027        public List<TokenizationRuleJson> getRules() {
028                if (myRules == null) {
029                        myRules = new ArrayList<>();
030                }
031                return myRules;
032        }
033
034        public void setRules(List<TokenizationRuleJson> theRules) {
035                myRules = theRules;
036        }
037
038        public TokenizationRuleJson addRule() {
039                TokenizationRuleJson rule = new TokenizationRuleJson();
040                addRule(rule);
041                return rule;
042        }
043
044        public TokenizationRulesJson addRule(@Nonnull TokenizationRuleJson theRule) {
045                Validate.notNull(theRule, "theRule must not be null");
046                getRules().add(theRule);
047                return this;
048        }
049
050        public static class ExampleSupplier implements Supplier<TokenizationRulesJson> {
051                @Override
052                public TokenizationRulesJson get() {
053                        TokenizationRulesJson rules = new TokenizationRulesJson();
054
055                        rules.addRule()
056                                        .setDescription("Rule for a path including a search parameter")
057                                        .setPath("Patient.identifier")
058                                        .setSearchParameter("identifier")
059                                        .setSearchValueNormalization(TokenizationValueNormalizationEnum.IDENTIFIER);
060
061                        rules.addRule()
062                                        .setDescription("Another rule for a path including a search parameter")
063                                        .setPath("Patient.name.family")
064                                        .setSearchParameter("family")
065                                        .setSearchValueNormalization(TokenizationValueNormalizationEnum.STRING);
066
067                        rules.addRule()
068                                        .setDescription("Rule for a path with no associated search parameter")
069                                        .setPath("Patient.maritalStatus")
070                                        .setSearchValueNormalization(TokenizationValueNormalizationEnum.NONE);
071
072                        return rules;
073                }
074        }
075}