001package org.hl7.fhir.instance.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.*;
034
035import org.hl7.fhir.exceptions.FHIRException;
036import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
037
038import ca.uhn.fhir.model.api.annotation.*;
039/**
040 * An occurrence of information being transmitted; e.g. an alert that was sent to a responsible provider, a public health agency was notified about a reportable condition.
041 */
042@ResourceDef(name="Communication", profile="http://hl7.org/fhir/Profile/Communication")
043public class Communication extends DomainResource {
044
045    public enum CommunicationStatus {
046        /**
047         * The communication transmission is ongoing.
048         */
049        INPROGRESS, 
050        /**
051         * The message transmission is complete, i.e., delivered to the recipient's destination.
052         */
053        COMPLETED, 
054        /**
055         * The communication transmission has been held by originating system/user request.
056         */
057        SUSPENDED, 
058        /**
059         * The receiving system has declined to accept the message.
060         */
061        REJECTED, 
062        /**
063         * There was a failure in transmitting the message out.
064         */
065        FAILED, 
066        /**
067         * added to help the parsers
068         */
069        NULL;
070        public static CommunicationStatus fromCode(String codeString) throws FHIRException {
071            if (codeString == null || "".equals(codeString))
072                return null;
073        if ("in-progress".equals(codeString))
074          return INPROGRESS;
075        if ("completed".equals(codeString))
076          return COMPLETED;
077        if ("suspended".equals(codeString))
078          return SUSPENDED;
079        if ("rejected".equals(codeString))
080          return REJECTED;
081        if ("failed".equals(codeString))
082          return FAILED;
083        throw new FHIRException("Unknown CommunicationStatus code '"+codeString+"'");
084        }
085        public String toCode() {
086          switch (this) {
087            case INPROGRESS: return "in-progress";
088            case COMPLETED: return "completed";
089            case SUSPENDED: return "suspended";
090            case REJECTED: return "rejected";
091            case FAILED: return "failed";
092            default: return "?";
093          }
094        }
095        public String getSystem() {
096          switch (this) {
097            case INPROGRESS: return "http://hl7.org/fhir/communication-status";
098            case COMPLETED: return "http://hl7.org/fhir/communication-status";
099            case SUSPENDED: return "http://hl7.org/fhir/communication-status";
100            case REJECTED: return "http://hl7.org/fhir/communication-status";
101            case FAILED: return "http://hl7.org/fhir/communication-status";
102            default: return "?";
103          }
104        }
105        public String getDefinition() {
106          switch (this) {
107            case INPROGRESS: return "The communication transmission is ongoing.";
108            case COMPLETED: return "The message transmission is complete, i.e., delivered to the recipient's destination.";
109            case SUSPENDED: return "The communication transmission has been held by originating system/user request.";
110            case REJECTED: return "The receiving system has declined to accept the message.";
111            case FAILED: return "There was a failure in transmitting the message out.";
112            default: return "?";
113          }
114        }
115        public String getDisplay() {
116          switch (this) {
117            case INPROGRESS: return "In Progress";
118            case COMPLETED: return "Completed";
119            case SUSPENDED: return "Suspended";
120            case REJECTED: return "Rejected";
121            case FAILED: return "Failed";
122            default: return "?";
123          }
124        }
125    }
126
127  public static class CommunicationStatusEnumFactory implements EnumFactory<CommunicationStatus> {
128    public CommunicationStatus fromCode(String codeString) throws IllegalArgumentException {
129      if (codeString == null || "".equals(codeString))
130            if (codeString == null || "".equals(codeString))
131                return null;
132        if ("in-progress".equals(codeString))
133          return CommunicationStatus.INPROGRESS;
134        if ("completed".equals(codeString))
135          return CommunicationStatus.COMPLETED;
136        if ("suspended".equals(codeString))
137          return CommunicationStatus.SUSPENDED;
138        if ("rejected".equals(codeString))
139          return CommunicationStatus.REJECTED;
140        if ("failed".equals(codeString))
141          return CommunicationStatus.FAILED;
142        throw new IllegalArgumentException("Unknown CommunicationStatus code '"+codeString+"'");
143        }
144        public Enumeration<CommunicationStatus> fromType(Base code) throws FHIRException {
145          if (code == null || code.isEmpty())
146            return null;
147          String codeString = ((PrimitiveType) code).asStringValue();
148          if (codeString == null || "".equals(codeString))
149            return null;
150        if ("in-progress".equals(codeString))
151          return new Enumeration<CommunicationStatus>(this, CommunicationStatus.INPROGRESS);
152        if ("completed".equals(codeString))
153          return new Enumeration<CommunicationStatus>(this, CommunicationStatus.COMPLETED);
154        if ("suspended".equals(codeString))
155          return new Enumeration<CommunicationStatus>(this, CommunicationStatus.SUSPENDED);
156        if ("rejected".equals(codeString))
157          return new Enumeration<CommunicationStatus>(this, CommunicationStatus.REJECTED);
158        if ("failed".equals(codeString))
159          return new Enumeration<CommunicationStatus>(this, CommunicationStatus.FAILED);
160        throw new FHIRException("Unknown CommunicationStatus code '"+codeString+"'");
161        }
162    public String toCode(CommunicationStatus code) {
163      if (code == CommunicationStatus.INPROGRESS)
164        return "in-progress";
165      if (code == CommunicationStatus.COMPLETED)
166        return "completed";
167      if (code == CommunicationStatus.SUSPENDED)
168        return "suspended";
169      if (code == CommunicationStatus.REJECTED)
170        return "rejected";
171      if (code == CommunicationStatus.FAILED)
172        return "failed";
173      return "?";
174      }
175    }
176
177    @Block()
178    public static class CommunicationPayloadComponent extends BackboneElement implements IBaseBackboneElement {
179        /**
180         * A communicated content (or for multi-part communications, one portion of the communication).
181         */
182        @Child(name = "content", type = {StringType.class, Attachment.class}, order=1, min=1, max=1, modifier=false, summary=true)
183        @Description(shortDefinition="Message part content", formalDefinition="A communicated content (or for multi-part communications, one portion of the communication)." )
184        protected Type content;
185
186        private static final long serialVersionUID = -1763459053L;
187
188    /*
189     * Constructor
190     */
191      public CommunicationPayloadComponent() {
192        super();
193      }
194
195    /*
196     * Constructor
197     */
198      public CommunicationPayloadComponent(Type content) {
199        super();
200        this.content = content;
201      }
202
203        /**
204         * @return {@link #content} (A communicated content (or for multi-part communications, one portion of the communication).)
205         */
206        public Type getContent() { 
207          return this.content;
208        }
209
210        /**
211         * @return {@link #content} (A communicated content (or for multi-part communications, one portion of the communication).)
212         */
213        public StringType getContentStringType() throws FHIRException { 
214          if (!(this.content instanceof StringType))
215            throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.content.getClass().getName()+" was encountered");
216          return (StringType) this.content;
217        }
218
219        public boolean hasContentStringType() { 
220          return this.content instanceof StringType;
221        }
222
223        /**
224         * @return {@link #content} (A communicated content (or for multi-part communications, one portion of the communication).)
225         */
226        public Attachment getContentAttachment() throws FHIRException { 
227          if (!(this.content instanceof Attachment))
228            throw new FHIRException("Type mismatch: the type Attachment was expected, but "+this.content.getClass().getName()+" was encountered");
229          return (Attachment) this.content;
230        }
231
232        public boolean hasContentAttachment() { 
233          return this.content instanceof Attachment;
234        }
235
236        /**
237         * @return {@link #content} (A communicated content (or for multi-part communications, one portion of the communication).)
238         */
239        public Reference getContentReference() throws FHIRException { 
240          if (!(this.content instanceof Reference))
241            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.content.getClass().getName()+" was encountered");
242          return (Reference) this.content;
243        }
244
245        public boolean hasContentReference() { 
246          return this.content instanceof Reference;
247        }
248
249        public boolean hasContent() { 
250          return this.content != null && !this.content.isEmpty();
251        }
252
253        /**
254         * @param value {@link #content} (A communicated content (or for multi-part communications, one portion of the communication).)
255         */
256        public CommunicationPayloadComponent setContent(Type value) { 
257          this.content = value;
258          return this;
259        }
260
261        protected void listChildren(List<Property> childrenList) {
262          super.listChildren(childrenList);
263          childrenList.add(new Property("content[x]", "string|Attachment|Reference(Any)", "A communicated content (or for multi-part communications, one portion of the communication).", 0, java.lang.Integer.MAX_VALUE, content));
264        }
265
266      @Override
267      public void setProperty(String name, Base value) throws FHIRException {
268        if (name.equals("content[x]"))
269          this.content = (Type) value; // Type
270        else
271          super.setProperty(name, value);
272      }
273
274      @Override
275      public Base addChild(String name) throws FHIRException {
276        if (name.equals("contentString")) {
277          this.content = new StringType();
278          return this.content;
279        }
280        else if (name.equals("contentAttachment")) {
281          this.content = new Attachment();
282          return this.content;
283        }
284        else if (name.equals("contentReference")) {
285          this.content = new Reference();
286          return this.content;
287        }
288        else
289          return super.addChild(name);
290      }
291
292      public CommunicationPayloadComponent copy() {
293        CommunicationPayloadComponent dst = new CommunicationPayloadComponent();
294        copyValues(dst);
295        dst.content = content == null ? null : content.copy();
296        return dst;
297      }
298
299      @Override
300      public boolean equalsDeep(Base other) {
301        if (!super.equalsDeep(other))
302          return false;
303        if (!(other instanceof CommunicationPayloadComponent))
304          return false;
305        CommunicationPayloadComponent o = (CommunicationPayloadComponent) other;
306        return compareDeep(content, o.content, true);
307      }
308
309      @Override
310      public boolean equalsShallow(Base other) {
311        if (!super.equalsShallow(other))
312          return false;
313        if (!(other instanceof CommunicationPayloadComponent))
314          return false;
315        CommunicationPayloadComponent o = (CommunicationPayloadComponent) other;
316        return true;
317      }
318
319      public boolean isEmpty() {
320        return super.isEmpty() && (content == null || content.isEmpty());
321      }
322
323  public String fhirType() {
324    return "Communication.payload";
325
326  }
327
328  }
329
330    /**
331     * Identifiers associated with this Communication that are defined by business processes and/ or used to refer to it when a direct URL reference to the resource itself is not appropriate (e.g. in CDA documents, or in written / printed documentation).
332     */
333    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
334    @Description(shortDefinition="Unique identifier", formalDefinition="Identifiers associated with this Communication that are defined by business processes and/ or used to refer to it when a direct URL reference to the resource itself is not appropriate (e.g. in CDA documents, or in written / printed documentation)." )
335    protected List<Identifier> identifier;
336
337    /**
338     * The type of message conveyed such as alert, notification, reminder, instruction, etc.
339     */
340    @Child(name = "category", type = {CodeableConcept.class}, order=1, min=0, max=1, modifier=false, summary=true)
341    @Description(shortDefinition="Message category", formalDefinition="The type of message conveyed such as alert, notification, reminder, instruction, etc." )
342    protected CodeableConcept category;
343
344    /**
345     * The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication.
346     */
347    @Child(name = "sender", type = {Device.class, Organization.class, Patient.class, Practitioner.class, RelatedPerson.class}, order=2, min=0, max=1, modifier=false, summary=true)
348    @Description(shortDefinition="Message sender", formalDefinition="The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication." )
349    protected Reference sender;
350
351    /**
352     * The actual object that is the target of the reference (The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication.)
353     */
354    protected Resource senderTarget;
355
356    /**
357     * The entity (e.g. person, organization, clinical information system, or device) which was the target of the communication. If receipts need to be tracked by individual, a separate resource instance will need to be created for each recipient.  Multiple recipient communications are intended where either a receipt(s) is not tracked (e.g. a mass mail-out) or is captured in aggregate (all emails confirmed received by a particular time).
358     */
359    @Child(name = "recipient", type = {Device.class, Organization.class, Patient.class, Practitioner.class, RelatedPerson.class, Group.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
360    @Description(shortDefinition="Message recipient", formalDefinition="The entity (e.g. person, organization, clinical information system, or device) which was the target of the communication. If receipts need to be tracked by individual, a separate resource instance will need to be created for each recipient.  Multiple recipient communications are intended where either a receipt(s) is not tracked (e.g. a mass mail-out) or is captured in aggregate (all emails confirmed received by a particular time)." )
361    protected List<Reference> recipient;
362    /**
363     * The actual objects that are the target of the reference (The entity (e.g. person, organization, clinical information system, or device) which was the target of the communication. If receipts need to be tracked by individual, a separate resource instance will need to be created for each recipient.  Multiple recipient communications are intended where either a receipt(s) is not tracked (e.g. a mass mail-out) or is captured in aggregate (all emails confirmed received by a particular time).)
364     */
365    protected List<Resource> recipientTarget;
366
367
368    /**
369     * Text, attachment(s), or resource(s) that was communicated to the recipient.
370     */
371    @Child(name = "payload", type = {}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
372    @Description(shortDefinition="Message payload", formalDefinition="Text, attachment(s), or resource(s) that was communicated to the recipient." )
373    protected List<CommunicationPayloadComponent> payload;
374
375    /**
376     * A channel that was used for this communication (e.g. email, fax).
377     */
378    @Child(name = "medium", type = {CodeableConcept.class}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
379    @Description(shortDefinition="A channel of communication", formalDefinition="A channel that was used for this communication (e.g. email, fax)." )
380    protected List<CodeableConcept> medium;
381
382    /**
383     * The status of the transmission.
384     */
385    @Child(name = "status", type = {CodeType.class}, order=6, min=0, max=1, modifier=true, summary=true)
386    @Description(shortDefinition="in-progress | completed | suspended | rejected | failed", formalDefinition="The status of the transmission." )
387    protected Enumeration<CommunicationStatus> status;
388
389    /**
390     * The encounter within which the communication was sent.
391     */
392    @Child(name = "encounter", type = {Encounter.class}, order=7, min=0, max=1, modifier=false, summary=true)
393    @Description(shortDefinition="Encounter leading to message", formalDefinition="The encounter within which the communication was sent." )
394    protected Reference encounter;
395
396    /**
397     * The actual object that is the target of the reference (The encounter within which the communication was sent.)
398     */
399    protected Encounter encounterTarget;
400
401    /**
402     * The time when this communication was sent.
403     */
404    @Child(name = "sent", type = {DateTimeType.class}, order=8, min=0, max=1, modifier=false, summary=true)
405    @Description(shortDefinition="When sent", formalDefinition="The time when this communication was sent." )
406    protected DateTimeType sent;
407
408    /**
409     * The time when this communication arrived at the destination.
410     */
411    @Child(name = "received", type = {DateTimeType.class}, order=9, min=0, max=1, modifier=false, summary=true)
412    @Description(shortDefinition="When received", formalDefinition="The time when this communication arrived at the destination." )
413    protected DateTimeType received;
414
415    /**
416     * The reason or justification for the communication.
417     */
418    @Child(name = "reason", type = {CodeableConcept.class}, order=10, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=true)
419    @Description(shortDefinition="Indication for message", formalDefinition="The reason or justification for the communication." )
420    protected List<CodeableConcept> reason;
421
422    /**
423     * The patient who was the focus of this communication.
424     */
425    @Child(name = "subject", type = {Patient.class}, order=11, min=0, max=1, modifier=false, summary=true)
426    @Description(shortDefinition="Focus of message", formalDefinition="The patient who was the focus of this communication." )
427    protected Reference subject;
428
429    /**
430     * The actual object that is the target of the reference (The patient who was the focus of this communication.)
431     */
432    protected Patient subjectTarget;
433
434    /**
435     * The communication request that was responsible for producing this communication.
436     */
437    @Child(name = "requestDetail", type = {CommunicationRequest.class}, order=12, min=0, max=1, modifier=false, summary=true)
438    @Description(shortDefinition="CommunicationRequest producing this message", formalDefinition="The communication request that was responsible for producing this communication." )
439    protected Reference requestDetail;
440
441    /**
442     * The actual object that is the target of the reference (The communication request that was responsible for producing this communication.)
443     */
444    protected CommunicationRequest requestDetailTarget;
445
446    private static final long serialVersionUID = -1654449146L;
447
448  /*
449   * Constructor
450   */
451    public Communication() {
452      super();
453    }
454
455    /**
456     * @return {@link #identifier} (Identifiers associated with this Communication that are defined by business processes and/ or used to refer to it when a direct URL reference to the resource itself is not appropriate (e.g. in CDA documents, or in written / printed documentation).)
457     */
458    public List<Identifier> getIdentifier() { 
459      if (this.identifier == null)
460        this.identifier = new ArrayList<Identifier>();
461      return this.identifier;
462    }
463
464    public boolean hasIdentifier() { 
465      if (this.identifier == null)
466        return false;
467      for (Identifier item : this.identifier)
468        if (!item.isEmpty())
469          return true;
470      return false;
471    }
472
473    /**
474     * @return {@link #identifier} (Identifiers associated with this Communication that are defined by business processes and/ or used to refer to it when a direct URL reference to the resource itself is not appropriate (e.g. in CDA documents, or in written / printed documentation).)
475     */
476    // syntactic sugar
477    public Identifier addIdentifier() { //3
478      Identifier t = new Identifier();
479      if (this.identifier == null)
480        this.identifier = new ArrayList<Identifier>();
481      this.identifier.add(t);
482      return t;
483    }
484
485    // syntactic sugar
486    public Communication addIdentifier(Identifier t) { //3
487      if (t == null)
488        return this;
489      if (this.identifier == null)
490        this.identifier = new ArrayList<Identifier>();
491      this.identifier.add(t);
492      return this;
493    }
494
495    /**
496     * @return {@link #category} (The type of message conveyed such as alert, notification, reminder, instruction, etc.)
497     */
498    public CodeableConcept getCategory() { 
499      if (this.category == null)
500        if (Configuration.errorOnAutoCreate())
501          throw new Error("Attempt to auto-create Communication.category");
502        else if (Configuration.doAutoCreate())
503          this.category = new CodeableConcept(); // cc
504      return this.category;
505    }
506
507    public boolean hasCategory() { 
508      return this.category != null && !this.category.isEmpty();
509    }
510
511    /**
512     * @param value {@link #category} (The type of message conveyed such as alert, notification, reminder, instruction, etc.)
513     */
514    public Communication setCategory(CodeableConcept value) { 
515      this.category = value;
516      return this;
517    }
518
519    /**
520     * @return {@link #sender} (The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication.)
521     */
522    public Reference getSender() { 
523      if (this.sender == null)
524        if (Configuration.errorOnAutoCreate())
525          throw new Error("Attempt to auto-create Communication.sender");
526        else if (Configuration.doAutoCreate())
527          this.sender = new Reference(); // cc
528      return this.sender;
529    }
530
531    public boolean hasSender() { 
532      return this.sender != null && !this.sender.isEmpty();
533    }
534
535    /**
536     * @param value {@link #sender} (The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication.)
537     */
538    public Communication setSender(Reference value) { 
539      this.sender = value;
540      return this;
541    }
542
543    /**
544     * @return {@link #sender} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication.)
545     */
546    public Resource getSenderTarget() { 
547      return this.senderTarget;
548    }
549
550    /**
551     * @param value {@link #sender} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication.)
552     */
553    public Communication setSenderTarget(Resource value) { 
554      this.senderTarget = value;
555      return this;
556    }
557
558    /**
559     * @return {@link #recipient} (The entity (e.g. person, organization, clinical information system, or device) which was the target of the communication. If receipts need to be tracked by individual, a separate resource instance will need to be created for each recipient.  Multiple recipient communications are intended where either a receipt(s) is not tracked (e.g. a mass mail-out) or is captured in aggregate (all emails confirmed received by a particular time).)
560     */
561    public List<Reference> getRecipient() { 
562      if (this.recipient == null)
563        this.recipient = new ArrayList<Reference>();
564      return this.recipient;
565    }
566
567    public boolean hasRecipient() { 
568      if (this.recipient == null)
569        return false;
570      for (Reference item : this.recipient)
571        if (!item.isEmpty())
572          return true;
573      return false;
574    }
575
576    /**
577     * @return {@link #recipient} (The entity (e.g. person, organization, clinical information system, or device) which was the target of the communication. If receipts need to be tracked by individual, a separate resource instance will need to be created for each recipient.  Multiple recipient communications are intended where either a receipt(s) is not tracked (e.g. a mass mail-out) or is captured in aggregate (all emails confirmed received by a particular time).)
578     */
579    // syntactic sugar
580    public Reference addRecipient() { //3
581      Reference t = new Reference();
582      if (this.recipient == null)
583        this.recipient = new ArrayList<Reference>();
584      this.recipient.add(t);
585      return t;
586    }
587
588    // syntactic sugar
589    public Communication addRecipient(Reference t) { //3
590      if (t == null)
591        return this;
592      if (this.recipient == null)
593        this.recipient = new ArrayList<Reference>();
594      this.recipient.add(t);
595      return this;
596    }
597
598    /**
599     * @return {@link #recipient} (The actual objects that are the target of the reference. The reference library doesn't populate this, but you can use this to hold the resources if you resolvethemt. The entity (e.g. person, organization, clinical information system, or device) which was the target of the communication. If receipts need to be tracked by individual, a separate resource instance will need to be created for each recipient.  Multiple recipient communications are intended where either a receipt(s) is not tracked (e.g. a mass mail-out) or is captured in aggregate (all emails confirmed received by a particular time).)
600     */
601    public List<Resource> getRecipientTarget() { 
602      if (this.recipientTarget == null)
603        this.recipientTarget = new ArrayList<Resource>();
604      return this.recipientTarget;
605    }
606
607    /**
608     * @return {@link #payload} (Text, attachment(s), or resource(s) that was communicated to the recipient.)
609     */
610    public List<CommunicationPayloadComponent> getPayload() { 
611      if (this.payload == null)
612        this.payload = new ArrayList<CommunicationPayloadComponent>();
613      return this.payload;
614    }
615
616    public boolean hasPayload() { 
617      if (this.payload == null)
618        return false;
619      for (CommunicationPayloadComponent item : this.payload)
620        if (!item.isEmpty())
621          return true;
622      return false;
623    }
624
625    /**
626     * @return {@link #payload} (Text, attachment(s), or resource(s) that was communicated to the recipient.)
627     */
628    // syntactic sugar
629    public CommunicationPayloadComponent addPayload() { //3
630      CommunicationPayloadComponent t = new CommunicationPayloadComponent();
631      if (this.payload == null)
632        this.payload = new ArrayList<CommunicationPayloadComponent>();
633      this.payload.add(t);
634      return t;
635    }
636
637    // syntactic sugar
638    public Communication addPayload(CommunicationPayloadComponent t) { //3
639      if (t == null)
640        return this;
641      if (this.payload == null)
642        this.payload = new ArrayList<CommunicationPayloadComponent>();
643      this.payload.add(t);
644      return this;
645    }
646
647    /**
648     * @return {@link #medium} (A channel that was used for this communication (e.g. email, fax).)
649     */
650    public List<CodeableConcept> getMedium() { 
651      if (this.medium == null)
652        this.medium = new ArrayList<CodeableConcept>();
653      return this.medium;
654    }
655
656    public boolean hasMedium() { 
657      if (this.medium == null)
658        return false;
659      for (CodeableConcept item : this.medium)
660        if (!item.isEmpty())
661          return true;
662      return false;
663    }
664
665    /**
666     * @return {@link #medium} (A channel that was used for this communication (e.g. email, fax).)
667     */
668    // syntactic sugar
669    public CodeableConcept addMedium() { //3
670      CodeableConcept t = new CodeableConcept();
671      if (this.medium == null)
672        this.medium = new ArrayList<CodeableConcept>();
673      this.medium.add(t);
674      return t;
675    }
676
677    // syntactic sugar
678    public Communication addMedium(CodeableConcept t) { //3
679      if (t == null)
680        return this;
681      if (this.medium == null)
682        this.medium = new ArrayList<CodeableConcept>();
683      this.medium.add(t);
684      return this;
685    }
686
687    /**
688     * @return {@link #status} (The status of the transmission.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
689     */
690    public Enumeration<CommunicationStatus> getStatusElement() { 
691      if (this.status == null)
692        if (Configuration.errorOnAutoCreate())
693          throw new Error("Attempt to auto-create Communication.status");
694        else if (Configuration.doAutoCreate())
695          this.status = new Enumeration<CommunicationStatus>(new CommunicationStatusEnumFactory()); // bb
696      return this.status;
697    }
698
699    public boolean hasStatusElement() { 
700      return this.status != null && !this.status.isEmpty();
701    }
702
703    public boolean hasStatus() { 
704      return this.status != null && !this.status.isEmpty();
705    }
706
707    /**
708     * @param value {@link #status} (The status of the transmission.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
709     */
710    public Communication setStatusElement(Enumeration<CommunicationStatus> value) { 
711      this.status = value;
712      return this;
713    }
714
715    /**
716     * @return The status of the transmission.
717     */
718    public CommunicationStatus getStatus() { 
719      return this.status == null ? null : this.status.getValue();
720    }
721
722    /**
723     * @param value The status of the transmission.
724     */
725    public Communication setStatus(CommunicationStatus value) { 
726      if (value == null)
727        this.status = null;
728      else {
729        if (this.status == null)
730          this.status = new Enumeration<CommunicationStatus>(new CommunicationStatusEnumFactory());
731        this.status.setValue(value);
732      }
733      return this;
734    }
735
736    /**
737     * @return {@link #encounter} (The encounter within which the communication was sent.)
738     */
739    public Reference getEncounter() { 
740      if (this.encounter == null)
741        if (Configuration.errorOnAutoCreate())
742          throw new Error("Attempt to auto-create Communication.encounter");
743        else if (Configuration.doAutoCreate())
744          this.encounter = new Reference(); // cc
745      return this.encounter;
746    }
747
748    public boolean hasEncounter() { 
749      return this.encounter != null && !this.encounter.isEmpty();
750    }
751
752    /**
753     * @param value {@link #encounter} (The encounter within which the communication was sent.)
754     */
755    public Communication setEncounter(Reference value) { 
756      this.encounter = value;
757      return this;
758    }
759
760    /**
761     * @return {@link #encounter} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The encounter within which the communication was sent.)
762     */
763    public Encounter getEncounterTarget() { 
764      if (this.encounterTarget == null)
765        if (Configuration.errorOnAutoCreate())
766          throw new Error("Attempt to auto-create Communication.encounter");
767        else if (Configuration.doAutoCreate())
768          this.encounterTarget = new Encounter(); // aa
769      return this.encounterTarget;
770    }
771
772    /**
773     * @param value {@link #encounter} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The encounter within which the communication was sent.)
774     */
775    public Communication setEncounterTarget(Encounter value) { 
776      this.encounterTarget = value;
777      return this;
778    }
779
780    /**
781     * @return {@link #sent} (The time when this communication was sent.). This is the underlying object with id, value and extensions. The accessor "getSent" gives direct access to the value
782     */
783    public DateTimeType getSentElement() { 
784      if (this.sent == null)
785        if (Configuration.errorOnAutoCreate())
786          throw new Error("Attempt to auto-create Communication.sent");
787        else if (Configuration.doAutoCreate())
788          this.sent = new DateTimeType(); // bb
789      return this.sent;
790    }
791
792    public boolean hasSentElement() { 
793      return this.sent != null && !this.sent.isEmpty();
794    }
795
796    public boolean hasSent() { 
797      return this.sent != null && !this.sent.isEmpty();
798    }
799
800    /**
801     * @param value {@link #sent} (The time when this communication was sent.). This is the underlying object with id, value and extensions. The accessor "getSent" gives direct access to the value
802     */
803    public Communication setSentElement(DateTimeType value) { 
804      this.sent = value;
805      return this;
806    }
807
808    /**
809     * @return The time when this communication was sent.
810     */
811    public Date getSent() { 
812      return this.sent == null ? null : this.sent.getValue();
813    }
814
815    /**
816     * @param value The time when this communication was sent.
817     */
818    public Communication setSent(Date value) { 
819      if (value == null)
820        this.sent = null;
821      else {
822        if (this.sent == null)
823          this.sent = new DateTimeType();
824        this.sent.setValue(value);
825      }
826      return this;
827    }
828
829    /**
830     * @return {@link #received} (The time when this communication arrived at the destination.). This is the underlying object with id, value and extensions. The accessor "getReceived" gives direct access to the value
831     */
832    public DateTimeType getReceivedElement() { 
833      if (this.received == null)
834        if (Configuration.errorOnAutoCreate())
835          throw new Error("Attempt to auto-create Communication.received");
836        else if (Configuration.doAutoCreate())
837          this.received = new DateTimeType(); // bb
838      return this.received;
839    }
840
841    public boolean hasReceivedElement() { 
842      return this.received != null && !this.received.isEmpty();
843    }
844
845    public boolean hasReceived() { 
846      return this.received != null && !this.received.isEmpty();
847    }
848
849    /**
850     * @param value {@link #received} (The time when this communication arrived at the destination.). This is the underlying object with id, value and extensions. The accessor "getReceived" gives direct access to the value
851     */
852    public Communication setReceivedElement(DateTimeType value) { 
853      this.received = value;
854      return this;
855    }
856
857    /**
858     * @return The time when this communication arrived at the destination.
859     */
860    public Date getReceived() { 
861      return this.received == null ? null : this.received.getValue();
862    }
863
864    /**
865     * @param value The time when this communication arrived at the destination.
866     */
867    public Communication setReceived(Date value) { 
868      if (value == null)
869        this.received = null;
870      else {
871        if (this.received == null)
872          this.received = new DateTimeType();
873        this.received.setValue(value);
874      }
875      return this;
876    }
877
878    /**
879     * @return {@link #reason} (The reason or justification for the communication.)
880     */
881    public List<CodeableConcept> getReason() { 
882      if (this.reason == null)
883        this.reason = new ArrayList<CodeableConcept>();
884      return this.reason;
885    }
886
887    public boolean hasReason() { 
888      if (this.reason == null)
889        return false;
890      for (CodeableConcept item : this.reason)
891        if (!item.isEmpty())
892          return true;
893      return false;
894    }
895
896    /**
897     * @return {@link #reason} (The reason or justification for the communication.)
898     */
899    // syntactic sugar
900    public CodeableConcept addReason() { //3
901      CodeableConcept t = new CodeableConcept();
902      if (this.reason == null)
903        this.reason = new ArrayList<CodeableConcept>();
904      this.reason.add(t);
905      return t;
906    }
907
908    // syntactic sugar
909    public Communication addReason(CodeableConcept t) { //3
910      if (t == null)
911        return this;
912      if (this.reason == null)
913        this.reason = new ArrayList<CodeableConcept>();
914      this.reason.add(t);
915      return this;
916    }
917
918    /**
919     * @return {@link #subject} (The patient who was the focus of this communication.)
920     */
921    public Reference getSubject() { 
922      if (this.subject == null)
923        if (Configuration.errorOnAutoCreate())
924          throw new Error("Attempt to auto-create Communication.subject");
925        else if (Configuration.doAutoCreate())
926          this.subject = new Reference(); // cc
927      return this.subject;
928    }
929
930    public boolean hasSubject() { 
931      return this.subject != null && !this.subject.isEmpty();
932    }
933
934    /**
935     * @param value {@link #subject} (The patient who was the focus of this communication.)
936     */
937    public Communication setSubject(Reference value) { 
938      this.subject = value;
939      return this;
940    }
941
942    /**
943     * @return {@link #subject} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The patient who was the focus of this communication.)
944     */
945    public Patient getSubjectTarget() { 
946      if (this.subjectTarget == null)
947        if (Configuration.errorOnAutoCreate())
948          throw new Error("Attempt to auto-create Communication.subject");
949        else if (Configuration.doAutoCreate())
950          this.subjectTarget = new Patient(); // aa
951      return this.subjectTarget;
952    }
953
954    /**
955     * @param value {@link #subject} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The patient who was the focus of this communication.)
956     */
957    public Communication setSubjectTarget(Patient value) { 
958      this.subjectTarget = value;
959      return this;
960    }
961
962    /**
963     * @return {@link #requestDetail} (The communication request that was responsible for producing this communication.)
964     */
965    public Reference getRequestDetail() { 
966      if (this.requestDetail == null)
967        if (Configuration.errorOnAutoCreate())
968          throw new Error("Attempt to auto-create Communication.requestDetail");
969        else if (Configuration.doAutoCreate())
970          this.requestDetail = new Reference(); // cc
971      return this.requestDetail;
972    }
973
974    public boolean hasRequestDetail() { 
975      return this.requestDetail != null && !this.requestDetail.isEmpty();
976    }
977
978    /**
979     * @param value {@link #requestDetail} (The communication request that was responsible for producing this communication.)
980     */
981    public Communication setRequestDetail(Reference value) { 
982      this.requestDetail = value;
983      return this;
984    }
985
986    /**
987     * @return {@link #requestDetail} The actual object that is the target of the reference. The reference library doesn't populate this, but you can use it to hold the resource if you resolve it. (The communication request that was responsible for producing this communication.)
988     */
989    public CommunicationRequest getRequestDetailTarget() { 
990      if (this.requestDetailTarget == null)
991        if (Configuration.errorOnAutoCreate())
992          throw new Error("Attempt to auto-create Communication.requestDetail");
993        else if (Configuration.doAutoCreate())
994          this.requestDetailTarget = new CommunicationRequest(); // aa
995      return this.requestDetailTarget;
996    }
997
998    /**
999     * @param value {@link #requestDetail} The actual object that is the target of the reference. The reference library doesn't use these, but you can use it to hold the resource if you resolve it. (The communication request that was responsible for producing this communication.)
1000     */
1001    public Communication setRequestDetailTarget(CommunicationRequest value) { 
1002      this.requestDetailTarget = value;
1003      return this;
1004    }
1005
1006      protected void listChildren(List<Property> childrenList) {
1007        super.listChildren(childrenList);
1008        childrenList.add(new Property("identifier", "Identifier", "Identifiers associated with this Communication that are defined by business processes and/ or used to refer to it when a direct URL reference to the resource itself is not appropriate (e.g. in CDA documents, or in written / printed documentation).", 0, java.lang.Integer.MAX_VALUE, identifier));
1009        childrenList.add(new Property("category", "CodeableConcept", "The type of message conveyed such as alert, notification, reminder, instruction, etc.", 0, java.lang.Integer.MAX_VALUE, category));
1010        childrenList.add(new Property("sender", "Reference(Device|Organization|Patient|Practitioner|RelatedPerson)", "The entity (e.g. person, organization, clinical information system, or device) which was the source of the communication.", 0, java.lang.Integer.MAX_VALUE, sender));
1011        childrenList.add(new Property("recipient", "Reference(Device|Organization|Patient|Practitioner|RelatedPerson|Group)", "The entity (e.g. person, organization, clinical information system, or device) which was the target of the communication. If receipts need to be tracked by individual, a separate resource instance will need to be created for each recipient.  Multiple recipient communications are intended where either a receipt(s) is not tracked (e.g. a mass mail-out) or is captured in aggregate (all emails confirmed received by a particular time).", 0, java.lang.Integer.MAX_VALUE, recipient));
1012        childrenList.add(new Property("payload", "", "Text, attachment(s), or resource(s) that was communicated to the recipient.", 0, java.lang.Integer.MAX_VALUE, payload));
1013        childrenList.add(new Property("medium", "CodeableConcept", "A channel that was used for this communication (e.g. email, fax).", 0, java.lang.Integer.MAX_VALUE, medium));
1014        childrenList.add(new Property("status", "code", "The status of the transmission.", 0, java.lang.Integer.MAX_VALUE, status));
1015        childrenList.add(new Property("encounter", "Reference(Encounter)", "The encounter within which the communication was sent.", 0, java.lang.Integer.MAX_VALUE, encounter));
1016        childrenList.add(new Property("sent", "dateTime", "The time when this communication was sent.", 0, java.lang.Integer.MAX_VALUE, sent));
1017        childrenList.add(new Property("received", "dateTime", "The time when this communication arrived at the destination.", 0, java.lang.Integer.MAX_VALUE, received));
1018        childrenList.add(new Property("reason", "CodeableConcept", "The reason or justification for the communication.", 0, java.lang.Integer.MAX_VALUE, reason));
1019        childrenList.add(new Property("subject", "Reference(Patient)", "The patient who was the focus of this communication.", 0, java.lang.Integer.MAX_VALUE, subject));
1020        childrenList.add(new Property("requestDetail", "Reference(CommunicationRequest)", "The communication request that was responsible for producing this communication.", 0, java.lang.Integer.MAX_VALUE, requestDetail));
1021      }
1022
1023      @Override
1024      public void setProperty(String name, Base value) throws FHIRException {
1025        if (name.equals("identifier"))
1026          this.getIdentifier().add(castToIdentifier(value));
1027        else if (name.equals("category"))
1028          this.category = castToCodeableConcept(value); // CodeableConcept
1029        else if (name.equals("sender"))
1030          this.sender = castToReference(value); // Reference
1031        else if (name.equals("recipient"))
1032          this.getRecipient().add(castToReference(value));
1033        else if (name.equals("payload"))
1034          this.getPayload().add((CommunicationPayloadComponent) value);
1035        else if (name.equals("medium"))
1036          this.getMedium().add(castToCodeableConcept(value));
1037        else if (name.equals("status"))
1038          this.status = new CommunicationStatusEnumFactory().fromType(value); // Enumeration<CommunicationStatus>
1039        else if (name.equals("encounter"))
1040          this.encounter = castToReference(value); // Reference
1041        else if (name.equals("sent"))
1042          this.sent = castToDateTime(value); // DateTimeType
1043        else if (name.equals("received"))
1044          this.received = castToDateTime(value); // DateTimeType
1045        else if (name.equals("reason"))
1046          this.getReason().add(castToCodeableConcept(value));
1047        else if (name.equals("subject"))
1048          this.subject = castToReference(value); // Reference
1049        else if (name.equals("requestDetail"))
1050          this.requestDetail = castToReference(value); // Reference
1051        else
1052          super.setProperty(name, value);
1053      }
1054
1055      @Override
1056      public Base addChild(String name) throws FHIRException {
1057        if (name.equals("identifier")) {
1058          return addIdentifier();
1059        }
1060        else if (name.equals("category")) {
1061          this.category = new CodeableConcept();
1062          return this.category;
1063        }
1064        else if (name.equals("sender")) {
1065          this.sender = new Reference();
1066          return this.sender;
1067        }
1068        else if (name.equals("recipient")) {
1069          return addRecipient();
1070        }
1071        else if (name.equals("payload")) {
1072          return addPayload();
1073        }
1074        else if (name.equals("medium")) {
1075          return addMedium();
1076        }
1077        else if (name.equals("status")) {
1078          throw new FHIRException("Cannot call addChild on a primitive type Communication.status");
1079        }
1080        else if (name.equals("encounter")) {
1081          this.encounter = new Reference();
1082          return this.encounter;
1083        }
1084        else if (name.equals("sent")) {
1085          throw new FHIRException("Cannot call addChild on a primitive type Communication.sent");
1086        }
1087        else if (name.equals("received")) {
1088          throw new FHIRException("Cannot call addChild on a primitive type Communication.received");
1089        }
1090        else if (name.equals("reason")) {
1091          return addReason();
1092        }
1093        else if (name.equals("subject")) {
1094          this.subject = new Reference();
1095          return this.subject;
1096        }
1097        else if (name.equals("requestDetail")) {
1098          this.requestDetail = new Reference();
1099          return this.requestDetail;
1100        }
1101        else
1102          return super.addChild(name);
1103      }
1104
1105  public String fhirType() {
1106    return "Communication";
1107
1108  }
1109
1110      public Communication copy() {
1111        Communication dst = new Communication();
1112        copyValues(dst);
1113        if (identifier != null) {
1114          dst.identifier = new ArrayList<Identifier>();
1115          for (Identifier i : identifier)
1116            dst.identifier.add(i.copy());
1117        };
1118        dst.category = category == null ? null : category.copy();
1119        dst.sender = sender == null ? null : sender.copy();
1120        if (recipient != null) {
1121          dst.recipient = new ArrayList<Reference>();
1122          for (Reference i : recipient)
1123            dst.recipient.add(i.copy());
1124        };
1125        if (payload != null) {
1126          dst.payload = new ArrayList<CommunicationPayloadComponent>();
1127          for (CommunicationPayloadComponent i : payload)
1128            dst.payload.add(i.copy());
1129        };
1130        if (medium != null) {
1131          dst.medium = new ArrayList<CodeableConcept>();
1132          for (CodeableConcept i : medium)
1133            dst.medium.add(i.copy());
1134        };
1135        dst.status = status == null ? null : status.copy();
1136        dst.encounter = encounter == null ? null : encounter.copy();
1137        dst.sent = sent == null ? null : sent.copy();
1138        dst.received = received == null ? null : received.copy();
1139        if (reason != null) {
1140          dst.reason = new ArrayList<CodeableConcept>();
1141          for (CodeableConcept i : reason)
1142            dst.reason.add(i.copy());
1143        };
1144        dst.subject = subject == null ? null : subject.copy();
1145        dst.requestDetail = requestDetail == null ? null : requestDetail.copy();
1146        return dst;
1147      }
1148
1149      protected Communication typedCopy() {
1150        return copy();
1151      }
1152
1153      @Override
1154      public boolean equalsDeep(Base other) {
1155        if (!super.equalsDeep(other))
1156          return false;
1157        if (!(other instanceof Communication))
1158          return false;
1159        Communication o = (Communication) other;
1160        return compareDeep(identifier, o.identifier, true) && compareDeep(category, o.category, true) && compareDeep(sender, o.sender, true)
1161           && compareDeep(recipient, o.recipient, true) && compareDeep(payload, o.payload, true) && compareDeep(medium, o.medium, true)
1162           && compareDeep(status, o.status, true) && compareDeep(encounter, o.encounter, true) && compareDeep(sent, o.sent, true)
1163           && compareDeep(received, o.received, true) && compareDeep(reason, o.reason, true) && compareDeep(subject, o.subject, true)
1164           && compareDeep(requestDetail, o.requestDetail, true);
1165      }
1166
1167      @Override
1168      public boolean equalsShallow(Base other) {
1169        if (!super.equalsShallow(other))
1170          return false;
1171        if (!(other instanceof Communication))
1172          return false;
1173        Communication o = (Communication) other;
1174        return compareValues(status, o.status, true) && compareValues(sent, o.sent, true) && compareValues(received, o.received, true)
1175          ;
1176      }
1177
1178      public boolean isEmpty() {
1179        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (category == null || category.isEmpty())
1180           && (sender == null || sender.isEmpty()) && (recipient == null || recipient.isEmpty()) && (payload == null || payload.isEmpty())
1181           && (medium == null || medium.isEmpty()) && (status == null || status.isEmpty()) && (encounter == null || encounter.isEmpty())
1182           && (sent == null || sent.isEmpty()) && (received == null || received.isEmpty()) && (reason == null || reason.isEmpty())
1183           && (subject == null || subject.isEmpty()) && (requestDetail == null || requestDetail.isEmpty())
1184          ;
1185      }
1186
1187  @Override
1188  public ResourceType getResourceType() {
1189    return ResourceType.Communication;
1190   }
1191
1192  @SearchParamDefinition(name="identifier", path="Communication.identifier", description="Unique identifier", type="token" )
1193  public static final String SP_IDENTIFIER = "identifier";
1194  @SearchParamDefinition(name="request", path="Communication.requestDetail", description="CommunicationRequest producing this message", type="reference" )
1195  public static final String SP_REQUEST = "request";
1196  @SearchParamDefinition(name="sender", path="Communication.sender", description="Message sender", type="reference" )
1197  public static final String SP_SENDER = "sender";
1198  @SearchParamDefinition(name="subject", path="Communication.subject", description="Focus of message", type="reference" )
1199  public static final String SP_SUBJECT = "subject";
1200  @SearchParamDefinition(name="patient", path="Communication.subject", description="Focus of message", type="reference" )
1201  public static final String SP_PATIENT = "patient";
1202  @SearchParamDefinition(name="recipient", path="Communication.recipient", description="Message recipient", type="reference" )
1203  public static final String SP_RECIPIENT = "recipient";
1204  @SearchParamDefinition(name="received", path="Communication.received", description="When received", type="date" )
1205  public static final String SP_RECEIVED = "received";
1206  @SearchParamDefinition(name="medium", path="Communication.medium", description="A channel of communication", type="token" )
1207  public static final String SP_MEDIUM = "medium";
1208  @SearchParamDefinition(name="encounter", path="Communication.encounter", description="Encounter leading to message", type="reference" )
1209  public static final String SP_ENCOUNTER = "encounter";
1210  @SearchParamDefinition(name="category", path="Communication.category", description="Message category", type="token" )
1211  public static final String SP_CATEGORY = "category";
1212  @SearchParamDefinition(name="sent", path="Communication.sent", description="When sent", type="date" )
1213  public static final String SP_SENT = "sent";
1214  @SearchParamDefinition(name="status", path="Communication.status", description="in-progress | completed | suspended | rejected | failed", type="token" )
1215  public static final String SP_STATUS = "status";
1216
1217}
1218