001package org.hl7.fhir.dstu2.model;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009  
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030*/
031
032// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
033import java.util.ArrayList;
034import java.util.Date;
035import java.util.List;
036
037import ca.uhn.fhir.model.api.annotation.Block;
038import ca.uhn.fhir.model.api.annotation.Child;
039import ca.uhn.fhir.model.api.annotation.Description;
040import ca.uhn.fhir.model.api.annotation.ResourceDef;
041import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
042import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
043import org.hl7.fhir.exceptions.FHIRException;
044
045/**
046 * A request to convey information; e.g. the CDS system proposes that an alert
047 * be sent to a responsible provider, the CDS system proposes that the public
048 * health agency be notified about a reportable condition.
049 */
050@ResourceDef(name = "CommunicationRequest", profile = "http://hl7.org/fhir/Profile/CommunicationRequest")
051public class CommunicationRequest extends DomainResource {
052
053  public enum CommunicationRequestStatus {
054    /**
055     * The request has been proposed.
056     */
057    PROPOSED,
058    /**
059     * The request has been planned.
060     */
061    PLANNED,
062    /**
063     * The request has been placed.
064     */
065    REQUESTED,
066    /**
067     * The receiving system has received the request but not yet decided whether it
068     * will be performed.
069     */
070    RECEIVED,
071    /**
072     * The receiving system has accepted the order, but work has not yet commenced.
073     */
074    ACCEPTED,
075    /**
076     * The work to fulfill the order is happening.
077     */
078    INPROGRESS,
079    /**
080     * The work has been complete, the report(s) released, and no further work is
081     * planned.
082     */
083    COMPLETED,
084    /**
085     * The request has been held by originating system/user request.
086     */
087    SUSPENDED,
088    /**
089     * The receiving system has declined to fulfill the request
090     */
091    REJECTED,
092    /**
093     * The communication was attempted, but due to some procedural error, it could
094     * not be completed.
095     */
096    FAILED,
097    /**
098     * added to help the parsers
099     */
100    NULL;
101
102    public static CommunicationRequestStatus fromCode(String codeString) throws FHIRException {
103      if (codeString == null || "".equals(codeString))
104        return null;
105      if ("proposed".equals(codeString))
106        return PROPOSED;
107      if ("planned".equals(codeString))
108        return PLANNED;
109      if ("requested".equals(codeString))
110        return REQUESTED;
111      if ("received".equals(codeString))
112        return RECEIVED;
113      if ("accepted".equals(codeString))
114        return ACCEPTED;
115      if ("in-progress".equals(codeString))
116        return INPROGRESS;
117      if ("completed".equals(codeString))
118        return COMPLETED;
119      if ("suspended".equals(codeString))
120        return SUSPENDED;
121      if ("rejected".equals(codeString))
122        return REJECTED;
123      if ("failed".equals(codeString))
124        return FAILED;
125      throw new FHIRException("Unknown CommunicationRequestStatus code '" + codeString + "'");
126    }
127
128    public String toCode() {
129      switch (this) {
130      case PROPOSED:
131        return "proposed";
132      case PLANNED:
133        return "planned";
134      case REQUESTED:
135        return "requested";
136      case RECEIVED:
137        return "received";
138      case ACCEPTED:
139        return "accepted";
140      case INPROGRESS:
141        return "in-progress";
142      case COMPLETED:
143        return "completed";
144      case SUSPENDED:
145        return "suspended";
146      case REJECTED:
147        return "rejected";
148      case FAILED:
149        return "failed";
150      case NULL:
151        return null;
152      default:
153        return "?";
154      }
155    }
156
157    public String getSystem() {
158      switch (this) {
159      case PROPOSED:
160        return "http://hl7.org/fhir/communication-request-status";
161      case PLANNED:
162        return "http://hl7.org/fhir/communication-request-status";
163      case REQUESTED:
164        return "http://hl7.org/fhir/communication-request-status";
165      case RECEIVED:
166        return "http://hl7.org/fhir/communication-request-status";
167      case ACCEPTED:
168        return "http://hl7.org/fhir/communication-request-status";
169      case INPROGRESS:
170        return "http://hl7.org/fhir/communication-request-status";
171      case COMPLETED:
172        return "http://hl7.org/fhir/communication-request-status";
173      case SUSPENDED:
174        return "http://hl7.org/fhir/communication-request-status";
175      case REJECTED:
176        return "http://hl7.org/fhir/communication-request-status";
177      case FAILED:
178        return "http://hl7.org/fhir/communication-request-status";
179      case NULL:
180        return null;
181      default:
182        return "?";
183      }
184    }
185
186    public String getDefinition() {
187      switch (this) {
188      case PROPOSED:
189        return "The request has been proposed.";
190      case PLANNED:
191        return "The request has been planned.";
192      case REQUESTED:
193        return "The request has been placed.";
194      case RECEIVED:
195        return "The receiving system has received the request but not yet decided whether it will be performed.";
196      case ACCEPTED:
197        return "The receiving system has accepted the order, but work has not yet commenced.";
198      case INPROGRESS:
199        return "The work to fulfill the order is happening.";
200      case COMPLETED:
201        return "The work has been complete, the report(s) released, and no further work is planned.";
202      case SUSPENDED:
203        return "The request has been held by originating system/user request.";
204      case REJECTED:
205        return "The receiving system has declined to fulfill the request";
206      case FAILED:
207        return "The communication was attempted, but due to some procedural error, it could not be completed.";
208      case NULL:
209        return null;
210      default:
211        return "?";
212      }
213    }
214
215    public String getDisplay() {
216      switch (this) {
217      case PROPOSED:
218        return "Proposed";
219      case PLANNED:
220        return "Planned";
221      case REQUESTED:
222        return "Requested";
223      case RECEIVED:
224        return "Received";
225      case ACCEPTED:
226        return "Accepted";
227      case INPROGRESS:
228        return "In Progress";
229      case COMPLETED:
230        return "Completed";
231      case SUSPENDED:
232        return "Suspended";
233      case REJECTED:
234        return "Rejected";
235      case FAILED:
236        return "Failed";
237      case NULL:
238        return null;
239      default:
240        return "?";
241      }
242    }
243  }
244
245  public static class CommunicationRequestStatusEnumFactory implements EnumFactory<CommunicationRequestStatus> {
246    public CommunicationRequestStatus fromCode(String codeString) throws IllegalArgumentException {
247      if (codeString == null || "".equals(codeString))
248        if (codeString == null || "".equals(codeString))
249          return null;
250      if ("proposed".equals(codeString))
251        return CommunicationRequestStatus.PROPOSED;
252      if ("planned".equals(codeString))
253        return CommunicationRequestStatus.PLANNED;
254      if ("requested".equals(codeString))
255        return CommunicationRequestStatus.REQUESTED;
256      if ("received".equals(codeString))
257        return CommunicationRequestStatus.RECEIVED;
258      if ("accepted".equals(codeString))
259        return CommunicationRequestStatus.ACCEPTED;
260      if ("in-progress".equals(codeString))
261        return CommunicationRequestStatus.INPROGRESS;
262      if ("completed".equals(codeString))
263        return CommunicationRequestStatus.COMPLETED;
264      if ("suspended".equals(codeString))
265        return CommunicationRequestStatus.SUSPENDED;
266      if ("rejected".equals(codeString))
267        return CommunicationRequestStatus.REJECTED;
268      if ("failed".equals(codeString))
269        return CommunicationRequestStatus.FAILED;
270      throw new IllegalArgumentException("Unknown CommunicationRequestStatus code '" + codeString + "'");
271    }
272
273    public Enumeration<CommunicationRequestStatus> fromType(Base code) throws FHIRException {
274      if (code == null || code.isEmpty())
275        return null;
276      String codeString = ((PrimitiveType) code).asStringValue();
277      if (codeString == null || "".equals(codeString))
278        return null;
279      if ("proposed".equals(codeString))
280        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.PROPOSED);
281      if ("planned".equals(codeString))
282        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.PLANNED);
283      if ("requested".equals(codeString))
284        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.REQUESTED);
285      if ("received".equals(codeString))
286        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.RECEIVED);
287      if ("accepted".equals(codeString))
288        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.ACCEPTED);
289      if ("in-progress".equals(codeString))
290        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.INPROGRESS);
291      if ("completed".equals(codeString))
292        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.COMPLETED);
293      if ("suspended".equals(codeString))
294        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.SUSPENDED);
295      if ("rejected".equals(codeString))
296        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.REJECTED);
297      if ("failed".equals(codeString))
298        return new Enumeration<CommunicationRequestStatus>(this, CommunicationRequestStatus.FAILED);
299      throw new FHIRException("Unknown CommunicationRequestStatus code '" + codeString + "'");
300    }
301
302    public String toCode(CommunicationRequestStatus code) {
303      if (code == CommunicationRequestStatus.PROPOSED)
304        return "proposed";
305      if (code == CommunicationRequestStatus.PLANNED)
306        return "planned";
307      if (code == CommunicationRequestStatus.REQUESTED)
308        return "requested";
309      if (code == CommunicationRequestStatus.RECEIVED)
310        return "received";
311      if (code == CommunicationRequestStatus.ACCEPTED)
312        return "accepted";
313      if (code == CommunicationRequestStatus.INPROGRESS)
314        return "in-progress";
315      if (code == CommunicationRequestStatus.COMPLETED)
316        return "completed";
317      if (code == CommunicationRequestStatus.SUSPENDED)
318        return "suspended";
319      if (code == CommunicationRequestStatus.REJECTED)
320        return "rejected";
321      if (code == CommunicationRequestStatus.FAILED)
322        return "failed";
323      return "?";
324    }
325  }
326
327  @Block()
328  public static class CommunicationRequestPayloadComponent extends BackboneElement implements IBaseBackboneElement {
329    /**
330     * The communicated content (or for multi-part communications, one portion of
331     * the communication).
332     */
333    @Child(name = "content", type = { StringType.class,
334        Attachment.class }, order = 1, min = 1, max = 1, modifier = false, summary = true)
335    @Description(shortDefinition = "Message part content", formalDefinition = "The communicated content (or for multi-part communications, one portion of the communication).")
336    protected Type content;
337
338    private static final long serialVersionUID = -1763459053L;
339
340    /*
341     * Constructor
342     */
343    public CommunicationRequestPayloadComponent() {
344      super();
345    }
346
347    /*
348     * Constructor
349     */
350    public CommunicationRequestPayloadComponent(Type content) {
351      super();
352      this.content = content;
353    }
354
355    /**
356     * @return {@link #content} (The communicated content (or for multi-part
357     *         communications, one portion of the communication).)
358     */
359    public Type getContent() {
360      return this.content;
361    }
362
363    /**
364     * @return {@link #content} (The communicated content (or for multi-part
365     *         communications, one portion of the communication).)
366     */
367    public StringType getContentStringType() throws FHIRException {
368      if (!(this.content instanceof StringType))
369        throw new FHIRException("Type mismatch: the type StringType was expected, but "
370            + this.content.getClass().getName() + " was encountered");
371      return (StringType) this.content;
372    }
373
374    public boolean hasContentStringType() {
375      return this.content instanceof StringType;
376    }
377
378    /**
379     * @return {@link #content} (The communicated content (or for multi-part
380     *         communications, one portion of the communication).)
381     */
382    public Attachment getContentAttachment() throws FHIRException {
383      if (!(this.content instanceof Attachment))
384        throw new FHIRException("Type mismatch: the type Attachment was expected, but "
385            + this.content.getClass().getName() + " was encountered");
386      return (Attachment) this.content;
387    }
388
389    public boolean hasContentAttachment() {
390      return this.content instanceof Attachment;
391    }
392
393    /**
394     * @return {@link #content} (The communicated content (or for multi-part
395     *         communications, one portion of the communication).)
396     */
397    public Reference getContentReference() throws FHIRException {
398      if (!(this.content instanceof Reference))
399        throw new FHIRException("Type mismatch: the type Reference was expected, but "
400            + this.content.getClass().getName() + " was encountered");
401      return (Reference) this.content;
402    }
403
404    public boolean hasContentReference() {
405      return this.content instanceof Reference;
406    }
407
408    public boolean hasContent() {
409      return this.content != null && !this.content.isEmpty();
410    }
411
412    /**
413     * @param value {@link #content} (The communicated content (or for multi-part
414     *              communications, one portion of the communication).)
415     */
416    public CommunicationRequestPayloadComponent setContent(Type value) {
417      this.content = value;
418      return this;
419    }
420
421    protected void listChildren(List<Property> childrenList) {
422      super.listChildren(childrenList);
423      childrenList.add(new Property("content[x]", "string|Attachment|Reference(Any)",
424          "The communicated content (or for multi-part communications, one portion of the communication).", 0,
425          java.lang.Integer.MAX_VALUE, content));
426    }
427
428    @Override
429    public void setProperty(String name, Base value) throws FHIRException {
430      if (name.equals("content[x]"))
431        this.content = (Type) value; // Type
432      else
433        super.setProperty(name, value);
434    }
435
436    @Override
437    public Base addChild(String name) throws FHIRException {
438      if (name.equals("contentString")) {
439        this.content = new StringType();
440        return this.content;
441      } else if (name.equals("contentAttachment")) {
442        this.content = new Attachment();
443        return this.content;
444      } else if (name.equals("contentReference")) {
445        this.content = new Reference();
446        return this.content;
447      } else
448        return super.addChild(name);
449    }
450
451    public CommunicationRequestPayloadComponent copy() {
452      CommunicationRequestPayloadComponent dst = new CommunicationRequestPayloadComponent();
453      copyValues(dst);
454      dst.content = content == null ? null : content.copy();
455      return dst;
456    }
457
458    @Override
459    public boolean equalsDeep(Base other) {
460      if (!super.equalsDeep(other))
461        return false;
462      if (!(other instanceof CommunicationRequestPayloadComponent))
463        return false;
464      CommunicationRequestPayloadComponent o = (CommunicationRequestPayloadComponent) other;
465      return compareDeep(content, o.content, true);
466    }
467
468    @Override
469    public boolean equalsShallow(Base other) {
470      if (!super.equalsShallow(other))
471        return false;
472      if (!(other instanceof CommunicationRequestPayloadComponent))
473        return false;
474      CommunicationRequestPayloadComponent o = (CommunicationRequestPayloadComponent) other;
475      return true;
476    }
477
478    public boolean isEmpty() {
479      return super.isEmpty() && (content == null || content.isEmpty());
480    }
481
482    public String fhirType() {
483      return "CommunicationRequest.payload";
484
485    }
486
487  }
488
489  /**
490   * A unique ID of this request for reference purposes. It must be provided if
491   * user wants it returned as part of any output, otherwise it will be
492   * autogenerated, if needed, by CDS system. Does not need to be the actual ID of
493   * the source system.
494   */
495  @Child(name = "identifier", type = {
496      Identifier.class }, order = 0, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
497  @Description(shortDefinition = "Unique identifier", formalDefinition = "A unique ID of this request for reference purposes. It must be provided if user wants it returned as part of any output, otherwise it will be autogenerated, if needed, by CDS system. Does not need to be the actual ID of the source system.")
498  protected List<Identifier> identifier;
499
500  /**
501   * The type of message to be sent such as alert, notification, reminder,
502   * instruction, etc.
503   */
504  @Child(name = "category", type = {
505      CodeableConcept.class }, order = 1, min = 0, max = 1, modifier = false, summary = true)
506  @Description(shortDefinition = "Message category", formalDefinition = "The type of message to be sent such as alert, notification, reminder, instruction, etc.")
507  protected CodeableConcept category;
508
509  /**
510   * The entity (e.g. person, organization, clinical information system, or
511   * device) which is to be the source of the communication.
512   */
513  @Child(name = "sender", type = { Device.class, Organization.class, Patient.class, Practitioner.class,
514      RelatedPerson.class }, order = 2, min = 0, max = 1, modifier = false, summary = true)
515  @Description(shortDefinition = "Message sender", formalDefinition = "The entity (e.g. person, organization, clinical information system, or device) which is to be the source of the communication.")
516  protected Reference sender;
517
518  /**
519   * The actual object that is the target of the reference (The entity (e.g.
520   * person, organization, clinical information system, or device) which is to be
521   * the source of the communication.)
522   */
523  protected Resource senderTarget;
524
525  /**
526   * The entity (e.g. person, organization, clinical information system, or
527   * device) which is the intended target of the communication.
528   */
529  @Child(name = "recipient", type = { Device.class, Organization.class, Patient.class, Practitioner.class,
530      RelatedPerson.class }, order = 3, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
531  @Description(shortDefinition = "Message recipient", formalDefinition = "The entity (e.g. person, organization, clinical information system, or device) which is the intended target of the communication.")
532  protected List<Reference> recipient;
533  /**
534   * The actual objects that are the target of the reference (The entity (e.g.
535   * person, organization, clinical information system, or device) which is the
536   * intended target of the communication.)
537   */
538  protected List<Resource> recipientTarget;
539
540  /**
541   * Text, attachment(s), or resource(s) to be communicated to the recipient.
542   */
543  @Child(name = "payload", type = {}, order = 4, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
544  @Description(shortDefinition = "Message payload", formalDefinition = "Text, attachment(s), or resource(s) to be communicated to the recipient.")
545  protected List<CommunicationRequestPayloadComponent> payload;
546
547  /**
548   * A channel that was used for this communication (e.g. email, fax).
549   */
550  @Child(name = "medium", type = {
551      CodeableConcept.class }, order = 5, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
552  @Description(shortDefinition = "A channel of communication", formalDefinition = "A channel that was used for this communication (e.g. email, fax).")
553  protected List<CodeableConcept> medium;
554
555  /**
556   * The responsible person who authorizes this order, e.g. physician. This may be
557   * different than the author of the order statement, e.g. clerk, who may have
558   * entered the statement into the order entry application.
559   */
560  @Child(name = "requester", type = { Practitioner.class, Patient.class,
561      RelatedPerson.class }, order = 6, min = 0, max = 1, modifier = false, summary = true)
562  @Description(shortDefinition = "An individual who requested a communication", formalDefinition = "The responsible person who authorizes this order, e.g. physician. This may be different than the author of the order statement, e.g. clerk, who may have entered the statement into the order entry application.")
563  protected Reference requester;
564
565  /**
566   * The actual object that is the target of the reference (The responsible person
567   * who authorizes this order, e.g. physician. This may be different than the
568   * author of the order statement, e.g. clerk, who may have entered the statement
569   * into the order entry application.)
570   */
571  protected Resource requesterTarget;
572
573  /**
574   * The status of the proposal or order.
575   */
576  @Child(name = "status", type = { CodeType.class }, order = 7, min = 0, max = 1, modifier = true, summary = true)
577  @Description(shortDefinition = "proposed | planned | requested | received | accepted | in-progress | completed | suspended | rejected | failed", formalDefinition = "The status of the proposal or order.")
578  protected Enumeration<CommunicationRequestStatus> status;
579
580  /**
581   * The encounter within which the communication request was created.
582   */
583  @Child(name = "encounter", type = { Encounter.class }, order = 8, min = 0, max = 1, modifier = false, summary = true)
584  @Description(shortDefinition = "Encounter leading to message", formalDefinition = "The encounter within which the communication request was created.")
585  protected Reference encounter;
586
587  /**
588   * The actual object that is the target of the reference (The encounter within
589   * which the communication request was created.)
590   */
591  protected Encounter encounterTarget;
592
593  /**
594   * The time when this communication is to occur.
595   */
596  @Child(name = "scheduled", type = { DateTimeType.class,
597      Period.class }, order = 9, min = 0, max = 1, modifier = false, summary = true)
598  @Description(shortDefinition = "When scheduled", formalDefinition = "The time when this communication is to occur.")
599  protected Type scheduled;
600
601  /**
602   * The reason or justification for the communication request.
603   */
604  @Child(name = "reason", type = {
605      CodeableConcept.class }, order = 10, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = true)
606  @Description(shortDefinition = "Indication for message", formalDefinition = "The reason or justification for the communication request.")
607  protected List<CodeableConcept> reason;
608
609  /**
610   * The time when the request was made.
611   */
612  @Child(name = "requestedOn", type = {
613      DateTimeType.class }, order = 11, min = 0, max = 1, modifier = false, summary = true)
614  @Description(shortDefinition = "When ordered or proposed", formalDefinition = "The time when the request was made.")
615  protected DateTimeType requestedOn;
616
617  /**
618   * The patient who is the focus of this communication request.
619   */
620  @Child(name = "subject", type = { Patient.class }, order = 12, min = 0, max = 1, modifier = false, summary = true)
621  @Description(shortDefinition = "Focus of message", formalDefinition = "The patient who is the focus of this communication request.")
622  protected Reference subject;
623
624  /**
625   * The actual object that is the target of the reference (The patient who is the
626   * focus of this communication request.)
627   */
628  protected Patient subjectTarget;
629
630  /**
631   * Characterizes how quickly the proposed act must be initiated. Includes
632   * concepts such as stat, urgent, routine.
633   */
634  @Child(name = "priority", type = {
635      CodeableConcept.class }, order = 13, min = 0, max = 1, modifier = false, summary = true)
636  @Description(shortDefinition = "Message urgency", formalDefinition = "Characterizes how quickly the proposed act must be initiated. Includes concepts such as stat, urgent, routine.")
637  protected CodeableConcept priority;
638
639  private static final long serialVersionUID = 146906020L;
640
641  /*
642   * Constructor
643   */
644  public CommunicationRequest() {
645    super();
646  }
647
648  /**
649   * @return {@link #identifier} (A unique ID of this request for reference
650   *         purposes. It must be provided if user wants it returned as part of
651   *         any output, otherwise it will be autogenerated, if needed, by CDS
652   *         system. Does not need to be the actual ID of the source system.)
653   */
654  public List<Identifier> getIdentifier() {
655    if (this.identifier == null)
656      this.identifier = new ArrayList<Identifier>();
657    return this.identifier;
658  }
659
660  public boolean hasIdentifier() {
661    if (this.identifier == null)
662      return false;
663    for (Identifier item : this.identifier)
664      if (!item.isEmpty())
665        return true;
666    return false;
667  }
668
669  /**
670   * @return {@link #identifier} (A unique ID of this request for reference
671   *         purposes. It must be provided if user wants it returned as part of
672   *         any output, otherwise it will be autogenerated, if needed, by CDS
673   *         system. Does not need to be the actual ID of the source system.)
674   */
675  // syntactic sugar
676  public Identifier addIdentifier() { // 3
677    Identifier t = new Identifier();
678    if (this.identifier == null)
679      this.identifier = new ArrayList<Identifier>();
680    this.identifier.add(t);
681    return t;
682  }
683
684  // syntactic sugar
685  public CommunicationRequest addIdentifier(Identifier t) { // 3
686    if (t == null)
687      return this;
688    if (this.identifier == null)
689      this.identifier = new ArrayList<Identifier>();
690    this.identifier.add(t);
691    return this;
692  }
693
694  /**
695   * @return {@link #category} (The type of message to be sent such as alert,
696   *         notification, reminder, instruction, etc.)
697   */
698  public CodeableConcept getCategory() {
699    if (this.category == null)
700      if (Configuration.errorOnAutoCreate())
701        throw new Error("Attempt to auto-create CommunicationRequest.category");
702      else if (Configuration.doAutoCreate())
703        this.category = new CodeableConcept(); // cc
704    return this.category;
705  }
706
707  public boolean hasCategory() {
708    return this.category != null && !this.category.isEmpty();
709  }
710
711  /**
712   * @param value {@link #category} (The type of message to be sent such as alert,
713   *              notification, reminder, instruction, etc.)
714   */
715  public CommunicationRequest setCategory(CodeableConcept value) {
716    this.category = value;
717    return this;
718  }
719
720  /**
721   * @return {@link #sender} (The entity (e.g. person, organization, clinical
722   *         information system, or device) which is to be the source of the
723   *         communication.)
724   */
725  public Reference getSender() {
726    if (this.sender == null)
727      if (Configuration.errorOnAutoCreate())
728        throw new Error("Attempt to auto-create CommunicationRequest.sender");
729      else if (Configuration.doAutoCreate())
730        this.sender = new Reference(); // cc
731    return this.sender;
732  }
733
734  public boolean hasSender() {
735    return this.sender != null && !this.sender.isEmpty();
736  }
737
738  /**
739   * @param value {@link #sender} (The entity (e.g. person, organization, clinical
740   *              information system, or device) which is to be the source of the
741   *              communication.)
742   */
743  public CommunicationRequest setSender(Reference value) {
744    this.sender = value;
745    return this;
746  }
747
748  /**
749   * @return {@link #sender} The actual object that is the target of the
750   *         reference. The reference library doesn't populate this, but you can
751   *         use it to hold the resource if you resolve it. (The entity (e.g.
752   *         person, organization, clinical information system, or device) which
753   *         is to be the source of the communication.)
754   */
755  public Resource getSenderTarget() {
756    return this.senderTarget;
757  }
758
759  /**
760   * @param value {@link #sender} The actual object that is the target of the
761   *              reference. The reference library doesn't use these, but you can
762   *              use it to hold the resource if you resolve it. (The entity (e.g.
763   *              person, organization, clinical information system, or device)
764   *              which is to be the source of the communication.)
765   */
766  public CommunicationRequest setSenderTarget(Resource value) {
767    this.senderTarget = value;
768    return this;
769  }
770
771  /**
772   * @return {@link #recipient} (The entity (e.g. person, organization, clinical
773   *         information system, or device) which is the intended target of the
774   *         communication.)
775   */
776  public List<Reference> getRecipient() {
777    if (this.recipient == null)
778      this.recipient = new ArrayList<Reference>();
779    return this.recipient;
780  }
781
782  public boolean hasRecipient() {
783    if (this.recipient == null)
784      return false;
785    for (Reference item : this.recipient)
786      if (!item.isEmpty())
787        return true;
788    return false;
789  }
790
791  /**
792   * @return {@link #recipient} (The entity (e.g. person, organization, clinical
793   *         information system, or device) which is the intended target of the
794   *         communication.)
795   */
796  // syntactic sugar
797  public Reference addRecipient() { // 3
798    Reference t = new Reference();
799    if (this.recipient == null)
800      this.recipient = new ArrayList<Reference>();
801    this.recipient.add(t);
802    return t;
803  }
804
805  // syntactic sugar
806  public CommunicationRequest addRecipient(Reference t) { // 3
807    if (t == null)
808      return this;
809    if (this.recipient == null)
810      this.recipient = new ArrayList<Reference>();
811    this.recipient.add(t);
812    return this;
813  }
814
815  /**
816   * @return {@link #recipient} (The actual objects that are the target of the
817   *         reference. The reference library doesn't populate this, but you can
818   *         use this to hold the resources if you resolvethemt. The entity (e.g.
819   *         person, organization, clinical information system, or device) which
820   *         is the intended target of the communication.)
821   */
822  public List<Resource> getRecipientTarget() {
823    if (this.recipientTarget == null)
824      this.recipientTarget = new ArrayList<Resource>();
825    return this.recipientTarget;
826  }
827
828  /**
829   * @return {@link #payload} (Text, attachment(s), or resource(s) to be
830   *         communicated to the recipient.)
831   */
832  public List<CommunicationRequestPayloadComponent> getPayload() {
833    if (this.payload == null)
834      this.payload = new ArrayList<CommunicationRequestPayloadComponent>();
835    return this.payload;
836  }
837
838  public boolean hasPayload() {
839    if (this.payload == null)
840      return false;
841    for (CommunicationRequestPayloadComponent item : this.payload)
842      if (!item.isEmpty())
843        return true;
844    return false;
845  }
846
847  /**
848   * @return {@link #payload} (Text, attachment(s), or resource(s) to be
849   *         communicated to the recipient.)
850   */
851  // syntactic sugar
852  public CommunicationRequestPayloadComponent addPayload() { // 3
853    CommunicationRequestPayloadComponent t = new CommunicationRequestPayloadComponent();
854    if (this.payload == null)
855      this.payload = new ArrayList<CommunicationRequestPayloadComponent>();
856    this.payload.add(t);
857    return t;
858  }
859
860  // syntactic sugar
861  public CommunicationRequest addPayload(CommunicationRequestPayloadComponent t) { // 3
862    if (t == null)
863      return this;
864    if (this.payload == null)
865      this.payload = new ArrayList<CommunicationRequestPayloadComponent>();
866    this.payload.add(t);
867    return this;
868  }
869
870  /**
871   * @return {@link #medium} (A channel that was used for this communication (e.g.
872   *         email, fax).)
873   */
874  public List<CodeableConcept> getMedium() {
875    if (this.medium == null)
876      this.medium = new ArrayList<CodeableConcept>();
877    return this.medium;
878  }
879
880  public boolean hasMedium() {
881    if (this.medium == null)
882      return false;
883    for (CodeableConcept item : this.medium)
884      if (!item.isEmpty())
885        return true;
886    return false;
887  }
888
889  /**
890   * @return {@link #medium} (A channel that was used for this communication (e.g.
891   *         email, fax).)
892   */
893  // syntactic sugar
894  public CodeableConcept addMedium() { // 3
895    CodeableConcept t = new CodeableConcept();
896    if (this.medium == null)
897      this.medium = new ArrayList<CodeableConcept>();
898    this.medium.add(t);
899    return t;
900  }
901
902  // syntactic sugar
903  public CommunicationRequest addMedium(CodeableConcept t) { // 3
904    if (t == null)
905      return this;
906    if (this.medium == null)
907      this.medium = new ArrayList<CodeableConcept>();
908    this.medium.add(t);
909    return this;
910  }
911
912  /**
913   * @return {@link #requester} (The responsible person who authorizes this order,
914   *         e.g. physician. This may be different than the author of the order
915   *         statement, e.g. clerk, who may have entered the statement into the
916   *         order entry application.)
917   */
918  public Reference getRequester() {
919    if (this.requester == null)
920      if (Configuration.errorOnAutoCreate())
921        throw new Error("Attempt to auto-create CommunicationRequest.requester");
922      else if (Configuration.doAutoCreate())
923        this.requester = new Reference(); // cc
924    return this.requester;
925  }
926
927  public boolean hasRequester() {
928    return this.requester != null && !this.requester.isEmpty();
929  }
930
931  /**
932   * @param value {@link #requester} (The responsible person who authorizes this
933   *              order, e.g. physician. This may be different than the author of
934   *              the order statement, e.g. clerk, who may have entered the
935   *              statement into the order entry application.)
936   */
937  public CommunicationRequest setRequester(Reference value) {
938    this.requester = value;
939    return this;
940  }
941
942  /**
943   * @return {@link #requester} The actual object that is the target of the
944   *         reference. The reference library doesn't populate this, but you can
945   *         use it to hold the resource if you resolve it. (The responsible
946   *         person who authorizes this order, e.g. physician. This may be
947   *         different than the author of the order statement, e.g. clerk, who may
948   *         have entered the statement into the order entry application.)
949   */
950  public Resource getRequesterTarget() {
951    return this.requesterTarget;
952  }
953
954  /**
955   * @param value {@link #requester} The actual object that is the target of the
956   *              reference. The reference library doesn't use these, but you can
957   *              use it to hold the resource if you resolve it. (The responsible
958   *              person who authorizes this order, e.g. physician. This may be
959   *              different than the author of the order statement, e.g. clerk,
960   *              who may have entered the statement into the order entry
961   *              application.)
962   */
963  public CommunicationRequest setRequesterTarget(Resource value) {
964    this.requesterTarget = value;
965    return this;
966  }
967
968  /**
969   * @return {@link #status} (The status of the proposal or order.). This is the
970   *         underlying object with id, value and extensions. The accessor
971   *         "getStatus" gives direct access to the value
972   */
973  public Enumeration<CommunicationRequestStatus> getStatusElement() {
974    if (this.status == null)
975      if (Configuration.errorOnAutoCreate())
976        throw new Error("Attempt to auto-create CommunicationRequest.status");
977      else if (Configuration.doAutoCreate())
978        this.status = new Enumeration<CommunicationRequestStatus>(new CommunicationRequestStatusEnumFactory()); // bb
979    return this.status;
980  }
981
982  public boolean hasStatusElement() {
983    return this.status != null && !this.status.isEmpty();
984  }
985
986  public boolean hasStatus() {
987    return this.status != null && !this.status.isEmpty();
988  }
989
990  /**
991   * @param value {@link #status} (The status of the proposal or order.). This is
992   *              the underlying object with id, value and extensions. The
993   *              accessor "getStatus" gives direct access to the value
994   */
995  public CommunicationRequest setStatusElement(Enumeration<CommunicationRequestStatus> value) {
996    this.status = value;
997    return this;
998  }
999
1000  /**
1001   * @return The status of the proposal or order.
1002   */
1003  public CommunicationRequestStatus getStatus() {
1004    return this.status == null ? null : this.status.getValue();
1005  }
1006
1007  /**
1008   * @param value The status of the proposal or order.
1009   */
1010  public CommunicationRequest setStatus(CommunicationRequestStatus value) {
1011    if (value == null)
1012      this.status = null;
1013    else {
1014      if (this.status == null)
1015        this.status = new Enumeration<CommunicationRequestStatus>(new CommunicationRequestStatusEnumFactory());
1016      this.status.setValue(value);
1017    }
1018    return this;
1019  }
1020
1021  /**
1022   * @return {@link #encounter} (The encounter within which the communication
1023   *         request was created.)
1024   */
1025  public Reference getEncounter() {
1026    if (this.encounter == null)
1027      if (Configuration.errorOnAutoCreate())
1028        throw new Error("Attempt to auto-create CommunicationRequest.encounter");
1029      else if (Configuration.doAutoCreate())
1030        this.encounter = new Reference(); // cc
1031    return this.encounter;
1032  }
1033
1034  public boolean hasEncounter() {
1035    return this.encounter != null && !this.encounter.isEmpty();
1036  }
1037
1038  /**
1039   * @param value {@link #encounter} (The encounter within which the communication
1040   *              request was created.)
1041   */
1042  public CommunicationRequest setEncounter(Reference value) {
1043    this.encounter = value;
1044    return this;
1045  }
1046
1047  /**
1048   * @return {@link #encounter} The actual object that is the target of the
1049   *         reference. The reference library doesn't populate this, but you can
1050   *         use it to hold the resource if you resolve it. (The encounter within
1051   *         which the communication request was created.)
1052   */
1053  public Encounter getEncounterTarget() {
1054    if (this.encounterTarget == null)
1055      if (Configuration.errorOnAutoCreate())
1056        throw new Error("Attempt to auto-create CommunicationRequest.encounter");
1057      else if (Configuration.doAutoCreate())
1058        this.encounterTarget = new Encounter(); // aa
1059    return this.encounterTarget;
1060  }
1061
1062  /**
1063   * @param value {@link #encounter} The actual object that is the target of the
1064   *              reference. The reference library doesn't use these, but you can
1065   *              use it to hold the resource if you resolve it. (The encounter
1066   *              within which the communication request was created.)
1067   */
1068  public CommunicationRequest setEncounterTarget(Encounter value) {
1069    this.encounterTarget = value;
1070    return this;
1071  }
1072
1073  /**
1074   * @return {@link #scheduled} (The time when this communication is to occur.)
1075   */
1076  public Type getScheduled() {
1077    return this.scheduled;
1078  }
1079
1080  /**
1081   * @return {@link #scheduled} (The time when this communication is to occur.)
1082   */
1083  public DateTimeType getScheduledDateTimeType() throws FHIRException {
1084    if (!(this.scheduled instanceof DateTimeType))
1085      throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "
1086          + this.scheduled.getClass().getName() + " was encountered");
1087    return (DateTimeType) this.scheduled;
1088  }
1089
1090  public boolean hasScheduledDateTimeType() {
1091    return this.scheduled instanceof DateTimeType;
1092  }
1093
1094  /**
1095   * @return {@link #scheduled} (The time when this communication is to occur.)
1096   */
1097  public Period getScheduledPeriod() throws FHIRException {
1098    if (!(this.scheduled instanceof Period))
1099      throw new FHIRException("Type mismatch: the type Period was expected, but " + this.scheduled.getClass().getName()
1100          + " was encountered");
1101    return (Period) this.scheduled;
1102  }
1103
1104  public boolean hasScheduledPeriod() {
1105    return this.scheduled instanceof Period;
1106  }
1107
1108  public boolean hasScheduled() {
1109    return this.scheduled != null && !this.scheduled.isEmpty();
1110  }
1111
1112  /**
1113   * @param value {@link #scheduled} (The time when this communication is to
1114   *              occur.)
1115   */
1116  public CommunicationRequest setScheduled(Type value) {
1117    this.scheduled = value;
1118    return this;
1119  }
1120
1121  /**
1122   * @return {@link #reason} (The reason or justification for the communication
1123   *         request.)
1124   */
1125  public List<CodeableConcept> getReason() {
1126    if (this.reason == null)
1127      this.reason = new ArrayList<CodeableConcept>();
1128    return this.reason;
1129  }
1130
1131  public boolean hasReason() {
1132    if (this.reason == null)
1133      return false;
1134    for (CodeableConcept item : this.reason)
1135      if (!item.isEmpty())
1136        return true;
1137    return false;
1138  }
1139
1140  /**
1141   * @return {@link #reason} (The reason or justification for the communication
1142   *         request.)
1143   */
1144  // syntactic sugar
1145  public CodeableConcept addReason() { // 3
1146    CodeableConcept t = new CodeableConcept();
1147    if (this.reason == null)
1148      this.reason = new ArrayList<CodeableConcept>();
1149    this.reason.add(t);
1150    return t;
1151  }
1152
1153  // syntactic sugar
1154  public CommunicationRequest addReason(CodeableConcept t) { // 3
1155    if (t == null)
1156      return this;
1157    if (this.reason == null)
1158      this.reason = new ArrayList<CodeableConcept>();
1159    this.reason.add(t);
1160    return this;
1161  }
1162
1163  /**
1164   * @return {@link #requestedOn} (The time when the request was made.). This is
1165   *         the underlying object with id, value and extensions. The accessor
1166   *         "getRequestedOn" gives direct access to the value
1167   */
1168  public DateTimeType getRequestedOnElement() {
1169    if (this.requestedOn == null)
1170      if (Configuration.errorOnAutoCreate())
1171        throw new Error("Attempt to auto-create CommunicationRequest.requestedOn");
1172      else if (Configuration.doAutoCreate())
1173        this.requestedOn = new DateTimeType(); // bb
1174    return this.requestedOn;
1175  }
1176
1177  public boolean hasRequestedOnElement() {
1178    return this.requestedOn != null && !this.requestedOn.isEmpty();
1179  }
1180
1181  public boolean hasRequestedOn() {
1182    return this.requestedOn != null && !this.requestedOn.isEmpty();
1183  }
1184
1185  /**
1186   * @param value {@link #requestedOn} (The time when the request was made.). This
1187   *              is the underlying object with id, value and extensions. The
1188   *              accessor "getRequestedOn" gives direct access to the value
1189   */
1190  public CommunicationRequest setRequestedOnElement(DateTimeType value) {
1191    this.requestedOn = value;
1192    return this;
1193  }
1194
1195  /**
1196   * @return The time when the request was made.
1197   */
1198  public Date getRequestedOn() {
1199    return this.requestedOn == null ? null : this.requestedOn.getValue();
1200  }
1201
1202  /**
1203   * @param value The time when the request was made.
1204   */
1205  public CommunicationRequest setRequestedOn(Date value) {
1206    if (value == null)
1207      this.requestedOn = null;
1208    else {
1209      if (this.requestedOn == null)
1210        this.requestedOn = new DateTimeType();
1211      this.requestedOn.setValue(value);
1212    }
1213    return this;
1214  }
1215
1216  /**
1217   * @return {@link #subject} (The patient who is the focus of this communication
1218   *         request.)
1219   */
1220  public Reference getSubject() {
1221    if (this.subject == null)
1222      if (Configuration.errorOnAutoCreate())
1223        throw new Error("Attempt to auto-create CommunicationRequest.subject");
1224      else if (Configuration.doAutoCreate())
1225        this.subject = new Reference(); // cc
1226    return this.subject;
1227  }
1228
1229  public boolean hasSubject() {
1230    return this.subject != null && !this.subject.isEmpty();
1231  }
1232
1233  /**
1234   * @param value {@link #subject} (The patient who is the focus of this
1235   *              communication request.)
1236   */
1237  public CommunicationRequest setSubject(Reference value) {
1238    this.subject = value;
1239    return this;
1240  }
1241
1242  /**
1243   * @return {@link #subject} The actual object that is the target of the
1244   *         reference. The reference library doesn't populate this, but you can
1245   *         use it to hold the resource if you resolve it. (The patient who is
1246   *         the focus of this communication request.)
1247   */
1248  public Patient getSubjectTarget() {
1249    if (this.subjectTarget == null)
1250      if (Configuration.errorOnAutoCreate())
1251        throw new Error("Attempt to auto-create CommunicationRequest.subject");
1252      else if (Configuration.doAutoCreate())
1253        this.subjectTarget = new Patient(); // aa
1254    return this.subjectTarget;
1255  }
1256
1257  /**
1258   * @param value {@link #subject} The actual object that is the target of the
1259   *              reference. The reference library doesn't use these, but you can
1260   *              use it to hold the resource if you resolve it. (The patient who
1261   *              is the focus of this communication request.)
1262   */
1263  public CommunicationRequest setSubjectTarget(Patient value) {
1264    this.subjectTarget = value;
1265    return this;
1266  }
1267
1268  /**
1269   * @return {@link #priority} (Characterizes how quickly the proposed act must be
1270   *         initiated. Includes concepts such as stat, urgent, routine.)
1271   */
1272  public CodeableConcept getPriority() {
1273    if (this.priority == null)
1274      if (Configuration.errorOnAutoCreate())
1275        throw new Error("Attempt to auto-create CommunicationRequest.priority");
1276      else if (Configuration.doAutoCreate())
1277        this.priority = new CodeableConcept(); // cc
1278    return this.priority;
1279  }
1280
1281  public boolean hasPriority() {
1282    return this.priority != null && !this.priority.isEmpty();
1283  }
1284
1285  /**
1286   * @param value {@link #priority} (Characterizes how quickly the proposed act
1287   *              must be initiated. Includes concepts such as stat, urgent,
1288   *              routine.)
1289   */
1290  public CommunicationRequest setPriority(CodeableConcept value) {
1291    this.priority = value;
1292    return this;
1293  }
1294
1295  protected void listChildren(List<Property> childrenList) {
1296    super.listChildren(childrenList);
1297    childrenList.add(new Property("identifier", "Identifier",
1298        "A unique ID of this request for reference purposes. It must be provided if user wants it returned as part of any output, otherwise it will be autogenerated, if needed, by CDS system. Does not need to be the actual ID of the source system.",
1299        0, java.lang.Integer.MAX_VALUE, identifier));
1300    childrenList.add(new Property("category", "CodeableConcept",
1301        "The type of message to be sent such as alert, notification, reminder, instruction, etc.", 0,
1302        java.lang.Integer.MAX_VALUE, category));
1303    childrenList.add(new Property("sender", "Reference(Device|Organization|Patient|Practitioner|RelatedPerson)",
1304        "The entity (e.g. person, organization, clinical information system, or device) which is to be the source of the communication.",
1305        0, java.lang.Integer.MAX_VALUE, sender));
1306    childrenList.add(new Property("recipient", "Reference(Device|Organization|Patient|Practitioner|RelatedPerson)",
1307        "The entity (e.g. person, organization, clinical information system, or device) which is the intended target of the communication.",
1308        0, java.lang.Integer.MAX_VALUE, recipient));
1309    childrenList
1310        .add(new Property("payload", "", "Text, attachment(s), or resource(s) to be communicated to the recipient.", 0,
1311            java.lang.Integer.MAX_VALUE, payload));
1312    childrenList.add(new Property("medium", "CodeableConcept",
1313        "A channel that was used for this communication (e.g. email, fax).", 0, java.lang.Integer.MAX_VALUE, medium));
1314    childrenList.add(new Property("requester", "Reference(Practitioner|Patient|RelatedPerson)",
1315        "The responsible person who authorizes this order, e.g. physician. This may be different than the author of the order statement, e.g. clerk, who may have entered the statement into the order entry application.",
1316        0, java.lang.Integer.MAX_VALUE, requester));
1317    childrenList.add(
1318        new Property("status", "code", "The status of the proposal or order.", 0, java.lang.Integer.MAX_VALUE, status));
1319    childrenList.add(new Property("encounter", "Reference(Encounter)",
1320        "The encounter within which the communication request was created.", 0, java.lang.Integer.MAX_VALUE,
1321        encounter));
1322    childrenList.add(new Property("scheduled[x]", "dateTime|Period", "The time when this communication is to occur.", 0,
1323        java.lang.Integer.MAX_VALUE, scheduled));
1324    childrenList.add(new Property("reason", "CodeableConcept",
1325        "The reason or justification for the communication request.", 0, java.lang.Integer.MAX_VALUE, reason));
1326    childrenList.add(new Property("requestedOn", "dateTime", "The time when the request was made.", 0,
1327        java.lang.Integer.MAX_VALUE, requestedOn));
1328    childrenList.add(new Property("subject", "Reference(Patient)",
1329        "The patient who is the focus of this communication request.", 0, java.lang.Integer.MAX_VALUE, subject));
1330    childrenList.add(new Property("priority", "CodeableConcept",
1331        "Characterizes how quickly the proposed act must be initiated. Includes concepts such as stat, urgent, routine.",
1332        0, java.lang.Integer.MAX_VALUE, priority));
1333  }
1334
1335  @Override
1336  public void setProperty(String name, Base value) throws FHIRException {
1337    if (name.equals("identifier"))
1338      this.getIdentifier().add(castToIdentifier(value));
1339    else if (name.equals("category"))
1340      this.category = castToCodeableConcept(value); // CodeableConcept
1341    else if (name.equals("sender"))
1342      this.sender = castToReference(value); // Reference
1343    else if (name.equals("recipient"))
1344      this.getRecipient().add(castToReference(value));
1345    else if (name.equals("payload"))
1346      this.getPayload().add((CommunicationRequestPayloadComponent) value);
1347    else if (name.equals("medium"))
1348      this.getMedium().add(castToCodeableConcept(value));
1349    else if (name.equals("requester"))
1350      this.requester = castToReference(value); // Reference
1351    else if (name.equals("status"))
1352      this.status = new CommunicationRequestStatusEnumFactory().fromType(value); // Enumeration<CommunicationRequestStatus>
1353    else if (name.equals("encounter"))
1354      this.encounter = castToReference(value); // Reference
1355    else if (name.equals("scheduled[x]"))
1356      this.scheduled = (Type) value; // Type
1357    else if (name.equals("reason"))
1358      this.getReason().add(castToCodeableConcept(value));
1359    else if (name.equals("requestedOn"))
1360      this.requestedOn = castToDateTime(value); // DateTimeType
1361    else if (name.equals("subject"))
1362      this.subject = castToReference(value); // Reference
1363    else if (name.equals("priority"))
1364      this.priority = castToCodeableConcept(value); // CodeableConcept
1365    else
1366      super.setProperty(name, value);
1367  }
1368
1369  @Override
1370  public Base addChild(String name) throws FHIRException {
1371    if (name.equals("identifier")) {
1372      return addIdentifier();
1373    } else if (name.equals("category")) {
1374      this.category = new CodeableConcept();
1375      return this.category;
1376    } else if (name.equals("sender")) {
1377      this.sender = new Reference();
1378      return this.sender;
1379    } else if (name.equals("recipient")) {
1380      return addRecipient();
1381    } else if (name.equals("payload")) {
1382      return addPayload();
1383    } else if (name.equals("medium")) {
1384      return addMedium();
1385    } else if (name.equals("requester")) {
1386      this.requester = new Reference();
1387      return this.requester;
1388    } else if (name.equals("status")) {
1389      throw new FHIRException("Cannot call addChild on a singleton property CommunicationRequest.status");
1390    } else if (name.equals("encounter")) {
1391      this.encounter = new Reference();
1392      return this.encounter;
1393    } else if (name.equals("scheduledDateTime")) {
1394      this.scheduled = new DateTimeType();
1395      return this.scheduled;
1396    } else if (name.equals("scheduledPeriod")) {
1397      this.scheduled = new Period();
1398      return this.scheduled;
1399    } else if (name.equals("reason")) {
1400      return addReason();
1401    } else if (name.equals("requestedOn")) {
1402      throw new FHIRException("Cannot call addChild on a singleton property CommunicationRequest.requestedOn");
1403    } else if (name.equals("subject")) {
1404      this.subject = new Reference();
1405      return this.subject;
1406    } else if (name.equals("priority")) {
1407      this.priority = new CodeableConcept();
1408      return this.priority;
1409    } else
1410      return super.addChild(name);
1411  }
1412
1413  public String fhirType() {
1414    return "CommunicationRequest";
1415
1416  }
1417
1418  public CommunicationRequest copy() {
1419    CommunicationRequest dst = new CommunicationRequest();
1420    copyValues(dst);
1421    if (identifier != null) {
1422      dst.identifier = new ArrayList<Identifier>();
1423      for (Identifier i : identifier)
1424        dst.identifier.add(i.copy());
1425    }
1426    ;
1427    dst.category = category == null ? null : category.copy();
1428    dst.sender = sender == null ? null : sender.copy();
1429    if (recipient != null) {
1430      dst.recipient = new ArrayList<Reference>();
1431      for (Reference i : recipient)
1432        dst.recipient.add(i.copy());
1433    }
1434    ;
1435    if (payload != null) {
1436      dst.payload = new ArrayList<CommunicationRequestPayloadComponent>();
1437      for (CommunicationRequestPayloadComponent i : payload)
1438        dst.payload.add(i.copy());
1439    }
1440    ;
1441    if (medium != null) {
1442      dst.medium = new ArrayList<CodeableConcept>();
1443      for (CodeableConcept i : medium)
1444        dst.medium.add(i.copy());
1445    }
1446    ;
1447    dst.requester = requester == null ? null : requester.copy();
1448    dst.status = status == null ? null : status.copy();
1449    dst.encounter = encounter == null ? null : encounter.copy();
1450    dst.scheduled = scheduled == null ? null : scheduled.copy();
1451    if (reason != null) {
1452      dst.reason = new ArrayList<CodeableConcept>();
1453      for (CodeableConcept i : reason)
1454        dst.reason.add(i.copy());
1455    }
1456    ;
1457    dst.requestedOn = requestedOn == null ? null : requestedOn.copy();
1458    dst.subject = subject == null ? null : subject.copy();
1459    dst.priority = priority == null ? null : priority.copy();
1460    return dst;
1461  }
1462
1463  protected CommunicationRequest typedCopy() {
1464    return copy();
1465  }
1466
1467  @Override
1468  public boolean equalsDeep(Base other) {
1469    if (!super.equalsDeep(other))
1470      return false;
1471    if (!(other instanceof CommunicationRequest))
1472      return false;
1473    CommunicationRequest o = (CommunicationRequest) other;
1474    return compareDeep(identifier, o.identifier, true) && compareDeep(category, o.category, true)
1475        && compareDeep(sender, o.sender, true) && compareDeep(recipient, o.recipient, true)
1476        && compareDeep(payload, o.payload, true) && compareDeep(medium, o.medium, true)
1477        && compareDeep(requester, o.requester, true) && compareDeep(status, o.status, true)
1478        && compareDeep(encounter, o.encounter, true) && compareDeep(scheduled, o.scheduled, true)
1479        && compareDeep(reason, o.reason, true) && compareDeep(requestedOn, o.requestedOn, true)
1480        && compareDeep(subject, o.subject, true) && compareDeep(priority, o.priority, true);
1481  }
1482
1483  @Override
1484  public boolean equalsShallow(Base other) {
1485    if (!super.equalsShallow(other))
1486      return false;
1487    if (!(other instanceof CommunicationRequest))
1488      return false;
1489    CommunicationRequest o = (CommunicationRequest) other;
1490    return compareValues(status, o.status, true) && compareValues(requestedOn, o.requestedOn, true);
1491  }
1492
1493  public boolean isEmpty() {
1494    return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (category == null || category.isEmpty())
1495        && (sender == null || sender.isEmpty()) && (recipient == null || recipient.isEmpty())
1496        && (payload == null || payload.isEmpty()) && (medium == null || medium.isEmpty())
1497        && (requester == null || requester.isEmpty()) && (status == null || status.isEmpty())
1498        && (encounter == null || encounter.isEmpty()) && (scheduled == null || scheduled.isEmpty())
1499        && (reason == null || reason.isEmpty()) && (requestedOn == null || requestedOn.isEmpty())
1500        && (subject == null || subject.isEmpty()) && (priority == null || priority.isEmpty());
1501  }
1502
1503  @Override
1504  public ResourceType getResourceType() {
1505    return ResourceType.CommunicationRequest;
1506  }
1507
1508  @SearchParamDefinition(name = "requester", path = "CommunicationRequest.requester", description = "An individual who requested a communication", type = "reference")
1509  public static final String SP_REQUESTER = "requester";
1510  @SearchParamDefinition(name = "identifier", path = "CommunicationRequest.identifier", description = "Unique identifier", type = "token")
1511  public static final String SP_IDENTIFIER = "identifier";
1512  @SearchParamDefinition(name = "subject", path = "CommunicationRequest.subject", description = "Focus of message", type = "reference")
1513  public static final String SP_SUBJECT = "subject";
1514  @SearchParamDefinition(name = "medium", path = "CommunicationRequest.medium", description = "A channel of communication", type = "token")
1515  public static final String SP_MEDIUM = "medium";
1516  @SearchParamDefinition(name = "encounter", path = "CommunicationRequest.encounter", description = "Encounter leading to message", type = "reference")
1517  public static final String SP_ENCOUNTER = "encounter";
1518  @SearchParamDefinition(name = "priority", path = "CommunicationRequest.priority", description = "Message urgency", type = "token")
1519  public static final String SP_PRIORITY = "priority";
1520  @SearchParamDefinition(name = "requested", path = "CommunicationRequest.requestedOn", description = "When ordered or proposed", type = "date")
1521  public static final String SP_REQUESTED = "requested";
1522  @SearchParamDefinition(name = "sender", path = "CommunicationRequest.sender", description = "Message sender", type = "reference")
1523  public static final String SP_SENDER = "sender";
1524  @SearchParamDefinition(name = "patient", path = "CommunicationRequest.subject", description = "Focus of message", type = "reference")
1525  public static final String SP_PATIENT = "patient";
1526  @SearchParamDefinition(name = "recipient", path = "CommunicationRequest.recipient", description = "Message recipient", type = "reference")
1527  public static final String SP_RECIPIENT = "recipient";
1528  @SearchParamDefinition(name = "time", path = "CommunicationRequest.scheduledDateTime", description = "When scheduled", type = "date")
1529  public static final String SP_TIME = "time";
1530  @SearchParamDefinition(name = "category", path = "CommunicationRequest.category", description = "Message category", type = "token")
1531  public static final String SP_CATEGORY = "category";
1532  @SearchParamDefinition(name = "status", path = "CommunicationRequest.status", description = "proposed | planned | requested | received | accepted | in-progress | completed | suspended | rejected | failed", type = "token")
1533  public static final String SP_STATUS = "status";
1534
1535}