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 * Documents a Contribution (change set) of one or more versions added to a change-controlled repository.
049 */
050@DatatypeDef(name="CONTRIBUTION")
051public class CONTRIBUTION extends LogicalBase implements ICompositeType {
052
053    /**
054     * Unique identifier for this Contribution.
055     */
056    @Child(name = "uid", type = {HIER_OBJECT_ID.class}, order=0, min=1, max=1, modifier=false, summary=false)
057    @Description(shortDefinition="Unique identifier for this Contribution", formalDefinition="Unique identifier for this Contribution." )
058    protected HIER_OBJECT_ID uid;
059
060    /**
061     * Set of references to Versions causing changes to this EHR. Each contribution contains a list of versions, which may include paths pointing to any number of versionable items, i.e. items of types such as COMPOSITION and FOLDER.
062     */
063    @Child(name = "versions", type = {OBJECT_REF.class}, order=1, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
064    @Description(shortDefinition="Set of references to Versions causing changes to this EHR", formalDefinition="Set of references to Versions causing changes to this EHR. Each contribution contains a list of versions, which may include paths pointing to any number of versionable items, i.e. items of types such as COMPOSITION and FOLDER." )
065    protected List<OBJECT_REF> versionsList;
066
067    /**
068     * Audit trail corresponding to the committal of this Contribution.
069     */
070    @Child(name = "audit", type = {AUDIT_DETAILS.class}, order=2, min=1, max=1, modifier=false, summary=false)
071    @Description(shortDefinition="Audit trail corresponding to the committal of this Contribution", formalDefinition="Audit trail corresponding to the committal of this Contribution." )
072    protected AUDIT_DETAILS audit;
073
074    private static final long serialVersionUID = 2043766363L;
075
076  /**
077   * Constructor
078   */
079    public CONTRIBUTION() {
080      super();
081    }
082
083  /**
084   * Constructor
085   */
086    public CONTRIBUTION(HIER_OBJECT_ID uid, OBJECT_REF versions, AUDIT_DETAILS audit) {
087      super();
088      this.setUid(uid);
089      this.addVersions(versions);
090      this.setAudit(audit);
091    }
092
093    /**
094     * @return {@link #uid} (Unique identifier for this Contribution.)
095     */
096    public HIER_OBJECT_ID getUid() { 
097      if (this.uid == null)
098        if (Configuration.errorOnAutoCreate())
099          throw new Error("Attempt to auto-create CONTRIBUTION.uid");
100        else if (Configuration.doAutoCreate())
101          this.uid = new HIER_OBJECT_ID(); // cc
102      return this.uid;
103    }
104
105    public boolean hasUid() { 
106      return this.uid != null && !this.uid.isEmpty();
107    }
108
109    /**
110     * @param value {@link #uid} (Unique identifier for this Contribution.)
111     */
112    public CONTRIBUTION setUid(HIER_OBJECT_ID value) { 
113      this.uid = value;
114      return this;
115    }
116
117    /**
118     * @return {@link #versions} (Set of references to Versions causing changes to this EHR. Each contribution contains a list of versions, which may include paths pointing to any number of versionable items, i.e. items of types such as COMPOSITION and FOLDER.)
119     */
120    public List<OBJECT_REF> getVersionsList() { 
121      if (this.versionsList == null)
122        this.versionsList = new ArrayList<OBJECT_REF>();
123      return this.versionsList;
124    }
125
126    /**
127     * @return Returns a reference to <code>this</code> for easy method chaining
128     */
129    public CONTRIBUTION setVersionsList(List<OBJECT_REF> theVersions) { 
130      this.versionsList = theVersions;
131      return this;
132    }
133
134    public boolean hasVersions() { 
135      if (this.versionsList == null)
136        return false;
137      for (OBJECT_REF item : this.versionsList)
138        if (!item.isEmpty())
139          return true;
140      return false;
141    }
142
143    public OBJECT_REF addVersions() { //3a
144      OBJECT_REF t = new OBJECT_REF();
145      if (this.versionsList == null)
146        this.versionsList = new ArrayList<OBJECT_REF>();
147      this.versionsList.add(t);
148      return t;
149    }
150
151    public CONTRIBUTION addVersions(OBJECT_REF t) { //3b
152      if (t == null)
153        return this;
154      if (this.versionsList == null)
155        this.versionsList = new ArrayList<OBJECT_REF>();
156      this.versionsList.add(t);
157      return this;
158    }
159
160    /**
161     * @return The first repetition of repeating field {@link #versions}, creating it if it does not already exist {3}
162     */
163    public OBJECT_REF getVersionsFirstRep() { 
164      if (getVersionsList().isEmpty()) {
165        addVersions();
166      }
167      return getVersionsList().get(0);
168    }
169
170    /**
171     * @return {@link #audit} (Audit trail corresponding to the committal of this Contribution.)
172     */
173    public AUDIT_DETAILS getAudit() { 
174      if (this.audit == null)
175        if (Configuration.errorOnAutoCreate())
176          throw new Error("Attempt to auto-create CONTRIBUTION.audit");
177        else if (Configuration.doAutoCreate())
178          this.audit = new AUDIT_DETAILS(); // cc
179      return this.audit;
180    }
181
182    public boolean hasAudit() { 
183      return this.audit != null && !this.audit.isEmpty();
184    }
185
186    /**
187     * @param value {@link #audit} (Audit trail corresponding to the committal of this Contribution.)
188     */
189    public CONTRIBUTION setAudit(AUDIT_DETAILS value) { 
190      this.audit = value;
191      return this;
192    }
193
194      protected void listChildren(List<Property> children) {
195        super.listChildren(children);
196        children.add(new Property("uid", "http://openehr.org/fhir/StructureDefinition/HIER-OBJECT-ID", "Unique identifier for this Contribution.", 0, 1, uid));
197        children.add(new Property("versions", "http://openehr.org/fhir/StructureDefinition/OBJECT-REF", "Set of references to Versions causing changes to this EHR. Each contribution contains a list of versions, which may include paths pointing to any number of versionable items, i.e. items of types such as COMPOSITION and FOLDER.", 0, java.lang.Integer.MAX_VALUE, versionsList));
198        children.add(new Property("audit", "http://openehr.org/fhir/StructureDefinition/AUDIT-DETAILS", "Audit trail corresponding to the committal of this Contribution.", 0, 1, audit));
199      }
200
201      @Override
202      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
203        switch (_hash) {
204        case 115792: /*uid*/  return new Property("uid", "http://openehr.org/fhir/StructureDefinition/HIER-OBJECT-ID", "Unique identifier for this Contribution.", 0, 1, uid);
205        case -1985053029: /*versions*/  return new Property("versions", "http://openehr.org/fhir/StructureDefinition/OBJECT-REF", "Set of references to Versions causing changes to this EHR. Each contribution contains a list of versions, which may include paths pointing to any number of versionable items, i.e. items of types such as COMPOSITION and FOLDER.", 0, java.lang.Integer.MAX_VALUE, versionsList);
206        case 93166555: /*audit*/  return new Property("audit", "http://openehr.org/fhir/StructureDefinition/AUDIT-DETAILS", "Audit trail corresponding to the committal of this Contribution.", 0, 1, audit);
207        default: return super.getNamedProperty(_hash, _name, _checkValid);
208        }
209
210      }
211
212      @Override
213      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
214        switch (hash) {
215        case 115792: /*uid*/ return this.uid == null ? new Base[0] : new Base[] {this.uid}; // HIER_OBJECT_ID
216        case -1985053029: /*versions*/ return this.versionsList == null ? new Base[0] : this.versionsList.toArray(new Base[this.versionsList.size()]); // OBJECT_REF
217        case 93166555: /*audit*/ return this.audit == null ? new Base[0] : new Base[] {this.audit}; // AUDIT_DETAILS
218        default: return super.getProperty(hash, name, checkValid);
219        }
220
221      }
222
223      @Override
224      public Base setProperty(int hash, String name, Base value) throws FHIRException {
225        switch (hash) {
226        case 115792: // uid
227          this.uid = (HIER_OBJECT_ID) value; // HIER_OBJECT_ID
228          return value;
229        case -1985053029: // versions
230          this.getVersionsList().add((OBJECT_REF) value); // OBJECT_REF
231          return value;
232        case 93166555: // audit
233          this.audit = (AUDIT_DETAILS) value; // AUDIT_DETAILS
234          return value;
235        default: return super.setProperty(hash, name, value);
236        }
237
238      }
239
240      @Override
241      public Base setProperty(String name, Base value) throws FHIRException {
242        if (name.equals("uid")) {
243          this.uid = (HIER_OBJECT_ID) value; // HIER_OBJECT_ID
244        } else if (name.equals("versions")) {
245          this.getVersionsList().add((OBJECT_REF) value); // OBJECT_REF
246        } else if (name.equals("audit")) {
247          this.audit = (AUDIT_DETAILS) value; // AUDIT_DETAILS
248        } else
249          return super.setProperty(name, value);
250        return value;
251      }
252
253      @Override
254      public Base makeProperty(int hash, String name) throws FHIRException {
255        switch (hash) {
256        case 115792:  return getUid();
257        case -1985053029:  return addVersions(); 
258        case 93166555:  return getAudit();
259        default: return super.makeProperty(hash, name);
260        }
261
262      }
263
264      @Override
265      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
266        switch (hash) {
267        case 115792: /*uid*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/HIER-OBJECT-ID"};
268        case -1985053029: /*versions*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/OBJECT-REF"};
269        case 93166555: /*audit*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/AUDIT-DETAILS"};
270        default: return super.getTypesForProperty(hash, name);
271        }
272
273      }
274
275      @Override
276      public Base addChild(String name) throws FHIRException {
277        if (name.equals("uid")) {
278          this.uid = new HIER_OBJECT_ID();
279          return this.uid;
280        }
281        else if (name.equals("versions")) {
282          return addVersions();
283        }
284        else if (name.equals("audit")) {
285          this.audit = new AUDIT_DETAILS();
286          return this.audit;
287        }
288        else
289          return super.addChild(name);
290      }
291
292  public String fhirType() {
293    return "CONTRIBUTION";
294
295  }
296
297      public CONTRIBUTION copy() {
298        CONTRIBUTION dst = new CONTRIBUTION();
299        copyValues(dst);
300        return dst;
301      }
302
303      public void copyValues(CONTRIBUTION dst) {
304        super.copyValues(dst);
305        dst.uid = uid == null ? null : uid.copy();
306        if (versionsList != null) {
307          dst.versionsList = new ArrayList<OBJECT_REF>();
308          for (OBJECT_REF i : versionsList)
309            dst.versionsList.add(i.copy());
310        };
311        dst.audit = audit == null ? null : audit.copy();
312      }
313
314      protected CONTRIBUTION typedCopy() {
315        return copy();
316      }
317
318      @Override
319      public boolean equalsDeep(Base other_) {
320        if (!super.equalsDeep(other_))
321          return false;
322        if (!(other_ instanceof CONTRIBUTION))
323          return false;
324        CONTRIBUTION o = (CONTRIBUTION) other_;
325        return compareDeep(uid, o.uid, true) && compareDeep(versionsList, o.versionsList, true) && compareDeep(audit, o.audit, true)
326          ;
327      }
328
329      @Override
330      public boolean equalsShallow(Base other_) {
331        if (!super.equalsShallow(other_))
332          return false;
333        if (!(other_ instanceof CONTRIBUTION))
334          return false;
335        CONTRIBUTION o = (CONTRIBUTION) other_;
336        return true;
337      }
338
339      public boolean isEmpty() {
340        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(uid, versionsList, audit
341          );
342      }
343
344
345}
346