001package org.hl7.fhir.dstu2.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 Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
033import java.util.ArrayList;
034import java.util.Date;
035import java.util.List;
036
037import ca.uhn.fhir.model.api.annotation.Block;
038import ca.uhn.fhir.model.api.annotation.Child;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.ResourceDef;
041import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
042import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
043import org.hl7.fhir.exceptions.FHIRException;
044import org.hl7.fhir.utilities.Utilities;
045
046/**
047 * The subscription resource is used to define a push based subscription from a
048 * server to another system. Once a subscription is registered with the server,
049 * the server checks every resource that is created or updated, and if the
050 * resource matches the given criteria, it sends a message on the defined
051 * "channel" so that another system is able to take an appropriate action.
052 */
053@ResourceDef(name = "Subscription", profile = "http://hl7.org/fhir/Profile/Subscription")
054public class Subscription extends DomainResource {
055
056  public enum SubscriptionStatus {
057    /**
058     * The client has requested the subscription, and the server has not yet set it
059     * up.
060     */
061    REQUESTED,
062    /**
063     * The subscription is active.
064     */
065    ACTIVE,
066    /**
067     * The server has an error executing the notification.
068     */
069    ERROR,
070    /**
071     * Too many errors have occurred or the subscription has expired.
072     */
073    OFF,
074    /**
075     * added to help the parsers
076     */
077    NULL;
078
079    public static SubscriptionStatus fromCode(String codeString) throws FHIRException {
080      if (codeString == null || "".equals(codeString))
081        return null;
082      if ("requested".equals(codeString))
083        return REQUESTED;
084      if ("active".equals(codeString))
085        return ACTIVE;
086      if ("error".equals(codeString))
087        return ERROR;
088      if ("off".equals(codeString))
089        return OFF;
090      throw new FHIRException("Unknown SubscriptionStatus code '" + codeString + "'");
091    }
092
093    public String toCode() {
094      switch (this) {
095      case REQUESTED:
096        return "requested";
097      case ACTIVE:
098        return "active";
099      case ERROR:
100        return "error";
101      case OFF:
102        return "off";
103      case NULL:
104        return null;
105      default:
106        return "?";
107      }
108    }
109
110    public String getSystem() {
111      switch (this) {
112      case REQUESTED:
113        return "http://hl7.org/fhir/subscription-status";
114      case ACTIVE:
115        return "http://hl7.org/fhir/subscription-status";
116      case ERROR:
117        return "http://hl7.org/fhir/subscription-status";
118      case OFF:
119        return "http://hl7.org/fhir/subscription-status";
120      case NULL:
121        return null;
122      default:
123        return "?";
124      }
125    }
126
127    public String getDefinition() {
128      switch (this) {
129      case REQUESTED:
130        return "The client has requested the subscription, and the server has not yet set it up.";
131      case ACTIVE:
132        return "The subscription is active.";
133      case ERROR:
134        return "The server has an error executing the notification.";
135      case OFF:
136        return "Too many errors have occurred or the subscription has expired.";
137      case NULL:
138        return null;
139      default:
140        return "?";
141      }
142    }
143
144    public String getDisplay() {
145      switch (this) {
146      case REQUESTED:
147        return "Requested";
148      case ACTIVE:
149        return "Active";
150      case ERROR:
151        return "Error";
152      case OFF:
153        return "Off";
154      case NULL:
155        return null;
156      default:
157        return "?";
158      }
159    }
160  }
161
162  public static class SubscriptionStatusEnumFactory implements EnumFactory<SubscriptionStatus> {
163    public SubscriptionStatus fromCode(String codeString) throws IllegalArgumentException {
164      if (codeString == null || "".equals(codeString))
165        if (codeString == null || "".equals(codeString))
166          return null;
167      if ("requested".equals(codeString))
168        return SubscriptionStatus.REQUESTED;
169      if ("active".equals(codeString))
170        return SubscriptionStatus.ACTIVE;
171      if ("error".equals(codeString))
172        return SubscriptionStatus.ERROR;
173      if ("off".equals(codeString))
174        return SubscriptionStatus.OFF;
175      throw new IllegalArgumentException("Unknown SubscriptionStatus code '" + codeString + "'");
176    }
177
178    public Enumeration<SubscriptionStatus> fromType(Base code) throws FHIRException {
179      if (code == null || code.isEmpty())
180        return null;
181      String codeString = ((PrimitiveType) code).asStringValue();
182      if (codeString == null || "".equals(codeString))
183        return null;
184      if ("requested".equals(codeString))
185        return new Enumeration<SubscriptionStatus>(this, SubscriptionStatus.REQUESTED);
186      if ("active".equals(codeString))
187        return new Enumeration<SubscriptionStatus>(this, SubscriptionStatus.ACTIVE);
188      if ("error".equals(codeString))
189        return new Enumeration<SubscriptionStatus>(this, SubscriptionStatus.ERROR);
190      if ("off".equals(codeString))
191        return new Enumeration<SubscriptionStatus>(this, SubscriptionStatus.OFF);
192      throw new FHIRException("Unknown SubscriptionStatus code '" + codeString + "'");
193    }
194
195    public String toCode(SubscriptionStatus code)
196   {
197       if (code == SubscriptionStatus.NULL)
198           return null;
199       if (code == SubscriptionStatus.REQUESTED)
200        return "requested";
201      if (code == SubscriptionStatus.ACTIVE)
202        return "active";
203      if (code == SubscriptionStatus.ERROR)
204        return "error";
205      if (code == SubscriptionStatus.OFF)
206        return "off";
207      return "?";
208   }
209  }
210
211  public enum SubscriptionChannelType {
212    /**
213     * The channel is executed by making a post to the URI. If a payload is
214     * included, the URL is interpreted as the service base, and an update (PUT) is
215     * made.
216     */
217    RESTHOOK,
218    /**
219     * The channel is executed by sending a packet across a web socket connection
220     * maintained by the client. The URL identifies the websocket, and the client
221     * binds to this URL.
222     */
223    WEBSOCKET,
224    /**
225     * The channel is executed by sending an email to the email addressed in the URI
226     * (which must be a mailto:).
227     */
228    EMAIL,
229    /**
230     * The channel is executed by sending an SMS message to the phone number
231     * identified in the URL (tel:).
232     */
233    SMS,
234    /**
235     * The channel is executed by sending a message (e.g. a Bundle with a
236     * MessageHeader resource etc.) to the application identified in the URI.
237     */
238    MESSAGE,
239    /**
240     * added to help the parsers
241     */
242    NULL;
243
244    public static SubscriptionChannelType fromCode(String codeString) throws FHIRException {
245      if (codeString == null || "".equals(codeString))
246        return null;
247      if ("rest-hook".equals(codeString))
248        return RESTHOOK;
249      if ("websocket".equals(codeString))
250        return WEBSOCKET;
251      if ("email".equals(codeString))
252        return EMAIL;
253      if ("sms".equals(codeString))
254        return SMS;
255      if ("message".equals(codeString))
256        return MESSAGE;
257      throw new FHIRException("Unknown SubscriptionChannelType code '" + codeString + "'");
258    }
259
260    public String toCode() {
261      switch (this) {
262      case RESTHOOK:
263        return "rest-hook";
264      case WEBSOCKET:
265        return "websocket";
266      case EMAIL:
267        return "email";
268      case SMS:
269        return "sms";
270      case MESSAGE:
271        return "message";
272      case NULL:
273        return null;
274      default:
275        return "?";
276      }
277    }
278
279    public String getSystem() {
280      switch (this) {
281      case RESTHOOK:
282        return "http://hl7.org/fhir/subscription-channel-type";
283      case WEBSOCKET:
284        return "http://hl7.org/fhir/subscription-channel-type";
285      case EMAIL:
286        return "http://hl7.org/fhir/subscription-channel-type";
287      case SMS:
288        return "http://hl7.org/fhir/subscription-channel-type";
289      case MESSAGE:
290        return "http://hl7.org/fhir/subscription-channel-type";
291      case NULL:
292        return null;
293      default:
294        return "?";
295      }
296    }
297
298    public String getDefinition() {
299      switch (this) {
300      case RESTHOOK:
301        return "The channel is executed by making a post to the URI. If a payload is included, the URL is interpreted as the service base, and an update (PUT) is made.";
302      case WEBSOCKET:
303        return "The channel is executed by sending a packet across a web socket connection maintained by the client. The URL identifies the websocket, and the client binds to this URL.";
304      case EMAIL:
305        return "The channel is executed by sending an email to the email addressed in the URI (which must be a mailto:).";
306      case SMS:
307        return "The channel is executed by sending an SMS message to the phone number identified in the URL (tel:).";
308      case MESSAGE:
309        return "The channel is executed by sending a message (e.g. a Bundle with a MessageHeader resource etc.) to the application identified in the URI.";
310      case NULL:
311        return null;
312      default:
313        return "?";
314      }
315    }
316
317    public String getDisplay() {
318      switch (this) {
319      case RESTHOOK:
320        return "Rest Hook";
321      case WEBSOCKET:
322        return "Websocket";
323      case EMAIL:
324        return "Email";
325      case SMS:
326        return "SMS";
327      case MESSAGE:
328        return "Message";
329      case NULL:
330        return null;
331      default:
332        return "?";
333      }
334    }
335  }
336
337  public static class SubscriptionChannelTypeEnumFactory implements EnumFactory<SubscriptionChannelType> {
338    public SubscriptionChannelType fromCode(String codeString) throws IllegalArgumentException {
339      if (codeString == null || "".equals(codeString))
340        if (codeString == null || "".equals(codeString))
341          return null;
342      if ("rest-hook".equals(codeString))
343        return SubscriptionChannelType.RESTHOOK;
344      if ("websocket".equals(codeString))
345        return SubscriptionChannelType.WEBSOCKET;
346      if ("email".equals(codeString))
347        return SubscriptionChannelType.EMAIL;
348      if ("sms".equals(codeString))
349        return SubscriptionChannelType.SMS;
350      if ("message".equals(codeString))
351        return SubscriptionChannelType.MESSAGE;
352      throw new IllegalArgumentException("Unknown SubscriptionChannelType code '" + codeString + "'");
353    }
354
355    public Enumeration<SubscriptionChannelType> fromType(Base code) throws FHIRException {
356      if (code == null || code.isEmpty())
357        return null;
358      String codeString = ((PrimitiveType) code).asStringValue();
359      if (codeString == null || "".equals(codeString))
360        return null;
361      if ("rest-hook".equals(codeString))
362        return new Enumeration<SubscriptionChannelType>(this, SubscriptionChannelType.RESTHOOK);
363      if ("websocket".equals(codeString))
364        return new Enumeration<SubscriptionChannelType>(this, SubscriptionChannelType.WEBSOCKET);
365      if ("email".equals(codeString))
366        return new Enumeration<SubscriptionChannelType>(this, SubscriptionChannelType.EMAIL);
367      if ("sms".equals(codeString))
368        return new Enumeration<SubscriptionChannelType>(this, SubscriptionChannelType.SMS);
369      if ("message".equals(codeString))
370        return new Enumeration<SubscriptionChannelType>(this, SubscriptionChannelType.MESSAGE);
371      throw new FHIRException("Unknown SubscriptionChannelType code '" + codeString + "'");
372    }
373
374    public String toCode(SubscriptionChannelType code)
375   {
376       if (code == SubscriptionChannelType.NULL)
377           return null;
378       if (code == SubscriptionChannelType.RESTHOOK)
379        return "rest-hook";
380      if (code == SubscriptionChannelType.WEBSOCKET)
381        return "websocket";
382      if (code == SubscriptionChannelType.EMAIL)
383        return "email";
384      if (code == SubscriptionChannelType.SMS)
385        return "sms";
386      if (code == SubscriptionChannelType.MESSAGE)
387        return "message";
388      return "?";
389   }
390  }
391
392  @Block()
393  public static class SubscriptionChannelComponent extends BackboneElement implements IBaseBackboneElement {
394    /**
395     * The type of channel to send notifications on.
396     */
397    @Child(name = "type", type = { CodeType.class }, order = 1, min = 1, max = 1, modifier = false, summary = true)
398    @Description(shortDefinition = "rest-hook | websocket | email | sms | message", formalDefinition = "The type of channel to send notifications on.")
399    protected Enumeration<SubscriptionChannelType> type;
400
401    /**
402     * The uri that describes the actual end-point to send messages to.
403     */
404    @Child(name = "endpoint", type = { UriType.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
405    @Description(shortDefinition = "Where the channel points to", formalDefinition = "The uri that describes the actual end-point to send messages to.")
406    protected UriType endpoint;
407
408    /**
409     * The mime type to send the payload in - either application/xml+fhir, or
410     * application/json+fhir. If the mime type is blank, then there is no payload in
411     * the notification, just a notification.
412     */
413    @Child(name = "payload", type = { StringType.class }, order = 3, min = 1, max = 1, modifier = false, summary = true)
414    @Description(shortDefinition = "Mimetype to send, or blank for no payload", formalDefinition = "The mime type to send the payload in - either application/xml+fhir, or application/json+fhir. If the mime type is blank, then there is no payload in the notification, just a notification.")
415    protected StringType payload;
416
417    /**
418     * Additional headers / information to send as part of the notification.
419     */
420    @Child(name = "header", type = { StringType.class }, order = 4, min = 0, max = 1, modifier = false, summary = true)
421    @Description(shortDefinition = "Usage depends on the channel type", formalDefinition = "Additional headers / information to send as part of the notification.")
422    protected StringType header;
423
424    private static final long serialVersionUID = -279715391L;
425
426    /*
427     * Constructor
428     */
429    public SubscriptionChannelComponent() {
430      super();
431    }
432
433    /*
434     * Constructor
435     */
436    public SubscriptionChannelComponent(Enumeration<SubscriptionChannelType> type, StringType payload) {
437      super();
438      this.type = type;
439      this.payload = payload;
440    }
441
442    /**
443     * @return {@link #type} (The type of channel to send notifications on.). This
444     *         is the underlying object with id, value and extensions. The accessor
445     *         "getType" gives direct access to the value
446     */
447    public Enumeration<SubscriptionChannelType> getTypeElement() {
448      if (this.type == null)
449        if (Configuration.errorOnAutoCreate())
450          throw new Error("Attempt to auto-create SubscriptionChannelComponent.type");
451        else if (Configuration.doAutoCreate())
452          this.type = new Enumeration<SubscriptionChannelType>(new SubscriptionChannelTypeEnumFactory()); // bb
453      return this.type;
454    }
455
456    public boolean hasTypeElement() {
457      return this.type != null && !this.type.isEmpty();
458    }
459
460    public boolean hasType() {
461      return this.type != null && !this.type.isEmpty();
462    }
463
464    /**
465     * @param value {@link #type} (The type of channel to send notifications on.).
466     *              This is the underlying object with id, value and extensions. The
467     *              accessor "getType" gives direct access to the value
468     */
469    public SubscriptionChannelComponent setTypeElement(Enumeration<SubscriptionChannelType> value) {
470      this.type = value;
471      return this;
472    }
473
474    /**
475     * @return The type of channel to send notifications on.
476     */
477    public SubscriptionChannelType getType() {
478      return this.type == null ? null : this.type.getValue();
479    }
480
481    /**
482     * @param value The type of channel to send notifications on.
483     */
484    public SubscriptionChannelComponent setType(SubscriptionChannelType value) {
485      if (this.type == null)
486        this.type = new Enumeration<SubscriptionChannelType>(new SubscriptionChannelTypeEnumFactory());
487      this.type.setValue(value);
488      return this;
489    }
490
491    /**
492     * @return {@link #endpoint} (The uri that describes the actual end-point to
493     *         send messages to.). This is the underlying object with id, value and
494     *         extensions. The accessor "getEndpoint" gives direct access to the
495     *         value
496     */
497    public UriType getEndpointElement() {
498      if (this.endpoint == null)
499        if (Configuration.errorOnAutoCreate())
500          throw new Error("Attempt to auto-create SubscriptionChannelComponent.endpoint");
501        else if (Configuration.doAutoCreate())
502          this.endpoint = new UriType(); // bb
503      return this.endpoint;
504    }
505
506    public boolean hasEndpointElement() {
507      return this.endpoint != null && !this.endpoint.isEmpty();
508    }
509
510    public boolean hasEndpoint() {
511      return this.endpoint != null && !this.endpoint.isEmpty();
512    }
513
514    /**
515     * @param value {@link #endpoint} (The uri that describes the actual end-point
516     *              to send messages to.). This is the underlying object with id,
517     *              value and extensions. The accessor "getEndpoint" gives direct
518     *              access to the value
519     */
520    public SubscriptionChannelComponent setEndpointElement(UriType value) {
521      this.endpoint = value;
522      return this;
523    }
524
525    /**
526     * @return The uri that describes the actual end-point to send messages to.
527     */
528    public String getEndpoint() {
529      return this.endpoint == null ? null : this.endpoint.getValue();
530    }
531
532    /**
533     * @param value The uri that describes the actual end-point to send messages to.
534     */
535    public SubscriptionChannelComponent setEndpoint(String value) {
536      if (Utilities.noString(value))
537        this.endpoint = null;
538      else {
539        if (this.endpoint == null)
540          this.endpoint = new UriType();
541        this.endpoint.setValue(value);
542      }
543      return this;
544    }
545
546    /**
547     * @return {@link #payload} (The mime type to send the payload in - either
548     *         application/xml+fhir, or application/json+fhir. If the mime type is
549     *         blank, then there is no payload in the notification, just a
550     *         notification.). This is the underlying object with id, value and
551     *         extensions. The accessor "getPayload" gives direct access to the
552     *         value
553     */
554    public StringType getPayloadElement() {
555      if (this.payload == null)
556        if (Configuration.errorOnAutoCreate())
557          throw new Error("Attempt to auto-create SubscriptionChannelComponent.payload");
558        else if (Configuration.doAutoCreate())
559          this.payload = new StringType(); // bb
560      return this.payload;
561    }
562
563    public boolean hasPayloadElement() {
564      return this.payload != null && !this.payload.isEmpty();
565    }
566
567    public boolean hasPayload() {
568      return this.payload != null && !this.payload.isEmpty();
569    }
570
571    /**
572     * @param value {@link #payload} (The mime type to send the payload in - either
573     *              application/xml+fhir, or application/json+fhir. If the mime type
574     *              is blank, then there is no payload in the notification, just a
575     *              notification.). This is the underlying object with id, value and
576     *              extensions. The accessor "getPayload" gives direct access to the
577     *              value
578     */
579    public SubscriptionChannelComponent setPayloadElement(StringType value) {
580      this.payload = value;
581      return this;
582    }
583
584    /**
585     * @return The mime type to send the payload in - either application/xml+fhir,
586     *         or application/json+fhir. If the mime type is blank, then there is no
587     *         payload in the notification, just a notification.
588     */
589    public String getPayload() {
590      return this.payload == null ? null : this.payload.getValue();
591    }
592
593    /**
594     * @param value The mime type to send the payload in - either
595     *              application/xml+fhir, or application/json+fhir. If the mime type
596     *              is blank, then there is no payload in the notification, just a
597     *              notification.
598     */
599    public SubscriptionChannelComponent setPayload(String value) {
600      if (this.payload == null)
601        this.payload = new StringType();
602      this.payload.setValue(value);
603      return this;
604    }
605
606    /**
607     * @return {@link #header} (Additional headers / information to send as part of
608     *         the notification.). This is the underlying object with id, value and
609     *         extensions. The accessor "getHeader" gives direct access to the value
610     */
611    public StringType getHeaderElement() {
612      if (this.header == null)
613        if (Configuration.errorOnAutoCreate())
614          throw new Error("Attempt to auto-create SubscriptionChannelComponent.header");
615        else if (Configuration.doAutoCreate())
616          this.header = new StringType(); // bb
617      return this.header;
618    }
619
620    public boolean hasHeaderElement() {
621      return this.header != null && !this.header.isEmpty();
622    }
623
624    public boolean hasHeader() {
625      return this.header != null && !this.header.isEmpty();
626    }
627
628    /**
629     * @param value {@link #header} (Additional headers / information to send as
630     *              part of the notification.). This is the underlying object with
631     *              id, value and extensions. The accessor "getHeader" gives direct
632     *              access to the value
633     */
634    public SubscriptionChannelComponent setHeaderElement(StringType value) {
635      this.header = value;
636      return this;
637    }
638
639    /**
640     * @return Additional headers / information to send as part of the notification.
641     */
642    public String getHeader() {
643      return this.header == null ? null : this.header.getValue();
644    }
645
646    /**
647     * @param value Additional headers / information to send as part of the
648     *              notification.
649     */
650    public SubscriptionChannelComponent setHeader(String value) {
651      if (Utilities.noString(value))
652        this.header = null;
653      else {
654        if (this.header == null)
655          this.header = new StringType();
656        this.header.setValue(value);
657      }
658      return this;
659    }
660
661    protected void listChildren(List<Property> childrenList) {
662      super.listChildren(childrenList);
663      childrenList.add(new Property("type", "code", "The type of channel to send notifications on.", 0,
664          java.lang.Integer.MAX_VALUE, type));
665      childrenList
666          .add(new Property("endpoint", "uri", "The uri that describes the actual end-point to send messages to.", 0,
667              java.lang.Integer.MAX_VALUE, endpoint));
668      childrenList.add(new Property("payload", "string",
669          "The mime type to send the payload in - either application/xml+fhir, or application/json+fhir. If the mime type is blank, then there is no payload in the notification, just a notification.",
670          0, java.lang.Integer.MAX_VALUE, payload));
671      childrenList
672          .add(new Property("header", "string", "Additional headers / information to send as part of the notification.",
673              0, java.lang.Integer.MAX_VALUE, header));
674    }
675
676    @Override
677    public void setProperty(String name, Base value) throws FHIRException {
678      if (name.equals("type"))
679        this.type = new SubscriptionChannelTypeEnumFactory().fromType(value); // Enumeration<SubscriptionChannelType>
680      else if (name.equals("endpoint"))
681        this.endpoint = castToUri(value); // UriType
682      else if (name.equals("payload"))
683        this.payload = castToString(value); // StringType
684      else if (name.equals("header"))
685        this.header = castToString(value); // StringType
686      else
687        super.setProperty(name, value);
688    }
689
690    @Override
691    public Base addChild(String name) throws FHIRException {
692      if (name.equals("type")) {
693        throw new FHIRException("Cannot call addChild on a singleton property Subscription.type");
694      } else if (name.equals("endpoint")) {
695        throw new FHIRException("Cannot call addChild on a singleton property Subscription.endpoint");
696      } else if (name.equals("payload")) {
697        throw new FHIRException("Cannot call addChild on a singleton property Subscription.payload");
698      } else if (name.equals("header")) {
699        throw new FHIRException("Cannot call addChild on a singleton property Subscription.header");
700      } else
701        return super.addChild(name);
702    }
703
704    public SubscriptionChannelComponent copy() {
705      SubscriptionChannelComponent dst = new SubscriptionChannelComponent();
706      copyValues(dst);
707      dst.type = type == null ? null : type.copy();
708      dst.endpoint = endpoint == null ? null : endpoint.copy();
709      dst.payload = payload == null ? null : payload.copy();
710      dst.header = header == null ? null : header.copy();
711      return dst;
712    }
713
714    @Override
715    public boolean equalsDeep(Base other) {
716      if (!super.equalsDeep(other))
717        return false;
718      if (!(other instanceof SubscriptionChannelComponent))
719        return false;
720      SubscriptionChannelComponent o = (SubscriptionChannelComponent) other;
721      return compareDeep(type, o.type, true) && compareDeep(endpoint, o.endpoint, true)
722          && compareDeep(payload, o.payload, true) && compareDeep(header, o.header, true);
723    }
724
725    @Override
726    public boolean equalsShallow(Base other) {
727      if (!super.equalsShallow(other))
728        return false;
729      if (!(other instanceof SubscriptionChannelComponent))
730        return false;
731      SubscriptionChannelComponent o = (SubscriptionChannelComponent) other;
732      return compareValues(type, o.type, true) && compareValues(endpoint, o.endpoint, true)
733          && compareValues(payload, o.payload, true) && compareValues(header, o.header, true);
734    }
735
736    public boolean isEmpty() {
737      return super.isEmpty() && (type == null || type.isEmpty()) && (endpoint == null || endpoint.isEmpty())
738          && (payload == null || payload.isEmpty()) && (header == null || header.isEmpty());
739    }
740
741    public String fhirType() {
742      return "Subscription.channel";
743
744    }
745
746  }
747
748  /**
749   * The rules that the server should use to determine when to generate
750   * notifications for this subscription.
751   */
752  @Child(name = "criteria", type = { StringType.class }, order = 0, min = 1, max = 1, modifier = false, summary = true)
753  @Description(shortDefinition = "Rule for server push criteria", formalDefinition = "The rules that the server should use to determine when to generate notifications for this subscription.")
754  protected StringType criteria;
755
756  /**
757   * Contact details for a human to contact about the subscription. The primary
758   * use of this for system administrator troubleshooting.
759   */
760  @Child(name = "contact", type = {
761      ContactPoint.class }, order = 1, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
762  @Description(shortDefinition = "Contact details for source (e.g. troubleshooting)", formalDefinition = "Contact details for a human to contact about the subscription. The primary use of this for system administrator troubleshooting.")
763  protected List<ContactPoint> contact;
764
765  /**
766   * A description of why this subscription is defined.
767   */
768  @Child(name = "reason", type = { StringType.class }, order = 2, min = 1, max = 1, modifier = false, summary = true)
769  @Description(shortDefinition = "Description of why this subscription was created", formalDefinition = "A description of why this subscription is defined.")
770  protected StringType reason;
771
772  /**
773   * The status of the subscription, which marks the server state for managing the
774   * subscription.
775   */
776  @Child(name = "status", type = { CodeType.class }, order = 3, min = 1, max = 1, modifier = true, summary = true)
777  @Description(shortDefinition = "requested | active | error | off", formalDefinition = "The status of the subscription, which marks the server state for managing the subscription.")
778  protected Enumeration<SubscriptionStatus> status;
779
780  /**
781   * A record of the last error that occurred when the server processed a
782   * notification.
783   */
784  @Child(name = "error", type = { StringType.class }, order = 4, min = 0, max = 1, modifier = false, summary = true)
785  @Description(shortDefinition = "Latest error note", formalDefinition = "A record of the last error that occurred when the server processed a notification.")
786  protected StringType error;
787
788  /**
789   * Details where to send notifications when resources are received that meet the
790   * criteria.
791   */
792  @Child(name = "channel", type = {}, order = 5, min = 1, max = 1, modifier = false, summary = true)
793  @Description(shortDefinition = "The channel on which to report matches to the criteria", formalDefinition = "Details where to send notifications when resources are received that meet the criteria.")
794  protected SubscriptionChannelComponent channel;
795
796  /**
797   * The time for the server to turn the subscription off.
798   */
799  @Child(name = "end", type = { InstantType.class }, order = 6, min = 0, max = 1, modifier = false, summary = true)
800  @Description(shortDefinition = "When to automatically delete the subscription", formalDefinition = "The time for the server to turn the subscription off.")
801  protected InstantType end;
802
803  /**
804   * A tag to add to any resource that matches the criteria, after the
805   * subscription is processed.
806   */
807  @Child(name = "tag", type = {
808      Coding.class }, order = 7, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
809  @Description(shortDefinition = "A tag to add to matching resources", formalDefinition = "A tag to add to any resource that matches the criteria, after the subscription is processed.")
810  protected List<Coding> tag;
811
812  private static final long serialVersionUID = -1390870804L;
813
814  /*
815   * Constructor
816   */
817  public Subscription() {
818    super();
819  }
820
821  /*
822   * Constructor
823   */
824  public Subscription(StringType criteria, StringType reason, Enumeration<SubscriptionStatus> status,
825      SubscriptionChannelComponent channel) {
826    super();
827    this.criteria = criteria;
828    this.reason = reason;
829    this.status = status;
830    this.channel = channel;
831  }
832
833  /**
834   * @return {@link #criteria} (The rules that the server should use to determine
835   *         when to generate notifications for this subscription.). This is the
836   *         underlying object with id, value and extensions. The accessor
837   *         "getCriteria" gives direct access to the value
838   */
839  public StringType getCriteriaElement() {
840    if (this.criteria == null)
841      if (Configuration.errorOnAutoCreate())
842        throw new Error("Attempt to auto-create Subscription.criteria");
843      else if (Configuration.doAutoCreate())
844        this.criteria = new StringType(); // bb
845    return this.criteria;
846  }
847
848  public boolean hasCriteriaElement() {
849    return this.criteria != null && !this.criteria.isEmpty();
850  }
851
852  public boolean hasCriteria() {
853    return this.criteria != null && !this.criteria.isEmpty();
854  }
855
856  /**
857   * @param value {@link #criteria} (The rules that the server should use to
858   *              determine when to generate notifications for this
859   *              subscription.). This is the underlying object with id, value and
860   *              extensions. The accessor "getCriteria" gives direct access to
861   *              the value
862   */
863  public Subscription setCriteriaElement(StringType value) {
864    this.criteria = value;
865    return this;
866  }
867
868  /**
869   * @return The rules that the server should use to determine when to generate
870   *         notifications for this subscription.
871   */
872  public String getCriteria() {
873    return this.criteria == null ? null : this.criteria.getValue();
874  }
875
876  /**
877   * @param value The rules that the server should use to determine when to
878   *              generate notifications for this subscription.
879   */
880  public Subscription setCriteria(String value) {
881    if (this.criteria == null)
882      this.criteria = new StringType();
883    this.criteria.setValue(value);
884    return this;
885  }
886
887  /**
888   * @return {@link #contact} (Contact details for a human to contact about the
889   *         subscription. The primary use of this for system administrator
890   *         troubleshooting.)
891   */
892  public List<ContactPoint> getContact() {
893    if (this.contact == null)
894      this.contact = new ArrayList<ContactPoint>();
895    return this.contact;
896  }
897
898  public boolean hasContact() {
899    if (this.contact == null)
900      return false;
901    for (ContactPoint item : this.contact)
902      if (!item.isEmpty())
903        return true;
904    return false;
905  }
906
907  /**
908   * @return {@link #contact} (Contact details for a human to contact about the
909   *         subscription. The primary use of this for system administrator
910   *         troubleshooting.)
911   */
912  // syntactic sugar
913  public ContactPoint addContact() { // 3
914    ContactPoint t = new ContactPoint();
915    if (this.contact == null)
916      this.contact = new ArrayList<ContactPoint>();
917    this.contact.add(t);
918    return t;
919  }
920
921  // syntactic sugar
922  public Subscription addContact(ContactPoint t) { // 3
923    if (t == null)
924      return this;
925    if (this.contact == null)
926      this.contact = new ArrayList<ContactPoint>();
927    this.contact.add(t);
928    return this;
929  }
930
931  /**
932   * @return {@link #reason} (A description of why this subscription is defined.).
933   *         This is the underlying object with id, value and extensions. The
934   *         accessor "getReason" gives direct access to the value
935   */
936  public StringType getReasonElement() {
937    if (this.reason == null)
938      if (Configuration.errorOnAutoCreate())
939        throw new Error("Attempt to auto-create Subscription.reason");
940      else if (Configuration.doAutoCreate())
941        this.reason = new StringType(); // bb
942    return this.reason;
943  }
944
945  public boolean hasReasonElement() {
946    return this.reason != null && !this.reason.isEmpty();
947  }
948
949  public boolean hasReason() {
950    return this.reason != null && !this.reason.isEmpty();
951  }
952
953  /**
954   * @param value {@link #reason} (A description of why this subscription is
955   *              defined.). This is the underlying object with id, value and
956   *              extensions. The accessor "getReason" gives direct access to the
957   *              value
958   */
959  public Subscription setReasonElement(StringType value) {
960    this.reason = value;
961    return this;
962  }
963
964  /**
965   * @return A description of why this subscription is defined.
966   */
967  public String getReason() {
968    return this.reason == null ? null : this.reason.getValue();
969  }
970
971  /**
972   * @param value A description of why this subscription is defined.
973   */
974  public Subscription setReason(String value) {
975    if (this.reason == null)
976      this.reason = new StringType();
977    this.reason.setValue(value);
978    return this;
979  }
980
981  /**
982   * @return {@link #status} (The status of the subscription, which marks the
983   *         server state for managing the subscription.). This is the underlying
984   *         object with id, value and extensions. The accessor "getStatus" gives
985   *         direct access to the value
986   */
987  public Enumeration<SubscriptionStatus> getStatusElement() {
988    if (this.status == null)
989      if (Configuration.errorOnAutoCreate())
990        throw new Error("Attempt to auto-create Subscription.status");
991      else if (Configuration.doAutoCreate())
992        this.status = new Enumeration<SubscriptionStatus>(new SubscriptionStatusEnumFactory()); // bb
993    return this.status;
994  }
995
996  public boolean hasStatusElement() {
997    return this.status != null && !this.status.isEmpty();
998  }
999
1000  public boolean hasStatus() {
1001    return this.status != null && !this.status.isEmpty();
1002  }
1003
1004  /**
1005   * @param value {@link #status} (The status of the subscription, which marks the
1006   *              server state for managing the subscription.). This is the
1007   *              underlying object with id, value and extensions. The accessor
1008   *              "getStatus" gives direct access to the value
1009   */
1010  public Subscription setStatusElement(Enumeration<SubscriptionStatus> value) {
1011    this.status = value;
1012    return this;
1013  }
1014
1015  /**
1016   * @return The status of the subscription, which marks the server state for
1017   *         managing the subscription.
1018   */
1019  public SubscriptionStatus getStatus() {
1020    return this.status == null ? null : this.status.getValue();
1021  }
1022
1023  /**
1024   * @param value The status of the subscription, which marks the server state for
1025   *              managing the subscription.
1026   */
1027  public Subscription setStatus(SubscriptionStatus value) {
1028    if (this.status == null)
1029      this.status = new Enumeration<SubscriptionStatus>(new SubscriptionStatusEnumFactory());
1030    this.status.setValue(value);
1031    return this;
1032  }
1033
1034  /**
1035   * @return {@link #error} (A record of the last error that occurred when the
1036   *         server processed a notification.). This is the underlying object with
1037   *         id, value and extensions. The accessor "getError" gives direct access
1038   *         to the value
1039   */
1040  public StringType getErrorElement() {
1041    if (this.error == null)
1042      if (Configuration.errorOnAutoCreate())
1043        throw new Error("Attempt to auto-create Subscription.error");
1044      else if (Configuration.doAutoCreate())
1045        this.error = new StringType(); // bb
1046    return this.error;
1047  }
1048
1049  public boolean hasErrorElement() {
1050    return this.error != null && !this.error.isEmpty();
1051  }
1052
1053  public boolean hasError() {
1054    return this.error != null && !this.error.isEmpty();
1055  }
1056
1057  /**
1058   * @param value {@link #error} (A record of the last error that occurred when
1059   *              the server processed a notification.). This is the underlying
1060   *              object with id, value and extensions. The accessor "getError"
1061   *              gives direct access to the value
1062   */
1063  public Subscription setErrorElement(StringType value) {
1064    this.error = value;
1065    return this;
1066  }
1067
1068  /**
1069   * @return A record of the last error that occurred when the server processed a
1070   *         notification.
1071   */
1072  public String getError() {
1073    return this.error == null ? null : this.error.getValue();
1074  }
1075
1076  /**
1077   * @param value A record of the last error that occurred when the server
1078   *              processed a notification.
1079   */
1080  public Subscription setError(String value) {
1081    if (Utilities.noString(value))
1082      this.error = null;
1083    else {
1084      if (this.error == null)
1085        this.error = new StringType();
1086      this.error.setValue(value);
1087    }
1088    return this;
1089  }
1090
1091  /**
1092   * @return {@link #channel} (Details where to send notifications when resources
1093   *         are received that meet the criteria.)
1094   */
1095  public SubscriptionChannelComponent getChannel() {
1096    if (this.channel == null)
1097      if (Configuration.errorOnAutoCreate())
1098        throw new Error("Attempt to auto-create Subscription.channel");
1099      else if (Configuration.doAutoCreate())
1100        this.channel = new SubscriptionChannelComponent(); // cc
1101    return this.channel;
1102  }
1103
1104  public boolean hasChannel() {
1105    return this.channel != null && !this.channel.isEmpty();
1106  }
1107
1108  /**
1109   * @param value {@link #channel} (Details where to send notifications when
1110   *              resources are received that meet the criteria.)
1111   */
1112  public Subscription setChannel(SubscriptionChannelComponent value) {
1113    this.channel = value;
1114    return this;
1115  }
1116
1117  /**
1118   * @return {@link #end} (The time for the server to turn the subscription off.).
1119   *         This is the underlying object with id, value and extensions. The
1120   *         accessor "getEnd" gives direct access to the value
1121   */
1122  public InstantType getEndElement() {
1123    if (this.end == null)
1124      if (Configuration.errorOnAutoCreate())
1125        throw new Error("Attempt to auto-create Subscription.end");
1126      else if (Configuration.doAutoCreate())
1127        this.end = new InstantType(); // bb
1128    return this.end;
1129  }
1130
1131  public boolean hasEndElement() {
1132    return this.end != null && !this.end.isEmpty();
1133  }
1134
1135  public boolean hasEnd() {
1136    return this.end != null && !this.end.isEmpty();
1137  }
1138
1139  /**
1140   * @param value {@link #end} (The time for the server to turn the subscription
1141   *              off.). This is the underlying object with id, value and
1142   *              extensions. The accessor "getEnd" gives direct access to the
1143   *              value
1144   */
1145  public Subscription setEndElement(InstantType value) {
1146    this.end = value;
1147    return this;
1148  }
1149
1150  /**
1151   * @return The time for the server to turn the subscription off.
1152   */
1153  public Date getEnd() {
1154    return this.end == null ? null : this.end.getValue();
1155  }
1156
1157  /**
1158   * @param value The time for the server to turn the subscription off.
1159   */
1160  public Subscription setEnd(Date value) {
1161    if (value == null)
1162      this.end = null;
1163    else {
1164      if (this.end == null)
1165        this.end = new InstantType();
1166      this.end.setValue(value);
1167    }
1168    return this;
1169  }
1170
1171  /**
1172   * @return {@link #tag} (A tag to add to any resource that matches the criteria,
1173   *         after the subscription is processed.)
1174   */
1175  public List<Coding> getTag() {
1176    if (this.tag == null)
1177      this.tag = new ArrayList<Coding>();
1178    return this.tag;
1179  }
1180
1181  public boolean hasTag() {
1182    if (this.tag == null)
1183      return false;
1184    for (Coding item : this.tag)
1185      if (!item.isEmpty())
1186        return true;
1187    return false;
1188  }
1189
1190  /**
1191   * @return {@link #tag} (A tag to add to any resource that matches the criteria,
1192   *         after the subscription is processed.)
1193   */
1194  // syntactic sugar
1195  public Coding addTag() { // 3
1196    Coding t = new Coding();
1197    if (this.tag == null)
1198      this.tag = new ArrayList<Coding>();
1199    this.tag.add(t);
1200    return t;
1201  }
1202
1203  // syntactic sugar
1204  public Subscription addTag(Coding t) { // 3
1205    if (t == null)
1206      return this;
1207    if (this.tag == null)
1208      this.tag = new ArrayList<Coding>();
1209    this.tag.add(t);
1210    return this;
1211  }
1212
1213  protected void listChildren(List<Property> childrenList) {
1214    super.listChildren(childrenList);
1215    childrenList.add(new Property("criteria", "string",
1216        "The rules that the server should use to determine when to generate notifications for this subscription.", 0,
1217        java.lang.Integer.MAX_VALUE, criteria));
1218    childrenList.add(new Property("contact", "ContactPoint",
1219        "Contact details for a human to contact about the subscription. The primary use of this for system administrator troubleshooting.",
1220        0, java.lang.Integer.MAX_VALUE, contact));
1221    childrenList.add(new Property("reason", "string", "A description of why this subscription is defined.", 0,
1222        java.lang.Integer.MAX_VALUE, reason));
1223    childrenList.add(new Property("status", "code",
1224        "The status of the subscription, which marks the server state for managing the subscription.", 0,
1225        java.lang.Integer.MAX_VALUE, status));
1226    childrenList.add(new Property("error", "string",
1227        "A record of the last error that occurred when the server processed a notification.", 0,
1228        java.lang.Integer.MAX_VALUE, error));
1229    childrenList.add(new Property("channel", "",
1230        "Details where to send notifications when resources are received that meet the criteria.", 0,
1231        java.lang.Integer.MAX_VALUE, channel));
1232    childrenList.add(new Property("end", "instant", "The time for the server to turn the subscription off.", 0,
1233        java.lang.Integer.MAX_VALUE, end));
1234    childrenList.add(new Property("tag", "Coding",
1235        "A tag to add to any resource that matches the criteria, after the subscription is processed.", 0,
1236        java.lang.Integer.MAX_VALUE, tag));
1237  }
1238
1239  @Override
1240  public void setProperty(String name, Base value) throws FHIRException {
1241    if (name.equals("criteria"))
1242      this.criteria = castToString(value); // StringType
1243    else if (name.equals("contact"))
1244      this.getContact().add(castToContactPoint(value));
1245    else if (name.equals("reason"))
1246      this.reason = castToString(value); // StringType
1247    else if (name.equals("status"))
1248      this.status = new SubscriptionStatusEnumFactory().fromType(value); // Enumeration<SubscriptionStatus>
1249    else if (name.equals("error"))
1250      this.error = castToString(value); // StringType
1251    else if (name.equals("channel"))
1252      this.channel = (SubscriptionChannelComponent) value; // SubscriptionChannelComponent
1253    else if (name.equals("end"))
1254      this.end = castToInstant(value); // InstantType
1255    else if (name.equals("tag"))
1256      this.getTag().add(castToCoding(value));
1257    else
1258      super.setProperty(name, value);
1259  }
1260
1261  @Override
1262  public Base addChild(String name) throws FHIRException {
1263    if (name.equals("criteria")) {
1264      throw new FHIRException("Cannot call addChild on a singleton property Subscription.criteria");
1265    } else if (name.equals("contact")) {
1266      return addContact();
1267    } else if (name.equals("reason")) {
1268      throw new FHIRException("Cannot call addChild on a singleton property Subscription.reason");
1269    } else if (name.equals("status")) {
1270      throw new FHIRException("Cannot call addChild on a singleton property Subscription.status");
1271    } else if (name.equals("error")) {
1272      throw new FHIRException("Cannot call addChild on a singleton property Subscription.error");
1273    } else if (name.equals("channel")) {
1274      this.channel = new SubscriptionChannelComponent();
1275      return this.channel;
1276    } else if (name.equals("end")) {
1277      throw new FHIRException("Cannot call addChild on a singleton property Subscription.end");
1278    } else if (name.equals("tag")) {
1279      return addTag();
1280    } else
1281      return super.addChild(name);
1282  }
1283
1284  public String fhirType() {
1285    return "Subscription";
1286
1287  }
1288
1289  public Subscription copy() {
1290    Subscription dst = new Subscription();
1291    copyValues(dst);
1292    dst.criteria = criteria == null ? null : criteria.copy();
1293    if (contact != null) {
1294      dst.contact = new ArrayList<ContactPoint>();
1295      for (ContactPoint i : contact)
1296        dst.contact.add(i.copy());
1297    }
1298    ;
1299    dst.reason = reason == null ? null : reason.copy();
1300    dst.status = status == null ? null : status.copy();
1301    dst.error = error == null ? null : error.copy();
1302    dst.channel = channel == null ? null : channel.copy();
1303    dst.end = end == null ? null : end.copy();
1304    if (tag != null) {
1305      dst.tag = new ArrayList<Coding>();
1306      for (Coding i : tag)
1307        dst.tag.add(i.copy());
1308    }
1309    ;
1310    return dst;
1311  }
1312
1313  protected Subscription typedCopy() {
1314    return copy();
1315  }
1316
1317  @Override
1318  public boolean equalsDeep(Base other) {
1319    if (!super.equalsDeep(other))
1320      return false;
1321    if (!(other instanceof Subscription))
1322      return false;
1323    Subscription o = (Subscription) other;
1324    return compareDeep(criteria, o.criteria, true) && compareDeep(contact, o.contact, true)
1325        && compareDeep(reason, o.reason, true) && compareDeep(status, o.status, true)
1326        && compareDeep(error, o.error, true) && compareDeep(channel, o.channel, true) && compareDeep(end, o.end, true)
1327        && compareDeep(tag, o.tag, true);
1328  }
1329
1330  @Override
1331  public boolean equalsShallow(Base other) {
1332    if (!super.equalsShallow(other))
1333      return false;
1334    if (!(other instanceof Subscription))
1335      return false;
1336    Subscription o = (Subscription) other;
1337    return compareValues(criteria, o.criteria, true) && compareValues(reason, o.reason, true)
1338        && compareValues(status, o.status, true) && compareValues(error, o.error, true)
1339        && compareValues(end, o.end, true);
1340  }
1341
1342  public boolean isEmpty() {
1343    return super.isEmpty() && (criteria == null || criteria.isEmpty()) && (contact == null || contact.isEmpty())
1344        && (reason == null || reason.isEmpty()) && (status == null || status.isEmpty())
1345        && (error == null || error.isEmpty()) && (channel == null || channel.isEmpty())
1346        && (end == null || end.isEmpty()) && (tag == null || tag.isEmpty());
1347  }
1348
1349  @Override
1350  public ResourceType getResourceType() {
1351    return ResourceType.Subscription;
1352  }
1353
1354  @SearchParamDefinition(name = "payload", path = "Subscription.channel.payload", description = "Mimetype to send, or blank for no payload", type = "string")
1355  public static final String SP_PAYLOAD = "payload";
1356  @SearchParamDefinition(name = "criteria", path = "Subscription.criteria", description = "Rule for server push criteria", type = "string")
1357  public static final String SP_CRITERIA = "criteria";
1358  @SearchParamDefinition(name = "contact", path = "Subscription.contact", description = "Contact details for source (e.g. troubleshooting)", type = "token")
1359  public static final String SP_CONTACT = "contact";
1360  @SearchParamDefinition(name = "tag", path = "Subscription.tag", description = "A tag to add to matching resources", type = "token")
1361  public static final String SP_TAG = "tag";
1362  @SearchParamDefinition(name = "type", path = "Subscription.channel.type", description = "rest-hook | websocket | email | sms | message", type = "token")
1363  public static final String SP_TYPE = "type";
1364  @SearchParamDefinition(name = "url", path = "Subscription.channel.endpoint", description = "Where the channel points to", type = "uri")
1365  public static final String SP_URL = "url";
1366  @SearchParamDefinition(name = "status", path = "Subscription.status", description = "requested | active | error | off", type = "token")
1367  public static final String SP_STATUS = "status";
1368
1369}