001package org.hl7.fhir.r5.openehr;
002
003
004/*
005  Copyright (c) 2011+, HL7, Inc.
006  All rights reserved.
007  
008  Redistribution and use in source and binary forms, with or without modification, \
009  are permitted provided that the following conditions are met:
010  
011   * Redistributions of source code must retain the above copyright notice, this \
012     list of conditions and the following disclaimer.
013   * Redistributions in binary form must reproduce the above copyright notice, \
014     this list of conditions and the following disclaimer in the documentation \
015     and/or other materials provided with the distribution.
016   * Neither the name of HL7 nor the names of its contributors may be used to 
017     endorse or promote products derived from this software without specific 
018     prior written permission.
019  
020  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND \
021  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED \
022  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \
023  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, \
024  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT \
025  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR \
026  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \
027  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) \
028  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE \
029  POSSIBILITY OF SUCH DAMAGE.
030  */
031
032// Generated on Thu, Mar 23, 2023 19:59+1100 for FHIR v5.0.0
033
034import java.util.ArrayList;
035import java.util.Date;
036import java.util.List;
037import org.hl7.fhir.r5.openehr.Enumerations.*;
038import org.hl7.fhir.exceptions.FHIRException;
039import org.hl7.fhir.r5.model.*;
040import org.hl7.fhir.instance.model.api.ICompositeType;
041import ca.uhn.fhir.model.api.annotation.Child;
042import ca.uhn.fhir.model.api.annotation.ChildOrder;
043import ca.uhn.fhir.model.api.annotation.DatatypeDef;
044import ca.uhn.fhir.model.api.annotation.Description;
045import ca.uhn.fhir.model.api.annotation.Block;
046
047/**
048 * Used to specify actions in the future. Enables simple and complex specifications to be expressed, including in a fully-computable workflow form. Used for any actionable statement such as medication and therapeutic orders, monitoring, recall and review. Enough details must be provided for the specification to be directly executed by an actor, either human or machine. Not to be used for plan items which are only specified in general terms.
049 */
050@DatatypeDef(name="INSTRUCTION")
051public class INSTRUCTION extends CARE_ENTRY implements ICompositeType {
052
053    /**
054     * Mandatory human-readable version of what the Instruction is about.
055     */
056    @Child(name = "narrative", type = {DV_TEXT.class}, order=0, min=1, max=1, modifier=false, summary=false)
057    @Description(shortDefinition="Mandatory human-readable version of what the Instruction is about", formalDefinition="Mandatory human-readable version of what the Instruction is about." )
058    protected DV_TEXT narrative;
059
060    /**
061     * Optional expiry date/time to assist determination of when an Instruction can be assumed to have expired. This helps prevent false listing of Instructions as Active when they clearly must have been terminated in some way or other.
062     */
063    @Child(name = "expiry_time", type = {DV_DATE_TIME.class}, order=1, min=0, max=1, modifier=false, summary=false)
064    @Description(shortDefinition="Optional expiry date/time to assist determination of when an Instruction can be assumed to have expired", formalDefinition="Optional expiry date/time to assist determination of when an Instruction can be assumed to have expired. This helps prevent false listing of Instructions as Active when they clearly must have been terminated in some way or other." )
065    protected DV_DATE_TIME expiry_time;
066
067    /**
068     * Optional workflow engine executable expression of the Instruction.
069     */
070    @Child(name = "wf_definition", type = {DV_PARSABLE.class}, order=2, min=0, max=1, modifier=false, summary=false)
071    @Description(shortDefinition="Optional workflow engine executable expression of the Instruction", formalDefinition="Optional workflow engine executable expression of the Instruction." )
072    protected DV_PARSABLE wf_definition;
073
074    /**
075     * List of all activities in Instruction.
076     */
077    @Child(name = "activities", type = {ACTIVITY.class}, order=3, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
078    @Description(shortDefinition="List of all activities in Instruction", formalDefinition="List of all activities in Instruction." )
079    protected List<ACTIVITY> activitiesList;
080
081    private static final long serialVersionUID = -797234340L;
082
083  /**
084   * Constructor
085   */
086    public INSTRUCTION() {
087      super();
088    }
089
090  /**
091   * Constructor
092   */
093    public INSTRUCTION(DV_TEXT narrative) {
094      super();
095      this.setNarrative(narrative);
096    }
097
098    /**
099     * @return {@link #narrative} (Mandatory human-readable version of what the Instruction is about.)
100     */
101    public DV_TEXT getNarrative() { 
102      if (this.narrative == null)
103        if (Configuration.errorOnAutoCreate())
104          throw new Error("Attempt to auto-create INSTRUCTION.narrative");
105        else if (Configuration.doAutoCreate())
106          this.narrative = new DV_TEXT(); // cc
107      return this.narrative;
108    }
109
110    public boolean hasNarrative() { 
111      return this.narrative != null && !this.narrative.isEmpty();
112    }
113
114    /**
115     * @param value {@link #narrative} (Mandatory human-readable version of what the Instruction is about.)
116     */
117    public INSTRUCTION setNarrative(DV_TEXT value) { 
118      this.narrative = value;
119      return this;
120    }
121
122    /**
123     * @return {@link #expiry_time} (Optional expiry date/time to assist determination of when an Instruction can be assumed to have expired. This helps prevent false listing of Instructions as Active when they clearly must have been terminated in some way or other.)
124     */
125    public DV_DATE_TIME getExpiry_time() { 
126      if (this.expiry_time == null)
127        if (Configuration.errorOnAutoCreate())
128          throw new Error("Attempt to auto-create INSTRUCTION.expiry_time");
129        else if (Configuration.doAutoCreate())
130          this.expiry_time = new DV_DATE_TIME(); // cc
131      return this.expiry_time;
132    }
133
134    public boolean hasExpiry_time() { 
135      return this.expiry_time != null && !this.expiry_time.isEmpty();
136    }
137
138    /**
139     * @param value {@link #expiry_time} (Optional expiry date/time to assist determination of when an Instruction can be assumed to have expired. This helps prevent false listing of Instructions as Active when they clearly must have been terminated in some way or other.)
140     */
141    public INSTRUCTION setExpiry_time(DV_DATE_TIME value) { 
142      this.expiry_time = value;
143      return this;
144    }
145
146    /**
147     * @return {@link #wf_definition} (Optional workflow engine executable expression of the Instruction.)
148     */
149    public DV_PARSABLE getWf_definition() { 
150      if (this.wf_definition == null)
151        if (Configuration.errorOnAutoCreate())
152          throw new Error("Attempt to auto-create INSTRUCTION.wf_definition");
153        else if (Configuration.doAutoCreate())
154          this.wf_definition = new DV_PARSABLE(); // cc
155      return this.wf_definition;
156    }
157
158    public boolean hasWf_definition() { 
159      return this.wf_definition != null && !this.wf_definition.isEmpty();
160    }
161
162    /**
163     * @param value {@link #wf_definition} (Optional workflow engine executable expression of the Instruction.)
164     */
165    public INSTRUCTION setWf_definition(DV_PARSABLE value) { 
166      this.wf_definition = value;
167      return this;
168    }
169
170    /**
171     * @return {@link #activities} (List of all activities in Instruction.)
172     */
173    public List<ACTIVITY> getActivitiesList() { 
174      if (this.activitiesList == null)
175        this.activitiesList = new ArrayList<ACTIVITY>();
176      return this.activitiesList;
177    }
178
179    /**
180     * @return Returns a reference to <code>this</code> for easy method chaining
181     */
182    public INSTRUCTION setActivitiesList(List<ACTIVITY> theActivities) { 
183      this.activitiesList = theActivities;
184      return this;
185    }
186
187    public boolean hasActivities() { 
188      if (this.activitiesList == null)
189        return false;
190      for (ACTIVITY item : this.activitiesList)
191        if (!item.isEmpty())
192          return true;
193      return false;
194    }
195
196    public ACTIVITY addActivities() { //3a
197      ACTIVITY t = new ACTIVITY();
198      if (this.activitiesList == null)
199        this.activitiesList = new ArrayList<ACTIVITY>();
200      this.activitiesList.add(t);
201      return t;
202    }
203
204    public INSTRUCTION addActivities(ACTIVITY t) { //3b
205      if (t == null)
206        return this;
207      if (this.activitiesList == null)
208        this.activitiesList = new ArrayList<ACTIVITY>();
209      this.activitiesList.add(t);
210      return this;
211    }
212
213    /**
214     * @return The first repetition of repeating field {@link #activities}, creating it if it does not already exist {3}
215     */
216    public ACTIVITY getActivitiesFirstRep() { 
217      if (getActivitiesList().isEmpty()) {
218        addActivities();
219      }
220      return getActivitiesList().get(0);
221    }
222
223      protected void listChildren(List<Property> children) {
224        super.listChildren(children);
225        children.add(new Property("narrative", "http://openehr.org/fhir/StructureDefinition/DV-TEXT", "Mandatory human-readable version of what the Instruction is about.", 0, 1, narrative));
226        children.add(new Property("expiry_time", "http://openehr.org/fhir/StructureDefinition/DV-DATE-TIME", "Optional expiry date/time to assist determination of when an Instruction can be assumed to have expired. This helps prevent false listing of Instructions as Active when they clearly must have been terminated in some way or other.", 0, 1, expiry_time));
227        children.add(new Property("wf_definition", "http://openehr.org/fhir/StructureDefinition/DV-PARSABLE", "Optional workflow engine executable expression of the Instruction.", 0, 1, wf_definition));
228        children.add(new Property("activities", "http://openehr.org/fhir/StructureDefinition/ACTIVITY", "List of all activities in Instruction.", 0, java.lang.Integer.MAX_VALUE, activitiesList));
229      }
230
231      @Override
232      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
233        switch (_hash) {
234        case 1750452338: /*narrative*/  return new Property("narrative", "http://openehr.org/fhir/StructureDefinition/DV-TEXT", "Mandatory human-readable version of what the Instruction is about.", 0, 1, narrative);
235        case 476403289: /*expiry_time*/  return new Property("expiry_time", "http://openehr.org/fhir/StructureDefinition/DV-DATE-TIME", "Optional expiry date/time to assist determination of when an Instruction can be assumed to have expired. This helps prevent false listing of Instructions as Active when they clearly must have been terminated in some way or other.", 0, 1, expiry_time);
236        case -199789373: /*wf_definition*/  return new Property("wf_definition", "http://openehr.org/fhir/StructureDefinition/DV-PARSABLE", "Optional workflow engine executable expression of the Instruction.", 0, 1, wf_definition);
237        case 2048605165: /*activities*/  return new Property("activities", "http://openehr.org/fhir/StructureDefinition/ACTIVITY", "List of all activities in Instruction.", 0, java.lang.Integer.MAX_VALUE, activitiesList);
238        default: return super.getNamedProperty(_hash, _name, _checkValid);
239        }
240
241      }
242
243      @Override
244      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
245        switch (hash) {
246        case 1750452338: /*narrative*/ return this.narrative == null ? new Base[0] : new Base[] {this.narrative}; // DV_TEXT
247        case 476403289: /*expiry_time*/ return this.expiry_time == null ? new Base[0] : new Base[] {this.expiry_time}; // DV_DATE_TIME
248        case -199789373: /*wf_definition*/ return this.wf_definition == null ? new Base[0] : new Base[] {this.wf_definition}; // DV_PARSABLE
249        case 2048605165: /*activities*/ return this.activitiesList == null ? new Base[0] : this.activitiesList.toArray(new Base[this.activitiesList.size()]); // ACTIVITY
250        default: return super.getProperty(hash, name, checkValid);
251        }
252
253      }
254
255      @Override
256      public Base setProperty(int hash, String name, Base value) throws FHIRException {
257        switch (hash) {
258        case 1750452338: // narrative
259          this.narrative = (DV_TEXT) value; // DV_TEXT
260          return value;
261        case 476403289: // expiry_time
262          this.expiry_time = (DV_DATE_TIME) value; // DV_DATE_TIME
263          return value;
264        case -199789373: // wf_definition
265          this.wf_definition = (DV_PARSABLE) value; // DV_PARSABLE
266          return value;
267        case 2048605165: // activities
268          this.getActivitiesList().add((ACTIVITY) value); // ACTIVITY
269          return value;
270        default: return super.setProperty(hash, name, value);
271        }
272
273      }
274
275      @Override
276      public Base setProperty(String name, Base value) throws FHIRException {
277        if (name.equals("narrative")) {
278          this.narrative = (DV_TEXT) value; // DV_TEXT
279        } else if (name.equals("expiry_time")) {
280          this.expiry_time = (DV_DATE_TIME) value; // DV_DATE_TIME
281        } else if (name.equals("wf_definition")) {
282          this.wf_definition = (DV_PARSABLE) value; // DV_PARSABLE
283        } else if (name.equals("activities")) {
284          this.getActivitiesList().add((ACTIVITY) value); // ACTIVITY
285        } else
286          return super.setProperty(name, value);
287        return value;
288      }
289
290      @Override
291      public Base makeProperty(int hash, String name) throws FHIRException {
292        switch (hash) {
293        case 1750452338:  return getNarrative();
294        case 476403289:  return getExpiry_time();
295        case -199789373:  return getWf_definition();
296        case 2048605165:  return addActivities(); 
297        default: return super.makeProperty(hash, name);
298        }
299
300      }
301
302      @Override
303      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
304        switch (hash) {
305        case 1750452338: /*narrative*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/DV-TEXT"};
306        case 476403289: /*expiry_time*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/DV-DATE-TIME"};
307        case -199789373: /*wf_definition*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/DV-PARSABLE"};
308        case 2048605165: /*activities*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/ACTIVITY"};
309        default: return super.getTypesForProperty(hash, name);
310        }
311
312      }
313
314      @Override
315      public Base addChild(String name) throws FHIRException {
316        if (name.equals("narrative")) {
317          this.narrative = new DV_TEXT();
318          return this.narrative;
319        }
320        else if (name.equals("expiry_time")) {
321          this.expiry_time = new DV_DATE_TIME();
322          return this.expiry_time;
323        }
324        else if (name.equals("wf_definition")) {
325          this.wf_definition = new DV_PARSABLE();
326          return this.wf_definition;
327        }
328        else if (name.equals("activities")) {
329          return addActivities();
330        }
331        else
332          return super.addChild(name);
333      }
334
335  public String fhirType() {
336    return "INSTRUCTION";
337
338  }
339
340      public INSTRUCTION copy() {
341        INSTRUCTION dst = new INSTRUCTION();
342        copyValues(dst);
343        return dst;
344      }
345
346      public void copyValues(INSTRUCTION dst) {
347        super.copyValues(dst);
348        dst.narrative = narrative == null ? null : narrative.copy();
349        dst.expiry_time = expiry_time == null ? null : expiry_time.copy();
350        dst.wf_definition = wf_definition == null ? null : wf_definition.copy();
351        if (activitiesList != null) {
352          dst.activitiesList = new ArrayList<ACTIVITY>();
353          for (ACTIVITY i : activitiesList)
354            dst.activitiesList.add(i.copy());
355        };
356      }
357
358      protected INSTRUCTION typedCopy() {
359        return copy();
360      }
361
362      @Override
363      public boolean equalsDeep(Base other_) {
364        if (!super.equalsDeep(other_))
365          return false;
366        if (!(other_ instanceof INSTRUCTION))
367          return false;
368        INSTRUCTION o = (INSTRUCTION) other_;
369        return compareDeep(narrative, o.narrative, true) && compareDeep(expiry_time, o.expiry_time, true)
370           && compareDeep(wf_definition, o.wf_definition, true) && compareDeep(activitiesList, o.activitiesList, true)
371          ;
372      }
373
374      @Override
375      public boolean equalsShallow(Base other_) {
376        if (!super.equalsShallow(other_))
377          return false;
378        if (!(other_ instanceof INSTRUCTION))
379          return false;
380        INSTRUCTION o = (INSTRUCTION) other_;
381        return true;
382      }
383
384      public boolean isEmpty() {
385        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(narrative, expiry_time, wf_definition
386          , activitiesList);
387      }
388
389
390}
391