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 * The concept of a named folder. It is strongly recommended that the inherited attribute uid be populated in top-level (i.e. tree-root) FOLDER objects, using the UID copied from the object_id() of the uid field of the enclosing VERSION object. For example, the ORIGINAL_VERSION.uid 87284370-2D4B-4e3d-A3F3-F303D2F4F34B::uk.nhs.ehr1::2 would be copied to the uid field of the top FOLDER object.
049 */
050@DatatypeDef(name="FOLDER")
051public class FOLDER extends LOCATABLE implements ICompositeType {
052
053    /**
054     * The list of references to other (usually) versioned objects logically in this folder.
055     */
056    @Child(name = "items", type = {OBJECT_REF.class}, order=0, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
057    @Description(shortDefinition="References to other (usually) versioned objects logically in this folder", formalDefinition="The list of references to other (usually) versioned objects logically in this folder." )
058    protected List<OBJECT_REF> itemsList;
059
060    /**
061     * Sub-folders of this FOLDER.
062     */
063    @Child(name = "folders", type = {FOLDER.class}, order=1, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
064    @Description(shortDefinition="Sub-folders of this FOLDER", formalDefinition="Sub-folders of this FOLDER." )
065    protected List<FOLDER> foldersList;
066
067    /**
068     * Archetypable meta-data for FOLDER.
069     */
070    @Child(name = "details", type = {ITEM_STRUCTURE.class}, order=2, min=0, max=1, modifier=false, summary=false)
071    @Description(shortDefinition="Archetypable meta-data for FOLDER", formalDefinition="Archetypable meta-data for FOLDER." )
072    protected ITEM_STRUCTURE details;
073
074    private static final long serialVersionUID = -979395577L;
075
076  /**
077   * Constructor
078   */
079    public FOLDER() {
080      super();
081    }
082
083    /**
084     * @return {@link #items} (The list of references to other (usually) versioned objects logically in this folder.)
085     */
086    public List<OBJECT_REF> getItemsList() { 
087      if (this.itemsList == null)
088        this.itemsList = new ArrayList<OBJECT_REF>();
089      return this.itemsList;
090    }
091
092    /**
093     * @return Returns a reference to <code>this</code> for easy method chaining
094     */
095    public FOLDER setItemsList(List<OBJECT_REF> theItems) { 
096      this.itemsList = theItems;
097      return this;
098    }
099
100    public boolean hasItems() { 
101      if (this.itemsList == null)
102        return false;
103      for (OBJECT_REF item : this.itemsList)
104        if (!item.isEmpty())
105          return true;
106      return false;
107    }
108
109    public OBJECT_REF addItems() { //3a
110      OBJECT_REF t = new OBJECT_REF();
111      if (this.itemsList == null)
112        this.itemsList = new ArrayList<OBJECT_REF>();
113      this.itemsList.add(t);
114      return t;
115    }
116
117    public FOLDER addItems(OBJECT_REF t) { //3b
118      if (t == null)
119        return this;
120      if (this.itemsList == null)
121        this.itemsList = new ArrayList<OBJECT_REF>();
122      this.itemsList.add(t);
123      return this;
124    }
125
126    /**
127     * @return The first repetition of repeating field {@link #items}, creating it if it does not already exist {3}
128     */
129    public OBJECT_REF getItemsFirstRep() { 
130      if (getItemsList().isEmpty()) {
131        addItems();
132      }
133      return getItemsList().get(0);
134    }
135
136    /**
137     * @return {@link #folders} (Sub-folders of this FOLDER.)
138     */
139    public List<FOLDER> getFoldersList() { 
140      if (this.foldersList == null)
141        this.foldersList = new ArrayList<FOLDER>();
142      return this.foldersList;
143    }
144
145    /**
146     * @return Returns a reference to <code>this</code> for easy method chaining
147     */
148    public FOLDER setFoldersList(List<FOLDER> theFolders) { 
149      this.foldersList = theFolders;
150      return this;
151    }
152
153    public boolean hasFolders() { 
154      if (this.foldersList == null)
155        return false;
156      for (FOLDER item : this.foldersList)
157        if (!item.isEmpty())
158          return true;
159      return false;
160    }
161
162    public FOLDER addFolders() { //3a
163      FOLDER t = new FOLDER();
164      if (this.foldersList == null)
165        this.foldersList = new ArrayList<FOLDER>();
166      this.foldersList.add(t);
167      return t;
168    }
169
170    public FOLDER addFolders(FOLDER t) { //3b
171      if (t == null)
172        return this;
173      if (this.foldersList == null)
174        this.foldersList = new ArrayList<FOLDER>();
175      this.foldersList.add(t);
176      return this;
177    }
178
179    /**
180     * @return The first repetition of repeating field {@link #folders}, creating it if it does not already exist {3}
181     */
182    public FOLDER getFoldersFirstRep() { 
183      if (getFoldersList().isEmpty()) {
184        addFolders();
185      }
186      return getFoldersList().get(0);
187    }
188
189    /**
190     * @return {@link #details} (Archetypable meta-data for FOLDER.)
191     */
192    public ITEM_STRUCTURE getDetails() { 
193      return this.details;
194    }
195
196    public boolean hasDetails() { 
197      return this.details != null && !this.details.isEmpty();
198    }
199
200    /**
201     * @param value {@link #details} (Archetypable meta-data for FOLDER.)
202     */
203    public FOLDER setDetails(ITEM_STRUCTURE value) { 
204      this.details = value;
205      return this;
206    }
207
208      protected void listChildren(List<Property> children) {
209        super.listChildren(children);
210        children.add(new Property("items", "http://openehr.org/fhir/StructureDefinition/OBJECT-REF", "The list of references to other (usually) versioned objects logically in this folder.", 0, java.lang.Integer.MAX_VALUE, itemsList));
211        children.add(new Property("folders", "http://openehr.org/fhir/StructureDefinition/FOLDER", "Sub-folders of this FOLDER.", 0, java.lang.Integer.MAX_VALUE, foldersList));
212        children.add(new Property("details", "http://openehr.org/fhir/StructureDefinition/ITEM-STRUCTURE", "Archetypable meta-data for FOLDER.", 0, 1, details));
213      }
214
215      @Override
216      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
217        switch (_hash) {
218        case 100526016: /*items*/  return new Property("items", "http://openehr.org/fhir/StructureDefinition/OBJECT-REF", "The list of references to other (usually) versioned objects logically in this folder.", 0, java.lang.Integer.MAX_VALUE, itemsList);
219        case -683249211: /*folders*/  return new Property("folders", "http://openehr.org/fhir/StructureDefinition/FOLDER", "Sub-folders of this FOLDER.", 0, java.lang.Integer.MAX_VALUE, foldersList);
220        case 1557721666: /*details*/  return new Property("details", "http://openehr.org/fhir/StructureDefinition/ITEM-STRUCTURE", "Archetypable meta-data for FOLDER.", 0, 1, details);
221        default: return super.getNamedProperty(_hash, _name, _checkValid);
222        }
223
224      }
225
226      @Override
227      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
228        switch (hash) {
229        case 100526016: /*items*/ return this.itemsList == null ? new Base[0] : this.itemsList.toArray(new Base[this.itemsList.size()]); // OBJECT_REF
230        case -683249211: /*folders*/ return this.foldersList == null ? new Base[0] : this.foldersList.toArray(new Base[this.foldersList.size()]); // FOLDER
231        case 1557721666: /*details*/ return this.details == null ? new Base[0] : new Base[] {this.details}; // ITEM_STRUCTURE
232        default: return super.getProperty(hash, name, checkValid);
233        }
234
235      }
236
237      @Override
238      public Base setProperty(int hash, String name, Base value) throws FHIRException {
239        switch (hash) {
240        case 100526016: // items
241          this.getItemsList().add((OBJECT_REF) value); // OBJECT_REF
242          return value;
243        case -683249211: // folders
244          this.getFoldersList().add((FOLDER) value); // FOLDER
245          return value;
246        case 1557721666: // details
247          this.details = (ITEM_STRUCTURE) value; // ITEM_STRUCTURE
248          return value;
249        default: return super.setProperty(hash, name, value);
250        }
251
252      }
253
254      @Override
255      public Base setProperty(String name, Base value) throws FHIRException {
256        if (name.equals("items")) {
257          this.getItemsList().add((OBJECT_REF) value); // OBJECT_REF
258        } else if (name.equals("folders")) {
259          this.getFoldersList().add((FOLDER) value); // FOLDER
260        } else if (name.equals("details")) {
261          this.details = (ITEM_STRUCTURE) value; // ITEM_STRUCTURE
262        } else
263          return super.setProperty(name, value);
264        return value;
265      }
266
267      @Override
268      public Base makeProperty(int hash, String name) throws FHIRException {
269        switch (hash) {
270        case 100526016:  return addItems(); 
271        case -683249211:  return addFolders(); 
272        case 1557721666: /*div*/
273          throw new Error("Unable to make an instance of the abstract property 'details'");
274        default: return super.makeProperty(hash, name);
275        }
276
277      }
278
279      @Override
280      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
281        switch (hash) {
282        case 100526016: /*items*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/OBJECT-REF"};
283        case -683249211: /*folders*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/FOLDER"};
284        case 1557721666: /*details*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/ITEM-STRUCTURE"};
285        default: return super.getTypesForProperty(hash, name);
286        }
287
288      }
289
290      @Override
291      public Base addChild(String name) throws FHIRException {
292        if (name.equals("items")) {
293          return addItems();
294        }
295        else if (name.equals("folders")) {
296          return addFolders();
297        }
298        else if (name.equals("details")) {
299          throw new FHIRException("Cannot call addChild on an abstract type FOLDER.details");
300        }
301        else
302          return super.addChild(name);
303      }
304
305  public String fhirType() {
306    return "FOLDER";
307
308  }
309
310      public FOLDER copy() {
311        FOLDER dst = new FOLDER();
312        copyValues(dst);
313        return dst;
314      }
315
316      public void copyValues(FOLDER dst) {
317        super.copyValues(dst);
318        if (itemsList != null) {
319          dst.itemsList = new ArrayList<OBJECT_REF>();
320          for (OBJECT_REF i : itemsList)
321            dst.itemsList.add(i.copy());
322        };
323        if (foldersList != null) {
324          dst.foldersList = new ArrayList<FOLDER>();
325          for (FOLDER i : foldersList)
326            dst.foldersList.add(i.copy());
327        };
328        dst.details = details == null ? null : details.copy();
329      }
330
331      protected FOLDER typedCopy() {
332        return copy();
333      }
334
335      @Override
336      public boolean equalsDeep(Base other_) {
337        if (!super.equalsDeep(other_))
338          return false;
339        if (!(other_ instanceof FOLDER))
340          return false;
341        FOLDER o = (FOLDER) other_;
342        return compareDeep(itemsList, o.itemsList, true) && compareDeep(foldersList, o.foldersList, true)
343           && compareDeep(details, o.details, true);
344      }
345
346      @Override
347      public boolean equalsShallow(Base other_) {
348        if (!super.equalsShallow(other_))
349          return false;
350        if (!(other_ instanceof FOLDER))
351          return false;
352        FOLDER o = (FOLDER) other_;
353        return true;
354      }
355
356      public boolean isEmpty() {
357        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(itemsList, foldersList, details
358          );
359      }
360
361
362}
363