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