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