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 org.apache.commons.lang3.builder.ToStringBuilder;
24  import org.apache.commons.lang3.builder.ToStringStyle;
25  
26  import javax.persistence.*;
27  import java.io.Serializable;
28  
29  import static org.apache.commons.lang3.StringUtils.left;
30  
31  //@formatter:off
32  @Table(name = "TRM_CODESYSTEM", uniqueConstraints = {
33  	@UniqueConstraint(name = "IDX_CS_CODESYSTEM", columnNames = {"CODE_SYSTEM_URI"})
34  })
35  @Entity()
36  //@formatter:on
37  public class TermCodeSystem implements Serializable {
38  	private static final long serialVersionUID = 1L;
39  	public static final int CS_NAME_LENGTH = 200;
40  
41  	@Column(name = "CODE_SYSTEM_URI", nullable = false)
42  	private String myCodeSystemUri;
43  
44  	@OneToOne()
45  	@JoinColumn(name = "CURRENT_VERSION_PID", referencedColumnName = "PID", nullable = true, foreignKey = @ForeignKey(name = "FK_TRMCODESYSTEM_CURVER"))
46  	private TermCodeSystemVersion myCurrentVersion;
47  	@Id()
48  	@SequenceGenerator(name = "SEQ_CODESYSTEM_PID", sequenceName = "SEQ_CODESYSTEM_PID")
49  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CODESYSTEM_PID")
50  	@Column(name = "PID")
51  	private Long myPid;
52  	@OneToOne()
53  	@JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "FK_TRMCODESYSTEM_RES"))
54  	private ResourceTable myResource;
55  	@Column(name = "RES_ID", insertable = false, updatable = false)
56  	private Long myResourcePid;
57  	@Column(name = "CS_NAME", nullable = true)
58  	private String myName;
59  
60  	public String getCodeSystemUri() {
61  		return myCodeSystemUri;
62  	}
63  
64  	public String getName() {
65  		return myName;
66  	}
67  
68  	public void setCodeSystemUri(String theCodeSystemUri) {
69  		myCodeSystemUri = theCodeSystemUri;
70  	}
71  
72  	public TermCodeSystemVersion getCurrentVersion() {
73  		return myCurrentVersion;
74  	}
75  
76  	public void setCurrentVersion(TermCodeSystemVersion theCurrentVersion) {
77  		myCurrentVersion = theCurrentVersion;
78  	}
79  
80  	public Long getPid() {
81  		return myPid;
82  	}
83  
84  	public ResourceTable getResource() {
85  		return myResource;
86  	}
87  
88  	public void setName(String theName) {
89  		myName = left(theName, CS_NAME_LENGTH);
90  	}
91  
92  	public void setResource(ResourceTable theResource) {
93  		myResource = theResource;
94  	}
95  
96  	@Override
97  	public String toString() {
98  		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
99  			.append("codeSystemUri", myCodeSystemUri)
100 			.append("currentVersion", myCurrentVersion)
101 			.append("pid", myPid)
102 			.append("resourcePid", myResourcePid)
103 			.append("name", myName)
104 			.toString();
105 	}
106 }