View Javadoc
1   package ca.uhn.fhir.jpa.entity;
2   
3   /*
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.context.FhirVersionEnum;
24  import ca.uhn.fhir.model.primitive.IdDt;
25  import ca.uhn.fhir.model.primitive.InstantDt;
26  import org.hibernate.annotations.OptimisticLock;
27  
28  import javax.persistence.*;
29  import java.util.Collection;
30  import java.util.Date;
31  
32  @MappedSuperclass
33  public abstract class BaseHasResource {
34  
35  	@Column(name = "RES_DELETED_AT", nullable = true)
36  	@Temporal(TemporalType.TIMESTAMP)
37  	private Date myDeleted;
38  
39  	// TODO: move to resource history table
40  	@Column(name = "RES_VERSION", nullable = true, length = 7)
41  	@Enumerated(EnumType.STRING)
42  	@OptimisticLock(excluded = true)
43  	private FhirVersionEnum myFhirVersion;
44  
45  	@OneToOne(optional = true, fetch = FetchType.EAGER, cascade = {}, orphanRemoval = false)
46  	@JoinColumn(name = "FORCED_ID_PID")
47  	@OptimisticLock(excluded = true)
48  	private ForcedId myForcedId;
49  
50  	@Column(name = "HAS_TAGS", nullable = false)
51  	@OptimisticLock(excluded = true)
52  	private boolean myHasTags;
53  
54  	@Temporal(TemporalType.TIMESTAMP)
55  	@Column(name = "RES_PUBLISHED", nullable = false)
56  	@OptimisticLock(excluded = true)
57  	private Date myPublished;
58  
59  	@Temporal(TemporalType.TIMESTAMP)
60  	@Column(name = "RES_UPDATED", nullable = false)
61  	@OptimisticLock(excluded = true)
62  	private Date myUpdated;
63  
64  	public abstract BaseTag addTag(TagDefinition theDef);
65  
66  	public Date getDeleted() {
67  		return myDeleted;
68  	}
69  
70  	public void setDeleted(Date theDate) {
71  		myDeleted = theDate;
72  	}
73  
74  
75  	public FhirVersionEnum getFhirVersion() {
76  		return myFhirVersion;
77  	}
78  
79  	public void setFhirVersion(FhirVersionEnum theFhirVersion) {
80  		myFhirVersion = theFhirVersion;
81  	}
82  
83  	public ForcedId getForcedId() {
84  		return myForcedId;
85  	}
86  
87  	public void setForcedId(ForcedId theForcedId) {
88  		myForcedId = theForcedId;
89  	}
90  
91  	public abstract Long getId();
92  
93  	public abstract IdDt getIdDt();
94  
95  	public InstantDt getPublished() {
96  		if (myPublished != null) {
97  			return new InstantDt(myPublished);
98  		} else {
99  			return null;
100 		}
101 	}
102 
103 	public void setPublished(Date thePublished) {
104 		myPublished = thePublished;
105 	}
106 
107 	public abstract Long getResourceId();
108 
109 	public abstract String getResourceType();
110 
111 	public abstract Collection<? extends BaseTag> getTags();
112 
113 	public InstantDt getUpdated() {
114 		return new InstantDt(myUpdated);
115 	}
116 
117 	public void setUpdated(Date theUpdated) {
118 		myUpdated = theUpdated;
119 	}
120 
121 	public Date getUpdatedDate() {
122 		return myUpdated;
123 	}
124 
125 	public abstract long getVersion();
126 
127 	public boolean isHasTags() {
128 		return myHasTags;
129 	}
130 
131 	public void setHasTags(boolean theHasTags) {
132 		myHasTags = theHasTags;
133 	}
134 
135 	public void setPublished(InstantDt thePublished) {
136 		myPublished = thePublished.getValue();
137 	}
138 
139 	public void setUpdated(InstantDt theUpdated) {
140 		myUpdated = theUpdated.getValue();
141 	}
142 
143 }