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