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