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.fhir.tokenization;
011
012import ca.cdr.api.model.json.TokenizationRuleJson;
013import ca.uhn.fhir.rest.api.server.RequestDetails;
014import jakarta.annotation.Nonnull;
015import org.hl7.fhir.instance.model.api.IBase;
016
017/**
018 * This class represents a single request to "de-tokenize" a previously tokenized string.
019 * The request will be processed by the same {@link ITokenizationProvider} that originally
020 * provided the tokenized string.
021 */
022public class DetokenizationRequest {
023
024        @Nonnull
025        private final String myToken;
026
027        @Nonnull
028        private final IBase myTarget;
029
030        @Nonnull
031        private final TokenizationRuleJson myRule;
032
033        /**
034         * Constructor
035         */
036        public DetokenizationRequest(
037                        @Nonnull IBase theTarget, @Nonnull String theToken, @Nonnull TokenizationRuleJson theRule) {
038                myTarget = theTarget;
039                myToken = theToken;
040                myRule = theRule;
041        }
042
043        /**
044         * This is the object which will receive the detokenized value. For example, if an Identifier instance was
045         * originally passed to the {@link ITokenizationProvider#tokenize(RequestDetails, TokenizationRequests)} method,
046         * then this will contain an empty Identifier instance. The provider does not need to modify or otherwise
047         * touch this object, but it is provided in case it will be helpful to the de-tokenization algorithm.
048         */
049        @Nonnull
050        public IBase getTarget() {
051                return myTarget;
052        }
053
054        /**
055         * This is the token string which needs to be reversed. In other words, this is the string that was
056         * previously supplied to {@link TokenizationResults#addResult(TokenizationRequest, String)} by the
057         * provider.
058         */
059        @Nonnull
060        public String getToken() {
061                return myToken;
062        }
063
064        /**
065         * This is the rule which caused the element to be detokenized
066         *
067         * @since 2025.08.R01
068         */
069        @Nonnull
070        public TokenizationRuleJson getRule() {
071                return myRule;
072        }
073}