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 java.io.Serializable;
24  
25  import javax.persistence.Column;
26  import javax.persistence.Entity;
27  import javax.persistence.EnumType;
28  import javax.persistence.Enumerated;
29  import javax.persistence.ForeignKey;
30  import javax.persistence.GeneratedValue;
31  import javax.persistence.GenerationType;
32  import javax.persistence.Id;
33  import javax.persistence.JoinColumn;
34  import javax.persistence.ManyToOne;
35  import javax.persistence.SequenceGenerator;
36  import javax.persistence.Table;
37  
38  @Entity
39  @Table(name = "TRM_CONCEPT_PC_LINK")
40  public class TermConceptParentChildLink implements Serializable {
41  	private static final long serialVersionUID = 1L;
42  
43  	@ManyToOne()
44  	@JoinColumn(name = "CHILD_PID", nullable = false, referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_TERM_CONCEPTPC_CHILD"))
45  	private TermConcept myChild;
46  
47  	@Column(name = "CHILD_PID", insertable = false, updatable = false)
48  	private Long myChildPid;
49  
50  	@ManyToOne()
51  	@JoinColumn(name = "CODESYSTEM_PID", nullable = false, foreignKey = @ForeignKey(name = "FK_TERM_CONCEPTPC_CS"))
52  	private TermCodeSystemVersion myCodeSystem;
53  
54  	@ManyToOne(cascade = {})
55  	@JoinColumn(name = "PARENT_PID", nullable = false, referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_TERM_CONCEPTPC_PARENT"))
56  	private TermConcept myParent;
57  
58  	@Column(name = "PARENT_PID", insertable = false, updatable = false)
59  	private Long myParentPid;
60  
61  	@Id()
62  	@SequenceGenerator(name = "SEQ_CONCEPT_PC_PID", sequenceName = "SEQ_CONCEPT_PC_PID")
63  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_PC_PID")
64  	@Column(name = "PID")
65  	private Long myPid;
66  
67  	@Enumerated(EnumType.ORDINAL)
68  	@Column(name = "REL_TYPE", length = 5, nullable = true)
69  	private RelationshipTypeEnum myRelationshipType;
70  
71  	@Override
72  	public boolean equals(Object obj) {
73  		if (this == obj)
74  			return true;
75  		if (obj == null)
76  			return false;
77  		if (getClass() != obj.getClass())
78  			return false;
79  		TermConceptParentChildLink other = (TermConceptParentChildLink) obj;
80  		if (myChild == null) {
81  			if (other.myChild != null)
82  				return false;
83  		} else if (!myChild.equals(other.myChild))
84  			return false;
85  		if (myCodeSystem == null) {
86  			if (other.myCodeSystem != null)
87  				return false;
88  		} else if (!myCodeSystem.equals(other.myCodeSystem))
89  			return false;
90  		if (myParent == null) {
91  			if (other.myParent != null)
92  				return false;
93  		} else if (!myParent.equals(other.myParent))
94  			return false;
95  		if (myRelationshipType != other.myRelationshipType)
96  			return false;
97  		return true;
98  	}
99  
100 	public TermConcept getChild() {
101 		return myChild;
102 	}
103 
104 	public Long getChildPid() {
105 		return myChildPid;
106 	}
107 
108 	public TermCodeSystemVersion getCodeSystem() {
109 		return myCodeSystem;
110 	}
111 
112 	public Long getId() {
113 		return myPid;
114 	}
115 
116 	public TermConcept getParent() {
117 		return myParent;
118 	}
119 
120 	public Long getParentPid() {
121 		return myParentPid;
122 	}
123 
124 	public RelationshipTypeEnum getRelationshipType() {
125 		return myRelationshipType;
126 	}
127 
128 	@Override
129 	public int hashCode() {
130 		final int prime = 31;
131 		int result = 1;
132 		result = prime * result + ((myChild == null) ? 0 : myChild.hashCode());
133 		result = prime * result + ((myCodeSystem == null) ? 0 : myCodeSystem.hashCode());
134 		result = prime * result + ((myParent == null) ? 0 : myParent.hashCode());
135 		result = prime * result + ((myRelationshipType == null) ? 0 : myRelationshipType.hashCode());
136 		return result;
137 	}
138 
139 	public void setChild(TermConcept theChild) {
140 		myChild = theChild;
141 	}
142 
143 	public void setCodeSystem(TermCodeSystemVersion theCodeSystem) {
144 		myCodeSystem = theCodeSystem;
145 	}
146 
147 	public void setParent(TermConcept theParent) {
148 		myParent = theParent;
149 	}
150 
151 	public void setRelationshipType(RelationshipTypeEnum theRelationshipType) {
152 		myRelationshipType = theRelationshipType;
153 	}
154 
155 	public enum RelationshipTypeEnum {
156 		// ********************************************
157 		// IF YOU ADD HERE MAKE SURE ORDER IS PRESERVED
158 		ISA
159 	}
160 }