001/*-
002 * #%L
003 * HAPI FHIR JPA Model
004 * %%
005 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.model.entity;
021
022import jakarta.persistence.Column;
023import jakarta.persistence.EmbeddedId;
024import jakarta.persistence.Entity;
025import jakarta.persistence.Table;
026
027import java.util.Objects;
028
029import static ca.uhn.fhir.jpa.model.entity.ResourceTable.FHIR_ID;
030import static ca.uhn.fhir.jpa.model.entity.ResourceTable.FHIR_ID_LENGTH;
031
032@Entity
033@Table(name = "HFJ_RES_IDENTIFIER_PT_UNIQ")
034public class ResourceIdentifierPatientUniqueEntity {
035
036        @EmbeddedId
037        private PatientIdentifierPk myPk;
038
039        @Column(name = FHIR_ID, length = FHIR_ID_LENGTH, nullable = false)
040        private String myFhirId;
041
042        public void setPk(PatientIdentifierPk thePk) {
043                myPk = thePk;
044        }
045
046        public String getFhirId() {
047                return myFhirId;
048        }
049
050        public void setFhirId(String theFhirId) {
051                myFhirId = theFhirId;
052        }
053
054        public static class PatientIdentifierPk {
055
056                @Column(name = "IDENT_SYSTEM_PID")
057                private Long mySystemPid;
058
059                @Column(name = "IDENT_VALUE", length = 500)
060                private String myValue;
061
062                /**
063                 * Constructor
064                 */
065                public PatientIdentifierPk() {
066                        // nothing
067                }
068
069                /**
070                 * Constructor
071                 */
072                public PatientIdentifierPk(Long theSystemPid, String theValue) {
073                        mySystemPid = theSystemPid;
074                        myValue = theValue;
075                }
076
077                @Override
078                public boolean equals(Object theO) {
079                        if (!(theO instanceof PatientIdentifierPk that)) {
080                                return false;
081                        }
082                        return Objects.equals(mySystemPid, that.mySystemPid) && Objects.equals(myValue, that.myValue);
083                }
084
085                @Override
086                public int hashCode() {
087                        return Objects.hash(mySystemPid, myValue);
088                }
089        }
090}