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