001package org.hl7.fhir.r4.model;
002
003
004
005/*
006  Copyright (c) 2011+, HL7, Inc.
007  All rights reserved.
008  
009  Redistribution and use in source and binary forms, with or without modification, 
010  are permitted provided that the following conditions are met:
011  
012   * Redistributions of source code must retain the above copyright notice, this 
013     list of conditions and the following disclaimer.
014   * Redistributions in binary form must reproduce the above copyright notice, 
015     this list of conditions and the following disclaimer in the documentation 
016     and/or other materials provided with the distribution.
017   * Neither the name of HL7 nor the names of its contributors may be used to 
018     endorse or promote products derived from this software without specific 
019     prior written permission.
020  
021  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
022  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
023  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
024  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
025  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
026  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
027  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
028  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
029  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
030  POSSIBILITY OF SUCH DAMAGE.
031  
032*/
033
034
035// Generated on Tue, May 12, 2020 07:26+1000 for FHIR v4.0.1
036
037import java.util.*;
038
039import org.hl7.fhir.utilities.Utilities;
040import ca.uhn.fhir.model.api.annotation.Child;
041import ca.uhn.fhir.model.api.annotation.ChildOrder;
042import ca.uhn.fhir.model.api.annotation.Description;
043import ca.uhn.fhir.model.api.annotation.DatatypeDef;
044import ca.uhn.fhir.model.api.annotation.Block;
045import org.hl7.fhir.instance.model.api.*;
046import org.hl7.fhir.exceptions.FHIRException;
047/**
048 * A expression that is evaluated in a specified context and returns a value. The context of use of the expression must specify the context in which the expression is evaluated, and how the result of the expression is used.
049 */
050@DatatypeDef(name="Expression")
051public class Expression extends Type implements ICompositeType {
052
053    public enum ExpressionLanguage {
054        /**
055         * Clinical Quality Language.
056         */
057        TEXT_CQL, 
058        /**
059         * FHIRPath.
060         */
061        TEXT_FHIRPATH, 
062        /**
063         * FHIR's RESTful query syntax - typically independent of base URL.
064         */
065        APPLICATION_XFHIRQUERY, 
066        /**
067         * added to help the parsers with the generic types
068         */
069        NULL;
070        public static ExpressionLanguage fromCode(String codeString) throws FHIRException {
071            if (codeString == null || "".equals(codeString))
072                return null;
073        if ("text/cql".equals(codeString))
074          return TEXT_CQL;
075        if ("text/fhirpath".equals(codeString))
076          return TEXT_FHIRPATH;
077        if ("application/x-fhir-query".equals(codeString))
078          return APPLICATION_XFHIRQUERY;
079        if (Configuration.isAcceptInvalidEnums())
080          return null;
081        else
082          throw new FHIRException("Unknown ExpressionLanguage code '"+codeString+"'");
083        }
084        public String toCode() {
085          switch (this) {
086            case TEXT_CQL: return "text/cql";
087            case TEXT_FHIRPATH: return "text/fhirpath";
088            case APPLICATION_XFHIRQUERY: return "application/x-fhir-query";
089            case NULL: return null;
090            default: return "?";
091          }
092        }
093        public String getSystem() {
094          switch (this) {
095            case TEXT_CQL: return "http://hl7.org/fhir/expression-language";
096            case TEXT_FHIRPATH: return "http://hl7.org/fhir/expression-language";
097            case APPLICATION_XFHIRQUERY: return "http://hl7.org/fhir/expression-language";
098            case NULL: return null;
099            default: return "?";
100          }
101        }
102        public String getDefinition() {
103          switch (this) {
104            case TEXT_CQL: return "Clinical Quality Language.";
105            case TEXT_FHIRPATH: return "FHIRPath.";
106            case APPLICATION_XFHIRQUERY: return "FHIR's RESTful query syntax - typically independent of base URL.";
107            case NULL: return null;
108            default: return "?";
109          }
110        }
111        public String getDisplay() {
112          switch (this) {
113            case TEXT_CQL: return "CQL";
114            case TEXT_FHIRPATH: return "FHIRPath";
115            case APPLICATION_XFHIRQUERY: return "FHIR Query";
116            case NULL: return null;
117            default: return "?";
118          }
119        }
120    }
121
122  public static class ExpressionLanguageEnumFactory implements EnumFactory<ExpressionLanguage> {
123    public ExpressionLanguage fromCode(String codeString) throws IllegalArgumentException {
124      if (codeString == null || "".equals(codeString))
125            if (codeString == null || "".equals(codeString))
126                return null;
127        if ("text/cql".equals(codeString))
128          return ExpressionLanguage.TEXT_CQL;
129        if ("text/fhirpath".equals(codeString))
130          return ExpressionLanguage.TEXT_FHIRPATH;
131        if ("application/x-fhir-query".equals(codeString))
132          return ExpressionLanguage.APPLICATION_XFHIRQUERY;
133        throw new IllegalArgumentException("Unknown ExpressionLanguage code '"+codeString+"'");
134        }
135        public Enumeration<ExpressionLanguage> fromType(Base code) throws FHIRException {
136          if (code == null)
137            return null;
138          if (code.isEmpty())
139            return new Enumeration<ExpressionLanguage>(this);
140          String codeString = ((PrimitiveType) code).asStringValue();
141          if (codeString == null || "".equals(codeString))
142            return null;
143        if ("text/cql".equals(codeString))
144          return new Enumeration<ExpressionLanguage>(this, ExpressionLanguage.TEXT_CQL);
145        if ("text/fhirpath".equals(codeString))
146          return new Enumeration<ExpressionLanguage>(this, ExpressionLanguage.TEXT_FHIRPATH);
147        if ("application/x-fhir-query".equals(codeString))
148          return new Enumeration<ExpressionLanguage>(this, ExpressionLanguage.APPLICATION_XFHIRQUERY);
149        throw new FHIRException("Unknown ExpressionLanguage code '"+codeString+"'");
150        }
151    public String toCode(ExpressionLanguage code) {
152      if (code == ExpressionLanguage.TEXT_CQL)
153        return "text/cql";
154      if (code == ExpressionLanguage.TEXT_FHIRPATH)
155        return "text/fhirpath";
156      if (code == ExpressionLanguage.APPLICATION_XFHIRQUERY)
157        return "application/x-fhir-query";
158      return "?";
159      }
160    public String toSystem(ExpressionLanguage code) {
161      return code.getSystem();
162      }
163    }
164
165    /**
166     * A brief, natural language description of the condition that effectively communicates the intended semantics.
167     */
168    @Child(name = "description", type = {StringType.class}, order=0, min=0, max=1, modifier=false, summary=true)
169    @Description(shortDefinition="Natural language description of the condition", formalDefinition="A brief, natural language description of the condition that effectively communicates the intended semantics." )
170    protected StringType description;
171
172    /**
173     * A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.
174     */
175    @Child(name = "name", type = {IdType.class}, order=1, min=0, max=1, modifier=false, summary=true)
176    @Description(shortDefinition="Short name assigned to expression for reuse", formalDefinition="A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined." )
177    protected IdType name;
178
179    /**
180     * The media type of the language for the expression.
181     */
182    @Child(name = "language", type = {CodeType.class}, order=2, min=1, max=1, modifier=false, summary=true)
183    @Description(shortDefinition="text/cql | text/fhirpath | application/x-fhir-query | etc.", formalDefinition="The media type of the language for the expression." )
184    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/expression-language")
185    protected CodeType language;
186
187    /**
188     * An expression in the specified language that returns a value.
189     */
190    @Child(name = "expression", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=true)
191    @Description(shortDefinition="Expression in specified language", formalDefinition="An expression in the specified language that returns a value." )
192    protected StringType expression;
193
194    /**
195     * A URI that defines where the expression is found.
196     */
197    @Child(name = "reference", type = {UriType.class}, order=4, min=0, max=1, modifier=false, summary=true)
198    @Description(shortDefinition="Where the expression is found", formalDefinition="A URI that defines where the expression is found." )
199    protected UriType reference;
200
201    private static final long serialVersionUID = -941986742L;
202
203  /**
204   * Constructor
205   */
206    public Expression() {
207      super();
208    }
209
210  /**
211   * Constructor
212   */
213    public Expression(CodeType language) {
214      super();
215      this.language = language;
216    }
217
218    /**
219     * @return {@link #description} (A brief, natural language description of the condition that effectively communicates the intended semantics.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value
220     */
221    public StringType getDescriptionElement() { 
222      if (this.description == null)
223        if (Configuration.errorOnAutoCreate())
224          throw new Error("Attempt to auto-create Expression.description");
225        else if (Configuration.doAutoCreate())
226          this.description = new StringType(); // bb
227      return this.description;
228    }
229
230    public boolean hasDescriptionElement() { 
231      return this.description != null && !this.description.isEmpty();
232    }
233
234    public boolean hasDescription() { 
235      return this.description != null && !this.description.isEmpty();
236    }
237
238    /**
239     * @param value {@link #description} (A brief, natural language description of the condition that effectively communicates the intended semantics.). This is the underlying object with id, value and extensions. The accessor "getDescription" gives direct access to the value
240     */
241    public Expression setDescriptionElement(StringType value) { 
242      this.description = value;
243      return this;
244    }
245
246    /**
247     * @return A brief, natural language description of the condition that effectively communicates the intended semantics.
248     */
249    public String getDescription() { 
250      return this.description == null ? null : this.description.getValue();
251    }
252
253    /**
254     * @param value A brief, natural language description of the condition that effectively communicates the intended semantics.
255     */
256    public Expression setDescription(String value) { 
257      if (Utilities.noString(value))
258        this.description = null;
259      else {
260        if (this.description == null)
261          this.description = new StringType();
262        this.description.setValue(value);
263      }
264      return this;
265    }
266
267    /**
268     * @return {@link #name} (A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value
269     */
270    public IdType getNameElement() { 
271      if (this.name == null)
272        if (Configuration.errorOnAutoCreate())
273          throw new Error("Attempt to auto-create Expression.name");
274        else if (Configuration.doAutoCreate())
275          this.name = new IdType(); // bb
276      return this.name;
277    }
278
279    public boolean hasNameElement() { 
280      return this.name != null && !this.name.isEmpty();
281    }
282
283    public boolean hasName() { 
284      return this.name != null && !this.name.isEmpty();
285    }
286
287    /**
288     * @param value {@link #name} (A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.). This is the underlying object with id, value and extensions. The accessor "getName" gives direct access to the value
289     */
290    public Expression setNameElement(IdType value) { 
291      this.name = value;
292      return this;
293    }
294
295    /**
296     * @return A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.
297     */
298    public String getName() { 
299      return this.name == null ? null : this.name.getValue();
300    }
301
302    /**
303     * @param value A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.
304     */
305    public Expression setName(String value) { 
306      if (Utilities.noString(value))
307        this.name = null;
308      else {
309        if (this.name == null)
310          this.name = new IdType();
311        this.name.setValue(value);
312      }
313      return this;
314    }
315
316    /**
317     * @return {@link #language} (The media type of the language for the expression.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
318     */
319    public CodeType getLanguageElement() { 
320      if (this.language == null)
321        if (Configuration.errorOnAutoCreate())
322          throw new Error("Attempt to auto-create Expression.language");
323        else if (Configuration.doAutoCreate())
324          this.language = new CodeType(); // bb
325      return this.language;
326    }
327
328    public boolean hasLanguageElement() { 
329      return this.language != null && !this.language.isEmpty();
330    }
331
332    public boolean hasLanguage() { 
333      return this.language != null && !this.language.isEmpty();
334    }
335
336    /**
337     * @param value {@link #language} (The media type of the language for the expression.). This is the underlying object with id, value and extensions. The accessor "getLanguage" gives direct access to the value
338     */
339    public Expression setLanguageElement(CodeType value) { 
340      this.language = value;
341      return this;
342    }
343
344    /**
345     * @return The media type of the language for the expression.
346     */
347    public String getLanguage() { 
348      return this.language == null ? null : this.language.getValue();
349    }
350
351    /**
352     * @param value The media type of the language for the expression.
353     */
354    public Expression setLanguage(String value) { 
355        if (this.language == null)
356          this.language = new CodeType();
357        this.language.setValue(value);
358      return this;
359    }
360
361    /**
362     * @return {@link #expression} (An expression in the specified language that returns a value.). This is the underlying object with id, value and extensions. The accessor "getExpression" gives direct access to the value
363     */
364    public StringType getExpressionElement() { 
365      if (this.expression == null)
366        if (Configuration.errorOnAutoCreate())
367          throw new Error("Attempt to auto-create Expression.expression");
368        else if (Configuration.doAutoCreate())
369          this.expression = new StringType(); // bb
370      return this.expression;
371    }
372
373    public boolean hasExpressionElement() { 
374      return this.expression != null && !this.expression.isEmpty();
375    }
376
377    public boolean hasExpression() { 
378      return this.expression != null && !this.expression.isEmpty();
379    }
380
381    /**
382     * @param value {@link #expression} (An expression in the specified language that returns a value.). This is the underlying object with id, value and extensions. The accessor "getExpression" gives direct access to the value
383     */
384    public Expression setExpressionElement(StringType value) { 
385      this.expression = value;
386      return this;
387    }
388
389    /**
390     * @return An expression in the specified language that returns a value.
391     */
392    public String getExpression() { 
393      return this.expression == null ? null : this.expression.getValue();
394    }
395
396    /**
397     * @param value An expression in the specified language that returns a value.
398     */
399    public Expression setExpression(String value) { 
400      if (Utilities.noString(value))
401        this.expression = null;
402      else {
403        if (this.expression == null)
404          this.expression = new StringType();
405        this.expression.setValue(value);
406      }
407      return this;
408    }
409
410    /**
411     * @return {@link #reference} (A URI that defines where the expression is found.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value
412     */
413    public UriType getReferenceElement() { 
414      if (this.reference == null)
415        if (Configuration.errorOnAutoCreate())
416          throw new Error("Attempt to auto-create Expression.reference");
417        else if (Configuration.doAutoCreate())
418          this.reference = new UriType(); // bb
419      return this.reference;
420    }
421
422    public boolean hasReferenceElement() { 
423      return this.reference != null && !this.reference.isEmpty();
424    }
425
426    public boolean hasReference() { 
427      return this.reference != null && !this.reference.isEmpty();
428    }
429
430    /**
431     * @param value {@link #reference} (A URI that defines where the expression is found.). This is the underlying object with id, value and extensions. The accessor "getReference" gives direct access to the value
432     */
433    public Expression setReferenceElement(UriType value) { 
434      this.reference = value;
435      return this;
436    }
437
438    /**
439     * @return A URI that defines where the expression is found.
440     */
441    public String getReference() { 
442      return this.reference == null ? null : this.reference.getValue();
443    }
444
445    /**
446     * @param value A URI that defines where the expression is found.
447     */
448    public Expression setReference(String value) { 
449      if (Utilities.noString(value))
450        this.reference = null;
451      else {
452        if (this.reference == null)
453          this.reference = new UriType();
454        this.reference.setValue(value);
455      }
456      return this;
457    }
458
459      protected void listChildren(List<Property> children) {
460        super.listChildren(children);
461        children.add(new Property("description", "string", "A brief, natural language description of the condition that effectively communicates the intended semantics.", 0, 1, description));
462        children.add(new Property("name", "id", "A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.", 0, 1, name));
463        children.add(new Property("language", "code", "The media type of the language for the expression.", 0, 1, language));
464        children.add(new Property("expression", "string", "An expression in the specified language that returns a value.", 0, 1, expression));
465        children.add(new Property("reference", "uri", "A URI that defines where the expression is found.", 0, 1, reference));
466      }
467
468      @Override
469      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
470        switch (_hash) {
471        case -1724546052: /*description*/  return new Property("description", "string", "A brief, natural language description of the condition that effectively communicates the intended semantics.", 0, 1, description);
472        case 3373707: /*name*/  return new Property("name", "id", "A short name assigned to the expression to allow for multiple reuse of the expression in the context where it is defined.", 0, 1, name);
473        case -1613589672: /*language*/  return new Property("language", "code", "The media type of the language for the expression.", 0, 1, language);
474        case -1795452264: /*expression*/  return new Property("expression", "string", "An expression in the specified language that returns a value.", 0, 1, expression);
475        case -925155509: /*reference*/  return new Property("reference", "uri", "A URI that defines where the expression is found.", 0, 1, reference);
476        default: return super.getNamedProperty(_hash, _name, _checkValid);
477        }
478
479      }
480
481      @Override
482      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
483        switch (hash) {
484        case -1724546052: /*description*/ return this.description == null ? new Base[0] : new Base[] {this.description}; // StringType
485        case 3373707: /*name*/ return this.name == null ? new Base[0] : new Base[] {this.name}; // IdType
486        case -1613589672: /*language*/ return this.language == null ? new Base[0] : new Base[] {this.language}; // Enumeration<ExpressionLanguage>
487        case -1795452264: /*expression*/ return this.expression == null ? new Base[0] : new Base[] {this.expression}; // StringType
488        case -925155509: /*reference*/ return this.reference == null ? new Base[0] : new Base[] {this.reference}; // UriType
489        default: return super.getProperty(hash, name, checkValid);
490        }
491
492      }
493
494      @Override
495      public Base setProperty(int hash, String name, Base value) throws FHIRException {
496        switch (hash) {
497        case -1724546052: // description
498          this.description = castToString(value); // StringType
499          return value;
500        case 3373707: // name
501          this.name = castToId(value); // IdType
502          return value;
503        case -1613589672: // language
504          this.language = castToCode(value); // Enumeration<ExpressionLanguage>
505          return value;
506        case -1795452264: // expression
507          this.expression = castToString(value); // StringType
508          return value;
509        case -925155509: // reference
510          this.reference = castToUri(value); // UriType
511          return value;
512        default: return super.setProperty(hash, name, value);
513        }
514
515      }
516
517      @Override
518      public Base setProperty(String name, Base value) throws FHIRException {
519        if (name.equals("description")) {
520          this.description = castToString(value); // StringType
521        } else if (name.equals("name")) {
522          this.name = castToId(value); // IdType
523        } else if (name.equals("language")) {
524          this.language = castToCode(value); // Enumeration<ExpressionLanguage>
525        } else if (name.equals("expression")) {
526          this.expression = castToString(value); // StringType
527        } else if (name.equals("reference")) {
528          this.reference = castToUri(value); // UriType
529        } else
530          return super.setProperty(name, value);
531        return value;
532      }
533
534      @Override
535      public Base makeProperty(int hash, String name) throws FHIRException {
536        switch (hash) {
537        case -1724546052:  return getDescriptionElement();
538        case 3373707:  return getNameElement();
539        case -1613589672:  return getLanguageElement();
540        case -1795452264:  return getExpressionElement();
541        case -925155509:  return getReferenceElement();
542        default: return super.makeProperty(hash, name);
543        }
544
545      }
546
547      @Override
548      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
549        switch (hash) {
550        case -1724546052: /*description*/ return new String[] {"string"};
551        case 3373707: /*name*/ return new String[] {"id"};
552        case -1613589672: /*language*/ return new String[] {"code"};
553        case -1795452264: /*expression*/ return new String[] {"string"};
554        case -925155509: /*reference*/ return new String[] {"uri"};
555        default: return super.getTypesForProperty(hash, name);
556        }
557
558      }
559
560      @Override
561      public Base addChild(String name) throws FHIRException {
562        if (name.equals("description")) {
563          throw new FHIRException("Cannot call addChild on a primitive type Expression.description");
564        }
565        else if (name.equals("name")) {
566          throw new FHIRException("Cannot call addChild on a primitive type Expression.name");
567        }
568        else if (name.equals("language")) {
569          throw new FHIRException("Cannot call addChild on a primitive type Expression.language");
570        }
571        else if (name.equals("expression")) {
572          throw new FHIRException("Cannot call addChild on a primitive type Expression.expression");
573        }
574        else if (name.equals("reference")) {
575          throw new FHIRException("Cannot call addChild on a primitive type Expression.reference");
576        }
577        else
578          return super.addChild(name);
579      }
580
581  public String fhirType() {
582    return "Expression";
583
584  }
585
586      public Expression copy() {
587        Expression dst = new Expression();
588        copyValues(dst);
589        return dst;
590      }
591
592      public void copyValues(Expression dst) {
593        super.copyValues(dst);
594        dst.description = description == null ? null : description.copy();
595        dst.name = name == null ? null : name.copy();
596        dst.language = language == null ? null : language.copy();
597        dst.expression = expression == null ? null : expression.copy();
598        dst.reference = reference == null ? null : reference.copy();
599      }
600
601      protected Expression typedCopy() {
602        return copy();
603      }
604
605      @Override
606      public boolean equalsDeep(Base other_) {
607        if (!super.equalsDeep(other_))
608          return false;
609        if (!(other_ instanceof Expression))
610          return false;
611        Expression o = (Expression) other_;
612        return compareDeep(description, o.description, true) && compareDeep(name, o.name, true) && compareDeep(language, o.language, true)
613           && compareDeep(expression, o.expression, true) && compareDeep(reference, o.reference, true);
614      }
615
616      @Override
617      public boolean equalsShallow(Base other_) {
618        if (!super.equalsShallow(other_))
619          return false;
620        if (!(other_ instanceof Expression))
621          return false;
622        Expression o = (Expression) other_;
623        return compareValues(description, o.description, true) && compareValues(name, o.name, true) && compareValues(language, o.language, true)
624           && compareValues(expression, o.expression, true) && compareValues(reference, o.reference, true);
625      }
626
627      public boolean isEmpty() {
628        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(description, name, language
629          , expression, reference);
630      }
631
632
633}