001package org.hl7.fhir.dstu2.model;
002
003/*-
004 * #%L
005 * org.hl7.fhir.dstu2
006 * %%
007 * Copyright (C) 2014 - 2019 Health Level 7
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024/*
025  Copyright (c) 2011+, HL7, Inc.
026  All rights reserved.
027  
028  Redistribution and use in source and binary forms, with or without modification, 
029  are permitted provided that the following conditions are met:
030  
031   * Redistributions of source code must retain the above copyright notice, this 
032     list of conditions and the following disclaimer.
033   * Redistributions in binary form must reproduce the above copyright notice, 
034     this list of conditions and the following disclaimer in the documentation 
035     and/or other materials provided with the distribution.
036   * Neither the name of HL7 nor the names of its contributors may be used to 
037     endorse or promote products derived from this software without specific 
038     prior written permission.
039  
040  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
041  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
042  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
043  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
044  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
045  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
046  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
047  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
048  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
049  POSSIBILITY OF SUCH DAMAGE.
050  
051*/
052
053// Generated on Wed, Jul 13, 2016 05:32+1000 for FHIR v1.0.2
054import java.util.ArrayList;
055import java.util.Date;
056import java.util.List;
057
058import ca.uhn.fhir.model.api.annotation.Block;
059import ca.uhn.fhir.model.api.annotation.Child;
060import ca.uhn.fhir.model.api.annotation.Description;
061import ca.uhn.fhir.model.api.annotation.ResourceDef;
062import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;
063import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
064import org.hl7.fhir.exceptions.FHIRException;
065import org.hl7.fhir.utilities.Utilities;
066/**
067 * A structured set of questions and their answers. The questions are ordered and grouped into coherent subsets, corresponding to the structure of the grouping of the underlying questions.
068 */
069@ResourceDef(name="QuestionnaireResponse", profile="http://hl7.org/fhir/Profile/QuestionnaireResponse")
070public class QuestionnaireResponse extends DomainResource {
071
072    public enum QuestionnaireResponseStatus {
073        /**
074         * This QuestionnaireResponse has been partially filled out with answers, but changes or additions are still expected to be made to it.
075         */
076        INPROGRESS, 
077        /**
078         * This QuestionnaireResponse has been filled out with answers, and the current content is regarded as definitive.
079         */
080        COMPLETED, 
081        /**
082         * This QuestionnaireResponse has been filled out with answers, then marked as complete, yet changes or additions have been made to it afterwards.
083         */
084        AMENDED, 
085        /**
086         * added to help the parsers
087         */
088        NULL;
089        public static QuestionnaireResponseStatus fromCode(String codeString) throws FHIRException {
090            if (codeString == null || "".equals(codeString))
091                return null;
092        if ("in-progress".equals(codeString))
093          return INPROGRESS;
094        if ("completed".equals(codeString))
095          return COMPLETED;
096        if ("amended".equals(codeString))
097          return AMENDED;
098        throw new FHIRException("Unknown QuestionnaireResponseStatus code '"+codeString+"'");
099        }
100        public String toCode() {
101          switch (this) {
102            case INPROGRESS: return "in-progress";
103            case COMPLETED: return "completed";
104            case AMENDED: return "amended";
105            default: return "?";
106          }
107        }
108        public String getSystem() {
109          switch (this) {
110            case INPROGRESS: return "http://hl7.org/fhir/questionnaire-answers-status";
111            case COMPLETED: return "http://hl7.org/fhir/questionnaire-answers-status";
112            case AMENDED: return "http://hl7.org/fhir/questionnaire-answers-status";
113            default: return "?";
114          }
115        }
116        public String getDefinition() {
117          switch (this) {
118            case INPROGRESS: return "This QuestionnaireResponse has been partially filled out with answers, but changes or additions are still expected to be made to it.";
119            case COMPLETED: return "This QuestionnaireResponse has been filled out with answers, and the current content is regarded as definitive.";
120            case AMENDED: return "This QuestionnaireResponse has been filled out with answers, then marked as complete, yet changes or additions have been made to it afterwards.";
121            default: return "?";
122          }
123        }
124        public String getDisplay() {
125          switch (this) {
126            case INPROGRESS: return "In Progress";
127            case COMPLETED: return "Completed";
128            case AMENDED: return "Amended";
129            default: return "?";
130          }
131        }
132    }
133
134  public static class QuestionnaireResponseStatusEnumFactory implements EnumFactory<QuestionnaireResponseStatus> {
135    public QuestionnaireResponseStatus fromCode(String codeString) throws IllegalArgumentException {
136      if (codeString == null || "".equals(codeString))
137            if (codeString == null || "".equals(codeString))
138                return null;
139        if ("in-progress".equals(codeString))
140          return QuestionnaireResponseStatus.INPROGRESS;
141        if ("completed".equals(codeString))
142          return QuestionnaireResponseStatus.COMPLETED;
143        if ("amended".equals(codeString))
144          return QuestionnaireResponseStatus.AMENDED;
145        throw new IllegalArgumentException("Unknown QuestionnaireResponseStatus code '"+codeString+"'");
146        }
147        public Enumeration<QuestionnaireResponseStatus> fromType(Base code) throws FHIRException {
148          if (code == null || code.isEmpty())
149            return null;
150          String codeString = ((PrimitiveType) code).asStringValue();
151          if (codeString == null || "".equals(codeString))
152            return null;
153        if ("in-progress".equals(codeString))
154          return new Enumeration<QuestionnaireResponseStatus>(this, QuestionnaireResponseStatus.INPROGRESS);
155        if ("completed".equals(codeString))
156          return new Enumeration<QuestionnaireResponseStatus>(this, QuestionnaireResponseStatus.COMPLETED);
157        if ("amended".equals(codeString))
158          return new Enumeration<QuestionnaireResponseStatus>(this, QuestionnaireResponseStatus.AMENDED);
159        throw new FHIRException("Unknown QuestionnaireResponseStatus code '"+codeString+"'");
160        }
161    public String toCode(QuestionnaireResponseStatus code) {
162      if (code == QuestionnaireResponseStatus.INPROGRESS)
163        return "in-progress";
164      if (code == QuestionnaireResponseStatus.COMPLETED)
165        return "completed";
166      if (code == QuestionnaireResponseStatus.AMENDED)
167        return "amended";
168      return "?";
169      }
170    }
171
172    @Block()
173    public static class GroupComponent extends BackboneElement implements IBaseBackboneElement {
174        /**
175         * Identifies the group from the Questionnaire that corresponds to this group in the QuestionnaireResponse resource.
176         */
177        @Child(name = "linkId", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=false)
178        @Description(shortDefinition="Corresponding group within Questionnaire", formalDefinition="Identifies the group from the Questionnaire that corresponds to this group in the QuestionnaireResponse resource." )
179        protected StringType linkId;
180
181        /**
182         * Text that is displayed above the contents of the group.
183         */
184        @Child(name = "title", type = {StringType.class}, order=2, min=0, max=1, modifier=false, summary=false)
185        @Description(shortDefinition="Name for this group", formalDefinition="Text that is displayed above the contents of the group." )
186        protected StringType title;
187
188        /**
189         * Additional text for the group, used for display purposes.
190         */
191        @Child(name = "text", type = {StringType.class}, order=3, min=0, max=1, modifier=false, summary=false)
192        @Description(shortDefinition="Additional text for the group", formalDefinition="Additional text for the group, used for display purposes." )
193        protected StringType text;
194
195        /**
196         * More specific subject this section's answers are about, details the subject given in QuestionnaireResponse.
197         */
198        @Child(name = "subject", type = {}, order=4, min=0, max=1, modifier=false, summary=false)
199        @Description(shortDefinition="The subject this group's answers are about", formalDefinition="More specific subject this section's answers are about, details the subject given in QuestionnaireResponse." )
200        protected Reference subject;
201
202        /**
203         * The actual object that is the target of the reference (More specific subject this section's answers are about, details the subject given in QuestionnaireResponse.)
204         */
205        protected Resource subjectTarget;
206
207        /**
208         * A sub-group within a group. The ordering of groups within this group is relevant.
209         */
210        @Child(name = "group", type = {GroupComponent.class}, order=5, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
211        @Description(shortDefinition="Nested questionnaire response group", formalDefinition="A sub-group within a group. The ordering of groups within this group is relevant." )
212        protected List<GroupComponent> group;
213
214        /**
215         * Set of questions within this group. The order of questions within the group is relevant.
216         */
217        @Child(name = "question", type = {}, order=6, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
218        @Description(shortDefinition="Questions in this group", formalDefinition="Set of questions within this group. The order of questions within the group is relevant." )
219        protected List<QuestionComponent> question;
220
221        private static final long serialVersionUID = -1045990435L;
222
223    /*
224     * Constructor
225     */
226      public GroupComponent() {
227        super();
228      }
229
230        /**
231         * @return {@link #linkId} (Identifies the group from the Questionnaire that corresponds to this group in the QuestionnaireResponse resource.). This is the underlying object with id, value and extensions. The accessor "getLinkId" gives direct access to the value
232         */
233        public StringType getLinkIdElement() { 
234          if (this.linkId == null)
235            if (Configuration.errorOnAutoCreate())
236              throw new Error("Attempt to auto-create GroupComponent.linkId");
237            else if (Configuration.doAutoCreate())
238              this.linkId = new StringType(); // bb
239          return this.linkId;
240        }
241
242        public boolean hasLinkIdElement() { 
243          return this.linkId != null && !this.linkId.isEmpty();
244        }
245
246        public boolean hasLinkId() { 
247          return this.linkId != null && !this.linkId.isEmpty();
248        }
249
250        /**
251         * @param value {@link #linkId} (Identifies the group from the Questionnaire that corresponds to this group in the QuestionnaireResponse resource.). This is the underlying object with id, value and extensions. The accessor "getLinkId" gives direct access to the value
252         */
253        public GroupComponent setLinkIdElement(StringType value) { 
254          this.linkId = value;
255          return this;
256        }
257
258        /**
259         * @return Identifies the group from the Questionnaire that corresponds to this group in the QuestionnaireResponse resource.
260         */
261        public String getLinkId() { 
262          return this.linkId == null ? null : this.linkId.getValue();
263        }
264
265        /**
266         * @param value Identifies the group from the Questionnaire that corresponds to this group in the QuestionnaireResponse resource.
267         */
268        public GroupComponent setLinkId(String value) { 
269          if (Utilities.noString(value))
270            this.linkId = null;
271          else {
272            if (this.linkId == null)
273              this.linkId = new StringType();
274            this.linkId.setValue(value);
275          }
276          return this;
277        }
278
279        /**
280         * @return {@link #title} (Text that is displayed above the contents of the group.). This is the underlying object with id, value and extensions. The accessor "getTitle" gives direct access to the value
281         */
282        public StringType getTitleElement() { 
283          if (this.title == null)
284            if (Configuration.errorOnAutoCreate())
285              throw new Error("Attempt to auto-create GroupComponent.title");
286            else if (Configuration.doAutoCreate())
287              this.title = new StringType(); // bb
288          return this.title;
289        }
290
291        public boolean hasTitleElement() { 
292          return this.title != null && !this.title.isEmpty();
293        }
294
295        public boolean hasTitle() { 
296          return this.title != null && !this.title.isEmpty();
297        }
298
299        /**
300         * @param value {@link #title} (Text that is displayed above the contents of the group.). This is the underlying object with id, value and extensions. The accessor "getTitle" gives direct access to the value
301         */
302        public GroupComponent setTitleElement(StringType value) { 
303          this.title = value;
304          return this;
305        }
306
307        /**
308         * @return Text that is displayed above the contents of the group.
309         */
310        public String getTitle() { 
311          return this.title == null ? null : this.title.getValue();
312        }
313
314        /**
315         * @param value Text that is displayed above the contents of the group.
316         */
317        public GroupComponent setTitle(String value) { 
318          if (Utilities.noString(value))
319            this.title = null;
320          else {
321            if (this.title == null)
322              this.title = new StringType();
323            this.title.setValue(value);
324          }
325          return this;
326        }
327
328        /**
329         * @return {@link #text} (Additional text for the group, used for display purposes.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
330         */
331        public StringType getTextElement() { 
332          if (this.text == null)
333            if (Configuration.errorOnAutoCreate())
334              throw new Error("Attempt to auto-create GroupComponent.text");
335            else if (Configuration.doAutoCreate())
336              this.text = new StringType(); // bb
337          return this.text;
338        }
339
340        public boolean hasTextElement() { 
341          return this.text != null && !this.text.isEmpty();
342        }
343
344        public boolean hasText() { 
345          return this.text != null && !this.text.isEmpty();
346        }
347
348        /**
349         * @param value {@link #text} (Additional text for the group, used for display purposes.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
350         */
351        public GroupComponent setTextElement(StringType value) { 
352          this.text = value;
353          return this;
354        }
355
356        /**
357         * @return Additional text for the group, used for display purposes.
358         */
359        public String getText() { 
360          return this.text == null ? null : this.text.getValue();
361        }
362
363        /**
364         * @param value Additional text for the group, used for display purposes.
365         */
366        public GroupComponent setText(String value) { 
367          if (Utilities.noString(value))
368            this.text = null;
369          else {
370            if (this.text == null)
371              this.text = new StringType();
372            this.text.setValue(value);
373          }
374          return this;
375        }
376
377        /**
378         * @return {@link #subject} (More specific subject this section's answers are about, details the subject given in QuestionnaireResponse.)
379         */
380        public Reference getSubject() { 
381          if (this.subject == null)
382            if (Configuration.errorOnAutoCreate())
383              throw new Error("Attempt to auto-create GroupComponent.subject");
384            else if (Configuration.doAutoCreate())
385              this.subject = new Reference(); // cc
386          return this.subject;
387        }
388
389        public boolean hasSubject() { 
390          return this.subject != null && !this.subject.isEmpty();
391        }
392
393        /**
394         * @param value {@link #subject} (More specific subject this section's answers are about, details the subject given in QuestionnaireResponse.)
395         */
396        public GroupComponent setSubject(Reference value) { 
397          this.subject = value;
398          return this;
399        }
400
401        /**
402         * @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. (More specific subject this section's answers are about, details the subject given in QuestionnaireResponse.)
403         */
404        public Resource getSubjectTarget() { 
405          return this.subjectTarget;
406        }
407
408        /**
409         * @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. (More specific subject this section's answers are about, details the subject given in QuestionnaireResponse.)
410         */
411        public GroupComponent setSubjectTarget(Resource value) { 
412          this.subjectTarget = value;
413          return this;
414        }
415
416        /**
417         * @return {@link #group} (A sub-group within a group. The ordering of groups within this group is relevant.)
418         */
419        public List<GroupComponent> getGroup() { 
420          if (this.group == null)
421            this.group = new ArrayList<GroupComponent>();
422          return this.group;
423        }
424
425        public boolean hasGroup() { 
426          if (this.group == null)
427            return false;
428          for (GroupComponent item : this.group)
429            if (!item.isEmpty())
430              return true;
431          return false;
432        }
433
434        /**
435         * @return {@link #group} (A sub-group within a group. The ordering of groups within this group is relevant.)
436         */
437    // syntactic sugar
438        public GroupComponent addGroup() { //3
439          GroupComponent t = new GroupComponent();
440          if (this.group == null)
441            this.group = new ArrayList<GroupComponent>();
442          this.group.add(t);
443          return t;
444        }
445
446    // syntactic sugar
447        public GroupComponent addGroup(GroupComponent t) { //3
448          if (t == null)
449            return this;
450          if (this.group == null)
451            this.group = new ArrayList<GroupComponent>();
452          this.group.add(t);
453          return this;
454        }
455
456        /**
457         * @return {@link #question} (Set of questions within this group. The order of questions within the group is relevant.)
458         */
459        public List<QuestionComponent> getQuestion() { 
460          if (this.question == null)
461            this.question = new ArrayList<QuestionComponent>();
462          return this.question;
463        }
464
465        public boolean hasQuestion() { 
466          if (this.question == null)
467            return false;
468          for (QuestionComponent item : this.question)
469            if (!item.isEmpty())
470              return true;
471          return false;
472        }
473
474        /**
475         * @return {@link #question} (Set of questions within this group. The order of questions within the group is relevant.)
476         */
477    // syntactic sugar
478        public QuestionComponent addQuestion() { //3
479          QuestionComponent t = new QuestionComponent();
480          if (this.question == null)
481            this.question = new ArrayList<QuestionComponent>();
482          this.question.add(t);
483          return t;
484        }
485
486    // syntactic sugar
487        public GroupComponent addQuestion(QuestionComponent t) { //3
488          if (t == null)
489            return this;
490          if (this.question == null)
491            this.question = new ArrayList<QuestionComponent>();
492          this.question.add(t);
493          return this;
494        }
495
496        protected void listChildren(List<Property> childrenList) {
497          super.listChildren(childrenList);
498          childrenList.add(new Property("linkId", "string", "Identifies the group from the Questionnaire that corresponds to this group in the QuestionnaireResponse resource.", 0, java.lang.Integer.MAX_VALUE, linkId));
499          childrenList.add(new Property("title", "string", "Text that is displayed above the contents of the group.", 0, java.lang.Integer.MAX_VALUE, title));
500          childrenList.add(new Property("text", "string", "Additional text for the group, used for display purposes.", 0, java.lang.Integer.MAX_VALUE, text));
501          childrenList.add(new Property("subject", "Reference(Any)", "More specific subject this section's answers are about, details the subject given in QuestionnaireResponse.", 0, java.lang.Integer.MAX_VALUE, subject));
502          childrenList.add(new Property("group", "@QuestionnaireResponse.group", "A sub-group within a group. The ordering of groups within this group is relevant.", 0, java.lang.Integer.MAX_VALUE, group));
503          childrenList.add(new Property("question", "", "Set of questions within this group. The order of questions within the group is relevant.", 0, java.lang.Integer.MAX_VALUE, question));
504        }
505
506      @Override
507      public void setProperty(String name, Base value) throws FHIRException {
508        if (name.equals("linkId"))
509          this.linkId = castToString(value); // StringType
510        else if (name.equals("title"))
511          this.title = castToString(value); // StringType
512        else if (name.equals("text"))
513          this.text = castToString(value); // StringType
514        else if (name.equals("subject"))
515          this.subject = castToReference(value); // Reference
516        else if (name.equals("group"))
517          this.getGroup().add((GroupComponent) value);
518        else if (name.equals("question"))
519          this.getQuestion().add((QuestionComponent) value);
520        else
521          super.setProperty(name, value);
522      }
523
524      @Override
525      public Base addChild(String name) throws FHIRException {
526        if (name.equals("linkId")) {
527          throw new FHIRException("Cannot call addChild on a primitive type QuestionnaireResponse.linkId");
528        }
529        else if (name.equals("title")) {
530          throw new FHIRException("Cannot call addChild on a primitive type QuestionnaireResponse.title");
531        }
532        else if (name.equals("text")) {
533          throw new FHIRException("Cannot call addChild on a primitive type QuestionnaireResponse.text");
534        }
535        else if (name.equals("subject")) {
536          this.subject = new Reference();
537          return this.subject;
538        }
539        else if (name.equals("group")) {
540          return addGroup();
541        }
542        else if (name.equals("question")) {
543          return addQuestion();
544        }
545        else
546          return super.addChild(name);
547      }
548
549      public GroupComponent copy() {
550        GroupComponent dst = new GroupComponent();
551        copyValues(dst);
552        dst.linkId = linkId == null ? null : linkId.copy();
553        dst.title = title == null ? null : title.copy();
554        dst.text = text == null ? null : text.copy();
555        dst.subject = subject == null ? null : subject.copy();
556        if (group != null) {
557          dst.group = new ArrayList<GroupComponent>();
558          for (GroupComponent i : group)
559            dst.group.add(i.copy());
560        };
561        if (question != null) {
562          dst.question = new ArrayList<QuestionComponent>();
563          for (QuestionComponent i : question)
564            dst.question.add(i.copy());
565        };
566        return dst;
567      }
568
569      @Override
570      public boolean equalsDeep(Base other) {
571        if (!super.equalsDeep(other))
572          return false;
573        if (!(other instanceof GroupComponent))
574          return false;
575        GroupComponent o = (GroupComponent) other;
576        return compareDeep(linkId, o.linkId, true) && compareDeep(title, o.title, true) && compareDeep(text, o.text, true)
577           && compareDeep(subject, o.subject, true) && compareDeep(group, o.group, true) && compareDeep(question, o.question, true)
578          ;
579      }
580
581      @Override
582      public boolean equalsShallow(Base other) {
583        if (!super.equalsShallow(other))
584          return false;
585        if (!(other instanceof GroupComponent))
586          return false;
587        GroupComponent o = (GroupComponent) other;
588        return compareValues(linkId, o.linkId, true) && compareValues(title, o.title, true) && compareValues(text, o.text, true)
589          ;
590      }
591
592      public boolean isEmpty() {
593        return super.isEmpty() && (linkId == null || linkId.isEmpty()) && (title == null || title.isEmpty())
594           && (text == null || text.isEmpty()) && (subject == null || subject.isEmpty()) && (group == null || group.isEmpty())
595           && (question == null || question.isEmpty());
596      }
597
598  public String fhirType() {
599    return "QuestionnaireResponse.group";
600
601  }
602
603  }
604
605    @Block()
606    public static class QuestionComponent extends BackboneElement implements IBaseBackboneElement {
607        /**
608         * Identifies the question from the Questionnaire that corresponds to this question in the QuestionnaireResponse resource.
609         */
610        @Child(name = "linkId", type = {StringType.class}, order=1, min=0, max=1, modifier=false, summary=false)
611        @Description(shortDefinition="Corresponding question within Questionnaire", formalDefinition="Identifies the question from the Questionnaire that corresponds to this question in the QuestionnaireResponse resource." )
612        protected StringType linkId;
613
614        /**
615         * The actual question as shown to the user to prompt them for an answer.
616         */
617        @Child(name = "text", type = {StringType.class}, order=2, min=0, max=1, modifier=false, summary=false)
618        @Description(shortDefinition="Text of the question as it is shown to the user", formalDefinition="The actual question as shown to the user to prompt them for an answer." )
619        protected StringType text;
620
621        /**
622         * The respondent's answer(s) to the question.
623         */
624        @Child(name = "answer", type = {}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
625        @Description(shortDefinition="The response(s) to the question", formalDefinition="The respondent's answer(s) to the question." )
626        protected List<QuestionAnswerComponent> answer;
627
628        private static final long serialVersionUID = -265263901L;
629
630    /*
631     * Constructor
632     */
633      public QuestionComponent() {
634        super();
635      }
636
637        /**
638         * @return {@link #linkId} (Identifies the question from the Questionnaire that corresponds to this question in the QuestionnaireResponse resource.). This is the underlying object with id, value and extensions. The accessor "getLinkId" gives direct access to the value
639         */
640        public StringType getLinkIdElement() { 
641          if (this.linkId == null)
642            if (Configuration.errorOnAutoCreate())
643              throw new Error("Attempt to auto-create QuestionComponent.linkId");
644            else if (Configuration.doAutoCreate())
645              this.linkId = new StringType(); // bb
646          return this.linkId;
647        }
648
649        public boolean hasLinkIdElement() { 
650          return this.linkId != null && !this.linkId.isEmpty();
651        }
652
653        public boolean hasLinkId() { 
654          return this.linkId != null && !this.linkId.isEmpty();
655        }
656
657        /**
658         * @param value {@link #linkId} (Identifies the question from the Questionnaire that corresponds to this question in the QuestionnaireResponse resource.). This is the underlying object with id, value and extensions. The accessor "getLinkId" gives direct access to the value
659         */
660        public QuestionComponent setLinkIdElement(StringType value) { 
661          this.linkId = value;
662          return this;
663        }
664
665        /**
666         * @return Identifies the question from the Questionnaire that corresponds to this question in the QuestionnaireResponse resource.
667         */
668        public String getLinkId() { 
669          return this.linkId == null ? null : this.linkId.getValue();
670        }
671
672        /**
673         * @param value Identifies the question from the Questionnaire that corresponds to this question in the QuestionnaireResponse resource.
674         */
675        public QuestionComponent setLinkId(String value) { 
676          if (Utilities.noString(value))
677            this.linkId = null;
678          else {
679            if (this.linkId == null)
680              this.linkId = new StringType();
681            this.linkId.setValue(value);
682          }
683          return this;
684        }
685
686        /**
687         * @return {@link #text} (The actual question as shown to the user to prompt them for an answer.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
688         */
689        public StringType getTextElement() { 
690          if (this.text == null)
691            if (Configuration.errorOnAutoCreate())
692              throw new Error("Attempt to auto-create QuestionComponent.text");
693            else if (Configuration.doAutoCreate())
694              this.text = new StringType(); // bb
695          return this.text;
696        }
697
698        public boolean hasTextElement() { 
699          return this.text != null && !this.text.isEmpty();
700        }
701
702        public boolean hasText() { 
703          return this.text != null && !this.text.isEmpty();
704        }
705
706        /**
707         * @param value {@link #text} (The actual question as shown to the user to prompt them for an answer.). This is the underlying object with id, value and extensions. The accessor "getText" gives direct access to the value
708         */
709        public QuestionComponent setTextElement(StringType value) { 
710          this.text = value;
711          return this;
712        }
713
714        /**
715         * @return The actual question as shown to the user to prompt them for an answer.
716         */
717        public String getText() { 
718          return this.text == null ? null : this.text.getValue();
719        }
720
721        /**
722         * @param value The actual question as shown to the user to prompt them for an answer.
723         */
724        public QuestionComponent setText(String value) { 
725          if (Utilities.noString(value))
726            this.text = null;
727          else {
728            if (this.text == null)
729              this.text = new StringType();
730            this.text.setValue(value);
731          }
732          return this;
733        }
734
735        /**
736         * @return {@link #answer} (The respondent's answer(s) to the question.)
737         */
738        public List<QuestionAnswerComponent> getAnswer() { 
739          if (this.answer == null)
740            this.answer = new ArrayList<QuestionAnswerComponent>();
741          return this.answer;
742        }
743
744        public boolean hasAnswer() { 
745          if (this.answer == null)
746            return false;
747          for (QuestionAnswerComponent item : this.answer)
748            if (!item.isEmpty())
749              return true;
750          return false;
751        }
752
753        /**
754         * @return {@link #answer} (The respondent's answer(s) to the question.)
755         */
756    // syntactic sugar
757        public QuestionAnswerComponent addAnswer() { //3
758          QuestionAnswerComponent t = new QuestionAnswerComponent();
759          if (this.answer == null)
760            this.answer = new ArrayList<QuestionAnswerComponent>();
761          this.answer.add(t);
762          return t;
763        }
764
765    // syntactic sugar
766        public QuestionComponent addAnswer(QuestionAnswerComponent t) { //3
767          if (t == null)
768            return this;
769          if (this.answer == null)
770            this.answer = new ArrayList<QuestionAnswerComponent>();
771          this.answer.add(t);
772          return this;
773        }
774
775        protected void listChildren(List<Property> childrenList) {
776          super.listChildren(childrenList);
777          childrenList.add(new Property("linkId", "string", "Identifies the question from the Questionnaire that corresponds to this question in the QuestionnaireResponse resource.", 0, java.lang.Integer.MAX_VALUE, linkId));
778          childrenList.add(new Property("text", "string", "The actual question as shown to the user to prompt them for an answer.", 0, java.lang.Integer.MAX_VALUE, text));
779          childrenList.add(new Property("answer", "", "The respondent's answer(s) to the question.", 0, java.lang.Integer.MAX_VALUE, answer));
780        }
781
782      @Override
783      public void setProperty(String name, Base value) throws FHIRException {
784        if (name.equals("linkId"))
785          this.linkId = castToString(value); // StringType
786        else if (name.equals("text"))
787          this.text = castToString(value); // StringType
788        else if (name.equals("answer"))
789          this.getAnswer().add((QuestionAnswerComponent) value);
790        else
791          super.setProperty(name, value);
792      }
793
794      @Override
795      public Base addChild(String name) throws FHIRException {
796        if (name.equals("linkId")) {
797          throw new FHIRException("Cannot call addChild on a primitive type QuestionnaireResponse.linkId");
798        }
799        else if (name.equals("text")) {
800          throw new FHIRException("Cannot call addChild on a primitive type QuestionnaireResponse.text");
801        }
802        else if (name.equals("answer")) {
803          return addAnswer();
804        }
805        else
806          return super.addChild(name);
807      }
808
809      public QuestionComponent copy() {
810        QuestionComponent dst = new QuestionComponent();
811        copyValues(dst);
812        dst.linkId = linkId == null ? null : linkId.copy();
813        dst.text = text == null ? null : text.copy();
814        if (answer != null) {
815          dst.answer = new ArrayList<QuestionAnswerComponent>();
816          for (QuestionAnswerComponent i : answer)
817            dst.answer.add(i.copy());
818        };
819        return dst;
820      }
821
822      @Override
823      public boolean equalsDeep(Base other) {
824        if (!super.equalsDeep(other))
825          return false;
826        if (!(other instanceof QuestionComponent))
827          return false;
828        QuestionComponent o = (QuestionComponent) other;
829        return compareDeep(linkId, o.linkId, true) && compareDeep(text, o.text, true) && compareDeep(answer, o.answer, true)
830          ;
831      }
832
833      @Override
834      public boolean equalsShallow(Base other) {
835        if (!super.equalsShallow(other))
836          return false;
837        if (!(other instanceof QuestionComponent))
838          return false;
839        QuestionComponent o = (QuestionComponent) other;
840        return compareValues(linkId, o.linkId, true) && compareValues(text, o.text, true);
841      }
842
843      public boolean isEmpty() {
844        return super.isEmpty() && (linkId == null || linkId.isEmpty()) && (text == null || text.isEmpty())
845           && (answer == null || answer.isEmpty());
846      }
847
848  public String fhirType() {
849    return "QuestionnaireResponse.group.question";
850
851  }
852
853  }
854
855    @Block()
856    public static class QuestionAnswerComponent extends BackboneElement implements IBaseBackboneElement {
857        /**
858         * The answer (or one of the answers) provided by the respondent to the question.
859         */
860        @Child(name = "value", type = {BooleanType.class, DecimalType.class, IntegerType.class, DateType.class, DateTimeType.class, InstantType.class, TimeType.class, StringType.class, UriType.class, Attachment.class, Coding.class, Quantity.class, Reference.class}, order=1, min=0, max=1, modifier=false, summary=false)
861        @Description(shortDefinition="Single-valued answer to the question", formalDefinition="The answer (or one of the answers) provided by the respondent to the question." )
862        protected Type value;
863
864        /**
865         * Nested group, containing nested question for this question. The order of groups within the question is relevant.
866         */
867        @Child(name = "group", type = {GroupComponent.class}, order=2, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
868        @Description(shortDefinition="Nested questionnaire group", formalDefinition="Nested group, containing nested question for this question. The order of groups within the question is relevant." )
869        protected List<GroupComponent> group;
870
871        private static final long serialVersionUID = -1223680118L;
872
873    /*
874     * Constructor
875     */
876      public QuestionAnswerComponent() {
877        super();
878      }
879
880        /**
881         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
882         */
883        public Type getValue() { 
884          return this.value;
885        }
886
887        /**
888         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
889         */
890        public BooleanType getValueBooleanType() throws FHIRException { 
891          if (!(this.value instanceof BooleanType))
892            throw new FHIRException("Type mismatch: the type BooleanType was expected, but "+this.value.getClass().getName()+" was encountered");
893          return (BooleanType) this.value;
894        }
895
896        public boolean hasValueBooleanType() { 
897          return this.value instanceof BooleanType;
898        }
899
900        /**
901         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
902         */
903        public DecimalType getValueDecimalType() throws FHIRException { 
904          if (!(this.value instanceof DecimalType))
905            throw new FHIRException("Type mismatch: the type DecimalType was expected, but "+this.value.getClass().getName()+" was encountered");
906          return (DecimalType) this.value;
907        }
908
909        public boolean hasValueDecimalType() { 
910          return this.value instanceof DecimalType;
911        }
912
913        /**
914         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
915         */
916        public IntegerType getValueIntegerType() throws FHIRException { 
917          if (!(this.value instanceof IntegerType))
918            throw new FHIRException("Type mismatch: the type IntegerType was expected, but "+this.value.getClass().getName()+" was encountered");
919          return (IntegerType) this.value;
920        }
921
922        public boolean hasValueIntegerType() { 
923          return this.value instanceof IntegerType;
924        }
925
926        /**
927         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
928         */
929        public DateType getValueDateType() throws FHIRException { 
930          if (!(this.value instanceof DateType))
931            throw new FHIRException("Type mismatch: the type DateType was expected, but "+this.value.getClass().getName()+" was encountered");
932          return (DateType) this.value;
933        }
934
935        public boolean hasValueDateType() { 
936          return this.value instanceof DateType;
937        }
938
939        /**
940         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
941         */
942        public DateTimeType getValueDateTimeType() throws FHIRException { 
943          if (!(this.value instanceof DateTimeType))
944            throw new FHIRException("Type mismatch: the type DateTimeType was expected, but "+this.value.getClass().getName()+" was encountered");
945          return (DateTimeType) this.value;
946        }
947
948        public boolean hasValueDateTimeType() { 
949          return this.value instanceof DateTimeType;
950        }
951
952        /**
953         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
954         */
955        public InstantType getValueInstantType() throws FHIRException { 
956          if (!(this.value instanceof InstantType))
957            throw new FHIRException("Type mismatch: the type InstantType was expected, but "+this.value.getClass().getName()+" was encountered");
958          return (InstantType) this.value;
959        }
960
961        public boolean hasValueInstantType() { 
962          return this.value instanceof InstantType;
963        }
964
965        /**
966         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
967         */
968        public TimeType getValueTimeType() throws FHIRException { 
969          if (!(this.value instanceof TimeType))
970            throw new FHIRException("Type mismatch: the type TimeType was expected, but "+this.value.getClass().getName()+" was encountered");
971          return (TimeType) this.value;
972        }
973
974        public boolean hasValueTimeType() { 
975          return this.value instanceof TimeType;
976        }
977
978        /**
979         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
980         */
981        public StringType getValueStringType() throws FHIRException { 
982          if (!(this.value instanceof StringType))
983            throw new FHIRException("Type mismatch: the type StringType was expected, but "+this.value.getClass().getName()+" was encountered");
984          return (StringType) this.value;
985        }
986
987        public boolean hasValueStringType() { 
988          return this.value instanceof StringType;
989        }
990
991        /**
992         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
993         */
994        public UriType getValueUriType() throws FHIRException { 
995          if (!(this.value instanceof UriType))
996            throw new FHIRException("Type mismatch: the type UriType was expected, but "+this.value.getClass().getName()+" was encountered");
997          return (UriType) this.value;
998        }
999
1000        public boolean hasValueUriType() { 
1001          return this.value instanceof UriType;
1002        }
1003
1004        /**
1005         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
1006         */
1007        public Attachment getValueAttachment() throws FHIRException { 
1008          if (!(this.value instanceof Attachment))
1009            throw new FHIRException("Type mismatch: the type Attachment was expected, but "+this.value.getClass().getName()+" was encountered");
1010          return (Attachment) this.value;
1011        }
1012
1013        public boolean hasValueAttachment() { 
1014          return this.value instanceof Attachment;
1015        }
1016
1017        /**
1018         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
1019         */
1020        public Coding getValueCoding() throws FHIRException { 
1021          if (!(this.value instanceof Coding))
1022            throw new FHIRException("Type mismatch: the type Coding was expected, but "+this.value.getClass().getName()+" was encountered");
1023          return (Coding) this.value;
1024        }
1025
1026        public boolean hasValueCoding() { 
1027          return this.value instanceof Coding;
1028        }
1029
1030        /**
1031         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
1032         */
1033        public Quantity getValueQuantity() throws FHIRException { 
1034          if (!(this.value instanceof Quantity))
1035            throw new FHIRException("Type mismatch: the type Quantity was expected, but "+this.value.getClass().getName()+" was encountered");
1036          return (Quantity) this.value;
1037        }
1038
1039        public boolean hasValueQuantity() { 
1040          return this.value instanceof Quantity;
1041        }
1042
1043        /**
1044         * @return {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
1045         */
1046        public Reference getValueReference() throws FHIRException { 
1047          if (!(this.value instanceof Reference))
1048            throw new FHIRException("Type mismatch: the type Reference was expected, but "+this.value.getClass().getName()+" was encountered");
1049          return (Reference) this.value;
1050        }
1051
1052        public boolean hasValueReference() { 
1053          return this.value instanceof Reference;
1054        }
1055
1056        public boolean hasValue() { 
1057          return this.value != null && !this.value.isEmpty();
1058        }
1059
1060        /**
1061         * @param value {@link #value} (The answer (or one of the answers) provided by the respondent to the question.)
1062         */
1063        public QuestionAnswerComponent setValue(Type value) { 
1064          this.value = value;
1065          return this;
1066        }
1067
1068        /**
1069         * @return {@link #group} (Nested group, containing nested question for this question. The order of groups within the question is relevant.)
1070         */
1071        public List<GroupComponent> getGroup() { 
1072          if (this.group == null)
1073            this.group = new ArrayList<GroupComponent>();
1074          return this.group;
1075        }
1076
1077        public boolean hasGroup() { 
1078          if (this.group == null)
1079            return false;
1080          for (GroupComponent item : this.group)
1081            if (!item.isEmpty())
1082              return true;
1083          return false;
1084        }
1085
1086        /**
1087         * @return {@link #group} (Nested group, containing nested question for this question. The order of groups within the question is relevant.)
1088         */
1089    // syntactic sugar
1090        public GroupComponent addGroup() { //3
1091          GroupComponent t = new GroupComponent();
1092          if (this.group == null)
1093            this.group = new ArrayList<GroupComponent>();
1094          this.group.add(t);
1095          return t;
1096        }
1097
1098    // syntactic sugar
1099        public QuestionAnswerComponent addGroup(GroupComponent t) { //3
1100          if (t == null)
1101            return this;
1102          if (this.group == null)
1103            this.group = new ArrayList<GroupComponent>();
1104          this.group.add(t);
1105          return this;
1106        }
1107
1108        protected void listChildren(List<Property> childrenList) {
1109          super.listChildren(childrenList);
1110          childrenList.add(new Property("value[x]", "boolean|decimal|integer|date|dateTime|instant|time|string|uri|Attachment|Coding|Quantity|Reference(Any)", "The answer (or one of the answers) provided by the respondent to the question.", 0, java.lang.Integer.MAX_VALUE, value));
1111          childrenList.add(new Property("group", "@QuestionnaireResponse.group", "Nested group, containing nested question for this question. The order of groups within the question is relevant.", 0, java.lang.Integer.MAX_VALUE, group));
1112        }
1113
1114      @Override
1115      public void setProperty(String name, Base value) throws FHIRException {
1116        if (name.equals("value[x]"))
1117          this.value = (Type) value; // Type
1118        else if (name.equals("group"))
1119          this.getGroup().add((GroupComponent) value);
1120        else
1121          super.setProperty(name, value);
1122      }
1123
1124      @Override
1125      public Base addChild(String name) throws FHIRException {
1126        if (name.equals("valueBoolean")) {
1127          this.value = new BooleanType();
1128          return this.value;
1129        }
1130        else if (name.equals("valueDecimal")) {
1131          this.value = new DecimalType();
1132          return this.value;
1133        }
1134        else if (name.equals("valueInteger")) {
1135          this.value = new IntegerType();
1136          return this.value;
1137        }
1138        else if (name.equals("valueDate")) {
1139          this.value = new DateType();
1140          return this.value;
1141        }
1142        else if (name.equals("valueDateTime")) {
1143          this.value = new DateTimeType();
1144          return this.value;
1145        }
1146        else if (name.equals("valueInstant")) {
1147          this.value = new InstantType();
1148          return this.value;
1149        }
1150        else if (name.equals("valueTime")) {
1151          this.value = new TimeType();
1152          return this.value;
1153        }
1154        else if (name.equals("valueString")) {
1155          this.value = new StringType();
1156          return this.value;
1157        }
1158        else if (name.equals("valueUri")) {
1159          this.value = new UriType();
1160          return this.value;
1161        }
1162        else if (name.equals("valueAttachment")) {
1163          this.value = new Attachment();
1164          return this.value;
1165        }
1166        else if (name.equals("valueCoding")) {
1167          this.value = new Coding();
1168          return this.value;
1169        }
1170        else if (name.equals("valueQuantity")) {
1171          this.value = new Quantity();
1172          return this.value;
1173        }
1174        else if (name.equals("valueReference")) {
1175          this.value = new Reference();
1176          return this.value;
1177        }
1178        else if (name.equals("group")) {
1179          return addGroup();
1180        }
1181        else
1182          return super.addChild(name);
1183      }
1184
1185      public QuestionAnswerComponent copy() {
1186        QuestionAnswerComponent dst = new QuestionAnswerComponent();
1187        copyValues(dst);
1188        dst.value = value == null ? null : value.copy();
1189        if (group != null) {
1190          dst.group = new ArrayList<GroupComponent>();
1191          for (GroupComponent i : group)
1192            dst.group.add(i.copy());
1193        };
1194        return dst;
1195      }
1196
1197      @Override
1198      public boolean equalsDeep(Base other) {
1199        if (!super.equalsDeep(other))
1200          return false;
1201        if (!(other instanceof QuestionAnswerComponent))
1202          return false;
1203        QuestionAnswerComponent o = (QuestionAnswerComponent) other;
1204        return compareDeep(value, o.value, true) && compareDeep(group, o.group, true);
1205      }
1206
1207      @Override
1208      public boolean equalsShallow(Base other) {
1209        if (!super.equalsShallow(other))
1210          return false;
1211        if (!(other instanceof QuestionAnswerComponent))
1212          return false;
1213        QuestionAnswerComponent o = (QuestionAnswerComponent) other;
1214        return true;
1215      }
1216
1217      public boolean isEmpty() {
1218        return super.isEmpty() && (value == null || value.isEmpty()) && (group == null || group.isEmpty())
1219          ;
1220      }
1221
1222  public String fhirType() {
1223    return "QuestionnaireResponse.group.question.answer";
1224
1225  }
1226
1227  }
1228
1229    /**
1230     * A business identifier assigned to a particular completed (or partially completed) questionnaire.
1231     */
1232    @Child(name = "identifier", type = {Identifier.class}, order=0, min=0, max=1, modifier=false, summary=true)
1233    @Description(shortDefinition="Unique id for this set of answers", formalDefinition="A business identifier assigned to a particular completed (or partially completed) questionnaire." )
1234    protected Identifier identifier;
1235
1236    /**
1237     * Indicates the Questionnaire resource that defines the form for which answers are being provided.
1238     */
1239    @Child(name = "questionnaire", type = {Questionnaire.class}, order=1, min=0, max=1, modifier=false, summary=true)
1240    @Description(shortDefinition="Form being answered", formalDefinition="Indicates the Questionnaire resource that defines the form for which answers are being provided." )
1241    protected Reference questionnaire;
1242
1243    /**
1244     * The actual object that is the target of the reference (Indicates the Questionnaire resource that defines the form for which answers are being provided.)
1245     */
1246    protected Questionnaire questionnaireTarget;
1247
1248    /**
1249     * The lifecycle status of the questionnaire response as a whole.
1250     */
1251    @Child(name = "status", type = {CodeType.class}, order=2, min=1, max=1, modifier=true, summary=true)
1252    @Description(shortDefinition="in-progress | completed | amended", formalDefinition="The lifecycle status of the questionnaire response as a whole." )
1253    protected Enumeration<QuestionnaireResponseStatus> status;
1254
1255    /**
1256     * The subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.
1257     */
1258    @Child(name = "subject", type = {}, order=3, min=0, max=1, modifier=false, summary=true)
1259    @Description(shortDefinition="The subject of the questions", formalDefinition="The subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information." )
1260    protected Reference subject;
1261
1262    /**
1263     * The actual object that is the target of the reference (The subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.)
1264     */
1265    protected Resource subjectTarget;
1266
1267    /**
1268     * Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.
1269     */
1270    @Child(name = "author", type = {Device.class, Practitioner.class, Patient.class, RelatedPerson.class}, order=4, min=0, max=1, modifier=false, summary=true)
1271    @Description(shortDefinition="Person who received and recorded the answers", formalDefinition="Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system." )
1272    protected Reference author;
1273
1274    /**
1275     * The actual object that is the target of the reference (Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.)
1276     */
1277    protected Resource authorTarget;
1278
1279    /**
1280     * The date and/or time that this version of the questionnaire response was authored.
1281     */
1282    @Child(name = "authored", type = {DateTimeType.class}, order=5, min=0, max=1, modifier=false, summary=true)
1283    @Description(shortDefinition="Date this version was authored", formalDefinition="The date and/or time that this version of the questionnaire response was authored." )
1284    protected DateTimeType authored;
1285
1286    /**
1287     * The person who answered the questions about the subject.
1288     */
1289    @Child(name = "source", type = {Patient.class, Practitioner.class, RelatedPerson.class}, order=6, min=0, max=1, modifier=false, summary=true)
1290    @Description(shortDefinition="The person who answered the questions", formalDefinition="The person who answered the questions about the subject." )
1291    protected Reference source;
1292
1293    /**
1294     * The actual object that is the target of the reference (The person who answered the questions about the subject.)
1295     */
1296    protected Resource sourceTarget;
1297
1298    /**
1299     * Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers.
1300     */
1301    @Child(name = "encounter", type = {Encounter.class}, order=7, min=0, max=1, modifier=false, summary=true)
1302    @Description(shortDefinition="Primary encounter during which the answers were collected", formalDefinition="Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers." )
1303    protected Reference encounter;
1304
1305    /**
1306     * The actual object that is the target of the reference (Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers.)
1307     */
1308    protected Encounter encounterTarget;
1309
1310    /**
1311     * A group of questions to a possibly similarly grouped set of questions in the questionnaire response.
1312     */
1313    @Child(name = "group", type = {}, order=8, min=0, max=1, modifier=false, summary=false)
1314    @Description(shortDefinition="Grouped questions", formalDefinition="A group of questions to a possibly similarly grouped set of questions in the questionnaire response." )
1315    protected GroupComponent group;
1316
1317    private static final long serialVersionUID = -1081988635L;
1318
1319  /*
1320   * Constructor
1321   */
1322    public QuestionnaireResponse() {
1323      super();
1324    }
1325
1326  /*
1327   * Constructor
1328   */
1329    public QuestionnaireResponse(Enumeration<QuestionnaireResponseStatus> status) {
1330      super();
1331      this.status = status;
1332    }
1333
1334    /**
1335     * @return {@link #identifier} (A business identifier assigned to a particular completed (or partially completed) questionnaire.)
1336     */
1337    public Identifier getIdentifier() { 
1338      if (this.identifier == null)
1339        if (Configuration.errorOnAutoCreate())
1340          throw new Error("Attempt to auto-create QuestionnaireResponse.identifier");
1341        else if (Configuration.doAutoCreate())
1342          this.identifier = new Identifier(); // cc
1343      return this.identifier;
1344    }
1345
1346    public boolean hasIdentifier() { 
1347      return this.identifier != null && !this.identifier.isEmpty();
1348    }
1349
1350    /**
1351     * @param value {@link #identifier} (A business identifier assigned to a particular completed (or partially completed) questionnaire.)
1352     */
1353    public QuestionnaireResponse setIdentifier(Identifier value) { 
1354      this.identifier = value;
1355      return this;
1356    }
1357
1358    /**
1359     * @return {@link #questionnaire} (Indicates the Questionnaire resource that defines the form for which answers are being provided.)
1360     */
1361    public Reference getQuestionnaire() { 
1362      if (this.questionnaire == null)
1363        if (Configuration.errorOnAutoCreate())
1364          throw new Error("Attempt to auto-create QuestionnaireResponse.questionnaire");
1365        else if (Configuration.doAutoCreate())
1366          this.questionnaire = new Reference(); // cc
1367      return this.questionnaire;
1368    }
1369
1370    public boolean hasQuestionnaire() { 
1371      return this.questionnaire != null && !this.questionnaire.isEmpty();
1372    }
1373
1374    /**
1375     * @param value {@link #questionnaire} (Indicates the Questionnaire resource that defines the form for which answers are being provided.)
1376     */
1377    public QuestionnaireResponse setQuestionnaire(Reference value) { 
1378      this.questionnaire = value;
1379      return this;
1380    }
1381
1382    /**
1383     * @return {@link #questionnaire} 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. (Indicates the Questionnaire resource that defines the form for which answers are being provided.)
1384     */
1385    public Questionnaire getQuestionnaireTarget() { 
1386      if (this.questionnaireTarget == null)
1387        if (Configuration.errorOnAutoCreate())
1388          throw new Error("Attempt to auto-create QuestionnaireResponse.questionnaire");
1389        else if (Configuration.doAutoCreate())
1390          this.questionnaireTarget = new Questionnaire(); // aa
1391      return this.questionnaireTarget;
1392    }
1393
1394    /**
1395     * @param value {@link #questionnaire} 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. (Indicates the Questionnaire resource that defines the form for which answers are being provided.)
1396     */
1397    public QuestionnaireResponse setQuestionnaireTarget(Questionnaire value) { 
1398      this.questionnaireTarget = value;
1399      return this;
1400    }
1401
1402    /**
1403     * @return {@link #status} (The lifecycle status of the questionnaire response as a whole.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1404     */
1405    public Enumeration<QuestionnaireResponseStatus> getStatusElement() { 
1406      if (this.status == null)
1407        if (Configuration.errorOnAutoCreate())
1408          throw new Error("Attempt to auto-create QuestionnaireResponse.status");
1409        else if (Configuration.doAutoCreate())
1410          this.status = new Enumeration<QuestionnaireResponseStatus>(new QuestionnaireResponseStatusEnumFactory()); // bb
1411      return this.status;
1412    }
1413
1414    public boolean hasStatusElement() { 
1415      return this.status != null && !this.status.isEmpty();
1416    }
1417
1418    public boolean hasStatus() { 
1419      return this.status != null && !this.status.isEmpty();
1420    }
1421
1422    /**
1423     * @param value {@link #status} (The lifecycle status of the questionnaire response as a whole.). This is the underlying object with id, value and extensions. The accessor "getStatus" gives direct access to the value
1424     */
1425    public QuestionnaireResponse setStatusElement(Enumeration<QuestionnaireResponseStatus> value) { 
1426      this.status = value;
1427      return this;
1428    }
1429
1430    /**
1431     * @return The lifecycle status of the questionnaire response as a whole.
1432     */
1433    public QuestionnaireResponseStatus getStatus() { 
1434      return this.status == null ? null : this.status.getValue();
1435    }
1436
1437    /**
1438     * @param value The lifecycle status of the questionnaire response as a whole.
1439     */
1440    public QuestionnaireResponse setStatus(QuestionnaireResponseStatus value) { 
1441        if (this.status == null)
1442          this.status = new Enumeration<QuestionnaireResponseStatus>(new QuestionnaireResponseStatusEnumFactory());
1443        this.status.setValue(value);
1444      return this;
1445    }
1446
1447    /**
1448     * @return {@link #subject} (The subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.)
1449     */
1450    public Reference getSubject() { 
1451      if (this.subject == null)
1452        if (Configuration.errorOnAutoCreate())
1453          throw new Error("Attempt to auto-create QuestionnaireResponse.subject");
1454        else if (Configuration.doAutoCreate())
1455          this.subject = new Reference(); // cc
1456      return this.subject;
1457    }
1458
1459    public boolean hasSubject() { 
1460      return this.subject != null && !this.subject.isEmpty();
1461    }
1462
1463    /**
1464     * @param value {@link #subject} (The subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.)
1465     */
1466    public QuestionnaireResponse setSubject(Reference value) { 
1467      this.subject = value;
1468      return this;
1469    }
1470
1471    /**
1472     * @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 subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.)
1473     */
1474    public Resource getSubjectTarget() { 
1475      return this.subjectTarget;
1476    }
1477
1478    /**
1479     * @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 subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.)
1480     */
1481    public QuestionnaireResponse setSubjectTarget(Resource value) { 
1482      this.subjectTarget = value;
1483      return this;
1484    }
1485
1486    /**
1487     * @return {@link #author} (Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.)
1488     */
1489    public Reference getAuthor() { 
1490      if (this.author == null)
1491        if (Configuration.errorOnAutoCreate())
1492          throw new Error("Attempt to auto-create QuestionnaireResponse.author");
1493        else if (Configuration.doAutoCreate())
1494          this.author = new Reference(); // cc
1495      return this.author;
1496    }
1497
1498    public boolean hasAuthor() { 
1499      return this.author != null && !this.author.isEmpty();
1500    }
1501
1502    /**
1503     * @param value {@link #author} (Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.)
1504     */
1505    public QuestionnaireResponse setAuthor(Reference value) { 
1506      this.author = value;
1507      return this;
1508    }
1509
1510    /**
1511     * @return {@link #author} 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. (Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.)
1512     */
1513    public Resource getAuthorTarget() { 
1514      return this.authorTarget;
1515    }
1516
1517    /**
1518     * @param value {@link #author} 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. (Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.)
1519     */
1520    public QuestionnaireResponse setAuthorTarget(Resource value) { 
1521      this.authorTarget = value;
1522      return this;
1523    }
1524
1525    /**
1526     * @return {@link #authored} (The date and/or time that this version of the questionnaire response was authored.). This is the underlying object with id, value and extensions. The accessor "getAuthored" gives direct access to the value
1527     */
1528    public DateTimeType getAuthoredElement() { 
1529      if (this.authored == null)
1530        if (Configuration.errorOnAutoCreate())
1531          throw new Error("Attempt to auto-create QuestionnaireResponse.authored");
1532        else if (Configuration.doAutoCreate())
1533          this.authored = new DateTimeType(); // bb
1534      return this.authored;
1535    }
1536
1537    public boolean hasAuthoredElement() { 
1538      return this.authored != null && !this.authored.isEmpty();
1539    }
1540
1541    public boolean hasAuthored() { 
1542      return this.authored != null && !this.authored.isEmpty();
1543    }
1544
1545    /**
1546     * @param value {@link #authored} (The date and/or time that this version of the questionnaire response was authored.). This is the underlying object with id, value and extensions. The accessor "getAuthored" gives direct access to the value
1547     */
1548    public QuestionnaireResponse setAuthoredElement(DateTimeType value) { 
1549      this.authored = value;
1550      return this;
1551    }
1552
1553    /**
1554     * @return The date and/or time that this version of the questionnaire response was authored.
1555     */
1556    public Date getAuthored() { 
1557      return this.authored == null ? null : this.authored.getValue();
1558    }
1559
1560    /**
1561     * @param value The date and/or time that this version of the questionnaire response was authored.
1562     */
1563    public QuestionnaireResponse setAuthored(Date value) { 
1564      if (value == null)
1565        this.authored = null;
1566      else {
1567        if (this.authored == null)
1568          this.authored = new DateTimeType();
1569        this.authored.setValue(value);
1570      }
1571      return this;
1572    }
1573
1574    /**
1575     * @return {@link #source} (The person who answered the questions about the subject.)
1576     */
1577    public Reference getSource() { 
1578      if (this.source == null)
1579        if (Configuration.errorOnAutoCreate())
1580          throw new Error("Attempt to auto-create QuestionnaireResponse.source");
1581        else if (Configuration.doAutoCreate())
1582          this.source = new Reference(); // cc
1583      return this.source;
1584    }
1585
1586    public boolean hasSource() { 
1587      return this.source != null && !this.source.isEmpty();
1588    }
1589
1590    /**
1591     * @param value {@link #source} (The person who answered the questions about the subject.)
1592     */
1593    public QuestionnaireResponse setSource(Reference value) { 
1594      this.source = value;
1595      return this;
1596    }
1597
1598    /**
1599     * @return {@link #source} 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 person who answered the questions about the subject.)
1600     */
1601    public Resource getSourceTarget() { 
1602      return this.sourceTarget;
1603    }
1604
1605    /**
1606     * @param value {@link #source} 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 person who answered the questions about the subject.)
1607     */
1608    public QuestionnaireResponse setSourceTarget(Resource value) { 
1609      this.sourceTarget = value;
1610      return this;
1611    }
1612
1613    /**
1614     * @return {@link #encounter} (Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers.)
1615     */
1616    public Reference getEncounter() { 
1617      if (this.encounter == null)
1618        if (Configuration.errorOnAutoCreate())
1619          throw new Error("Attempt to auto-create QuestionnaireResponse.encounter");
1620        else if (Configuration.doAutoCreate())
1621          this.encounter = new Reference(); // cc
1622      return this.encounter;
1623    }
1624
1625    public boolean hasEncounter() { 
1626      return this.encounter != null && !this.encounter.isEmpty();
1627    }
1628
1629    /**
1630     * @param value {@link #encounter} (Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers.)
1631     */
1632    public QuestionnaireResponse setEncounter(Reference value) { 
1633      this.encounter = value;
1634      return this;
1635    }
1636
1637    /**
1638     * @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. (Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers.)
1639     */
1640    public Encounter getEncounterTarget() { 
1641      if (this.encounterTarget == null)
1642        if (Configuration.errorOnAutoCreate())
1643          throw new Error("Attempt to auto-create QuestionnaireResponse.encounter");
1644        else if (Configuration.doAutoCreate())
1645          this.encounterTarget = new Encounter(); // aa
1646      return this.encounterTarget;
1647    }
1648
1649    /**
1650     * @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. (Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers.)
1651     */
1652    public QuestionnaireResponse setEncounterTarget(Encounter value) { 
1653      this.encounterTarget = value;
1654      return this;
1655    }
1656
1657    /**
1658     * @return {@link #group} (A group of questions to a possibly similarly grouped set of questions in the questionnaire response.)
1659     */
1660    public GroupComponent getGroup() { 
1661      if (this.group == null)
1662        if (Configuration.errorOnAutoCreate())
1663          throw new Error("Attempt to auto-create QuestionnaireResponse.group");
1664        else if (Configuration.doAutoCreate())
1665          this.group = new GroupComponent(); // cc
1666      return this.group;
1667    }
1668
1669    public boolean hasGroup() { 
1670      return this.group != null && !this.group.isEmpty();
1671    }
1672
1673    /**
1674     * @param value {@link #group} (A group of questions to a possibly similarly grouped set of questions in the questionnaire response.)
1675     */
1676    public QuestionnaireResponse setGroup(GroupComponent value) { 
1677      this.group = value;
1678      return this;
1679    }
1680
1681      protected void listChildren(List<Property> childrenList) {
1682        super.listChildren(childrenList);
1683        childrenList.add(new Property("identifier", "Identifier", "A business identifier assigned to a particular completed (or partially completed) questionnaire.", 0, java.lang.Integer.MAX_VALUE, identifier));
1684        childrenList.add(new Property("questionnaire", "Reference(Questionnaire)", "Indicates the Questionnaire resource that defines the form for which answers are being provided.", 0, java.lang.Integer.MAX_VALUE, questionnaire));
1685        childrenList.add(new Property("status", "code", "The lifecycle status of the questionnaire response as a whole.", 0, java.lang.Integer.MAX_VALUE, status));
1686        childrenList.add(new Property("subject", "Reference(Any)", "The subject of the questionnaire response.  This could be a patient, organization, practitioner, device, etc.  This is who/what the answers apply to, but is not necessarily the source of information.", 0, java.lang.Integer.MAX_VALUE, subject));
1687        childrenList.add(new Property("author", "Reference(Device|Practitioner|Patient|RelatedPerson)", "Person who received the answers to the questions in the QuestionnaireResponse and recorded them in the system.", 0, java.lang.Integer.MAX_VALUE, author));
1688        childrenList.add(new Property("authored", "dateTime", "The date and/or time that this version of the questionnaire response was authored.", 0, java.lang.Integer.MAX_VALUE, authored));
1689        childrenList.add(new Property("source", "Reference(Patient|Practitioner|RelatedPerson)", "The person who answered the questions about the subject.", 0, java.lang.Integer.MAX_VALUE, source));
1690        childrenList.add(new Property("encounter", "Reference(Encounter)", "Encounter during which this set of questionnaire response were collected. When there were multiple encounters, this is the one considered most relevant to the context of the answers.", 0, java.lang.Integer.MAX_VALUE, encounter));
1691        childrenList.add(new Property("group", "", "A group of questions to a possibly similarly grouped set of questions in the questionnaire response.", 0, java.lang.Integer.MAX_VALUE, group));
1692      }
1693
1694      @Override
1695      public void setProperty(String name, Base value) throws FHIRException {
1696        if (name.equals("identifier"))
1697          this.identifier = castToIdentifier(value); // Identifier
1698        else if (name.equals("questionnaire"))
1699          this.questionnaire = castToReference(value); // Reference
1700        else if (name.equals("status"))
1701          this.status = new QuestionnaireResponseStatusEnumFactory().fromType(value); // Enumeration<QuestionnaireResponseStatus>
1702        else if (name.equals("subject"))
1703          this.subject = castToReference(value); // Reference
1704        else if (name.equals("author"))
1705          this.author = castToReference(value); // Reference
1706        else if (name.equals("authored"))
1707          this.authored = castToDateTime(value); // DateTimeType
1708        else if (name.equals("source"))
1709          this.source = castToReference(value); // Reference
1710        else if (name.equals("encounter"))
1711          this.encounter = castToReference(value); // Reference
1712        else if (name.equals("group"))
1713          this.group = (GroupComponent) value; // GroupComponent
1714        else
1715          super.setProperty(name, value);
1716      }
1717
1718      @Override
1719      public Base addChild(String name) throws FHIRException {
1720        if (name.equals("identifier")) {
1721          this.identifier = new Identifier();
1722          return this.identifier;
1723        }
1724        else if (name.equals("questionnaire")) {
1725          this.questionnaire = new Reference();
1726          return this.questionnaire;
1727        }
1728        else if (name.equals("status")) {
1729          throw new FHIRException("Cannot call addChild on a primitive type QuestionnaireResponse.status");
1730        }
1731        else if (name.equals("subject")) {
1732          this.subject = new Reference();
1733          return this.subject;
1734        }
1735        else if (name.equals("author")) {
1736          this.author = new Reference();
1737          return this.author;
1738        }
1739        else if (name.equals("authored")) {
1740          throw new FHIRException("Cannot call addChild on a primitive type QuestionnaireResponse.authored");
1741        }
1742        else if (name.equals("source")) {
1743          this.source = new Reference();
1744          return this.source;
1745        }
1746        else if (name.equals("encounter")) {
1747          this.encounter = new Reference();
1748          return this.encounter;
1749        }
1750        else if (name.equals("group")) {
1751          this.group = new GroupComponent();
1752          return this.group;
1753        }
1754        else
1755          return super.addChild(name);
1756      }
1757
1758  public String fhirType() {
1759    return "QuestionnaireResponse";
1760
1761  }
1762
1763      public QuestionnaireResponse copy() {
1764        QuestionnaireResponse dst = new QuestionnaireResponse();
1765        copyValues(dst);
1766        dst.identifier = identifier == null ? null : identifier.copy();
1767        dst.questionnaire = questionnaire == null ? null : questionnaire.copy();
1768        dst.status = status == null ? null : status.copy();
1769        dst.subject = subject == null ? null : subject.copy();
1770        dst.author = author == null ? null : author.copy();
1771        dst.authored = authored == null ? null : authored.copy();
1772        dst.source = source == null ? null : source.copy();
1773        dst.encounter = encounter == null ? null : encounter.copy();
1774        dst.group = group == null ? null : group.copy();
1775        return dst;
1776      }
1777
1778      protected QuestionnaireResponse typedCopy() {
1779        return copy();
1780      }
1781
1782      @Override
1783      public boolean equalsDeep(Base other) {
1784        if (!super.equalsDeep(other))
1785          return false;
1786        if (!(other instanceof QuestionnaireResponse))
1787          return false;
1788        QuestionnaireResponse o = (QuestionnaireResponse) other;
1789        return compareDeep(identifier, o.identifier, true) && compareDeep(questionnaire, o.questionnaire, true)
1790           && compareDeep(status, o.status, true) && compareDeep(subject, o.subject, true) && compareDeep(author, o.author, true)
1791           && compareDeep(authored, o.authored, true) && compareDeep(source, o.source, true) && compareDeep(encounter, o.encounter, true)
1792           && compareDeep(group, o.group, true);
1793      }
1794
1795      @Override
1796      public boolean equalsShallow(Base other) {
1797        if (!super.equalsShallow(other))
1798          return false;
1799        if (!(other instanceof QuestionnaireResponse))
1800          return false;
1801        QuestionnaireResponse o = (QuestionnaireResponse) other;
1802        return compareValues(status, o.status, true) && compareValues(authored, o.authored, true);
1803      }
1804
1805      public boolean isEmpty() {
1806        return super.isEmpty() && (identifier == null || identifier.isEmpty()) && (questionnaire == null || questionnaire.isEmpty())
1807           && (status == null || status.isEmpty()) && (subject == null || subject.isEmpty()) && (author == null || author.isEmpty())
1808           && (authored == null || authored.isEmpty()) && (source == null || source.isEmpty()) && (encounter == null || encounter.isEmpty())
1809           && (group == null || group.isEmpty());
1810      }
1811
1812  @Override
1813  public ResourceType getResourceType() {
1814    return ResourceType.QuestionnaireResponse;
1815   }
1816
1817  @SearchParamDefinition(name="authored", path="QuestionnaireResponse.authored", description="When the questionnaire was authored", type="date" )
1818  public static final String SP_AUTHORED = "authored";
1819  @SearchParamDefinition(name="questionnaire", path="QuestionnaireResponse.questionnaire", description="The questionnaire the answers are provided for", type="reference" )
1820  public static final String SP_QUESTIONNAIRE = "questionnaire";
1821  @SearchParamDefinition(name="subject", path="QuestionnaireResponse.subject", description="The subject of the questionnaire", type="reference" )
1822  public static final String SP_SUBJECT = "subject";
1823  @SearchParamDefinition(name="author", path="QuestionnaireResponse.author", description="The author of the questionnaire", type="reference" )
1824  public static final String SP_AUTHOR = "author";
1825  @SearchParamDefinition(name="patient", path="QuestionnaireResponse.subject", description="The patient that is the subject of the questionnaire", type="reference" )
1826  public static final String SP_PATIENT = "patient";
1827  @SearchParamDefinition(name="encounter", path="QuestionnaireResponse.encounter", description="Encounter during which questionnaire was authored", type="reference" )
1828  public static final String SP_ENCOUNTER = "encounter";
1829  @SearchParamDefinition(name="source", path="QuestionnaireResponse.source", description="The person who answered the questions", type="reference" )
1830  public static final String SP_SOURCE = "source";
1831  @SearchParamDefinition(name="status", path="QuestionnaireResponse.status", description="The status of the questionnaire response", type="token" )
1832  public static final String SP_STATUS = "status";
1833
1834}
1835