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