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 * Root object of a linear history, i.e. time series structure. This is a generic class whose type parameter must be a descendant of ITEM_STRUCTURE, ensuring that each Event in the events of a given instance is of the same structural type, i.e. ITEM_TREE, ITEM_LIST etc. For a periodic series of events, period will be set, and the time of each Event in the History must correspond; i.e. the EVENT.offset must be a multiple of period for each Event. Missing events in a period History are however allowed.
049 */
050@DatatypeDef(name="HISTORY")
051public class HISTORY extends DATA_STRUCTURE implements ICompositeType {
052
053    /**
054     * Time origin of this event history. The first event is not necessarily at the origin point.
055     */
056    @Child(name = "origin", type = {DV_DATE_TIME.class}, order=0, min=1, max=1, modifier=false, summary=false)
057    @Description(shortDefinition="Time origin of this event history", formalDefinition="Time origin of this event history. The first event is not necessarily at the origin point." )
058    protected DV_DATE_TIME origin;
059
060    /**
061     * Period between samples in this segment if periodic.
062     */
063    @Child(name = "period", type = {DV_DURATION.class}, order=1, min=0, max=1, modifier=false, summary=false)
064    @Description(shortDefinition="Period between samples in this segment if periodic", formalDefinition="Period between samples in this segment if periodic." )
065    protected DV_DURATION period;
066
067    /**
068     * Duration of the entire History; either corresponds to the duration of all the events, and/or the duration represented by the summary, if it exists.
069     */
070    @Child(name = "duration", type = {DV_DURATION.class}, order=2, min=0, max=1, modifier=false, summary=false)
071    @Description(shortDefinition="Duration of the entire History", formalDefinition="Duration of the entire History; either corresponds to the duration of all the events, and/or the duration represented by the summary, if it exists." )
072    protected DV_DURATION duration;
073
074    /**
075     * Optional summary data that aggregates, organizes, reduces and transforms the event series. This may be a text or image that presents a graphical presentation, or some data that assists with the interpretation of the data
076     */
077    @Child(name = "summary", type = {ITEM_STRUCTURE.class}, order=3, min=0, max=1, modifier=false, summary=false)
078    @Description(shortDefinition="Optional summary data that aggregates, organizes, reduces and transforms the event series", formalDefinition="Optional summary data that aggregates, organizes, reduces and transforms the event series. This may be a text or image that presents a graphical presentation, or some data that assists with the interpretation of the data" )
079    protected ITEM_STRUCTURE summary;
080
081    /**
082     * The events in the series. This attribute is of a generic type whose parameter must be a descendant of ITEM_STRUCTURE
083     */
084    @Child(name = "events", type = {EVENT.class}, order=4, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
085    @Description(shortDefinition="The events in the series", formalDefinition="The events in the series. This attribute is of a generic type whose parameter must be a descendant of ITEM_STRUCTURE" )
086    protected List<EVENT> eventsList;
087
088    private static final long serialVersionUID = 1582352314L;
089
090  /**
091   * Constructor
092   */
093    public HISTORY() {
094      super();
095    }
096
097  /**
098   * Constructor
099   */
100    public HISTORY(DV_DATE_TIME origin) {
101      super();
102      this.setOrigin(origin);
103    }
104
105    /**
106     * @return {@link #origin} (Time origin of this event history. The first event is not necessarily at the origin point.)
107     */
108    public DV_DATE_TIME getOrigin() { 
109      if (this.origin == null)
110        if (Configuration.errorOnAutoCreate())
111          throw new Error("Attempt to auto-create HISTORY.origin");
112        else if (Configuration.doAutoCreate())
113          this.origin = new DV_DATE_TIME(); // cc
114      return this.origin;
115    }
116
117    public boolean hasOrigin() { 
118      return this.origin != null && !this.origin.isEmpty();
119    }
120
121    /**
122     * @param value {@link #origin} (Time origin of this event history. The first event is not necessarily at the origin point.)
123     */
124    public HISTORY setOrigin(DV_DATE_TIME value) { 
125      this.origin = value;
126      return this;
127    }
128
129    /**
130     * @return {@link #period} (Period between samples in this segment if periodic.)
131     */
132    public DV_DURATION getPeriod() { 
133      if (this.period == null)
134        if (Configuration.errorOnAutoCreate())
135          throw new Error("Attempt to auto-create HISTORY.period");
136        else if (Configuration.doAutoCreate())
137          this.period = new DV_DURATION(); // cc
138      return this.period;
139    }
140
141    public boolean hasPeriod() { 
142      return this.period != null && !this.period.isEmpty();
143    }
144
145    /**
146     * @param value {@link #period} (Period between samples in this segment if periodic.)
147     */
148    public HISTORY setPeriod(DV_DURATION value) { 
149      this.period = value;
150      return this;
151    }
152
153    /**
154     * @return {@link #duration} (Duration of the entire History; either corresponds to the duration of all the events, and/or the duration represented by the summary, if it exists.)
155     */
156    public DV_DURATION getDuration() { 
157      if (this.duration == null)
158        if (Configuration.errorOnAutoCreate())
159          throw new Error("Attempt to auto-create HISTORY.duration");
160        else if (Configuration.doAutoCreate())
161          this.duration = new DV_DURATION(); // cc
162      return this.duration;
163    }
164
165    public boolean hasDuration() { 
166      return this.duration != null && !this.duration.isEmpty();
167    }
168
169    /**
170     * @param value {@link #duration} (Duration of the entire History; either corresponds to the duration of all the events, and/or the duration represented by the summary, if it exists.)
171     */
172    public HISTORY setDuration(DV_DURATION value) { 
173      this.duration = value;
174      return this;
175    }
176
177    /**
178     * @return {@link #summary} (Optional summary data that aggregates, organizes, reduces and transforms the event series. This may be a text or image that presents a graphical presentation, or some data that assists with the interpretation of the data)
179     */
180    public ITEM_STRUCTURE getSummary() { 
181      return this.summary;
182    }
183
184    public boolean hasSummary() { 
185      return this.summary != null && !this.summary.isEmpty();
186    }
187
188    /**
189     * @param value {@link #summary} (Optional summary data that aggregates, organizes, reduces and transforms the event series. This may be a text or image that presents a graphical presentation, or some data that assists with the interpretation of the data)
190     */
191    public HISTORY setSummary(ITEM_STRUCTURE value) { 
192      this.summary = value;
193      return this;
194    }
195
196    /**
197     * @return {@link #events} (The events in the series. This attribute is of a generic type whose parameter must be a descendant of ITEM_STRUCTURE)
198     */
199    public List<EVENT> getEventsList() { 
200      if (this.eventsList == null)
201        this.eventsList = new ArrayList<EVENT>();
202      return this.eventsList;
203    }
204
205    /**
206     * @return Returns a reference to <code>this</code> for easy method chaining
207     */
208    public HISTORY setEventsList(List<EVENT> theEvents) { 
209      this.eventsList = theEvents;
210      return this;
211    }
212
213    public boolean hasEvents() { 
214      if (this.eventsList == null)
215        return false;
216      for (EVENT item : this.eventsList)
217        if (!item.isEmpty())
218          return true;
219      return false;
220    }
221
222    public HISTORY addEvents(EVENT t) { //3b
223      if (t == null)
224        return this;
225      if (this.eventsList == null)
226        this.eventsList = new ArrayList<EVENT>();
227      this.eventsList.add(t);
228      return this;
229    }
230
231      protected void listChildren(List<Property> children) {
232        super.listChildren(children);
233        children.add(new Property("origin", "http://openehr.org/fhir/StructureDefinition/DV-DATE-TIME", "Time origin of this event history. The first event is not necessarily at the origin point.", 0, 1, origin));
234        children.add(new Property("period", "http://openehr.org/fhir/StructureDefinition/DV-DURATION", "Period between samples in this segment if periodic.", 0, 1, period));
235        children.add(new Property("duration", "http://openehr.org/fhir/StructureDefinition/DV-DURATION", "Duration of the entire History; either corresponds to the duration of all the events, and/or the duration represented by the summary, if it exists.", 0, 1, duration));
236        children.add(new Property("summary", "http://openehr.org/fhir/StructureDefinition/ITEM-STRUCTURE", "Optional summary data that aggregates, organizes, reduces and transforms the event series. This may be a text or image that presents a graphical presentation, or some data that assists with the interpretation of the data", 0, 1, summary));
237        children.add(new Property("events", "http://openehr.org/fhir/StructureDefinition/EVENT", "The events in the series. This attribute is of a generic type whose parameter must be a descendant of ITEM_STRUCTURE", 0, java.lang.Integer.MAX_VALUE, eventsList));
238      }
239
240      @Override
241      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
242        switch (_hash) {
243        case -1008619738: /*origin*/  return new Property("origin", "http://openehr.org/fhir/StructureDefinition/DV-DATE-TIME", "Time origin of this event history. The first event is not necessarily at the origin point.", 0, 1, origin);
244        case -991726143: /*period*/  return new Property("period", "http://openehr.org/fhir/StructureDefinition/DV-DURATION", "Period between samples in this segment if periodic.", 0, 1, period);
245        case -1992012396: /*duration*/  return new Property("duration", "http://openehr.org/fhir/StructureDefinition/DV-DURATION", "Duration of the entire History; either corresponds to the duration of all the events, and/or the duration represented by the summary, if it exists.", 0, 1, duration);
246        case -1857640538: /*summary*/  return new Property("summary", "http://openehr.org/fhir/StructureDefinition/ITEM-STRUCTURE", "Optional summary data that aggregates, organizes, reduces and transforms the event series. This may be a text or image that presents a graphical presentation, or some data that assists with the interpretation of the data", 0, 1, summary);
247        case -1291329255: /*events*/  return new Property("events", "http://openehr.org/fhir/StructureDefinition/EVENT", "The events in the series. This attribute is of a generic type whose parameter must be a descendant of ITEM_STRUCTURE", 0, java.lang.Integer.MAX_VALUE, eventsList);
248        default: return super.getNamedProperty(_hash, _name, _checkValid);
249        }
250
251      }
252
253      @Override
254      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
255        switch (hash) {
256        case -1008619738: /*origin*/ return this.origin == null ? new Base[0] : new Base[] {this.origin}; // DV_DATE_TIME
257        case -991726143: /*period*/ return this.period == null ? new Base[0] : new Base[] {this.period}; // DV_DURATION
258        case -1992012396: /*duration*/ return this.duration == null ? new Base[0] : new Base[] {this.duration}; // DV_DURATION
259        case -1857640538: /*summary*/ return this.summary == null ? new Base[0] : new Base[] {this.summary}; // ITEM_STRUCTURE
260        case -1291329255: /*events*/ return this.eventsList == null ? new Base[0] : this.eventsList.toArray(new Base[this.eventsList.size()]); // EVENT
261        default: return super.getProperty(hash, name, checkValid);
262        }
263
264      }
265
266      @Override
267      public Base setProperty(int hash, String name, Base value) throws FHIRException {
268        switch (hash) {
269        case -1008619738: // origin
270          this.origin = (DV_DATE_TIME) value; // DV_DATE_TIME
271          return value;
272        case -991726143: // period
273          this.period = (DV_DURATION) value; // DV_DURATION
274          return value;
275        case -1992012396: // duration
276          this.duration = (DV_DURATION) value; // DV_DURATION
277          return value;
278        case -1857640538: // summary
279          this.summary = (ITEM_STRUCTURE) value; // ITEM_STRUCTURE
280          return value;
281        case -1291329255: // events
282          this.getEventsList().add((EVENT) value); // EVENT
283          return value;
284        default: return super.setProperty(hash, name, value);
285        }
286
287      }
288
289      @Override
290      public Base setProperty(String name, Base value) throws FHIRException {
291        if (name.equals("origin")) {
292          this.origin = (DV_DATE_TIME) value; // DV_DATE_TIME
293        } else if (name.equals("period")) {
294          this.period = (DV_DURATION) value; // DV_DURATION
295        } else if (name.equals("duration")) {
296          this.duration = (DV_DURATION) value; // DV_DURATION
297        } else if (name.equals("summary")) {
298          this.summary = (ITEM_STRUCTURE) value; // ITEM_STRUCTURE
299        } else if (name.equals("events")) {
300          this.getEventsList().add((EVENT) value); // EVENT
301        } else
302          return super.setProperty(name, value);
303        return value;
304      }
305
306      @Override
307      public Base makeProperty(int hash, String name) throws FHIRException {
308        switch (hash) {
309        case -1008619738:  return getOrigin();
310        case -991726143:  return getPeriod();
311        case -1992012396:  return getDuration();
312        case -1857640538: /*div*/
313          throw new Error("Unable to make an instance of the abstract property 'summary'");
314        case -1291329255: /*div*/
315          throw new Error("Unable to make an instance of the abstract property 'events'");
316        default: return super.makeProperty(hash, name);
317        }
318
319      }
320
321      @Override
322      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
323        switch (hash) {
324        case -1008619738: /*origin*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/DV-DATE-TIME"};
325        case -991726143: /*period*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/DV-DURATION"};
326        case -1992012396: /*duration*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/DV-DURATION"};
327        case -1857640538: /*summary*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/ITEM-STRUCTURE"};
328        case -1291329255: /*events*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/EVENT"};
329        default: return super.getTypesForProperty(hash, name);
330        }
331
332      }
333
334      @Override
335      public Base addChild(String name) throws FHIRException {
336        if (name.equals("origin")) {
337          this.origin = new DV_DATE_TIME();
338          return this.origin;
339        }
340        else if (name.equals("period")) {
341          this.period = new DV_DURATION();
342          return this.period;
343        }
344        else if (name.equals("duration")) {
345          this.duration = new DV_DURATION();
346          return this.duration;
347        }
348        else if (name.equals("summary")) {
349          throw new FHIRException("Cannot call addChild on an abstract type HISTORY.summary");
350        }
351        else if (name.equals("events")) {
352          throw new FHIRException("Cannot call addChild on an abstract type HISTORY.events");
353        }
354        else
355          return super.addChild(name);
356      }
357
358  public String fhirType() {
359    return "HISTORY";
360
361  }
362
363      public HISTORY copy() {
364        HISTORY dst = new HISTORY();
365        copyValues(dst);
366        return dst;
367      }
368
369      public void copyValues(HISTORY dst) {
370        super.copyValues(dst);
371        dst.origin = origin == null ? null : origin.copy();
372        dst.period = period == null ? null : period.copy();
373        dst.duration = duration == null ? null : duration.copy();
374        dst.summary = summary == null ? null : summary.copy();
375        if (eventsList != null) {
376          dst.eventsList = new ArrayList<EVENT>();
377          for (EVENT i : eventsList)
378            dst.eventsList.add(i.copy());
379        };
380      }
381
382      protected HISTORY typedCopy() {
383        return copy();
384      }
385
386      @Override
387      public boolean equalsDeep(Base other_) {
388        if (!super.equalsDeep(other_))
389          return false;
390        if (!(other_ instanceof HISTORY))
391          return false;
392        HISTORY o = (HISTORY) other_;
393        return compareDeep(origin, o.origin, true) && compareDeep(period, o.period, true) && compareDeep(duration, o.duration, true)
394           && compareDeep(summary, o.summary, true) && compareDeep(eventsList, o.eventsList, true);
395      }
396
397      @Override
398      public boolean equalsShallow(Base other_) {
399        if (!super.equalsShallow(other_))
400          return false;
401        if (!(other_ instanceof HISTORY))
402          return false;
403        HISTORY o = (HISTORY) other_;
404        return true;
405      }
406
407      public boolean isEmpty() {
408        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(origin, period, duration
409          , summary, eventsList);
410      }
411
412
413}
414