001package org.hl7.fhir.dstu2016may.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Sun, May 8, 2016 03:05+1000 for FHIR v1.4.0
033import java.util.List;
034
035import org.hl7.fhir.exceptions.FHIRException;
036import org.hl7.fhir.instance.model.api.ICompositeType;
037import org.hl7.fhir.utilities.Utilities;
038
039import ca.uhn.fhir.model.api.annotation.Child;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Description;
042/**
043 * A description of a triggering event.
044 */
045@DatatypeDef(name="TriggerDefinition")
046public class TriggerDefinition extends Type implements ICompositeType {
047
048    public enum TriggerType {
049        /**
050         * The trigger occurs in response to a specific named event
051         */
052        NAMEDEVENT, 
053        /**
054         * The trigger occurs at a specific time or periodically as described by a timing or schedule
055         */
056        PERIODIC, 
057        /**
058         * The trigger occurs whenever data of a particular type is added
059         */
060        DATAADDED, 
061        /**
062         * The trigger occurs whenever data of a particular type is modified
063         */
064        DATAMODIFIED, 
065        /**
066         * The trigger occurs whenever data of a particular type is removed
067         */
068        DATAREMOVED, 
069        /**
070         * The trigger occurs whenever data of a particular type is accessed
071         */
072        DATAACCESSED, 
073        /**
074         * The trigger occurs whenever access to data of a particular type is completed
075         */
076        DATAACCESSENDED, 
077        /**
078         * added to help the parsers
079         */
080        NULL;
081        public static TriggerType fromCode(String codeString) throws FHIRException {
082            if (codeString == null || "".equals(codeString))
083                return null;
084        if ("named-event".equals(codeString))
085          return NAMEDEVENT;
086        if ("periodic".equals(codeString))
087          return PERIODIC;
088        if ("data-added".equals(codeString))
089          return DATAADDED;
090        if ("data-modified".equals(codeString))
091          return DATAMODIFIED;
092        if ("data-removed".equals(codeString))
093          return DATAREMOVED;
094        if ("data-accessed".equals(codeString))
095          return DATAACCESSED;
096        if ("data-access-ended".equals(codeString))
097          return DATAACCESSENDED;
098        throw new FHIRException("Unknown TriggerType code '"+codeString+"'");
099        }
100        public String toCode() {
101          switch (this) {
102            case NAMEDEVENT: return "named-event";
103            case PERIODIC: return "periodic";
104            case DATAADDED: return "data-added";
105            case DATAMODIFIED: return "data-modified";
106            case DATAREMOVED: return "data-removed";
107            case DATAACCESSED: return "data-accessed";
108            case DATAACCESSENDED: return "data-access-ended";
109            default: return "?";
110          }
111        }
112        public String getSystem() {
113          switch (this) {
114            case NAMEDEVENT: return "http://hl7.org/fhir/trigger-type";
115            case PERIODIC: return "http://hl7.org/fhir/trigger-type";
116            case DATAADDED: return "http://hl7.org/fhir/trigger-type";
117            case DATAMODIFIED: return "http://hl7.org/fhir/trigger-type";
118            case DATAREMOVED: return "http://hl7.org/fhir/trigger-type";
119            case DATAACCESSED: return "http://hl7.org/fhir/trigger-type";
120            case DATAACCESSENDED: return "http://hl7.org/fhir/trigger-type";
121            default: return "?";
122          }
123        }
124        public String getDefinition() {
125          switch (this) {
126            case NAMEDEVENT: return "The trigger occurs in response to a specific named event";
127            case PERIODIC: return "The trigger occurs at a specific time or periodically as described by a timing or schedule";
128            case DATAADDED: return "The trigger occurs whenever data of a particular type is added";
129            case DATAMODIFIED: return "The trigger occurs whenever data of a particular type is modified";
130            case DATAREMOVED: return "The trigger occurs whenever data of a particular type is removed";
131            case DATAACCESSED: return "The trigger occurs whenever data of a particular type is accessed";
132            case DATAACCESSENDED: return "The trigger occurs whenever access to data of a particular type is completed";
133            default: return "?";
134          }
135        }
136        public String getDisplay() {
137          switch (this) {
138            case NAMEDEVENT: return "Named Event";
139            case PERIODIC: return "Periodic";
140            case DATAADDED: return "Data Added";
141            case DATAMODIFIED: return "Data Modified";
142            case DATAREMOVED: return "Data Removed";
143            case DATAACCESSED: return "Data Accessed";
144            case DATAACCESSENDED: return "Data Access Ended";
145            default: return "?";
146          }
147        }
148    }
149
150  public static class TriggerTypeEnumFactory implements EnumFactory<TriggerType> {
151    public TriggerType fromCode(String codeString) throws IllegalArgumentException {
152      if (codeString == null || "".equals(codeString))
153            if (codeString == null || "".equals(codeString))
154                return null;
155        if ("named-event".equals(codeString))
156          return TriggerType.NAMEDEVENT;
157        if ("periodic".equals(codeString))
158          return TriggerType.PERIODIC;
159        if ("data-added".equals(codeString))
160          return TriggerType.DATAADDED;
161        if ("data-modified".equals(codeString))
162          return TriggerType.DATAMODIFIED;
163        if ("data-removed".equals(codeString))
164          return TriggerType.DATAREMOVED;
165        if ("data-accessed".equals(codeString))
166          return TriggerType.DATAACCESSED;
167        if ("data-access-ended".equals(codeString))
168          return TriggerType.DATAACCESSENDED;
169        throw new IllegalArgumentException("Unknown TriggerType code '"+codeString+"'");
170        }
171        public Enumeration<TriggerType> fromType(Base code) throws FHIRException {
172          if (code == null || code.isEmpty())
173            return null;
174          String codeString = ((PrimitiveType) code).asStringValue();
175          if (codeString == null || "".equals(codeString))
176            return null;
177        if ("named-event".equals(codeString))
178          return new Enumeration<TriggerType>(this, TriggerType.NAMEDEVENT);
179        if ("periodic".equals(codeString))
180          return new Enumeration<TriggerType>(this, TriggerType.PERIODIC);
181        if ("data-added".equals(codeString))
182          return new Enumeration<TriggerType>(this, TriggerType.DATAADDED);
183        if ("data-modified".equals(codeString))
184          return new Enumeration<TriggerType>(this, TriggerType.DATAMODIFIED);
185        if ("data-removed".equals(codeString))
186          return new Enumeration<TriggerType>(this, TriggerType.DATAREMOVED);
187        if ("data-accessed".equals(codeString))
188          return new Enumeration<TriggerType>(this, TriggerType.DATAACCESSED);
189        if ("data-access-ended".equals(codeString))
190          return new Enumeration<TriggerType>(this, TriggerType.DATAACCESSENDED);
191        throw new FHIRException("Unknown TriggerType code '"+codeString+"'");
192        }
193    public String toCode(TriggerType code) {
194      if (code == TriggerType.NAMEDEVENT)
195        return "named-event";
196      if (code == TriggerType.PERIODIC)
197        return "periodic";
198      if (code == TriggerType.DATAADDED)
199        return "data-added";
200      if (code == TriggerType.DATAMODIFIED)
201        return "data-modified";
202      if (code == TriggerType.DATAREMOVED)
203        return "data-removed";
204      if (code == TriggerType.DATAACCESSED)
205        return "data-accessed";
206      if (code == TriggerType.DATAACCESSENDED)
207        return "data-access-ended";
208      return "?";
209      }
210    public String toSystem(TriggerType code) {
211      return code.getSystem();
212      }
213    }
214
215    /**
216     * The type of triggering event.
217     */
218    @Child(name = "type", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
219    @Description(shortDefinition="named-event | periodic | data-added | data-modified | data-removed | data-accessed | data-access-ended", formalDefinition="The type of triggering event." )
220    protected Enumeration<TriggerType> type;
221
222    /**
223     * The name of the event (if this is a named-event trigger).
224     */
225    @Child(name = "eventName", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
226    @Description(shortDefinition="Name of the event", formalDefinition="The name of the event (if this is a named-event trigger)." )
227    protected StringType eventName;
228
229    /**
230     * The timing of the event (if this is a period trigger).
231     */
232    @Child(name = "eventTiming", type = {Timing.class, Schedule.class, DateType.class, DateTimeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
233    @Description(shortDefinition="Timing of the event", formalDefinition="The timing of the event (if this is a period trigger)." )
234    protected Type eventTiming;
235
236    /**
237     * The triggering data of the event (if this is a data trigger).
238     */
239    @Child(name = "eventData", type = {DataRequirement.class}, order=3, min=0, max=1, modifier=false, summary=true)
240    @Description(shortDefinition="Triggering data of the event", formalDefinition="The triggering data of the event (if this is a data trigger)." )
241    protected DataRequirement eventData;
242
243    private static final long serialVersionUID = -1695534864L;
244
245  /**
246   * Constructor
247   */
248    public TriggerDefinition() {
249      super();
250    }
251
252  /**
253   * Constructor
254   */
255    public TriggerDefinition(Enumeration<TriggerType> type) {
256      super();
257      this.type = type;
258    }
259
260    /**
261     * @return {@link #type} (The type of triggering event.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
262     */
263    public Enumeration<TriggerType> getTypeElement() { 
264      if (this.type == null)
265        if (Configuration.errorOnAutoCreate())
266          throw new Error("Attempt to auto-create TriggerDefinition.type");
267        else if (Configuration.doAutoCreate())
268          this.type = new Enumeration<TriggerType>(new TriggerTypeEnumFactory()); // bb
269      return this.type;
270    }
271
272    public boolean hasTypeElement() { 
273      return this.type != null && !this.type.isEmpty();
274    }
275
276    public boolean hasType() { 
277      return this.type != null && !this.type.isEmpty();
278    }
279
280    /**
281     * @param value {@link #type} (The type of triggering event.). This is the underlying object with id, value and extensions. The accessor "getType" gives direct access to the value
282     */
283    public TriggerDefinition setTypeElement(Enumeration<TriggerType> value) { 
284      this.type = value;
285      return this;
286    }
287
288    /**
289     * @return The type of triggering event.
290     */
291    public TriggerType getType() { 
292      return this.type == null ? null : this.type.getValue();
293    }
294
295    /**
296     * @param value The type of triggering event.
297     */
298    public TriggerDefinition setType(TriggerType value) { 
299        if (this.type == null)
300          this.type = new Enumeration<TriggerType>(new TriggerTypeEnumFactory());
301        this.type.setValue(value);
302      return this;
303    }
304
305    /**
306     * @return {@link #eventName} (The name of the event (if this is a named-event trigger).). This is the underlying object with id, value and extensions. The accessor "getEventName" gives direct access to the value
307     */
308    public StringType getEventNameElement() { 
309      if (this.eventName == null)
310        if (Configuration.errorOnAutoCreate())
311          throw new Error("Attempt to auto-create TriggerDefinition.eventName");
312        else if (Configuration.doAutoCreate())
313          this.eventName = new StringType(); // bb
314      return this.eventName;
315    }
316
317    public boolean hasEventNameElement() { 
318      return this.eventName != null && !this.eventName.isEmpty();
319    }
320
321    public boolean hasEventName() { 
322      return this.eventName != null && !this.eventName.isEmpty();
323    }
324
325    /**
326     * @param value {@link #eventName} (The name of the event (if this is a named-event trigger).). This is the underlying object with id, value and extensions. The accessor "getEventName" gives direct access to the value
327     */
328    public TriggerDefinition setEventNameElement(StringType value) { 
329      this.eventName = value;
330      return this;
331    }
332
333    /**
334     * @return The name of the event (if this is a named-event trigger).
335     */
336    public String getEventName() { 
337      return this.eventName == null ? null : this.eventName.getValue();
338    }
339
340    /**
341     * @param value The name of the event (if this is a named-event trigger).
342     */
343    public TriggerDefinition setEventName(String value) { 
344      if (Utilities.noString(value))
345        this.eventName = null;
346      else {
347        if (this.eventName == null)
348          this.eventName = new StringType();
349        this.eventName.setValue(value);
350      }
351      return this;
352    }
353
354    /**
355     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
356     */
357    public Type getEventTiming() { 
358      return this.eventTiming;
359    }
360
361    /**
362     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
363     */
364    public Timing getEventTimingTiming() throws FHIRException { 
365      if (!(this.eventTiming instanceof Timing))
366        throw new FHIRException("Type mismatch: the type Timing was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
367      return (Timing) this.eventTiming;
368    }
369
370    public boolean hasEventTimingTiming() { 
371      return this.eventTiming instanceof Timing;
372    }
373
374    /**
375     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
376     */
377    public Reference getEventTimingReference() throws FHIRException { 
378      if (!(this.eventTiming instanceof Reference))
379        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
380      return (Reference) this.eventTiming;
381    }
382
383    public boolean hasEventTimingReference() { 
384      return this.eventTiming instanceof Reference;
385    }
386
387    /**
388     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
389     */
390    public DateType getEventTimingDateType() throws FHIRException { 
391      if (!(this.eventTiming instanceof DateType))
392        throw new FHIRException("Type mismatch: the type DateType was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
393      return (DateType) this.eventTiming;
394    }
395
396    public boolean hasEventTimingDateType() { 
397      return this.eventTiming instanceof DateType;
398    }
399
400    /**
401     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
402     */
403    public DateTimeType getEventTimingDateTimeType() throws FHIRException { 
404      if (!(this.eventTiming instanceof DateTimeType))
405        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
406      return (DateTimeType) this.eventTiming;
407    }
408
409    public boolean hasEventTimingDateTimeType() { 
410      return this.eventTiming instanceof DateTimeType;
411    }
412
413    public boolean hasEventTiming() { 
414      return this.eventTiming != null && !this.eventTiming.isEmpty();
415    }
416
417    /**
418     * @param value {@link #eventTiming} (The timing of the event (if this is a period trigger).)
419     */
420    public TriggerDefinition setEventTiming(Type value) { 
421      this.eventTiming = value;
422      return this;
423    }
424
425    /**
426     * @return {@link #eventData} (The triggering data of the event (if this is a data trigger).)
427     */
428    public DataRequirement getEventData() { 
429      if (this.eventData == null)
430        if (Configuration.errorOnAutoCreate())
431          throw new Error("Attempt to auto-create TriggerDefinition.eventData");
432        else if (Configuration.doAutoCreate())
433          this.eventData = new DataRequirement(); // cc
434      return this.eventData;
435    }
436
437    public boolean hasEventData() { 
438      return this.eventData != null && !this.eventData.isEmpty();
439    }
440
441    /**
442     * @param value {@link #eventData} (The triggering data of the event (if this is a data trigger).)
443     */
444    public TriggerDefinition setEventData(DataRequirement value) { 
445      this.eventData = value;
446      return this;
447    }
448
449      protected void listChildren(List<Property> childrenList) {
450        super.listChildren(childrenList);
451        childrenList.add(new Property("type", "code", "The type of triggering event.", 0, java.lang.Integer.MAX_VALUE, type));
452        childrenList.add(new Property("eventName", "string", "The name of the event (if this is a named-event trigger).", 0, java.lang.Integer.MAX_VALUE, eventName));
453        childrenList.add(new Property("eventTiming[x]", "Timing|Reference(Schedule)|date|dateTime", "The timing of the event (if this is a period trigger).", 0, java.lang.Integer.MAX_VALUE, eventTiming));
454        childrenList.add(new Property("eventData", "DataRequirement", "The triggering data of the event (if this is a data trigger).", 0, java.lang.Integer.MAX_VALUE, eventData));
455      }
456
457      @Override
458      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
459        switch (hash) {
460        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // Enumeration<TriggerType>
461        case 31228997: /*eventName*/ return this.eventName == null ? new Base[0] : new Base[] {this.eventName}; // StringType
462        case 125465476: /*eventTiming*/ return this.eventTiming == null ? new Base[0] : new Base[] {this.eventTiming}; // Type
463        case 30931300: /*eventData*/ return this.eventData == null ? new Base[0] : new Base[] {this.eventData}; // DataRequirement
464        default: return super.getProperty(hash, name, checkValid);
465        }
466
467      }
468
469      @Override
470      public void setProperty(int hash, String name, Base value) throws FHIRException {
471        switch (hash) {
472        case 3575610: // type
473          this.type = new TriggerTypeEnumFactory().fromType(value); // Enumeration<TriggerType>
474          break;
475        case 31228997: // eventName
476          this.eventName = castToString(value); // StringType
477          break;
478        case 125465476: // eventTiming
479          this.eventTiming = (Type) value; // Type
480          break;
481        case 30931300: // eventData
482          this.eventData = castToDataRequirement(value); // DataRequirement
483          break;
484        default: super.setProperty(hash, name, value);
485        }
486
487      }
488
489      @Override
490      public void setProperty(String name, Base value) throws FHIRException {
491        if (name.equals("type"))
492          this.type = new TriggerTypeEnumFactory().fromType(value); // Enumeration<TriggerType>
493        else if (name.equals("eventName"))
494          this.eventName = castToString(value); // StringType
495        else if (name.equals("eventTiming[x]"))
496          this.eventTiming = (Type) value; // Type
497        else if (name.equals("eventData"))
498          this.eventData = castToDataRequirement(value); // DataRequirement
499        else
500          super.setProperty(name, value);
501      }
502
503      @Override
504      public Base makeProperty(int hash, String name) throws FHIRException {
505        switch (hash) {
506        case 3575610: throw new FHIRException("Cannot make property type as it is not a complex type"); // Enumeration<TriggerType>
507        case 31228997: throw new FHIRException("Cannot make property eventName as it is not a complex type"); // StringType
508        case 1120539260:  return getEventTiming(); // Type
509        case 30931300:  return getEventData(); // DataRequirement
510        default: return super.makeProperty(hash, name);
511        }
512
513      }
514
515      @Override
516      public Base addChild(String name) throws FHIRException {
517        if (name.equals("type")) {
518          throw new FHIRException("Cannot call addChild on a primitive type TriggerDefinition.type");
519        }
520        else if (name.equals("eventName")) {
521          throw new FHIRException("Cannot call addChild on a primitive type TriggerDefinition.eventName");
522        }
523        else if (name.equals("eventTimingTiming")) {
524          this.eventTiming = new Timing();
525          return this.eventTiming;
526        }
527        else if (name.equals("eventTimingReference")) {
528          this.eventTiming = new Reference();
529          return this.eventTiming;
530        }
531        else if (name.equals("eventTimingDate")) {
532          this.eventTiming = new DateType();
533          return this.eventTiming;
534        }
535        else if (name.equals("eventTimingDateTime")) {
536          this.eventTiming = new DateTimeType();
537          return this.eventTiming;
538        }
539        else if (name.equals("eventData")) {
540          this.eventData = new DataRequirement();
541          return this.eventData;
542        }
543        else
544          return super.addChild(name);
545      }
546
547  public String fhirType() {
548    return "TriggerDefinition";
549
550  }
551
552      public TriggerDefinition copy() {
553        TriggerDefinition dst = new TriggerDefinition();
554        copyValues(dst);
555        dst.type = type == null ? null : type.copy();
556        dst.eventName = eventName == null ? null : eventName.copy();
557        dst.eventTiming = eventTiming == null ? null : eventTiming.copy();
558        dst.eventData = eventData == null ? null : eventData.copy();
559        return dst;
560      }
561
562      protected TriggerDefinition typedCopy() {
563        return copy();
564      }
565
566      @Override
567      public boolean equalsDeep(Base other) {
568        if (!super.equalsDeep(other))
569          return false;
570        if (!(other instanceof TriggerDefinition))
571          return false;
572        TriggerDefinition o = (TriggerDefinition) other;
573        return compareDeep(type, o.type, true) && compareDeep(eventName, o.eventName, true) && compareDeep(eventTiming, o.eventTiming, true)
574           && compareDeep(eventData, o.eventData, true);
575      }
576
577      @Override
578      public boolean equalsShallow(Base other) {
579        if (!super.equalsShallow(other))
580          return false;
581        if (!(other instanceof TriggerDefinition))
582          return false;
583        TriggerDefinition o = (TriggerDefinition) other;
584        return compareValues(type, o.type, true) && compareValues(eventName, o.eventName, true);
585      }
586
587      public boolean isEmpty() {
588        return super.isEmpty() && (type == null || type.isEmpty()) && (eventName == null || eventName.isEmpty())
589           && (eventTiming == null || eventTiming.isEmpty()) && (eventData == null || eventData.isEmpty())
590          ;
591      }
592
593
594}
595