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.util.CoverageIgnore;
24  
25  import javax.persistence.*;
26  import java.io.Serializable;
27  import java.util.ArrayList;
28  import java.util.Collection;
29  
30  //@formatter:off
31  @Table(name = "TRM_CODESYSTEM_VER"
32  	// Note, we used to have a constraint named IDX_CSV_RESOURCEPID_AND_VER (don't reuse this)
33  )
34  @Entity()
35  //@formatter:on
36  public class TermCodeSystemVersion implements Serializable {
37  	private static final long serialVersionUID = 1L;
38  
39  	@OneToMany(fetch = FetchType.LAZY, mappedBy = "myCodeSystem")
40  	private Collection<TermConcept> myConcepts;
41  
42  	@Id()
43  	@SequenceGenerator(name = "SEQ_CODESYSTEMVER_PID", sequenceName = "SEQ_CODESYSTEMVER_PID")
44  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CODESYSTEMVER_PID")
45  	@Column(name = "PID")
46  	private Long myId;
47  
48  	@OneToOne()
49  	@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "FK_CODESYSVER_RES_ID"))
50  	private ResourceTable myResource;
51  
52  	@Column(name = "CS_VERSION_ID", nullable = true, updatable = false)
53  	private String myCodeSystemVersionId;
54  	/**
55  	 * This was added in HAPI FHIR 3.3.0 and is nullable just to avoid migration
56  	 * issued. It should be made non-nullable at some point.
57  	 */
58  	@ManyToOne
59  	@JoinColumn(name = "CODESYSTEM_PID", referencedColumnName = "PID", nullable = true, foreignKey = @ForeignKey(name = "FK_CODESYSVER_CS_ID"))
60  	private TermCodeSystem myCodeSystem;
61  	@SuppressWarnings("unused")
62  	@OneToOne(mappedBy = "myCurrentVersion", optional = true)
63  	private TermCodeSystem myCodeSystemHavingThisVersionAsCurrentVersionIfAny;
64  
65  	/**
66  	 * Constructor
67  	 */
68  	public TermCodeSystemVersion() {
69  		super();
70  	}
71  
72  	@CoverageIgnore
73  	@Override
74  	public boolean equals(Object obj) {
75  		if (this == obj) {
76  			return true;
77  		}
78  		if (obj == null) {
79  			return false;
80  		}
81  		if (!(obj instanceof TermCodeSystemVersion)) {
82  			return false;
83  		}
84  		TermCodeSystemVersion other = (TermCodeSystemVersion) obj;
85  		if ((myResource.getId() == null) != (other.myResource.getId() == null)) {
86  			return false;
87  		} else if (!myResource.getId().equals(other.myResource.getId())) {
88  			return false;
89  		}
90  
91  		if (myCodeSystemVersionId == null) {
92  			if (other.myCodeSystemVersionId != null) {
93  				return false;
94  			}
95  		} else if (!myCodeSystemVersionId.equals(other.myCodeSystemVersionId)) {
96  			return false;
97  		}
98  		return true;
99  	}
100 
101 	public TermCodeSystem getCodeSystem() {
102 		return myCodeSystem;
103 	}
104 
105 	public void setCodeSystem(TermCodeSystem theCodeSystem) {
106 		myCodeSystem = theCodeSystem;
107 	}
108 
109 	public String getCodeSystemVersionId() {
110 		return myCodeSystemVersionId;
111 	}
112 
113 	public void setCodeSystemVersionId(String theCodeSystemVersionId) {
114 		myCodeSystemVersionId = theCodeSystemVersionId;
115 	}
116 
117 	public Collection<TermConcept> getConcepts() {
118 		if (myConcepts == null) {
119 			myConcepts = new ArrayList<>();
120 		}
121 		return myConcepts;
122 	}
123 
124 	public Long getPid() {
125 		return myId;
126 	}
127 
128 	public ResourceTable getResource() {
129 		return myResource;
130 	}
131 
132 	public void setResource(ResourceTable theResource) {
133 		myResource = theResource;
134 	}
135 
136 	@Override
137 	public int hashCode() {
138 		final int prime = 31;
139 		int result = 1;
140 		result = prime * result + ((myResource.getId() == null) ? 0 : myResource.getId().hashCode());
141 		result = prime * result + ((myCodeSystemVersionId == null) ? 0 : myCodeSystemVersionId.hashCode());
142 		return result;
143 	}
144 
145 }