001package org.hl7.fhir.dstu3.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 Mon, Apr 17, 2017 17:38-0400 for FHIR v3.0.1
033
034import java.util.*;
035
036import org.hl7.fhir.utilities.Utilities;
037import ca.uhn.fhir.model.api.annotation.Child;
038import ca.uhn.fhir.model.api.annotation.ChildOrder;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.DatatypeDef;
041import ca.uhn.fhir.model.api.annotation.Block;
042import org.hl7.fhir.instance.model.api.*;
043import org.hl7.fhir.exceptions.FHIRException;
044/**
045 * A description of a triggering event.
046 */
047@DatatypeDef(name="TriggerDefinition")
048public class TriggerDefinition extends Type implements ICompositeType {
049
050    public enum TriggerType {
051        /**
052         * The trigger occurs in response to a specific named event
053         */
054        NAMEDEVENT, 
055        /**
056         * The trigger occurs at a specific time or periodically as described by a timing or schedule
057         */
058        PERIODIC, 
059        /**
060         * The trigger occurs whenever data of a particular type is added
061         */
062        DATAADDED, 
063        /**
064         * The trigger occurs whenever data of a particular type is modified
065         */
066        DATAMODIFIED, 
067        /**
068         * The trigger occurs whenever data of a particular type is removed
069         */
070        DATAREMOVED, 
071        /**
072         * The trigger occurs whenever data of a particular type is accessed
073         */
074        DATAACCESSED, 
075        /**
076         * The trigger occurs whenever access to data of a particular type is completed
077         */
078        DATAACCESSENDED, 
079        /**
080         * added to help the parsers with the generic types
081         */
082        NULL;
083        public static TriggerType fromCode(String codeString) throws FHIRException {
084            if (codeString == null || "".equals(codeString))
085                return null;
086        if ("named-event".equals(codeString))
087          return NAMEDEVENT;
088        if ("periodic".equals(codeString))
089          return PERIODIC;
090        if ("data-added".equals(codeString))
091          return DATAADDED;
092        if ("data-modified".equals(codeString))
093          return DATAMODIFIED;
094        if ("data-removed".equals(codeString))
095          return DATAREMOVED;
096        if ("data-accessed".equals(codeString))
097          return DATAACCESSED;
098        if ("data-access-ended".equals(codeString))
099          return DATAACCESSENDED;
100        if (Configuration.isAcceptInvalidEnums())
101          return null;
102        else
103          throw new FHIRException("Unknown TriggerType code '"+codeString+"'");
104        }
105        public String toCode() {
106          switch (this) {
107            case NAMEDEVENT: return "named-event";
108            case PERIODIC: return "periodic";
109            case DATAADDED: return "data-added";
110            case DATAMODIFIED: return "data-modified";
111            case DATAREMOVED: return "data-removed";
112            case DATAACCESSED: return "data-accessed";
113            case DATAACCESSENDED: return "data-access-ended";
114            default: return "?";
115          }
116        }
117        public String getSystem() {
118          switch (this) {
119            case NAMEDEVENT: return "http://hl7.org/fhir/trigger-type";
120            case PERIODIC: return "http://hl7.org/fhir/trigger-type";
121            case DATAADDED: return "http://hl7.org/fhir/trigger-type";
122            case DATAMODIFIED: return "http://hl7.org/fhir/trigger-type";
123            case DATAREMOVED: return "http://hl7.org/fhir/trigger-type";
124            case DATAACCESSED: return "http://hl7.org/fhir/trigger-type";
125            case DATAACCESSENDED: return "http://hl7.org/fhir/trigger-type";
126            default: return "?";
127          }
128        }
129        public String getDefinition() {
130          switch (this) {
131            case NAMEDEVENT: return "The trigger occurs in response to a specific named event";
132            case PERIODIC: return "The trigger occurs at a specific time or periodically as described by a timing or schedule";
133            case DATAADDED: return "The trigger occurs whenever data of a particular type is added";
134            case DATAMODIFIED: return "The trigger occurs whenever data of a particular type is modified";
135            case DATAREMOVED: return "The trigger occurs whenever data of a particular type is removed";
136            case DATAACCESSED: return "The trigger occurs whenever data of a particular type is accessed";
137            case DATAACCESSENDED: return "The trigger occurs whenever access to data of a particular type is completed";
138            default: return "?";
139          }
140        }
141        public String getDisplay() {
142          switch (this) {
143            case NAMEDEVENT: return "Named Event";
144            case PERIODIC: return "Periodic";
145            case DATAADDED: return "Data Added";
146            case DATAMODIFIED: return "Data Modified";
147            case DATAREMOVED: return "Data Removed";
148            case DATAACCESSED: return "Data Accessed";
149            case DATAACCESSENDED: return "Data Access Ended";
150            default: return "?";
151          }
152        }
153    }
154
155  public static class TriggerTypeEnumFactory implements EnumFactory<TriggerType> {
156    public TriggerType fromCode(String codeString) throws IllegalArgumentException {
157      if (codeString == null || "".equals(codeString))
158            if (codeString == null || "".equals(codeString))
159                return null;
160        if ("named-event".equals(codeString))
161          return TriggerType.NAMEDEVENT;
162        if ("periodic".equals(codeString))
163          return TriggerType.PERIODIC;
164        if ("data-added".equals(codeString))
165          return TriggerType.DATAADDED;
166        if ("data-modified".equals(codeString))
167          return TriggerType.DATAMODIFIED;
168        if ("data-removed".equals(codeString))
169          return TriggerType.DATAREMOVED;
170        if ("data-accessed".equals(codeString))
171          return TriggerType.DATAACCESSED;
172        if ("data-access-ended".equals(codeString))
173          return TriggerType.DATAACCESSENDED;
174        throw new IllegalArgumentException("Unknown TriggerType code '"+codeString+"'");
175        }
176        public Enumeration<TriggerType> fromType(Base code) throws FHIRException {
177          if (code == null)
178            return null;
179          if (code.isEmpty())
180            return new Enumeration<TriggerType>(this);
181          String codeString = ((PrimitiveType) code).asStringValue();
182          if (codeString == null || "".equals(codeString))
183            return null;
184        if ("named-event".equals(codeString))
185          return new Enumeration<TriggerType>(this, TriggerType.NAMEDEVENT);
186        if ("periodic".equals(codeString))
187          return new Enumeration<TriggerType>(this, TriggerType.PERIODIC);
188        if ("data-added".equals(codeString))
189          return new Enumeration<TriggerType>(this, TriggerType.DATAADDED);
190        if ("data-modified".equals(codeString))
191          return new Enumeration<TriggerType>(this, TriggerType.DATAMODIFIED);
192        if ("data-removed".equals(codeString))
193          return new Enumeration<TriggerType>(this, TriggerType.DATAREMOVED);
194        if ("data-accessed".equals(codeString))
195          return new Enumeration<TriggerType>(this, TriggerType.DATAACCESSED);
196        if ("data-access-ended".equals(codeString))
197          return new Enumeration<TriggerType>(this, TriggerType.DATAACCESSENDED);
198        throw new FHIRException("Unknown TriggerType code '"+codeString+"'");
199        }
200    public String toCode(TriggerType code) {
201      if (code == TriggerType.NAMEDEVENT)
202        return "named-event";
203      if (code == TriggerType.PERIODIC)
204        return "periodic";
205      if (code == TriggerType.DATAADDED)
206        return "data-added";
207      if (code == TriggerType.DATAMODIFIED)
208        return "data-modified";
209      if (code == TriggerType.DATAREMOVED)
210        return "data-removed";
211      if (code == TriggerType.DATAACCESSED)
212        return "data-accessed";
213      if (code == TriggerType.DATAACCESSENDED)
214        return "data-access-ended";
215      return "?";
216      }
217    public String toSystem(TriggerType code) {
218      return code.getSystem();
219      }
220    }
221
222    /**
223     * The type of triggering event.
224     */
225    @Child(name = "type", type = {CodeType.class}, order=0, min=1, max=1, modifier=false, summary=true)
226    @Description(shortDefinition="named-event | periodic | data-added | data-modified | data-removed | data-accessed | data-access-ended", formalDefinition="The type of triggering event." )
227    @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/trigger-type")
228    protected Enumeration<TriggerType> type;
229
230    /**
231     * The name of the event (if this is a named-event trigger).
232     */
233    @Child(name = "eventName", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=true)
234    @Description(shortDefinition="Triggering event name", formalDefinition="The name of the event (if this is a named-event trigger)." )
235    protected StringType eventName;
236
237    /**
238     * The timing of the event (if this is a period trigger).
239     */
240    @Child(name = "eventTiming", type = {Timing.class, Schedule.class, DateType.class, DateTimeType.class}, order=2, min=0, max=1, modifier=false, summary=true)
241    @Description(shortDefinition="Timing of the event", formalDefinition="The timing of the event (if this is a period trigger)." )
242    protected Type eventTiming;
243
244    /**
245     * The triggering data of the event (if this is a data trigger).
246     */
247    @Child(name = "eventData", type = {DataRequirement.class}, order=3, min=0, max=1, modifier=false, summary=true)
248    @Description(shortDefinition="Triggering data of the event", formalDefinition="The triggering data of the event (if this is a data trigger)." )
249    protected DataRequirement eventData;
250
251    private static final long serialVersionUID = -1695534864L;
252
253  /**
254   * Constructor
255   */
256    public TriggerDefinition() {
257      super();
258    }
259
260  /**
261   * Constructor
262   */
263    public TriggerDefinition(Enumeration<TriggerType> type) {
264      super();
265      this.type = type;
266    }
267
268    /**
269     * @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
270     */
271    public Enumeration<TriggerType> getTypeElement() { 
272      if (this.type == null)
273        if (Configuration.errorOnAutoCreate())
274          throw new Error("Attempt to auto-create TriggerDefinition.type");
275        else if (Configuration.doAutoCreate())
276          this.type = new Enumeration<TriggerType>(new TriggerTypeEnumFactory()); // bb
277      return this.type;
278    }
279
280    public boolean hasTypeElement() { 
281      return this.type != null && !this.type.isEmpty();
282    }
283
284    public boolean hasType() { 
285      return this.type != null && !this.type.isEmpty();
286    }
287
288    /**
289     * @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
290     */
291    public TriggerDefinition setTypeElement(Enumeration<TriggerType> value) { 
292      this.type = value;
293      return this;
294    }
295
296    /**
297     * @return The type of triggering event.
298     */
299    public TriggerType getType() { 
300      return this.type == null ? null : this.type.getValue();
301    }
302
303    /**
304     * @param value The type of triggering event.
305     */
306    public TriggerDefinition setType(TriggerType value) { 
307        if (this.type == null)
308          this.type = new Enumeration<TriggerType>(new TriggerTypeEnumFactory());
309        this.type.setValue(value);
310      return this;
311    }
312
313    /**
314     * @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
315     */
316    public StringType getEventNameElement() { 
317      if (this.eventName == null)
318        if (Configuration.errorOnAutoCreate())
319          throw new Error("Attempt to auto-create TriggerDefinition.eventName");
320        else if (Configuration.doAutoCreate())
321          this.eventName = new StringType(); // bb
322      return this.eventName;
323    }
324
325    public boolean hasEventNameElement() { 
326      return this.eventName != null && !this.eventName.isEmpty();
327    }
328
329    public boolean hasEventName() { 
330      return this.eventName != null && !this.eventName.isEmpty();
331    }
332
333    /**
334     * @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
335     */
336    public TriggerDefinition setEventNameElement(StringType value) { 
337      this.eventName = value;
338      return this;
339    }
340
341    /**
342     * @return The name of the event (if this is a named-event trigger).
343     */
344    public String getEventName() { 
345      return this.eventName == null ? null : this.eventName.getValue();
346    }
347
348    /**
349     * @param value The name of the event (if this is a named-event trigger).
350     */
351    public TriggerDefinition setEventName(String value) { 
352      if (Utilities.noString(value))
353        this.eventName = null;
354      else {
355        if (this.eventName == null)
356          this.eventName = new StringType();
357        this.eventName.setValue(value);
358      }
359      return this;
360    }
361
362    /**
363     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
364     */
365    public Type getEventTiming() { 
366      return this.eventTiming;
367    }
368
369    /**
370     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
371     */
372    public Timing getEventTimingTiming() throws FHIRException { 
373      if (!(this.eventTiming instanceof Timing))
374        throw new FHIRException("Type mismatch: the type Timing was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
375      return (Timing) this.eventTiming;
376    }
377
378    public boolean hasEventTimingTiming() { 
379      return this.eventTiming instanceof Timing;
380    }
381
382    /**
383     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
384     */
385    public Reference getEventTimingReference() throws FHIRException { 
386      if (!(this.eventTiming instanceof Reference))
387        throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
388      return (Reference) this.eventTiming;
389    }
390
391    public boolean hasEventTimingReference() { 
392      return this.eventTiming instanceof Reference;
393    }
394
395    /**
396     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
397     */
398    public DateType getEventTimingDateType() throws FHIRException { 
399      if (!(this.eventTiming instanceof DateType))
400        throw new FHIRException("Type mismatch: the type DateType was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
401      return (DateType) this.eventTiming;
402    }
403
404    public boolean hasEventTimingDateType() { 
405      return this.eventTiming instanceof DateType;
406    }
407
408    /**
409     * @return {@link #eventTiming} (The timing of the event (if this is a period trigger).)
410     */
411    public DateTimeType getEventTimingDateTimeType() throws FHIRException { 
412      if (!(this.eventTiming instanceof DateTimeType))
413        throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.eventTiming.getClass().getName()+" was encountered");
414      return (DateTimeType) this.eventTiming;
415    }
416
417    public boolean hasEventTimingDateTimeType() { 
418      return this.eventTiming instanceof DateTimeType;
419    }
420
421    public boolean hasEventTiming() { 
422      return this.eventTiming != null && !this.eventTiming.isEmpty();
423    }
424
425    /**
426     * @param value {@link #eventTiming} (The timing of the event (if this is a period trigger).)
427     */
428    public TriggerDefinition setEventTiming(Type value) { 
429      this.eventTiming = value;
430      return this;
431    }
432
433    /**
434     * @return {@link #eventData} (The triggering data of the event (if this is a data trigger).)
435     */
436    public DataRequirement getEventData() { 
437      if (this.eventData == null)
438        if (Configuration.errorOnAutoCreate())
439          throw new Error("Attempt to auto-create TriggerDefinition.eventData");
440        else if (Configuration.doAutoCreate())
441          this.eventData = new DataRequirement(); // cc
442      return this.eventData;
443    }
444
445    public boolean hasEventData() { 
446      return this.eventData != null && !this.eventData.isEmpty();
447    }
448
449    /**
450     * @param value {@link #eventData} (The triggering data of the event (if this is a data trigger).)
451     */
452    public TriggerDefinition setEventData(DataRequirement value) { 
453      this.eventData = value;
454      return this;
455    }
456
457      protected void listChildren(List<Property> childrenList) {
458        super.listChildren(childrenList);
459        childrenList.add(new Property("type", "code", "The type of triggering event.", 0, java.lang.Integer.MAX_VALUE, type));
460        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));
461        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));
462        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));
463      }
464
465      @Override
466      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
467        switch (hash) {
468        case 3575610: /*type*/ return this.type == null ? new Base[0] : new Base[] {this.type}; // Enumeration<TriggerType>
469        case 31228997: /*eventName*/ return this.eventName == null ? new Base[0] : new Base[] {this.eventName}; // StringType
470        case 125465476: /*eventTiming*/ return this.eventTiming == null ? new Base[0] : new Base[] {this.eventTiming}; // Type
471        case 30931300: /*eventData*/ return this.eventData == null ? new Base[0] : new Base[] {this.eventData}; // DataRequirement
472        default: return super.getProperty(hash, name, checkValid);
473        }
474
475      }
476
477      @Override
478      public Base setProperty(int hash, String name, Base value) throws FHIRException {
479        switch (hash) {
480        case 3575610: // type
481          value = new TriggerTypeEnumFactory().fromType(castToCode(value));
482          this.type = (Enumeration) value; // Enumeration<TriggerType>
483          return value;
484        case 31228997: // eventName
485          this.eventName = castToString(value); // StringType
486          return value;
487        case 125465476: // eventTiming
488          this.eventTiming = castToType(value); // Type
489          return value;
490        case 30931300: // eventData
491          this.eventData = castToDataRequirement(value); // DataRequirement
492          return value;
493        default: return super.setProperty(hash, name, value);
494        }
495
496      }
497
498      @Override
499      public Base setProperty(String name, Base value) throws FHIRException {
500        if (name.equals("type")) {
501          value = new TriggerTypeEnumFactory().fromType(castToCode(value));
502          this.type = (Enumeration) value; // Enumeration<TriggerType>
503        } else if (name.equals("eventName")) {
504          this.eventName = castToString(value); // StringType
505        } else if (name.equals("eventTiming[x]")) {
506          this.eventTiming = castToType(value); // Type
507        } else if (name.equals("eventData")) {
508          this.eventData = castToDataRequirement(value); // DataRequirement
509        } else
510          return super.setProperty(name, value);
511        return value;
512      }
513
514      @Override
515      public Base makeProperty(int hash, String name) throws FHIRException {
516        switch (hash) {
517        case 3575610:  return getTypeElement();
518        case 31228997:  return getEventNameElement();
519        case 1120539260:  return getEventTiming(); 
520        case 125465476:  return getEventTiming(); 
521        case 30931300:  return getEventData(); 
522        default: return super.makeProperty(hash, name);
523        }
524
525      }
526
527      @Override
528      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
529        switch (hash) {
530        case 3575610: /*type*/ return new String[] {"code"};
531        case 31228997: /*eventName*/ return new String[] {"string"};
532        case 125465476: /*eventTiming*/ return new String[] {"Timing", "Reference", "date", "dateTime"};
533        case 30931300: /*eventData*/ return new String[] {"DataRequirement"};
534        default: return super.getTypesForProperty(hash, name);
535        }
536
537      }
538
539      @Override
540      public Base addChild(String name) throws FHIRException {
541        if (name.equals("type")) {
542          throw new FHIRException("Cannot call addChild on a primitive type TriggerDefinition.type");
543        }
544        else if (name.equals("eventName")) {
545          throw new FHIRException("Cannot call addChild on a primitive type TriggerDefinition.eventName");
546        }
547        else if (name.equals("eventTimingTiming")) {
548          this.eventTiming = new Timing();
549          return this.eventTiming;
550        }
551        else if (name.equals("eventTimingReference")) {
552          this.eventTiming = new Reference();
553          return this.eventTiming;
554        }
555        else if (name.equals("eventTimingDate")) {
556          this.eventTiming = new DateType();
557          return this.eventTiming;
558        }
559        else if (name.equals("eventTimingDateTime")) {
560          this.eventTiming = new DateTimeType();
561          return this.eventTiming;
562        }
563        else if (name.equals("eventData")) {
564          this.eventData = new DataRequirement();
565          return this.eventData;
566        }
567        else
568          return super.addChild(name);
569      }
570
571  public String fhirType() {
572    return "TriggerDefinition";
573
574  }
575
576      public TriggerDefinition copy() {
577        TriggerDefinition dst = new TriggerDefinition();
578        copyValues(dst);
579        dst.type = type == null ? null : type.copy();
580        dst.eventName = eventName == null ? null : eventName.copy();
581        dst.eventTiming = eventTiming == null ? null : eventTiming.copy();
582        dst.eventData = eventData == null ? null : eventData.copy();
583        return dst;
584      }
585
586      protected TriggerDefinition typedCopy() {
587        return copy();
588      }
589
590      @Override
591      public boolean equalsDeep(Base other) {
592        if (!super.equalsDeep(other))
593          return false;
594        if (!(other instanceof TriggerDefinition))
595          return false;
596        TriggerDefinition o = (TriggerDefinition) other;
597        return compareDeep(type, o.type, true) && compareDeep(eventName, o.eventName, true) && compareDeep(eventTiming, o.eventTiming, true)
598           && compareDeep(eventData, o.eventData, true);
599      }
600
601      @Override
602      public boolean equalsShallow(Base other) {
603        if (!super.equalsShallow(other))
604          return false;
605        if (!(other instanceof TriggerDefinition))
606          return false;
607        TriggerDefinition o = (TriggerDefinition) other;
608        return compareValues(type, o.type, true) && compareValues(eventName, o.eventName, true);
609      }
610
611      public boolean isEmpty() {
612        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(type, eventName, eventTiming
613          , eventData);
614      }
615
616
617}
618