001/*-
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.context.support;
021
022import org.apache.commons.lang3.Validate;
023
024import java.util.Objects;
025
026/**
027 * Options for ValueSet expansion
028 *
029 * @see IValidationSupport
030 */
031public class ValueSetExpansionOptions {
032
033        private boolean myFailOnMissingCodeSystem = true;
034        private int myCount = 1000;
035        private int myOffset = 0;
036        private boolean myIncludeHierarchy;
037        private String myFilter;
038
039        private String myDisplayLanguage;
040
041        public String getFilter() {
042                return myFilter;
043        }
044
045        public ValueSetExpansionOptions setFilter(String theFilter) {
046                myFilter = theFilter;
047                return this;
048        }
049
050        /**
051         * The number of codes to return.
052         * <p>
053         * Default is 1000
054         * </p>
055         */
056        public int getCount() {
057                return myCount;
058        }
059
060        /**
061         * The number of codes to return.
062         * <p>
063         * Default is 1000
064         * </p>
065         */
066        public ValueSetExpansionOptions setCount(int theCount) {
067                Validate.isTrue(theCount >= 0, "theCount must be >= 0");
068                myCount = theCount;
069                return this;
070        }
071
072        /**
073         * The code index to start at (i.e the individual code index, not the page number)
074         */
075        public int getOffset() {
076                return myOffset;
077        }
078
079        /**
080         * The code index to start at (i.e the individual code index, not the page number)
081         */
082        public ValueSetExpansionOptions setOffset(int theOffset) {
083                Validate.isTrue(theOffset >= 0, "theOffset must be >= 0");
084                myOffset = theOffset;
085                return this;
086        }
087
088        /**
089         * Should the expansion fail if a codesystem is referenced by the valueset, but
090         * it can not be found?
091         * <p>
092         * Default is <code>true</code>
093         * </p>
094         */
095        public boolean isFailOnMissingCodeSystem() {
096                return myFailOnMissingCodeSystem;
097        }
098
099        /**
100         * Should the expansion fail if a codesystem is referenced by the valueset, but
101         * it can not be found?
102         * <p>
103         * Default is <code>true</code>
104         * </p>
105         */
106        public ValueSetExpansionOptions setFailOnMissingCodeSystem(boolean theFailOnMissingCodeSystem) {
107                myFailOnMissingCodeSystem = theFailOnMissingCodeSystem;
108                return this;
109        }
110
111        public boolean isIncludeHierarchy() {
112                return myIncludeHierarchy;
113        }
114
115        public void setIncludeHierarchy(boolean theIncludeHierarchy) {
116                myIncludeHierarchy = theIncludeHierarchy;
117        }
118
119        public static ValueSetExpansionOptions forOffsetAndCount(int theOffset, int theCount) {
120                return new ValueSetExpansionOptions().setOffset(theOffset).setCount(theCount);
121        }
122
123        public String getTheDisplayLanguage() {
124                return myDisplayLanguage;
125        }
126
127        public ValueSetExpansionOptions setTheDisplayLanguage(String theDisplayLanguage) {
128                myDisplayLanguage = theDisplayLanguage;
129                return this;
130        }
131
132        @Override
133        public boolean equals(Object theO) {
134                if (this == theO) return true;
135                if (!(theO instanceof ValueSetExpansionOptions)) return false;
136                ValueSetExpansionOptions that = (ValueSetExpansionOptions) theO;
137                return myFailOnMissingCodeSystem == that.myFailOnMissingCodeSystem
138                                && myCount == that.myCount
139                                && myOffset == that.myOffset
140                                && myIncludeHierarchy == that.myIncludeHierarchy
141                                && Objects.equals(myFilter, that.myFilter)
142                                && Objects.equals(myDisplayLanguage, that.myDisplayLanguage);
143        }
144
145        @Override
146        public int hashCode() {
147                return Objects.hash(
148                                myFailOnMissingCodeSystem, myCount, myOffset, myIncludeHierarchy, myFilter, myDisplayLanguage);
149        }
150}