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 * An entry in a revision history, corresponding to a version from a versioned container. Consists of AUDIT_DETAILS instances with revision identifier of the revision to which the AUDIT_DETAILS instance belongs.
049 */
050@DatatypeDef(name="REVISION_HISTORY_ITEM")
051public class REVISION_HISTORY_ITEM extends LogicalBase implements ICompositeType {
052
053    /**
054     * Version identifier for this revision.
055     */
056    @Child(name = "version_id", type = {OBJECT_VERSION_ID.class}, order=0, min=1, max=1, modifier=false, summary=false)
057    @Description(shortDefinition="Version identifier for this revision", formalDefinition="Version identifier for this revision." )
058    protected OBJECT_VERSION_ID version_id;
059
060    /**
061     * The audits for this revision; there will always be at least one commit audit (which may itself be an ATTESTATION), there may also be further attestations.
062     */
063    @Child(name = "audits", type = {AUDIT_DETAILS.class}, order=1, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
064    @Description(shortDefinition="The audits for this revision (at least one)", formalDefinition="The audits for this revision; there will always be at least one commit audit (which may itself be an ATTESTATION), there may also be further attestations." )
065    protected List<AUDIT_DETAILS> auditsList;
066
067    private static final long serialVersionUID = -444855928L;
068
069  /**
070   * Constructor
071   */
072    public REVISION_HISTORY_ITEM() {
073      super();
074    }
075
076  /**
077   * Constructor
078   */
079    public REVISION_HISTORY_ITEM(OBJECT_VERSION_ID version_id, AUDIT_DETAILS audits) {
080      super();
081      this.setVersion_id(version_id);
082      this.addAudits(audits);
083    }
084
085    /**
086     * @return {@link #version_id} (Version identifier for this revision.)
087     */
088    public OBJECT_VERSION_ID getVersion_id() { 
089      if (this.version_id == null)
090        if (Configuration.errorOnAutoCreate())
091          throw new Error("Attempt to auto-create REVISION_HISTORY_ITEM.version_id");
092        else if (Configuration.doAutoCreate())
093          this.version_id = new OBJECT_VERSION_ID(); // cc
094      return this.version_id;
095    }
096
097    public boolean hasVersion_id() { 
098      return this.version_id != null && !this.version_id.isEmpty();
099    }
100
101    /**
102     * @param value {@link #version_id} (Version identifier for this revision.)
103     */
104    public REVISION_HISTORY_ITEM setVersion_id(OBJECT_VERSION_ID value) { 
105      this.version_id = value;
106      return this;
107    }
108
109    /**
110     * @return {@link #audits} (The audits for this revision; there will always be at least one commit audit (which may itself be an ATTESTATION), there may also be further attestations.)
111     */
112    public List<AUDIT_DETAILS> getAuditsList() { 
113      if (this.auditsList == null)
114        this.auditsList = new ArrayList<AUDIT_DETAILS>();
115      return this.auditsList;
116    }
117
118    /**
119     * @return Returns a reference to <code>this</code> for easy method chaining
120     */
121    public REVISION_HISTORY_ITEM setAuditsList(List<AUDIT_DETAILS> theAudits) { 
122      this.auditsList = theAudits;
123      return this;
124    }
125
126    public boolean hasAudits() { 
127      if (this.auditsList == null)
128        return false;
129      for (AUDIT_DETAILS item : this.auditsList)
130        if (!item.isEmpty())
131          return true;
132      return false;
133    }
134
135    public AUDIT_DETAILS addAudits() { //3a
136      AUDIT_DETAILS t = new AUDIT_DETAILS();
137      if (this.auditsList == null)
138        this.auditsList = new ArrayList<AUDIT_DETAILS>();
139      this.auditsList.add(t);
140      return t;
141    }
142
143    public REVISION_HISTORY_ITEM addAudits(AUDIT_DETAILS t) { //3b
144      if (t == null)
145        return this;
146      if (this.auditsList == null)
147        this.auditsList = new ArrayList<AUDIT_DETAILS>();
148      this.auditsList.add(t);
149      return this;
150    }
151
152    /**
153     * @return The first repetition of repeating field {@link #audits}, creating it if it does not already exist {3}
154     */
155    public AUDIT_DETAILS getAuditsFirstRep() { 
156      if (getAuditsList().isEmpty()) {
157        addAudits();
158      }
159      return getAuditsList().get(0);
160    }
161
162      protected void listChildren(List<Property> children) {
163        super.listChildren(children);
164        children.add(new Property("version_id", "http://openehr.org/fhir/StructureDefinition/OBJECT-VERSION-ID", "Version identifier for this revision.", 0, 1, version_id));
165        children.add(new Property("audits", "http://openehr.org/fhir/StructureDefinition/AUDIT-DETAILS", "The audits for this revision; there will always be at least one commit audit (which may itself be an ATTESTATION), there may also be further attestations.", 0, java.lang.Integer.MAX_VALUE, auditsList));
166      }
167
168      @Override
169      public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException {
170        switch (_hash) {
171        case -670497310: /*version_id*/  return new Property("version_id", "http://openehr.org/fhir/StructureDefinition/OBJECT-VERSION-ID", "Version identifier for this revision.", 0, 1, version_id);
172        case -1406803976: /*audits*/  return new Property("audits", "http://openehr.org/fhir/StructureDefinition/AUDIT-DETAILS", "The audits for this revision; there will always be at least one commit audit (which may itself be an ATTESTATION), there may also be further attestations.", 0, java.lang.Integer.MAX_VALUE, auditsList);
173        default: return super.getNamedProperty(_hash, _name, _checkValid);
174        }
175
176      }
177
178      @Override
179      public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
180        switch (hash) {
181        case -670497310: /*version_id*/ return this.version_id == null ? new Base[0] : new Base[] {this.version_id}; // OBJECT_VERSION_ID
182        case -1406803976: /*audits*/ return this.auditsList == null ? new Base[0] : this.auditsList.toArray(new Base[this.auditsList.size()]); // AUDIT_DETAILS
183        default: return super.getProperty(hash, name, checkValid);
184        }
185
186      }
187
188      @Override
189      public Base setProperty(int hash, String name, Base value) throws FHIRException {
190        switch (hash) {
191        case -670497310: // version_id
192          this.version_id = (OBJECT_VERSION_ID) value; // OBJECT_VERSION_ID
193          return value;
194        case -1406803976: // audits
195          this.getAuditsList().add((AUDIT_DETAILS) value); // AUDIT_DETAILS
196          return value;
197        default: return super.setProperty(hash, name, value);
198        }
199
200      }
201
202      @Override
203      public Base setProperty(String name, Base value) throws FHIRException {
204        if (name.equals("version_id")) {
205          this.version_id = (OBJECT_VERSION_ID) value; // OBJECT_VERSION_ID
206        } else if (name.equals("audits")) {
207          this.getAuditsList().add((AUDIT_DETAILS) value); // AUDIT_DETAILS
208        } else
209          return super.setProperty(name, value);
210        return value;
211      }
212
213      @Override
214      public Base makeProperty(int hash, String name) throws FHIRException {
215        switch (hash) {
216        case -670497310:  return getVersion_id();
217        case -1406803976:  return addAudits(); 
218        default: return super.makeProperty(hash, name);
219        }
220
221      }
222
223      @Override
224      public String[] getTypesForProperty(int hash, String name) throws FHIRException {
225        switch (hash) {
226        case -670497310: /*version_id*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/OBJECT-VERSION-ID"};
227        case -1406803976: /*audits*/ return new String[] {"http://openehr.org/fhir/StructureDefinition/AUDIT-DETAILS"};
228        default: return super.getTypesForProperty(hash, name);
229        }
230
231      }
232
233      @Override
234      public Base addChild(String name) throws FHIRException {
235        if (name.equals("version_id")) {
236          this.version_id = new OBJECT_VERSION_ID();
237          return this.version_id;
238        }
239        else if (name.equals("audits")) {
240          return addAudits();
241        }
242        else
243          return super.addChild(name);
244      }
245
246  public String fhirType() {
247    return "REVISION_HISTORY_ITEM";
248
249  }
250
251      public REVISION_HISTORY_ITEM copy() {
252        REVISION_HISTORY_ITEM dst = new REVISION_HISTORY_ITEM();
253        copyValues(dst);
254        return dst;
255      }
256
257      public void copyValues(REVISION_HISTORY_ITEM dst) {
258        super.copyValues(dst);
259        dst.version_id = version_id == null ? null : version_id.copy();
260        if (auditsList != null) {
261          dst.auditsList = new ArrayList<AUDIT_DETAILS>();
262          for (AUDIT_DETAILS i : auditsList)
263            dst.auditsList.add(i.copy());
264        };
265      }
266
267      protected REVISION_HISTORY_ITEM typedCopy() {
268        return copy();
269      }
270
271      @Override
272      public boolean equalsDeep(Base other_) {
273        if (!super.equalsDeep(other_))
274          return false;
275        if (!(other_ instanceof REVISION_HISTORY_ITEM))
276          return false;
277        REVISION_HISTORY_ITEM o = (REVISION_HISTORY_ITEM) other_;
278        return compareDeep(version_id, o.version_id, true) && compareDeep(auditsList, o.auditsList, true)
279          ;
280      }
281
282      @Override
283      public boolean equalsShallow(Base other_) {
284        if (!super.equalsShallow(other_))
285          return false;
286        if (!(other_ instanceof REVISION_HISTORY_ITEM))
287          return false;
288        REVISION_HISTORY_ITEM o = (REVISION_HISTORY_ITEM) other_;
289        return true;
290      }
291
292      public boolean isEmpty() {
293        return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(version_id, auditsList);
294      }
295
296
297}
298