Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-1351 | Change operation opeFor field to enum #1427

Merged
102 changes: 51 additions & 51 deletions sql/load_demo_data.sql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sql/step_04_all_following_steps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ source step_a106_medicaldsrstock_control.sql;
source step_a107_add_permission_admin_access.sql;
source step_a108_audit_dicom_type_and_dicom_data.sql;
source step_a109_update_user_settings_table_constraints_and_add_usergroups_permissions.sql;
source step_a110_update_operations_table_change_ope_for_to_enum.sql;
11 changes: 11 additions & 0 deletions sql/step_a110_update_operations_table_change_ope_for_to_enum.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ALTER TABLE OH_OPERATION MODIFY COLUMN OPE_FOR VARCHAR(20);

UPDATE OH_OPERATION
SET OPE_FOR='opd_admission' WHERE OPE_FOR='1';
UPDATE OH_OPERATION
SET OPE_FOR='admission' WHERE OPE_FOR='2';
UPDATE OH_OPERATION
SET OPE_FOR='opd' WHERE OPE_FOR='3';

ALTER TABLE OH_OPERATION
MODIFY COLUMN OPE_FOR ENUM('opd', 'admission', 'opd_admission') DEFAULT 'opd_admission';
SteveGT96 marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 additions & 0 deletions src/main/java/org/isf/operation/enums/OperationTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Open Hospital (www.open-hospital.org)
* Copyright © 2006-2024 Informatici Senza Frontiere ([email protected])
*
* Open Hospital is a free and open source software for healthcare data management.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* https://www.gnu.org/licenses/gpl-3.0-standalone.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.isf.operation.enums;
mwithi marked this conversation as resolved.
Show resolved Hide resolved

public enum OperationTarget {
opd, admission, opd_admission;
}
194 changes: 96 additions & 98 deletions src/main/java/org/isf/operation/model/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
Expand All @@ -33,12 +35,13 @@
import jakarta.persistence.Version;
import jakarta.validation.constraints.NotNull;

import org.isf.operation.enums.OperationTarget;
import org.isf.opetype.model.OperationType;
import org.isf.utils.db.Auditable;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@Entity
@Table(name="OH_OPERATION")
@Table(name = "OH_OPERATION")
@EntityListeners(AuditingEntityListener.class)
@AttributeOverride(name = "createdBy", column = @Column(name = "OPE_CREATED_BY", updatable = false))
@AttributeOverride(name = "createdDate", column = @Column(name = "OPE_CREATED_DATE", updatable = false))
Expand All @@ -48,39 +51,33 @@
public class Operation extends Auditable<String> {

@Id
@Column(name="OPE_ID_A")
private String code;
@Column(name = "OPE_ID_A")
private String code;

@NotNull
@Column(name="OPE_DESC")
private String description;
@Column(name = "OPE_DESC")
private String description;

@NotNull
@ManyToOne
@JoinColumn(name="OPE_OCL_ID_A")
private OperationType type;
@JoinColumn(name = "OPE_OCL_ID_A")
private OperationType type;

@NotNull
@Column(name="OPE_STAT")
private Integer major;

/*
* //TODO: replace "integers" values with mnemonic ones, CHAR(1) -> VARCHAR(10)
* "1" = OPD / ADMISSION
* "2" = ADMISSION
* "3" = OPD
*/
@Column(name="OPE_FOR")
private String operFor;


@Column(name = "OPE_STAT")
private Integer major;

@Enumerated(EnumType.STRING)
@Column(name = "OPE_FOR", columnDefinition = "ENUM('opd', 'admission', 'opd_admission')")
SteveGT96 marked this conversation as resolved.
Show resolved Hide resolved
private OperationTarget opeFor;

@Version
@Column(name="OPE_LOCK")
private Integer lock;
@Column(name = "OPE_LOCK")
private Integer lock;

@Transient
private volatile int hashCode;
private volatile int hashCode;

public Operation() {
super();
}
Expand All @@ -91,95 +88,96 @@ public Operation() {
* @param aType
*/
public Operation(String aCode, String aDescription, OperationType aType, Integer major) {
this(aCode, aDescription, aType, major, OperationTarget.opd_admission);
}

public Operation(String aCode, String aDescription, OperationType aType, Integer major, OperationTarget opeFor) {
super();
this.code = aCode;
this.description = aDescription;
this.type = aType;
this.major = major;
this.opeFor = opeFor;
}

public String getCode() {
return this.code;
}
public void setCode(String aCode) {
this.code = aCode;
}
public void setOpeFor(String operFor) {
this.operFor = operFor;
}
public String getOpeFor() {
return this.operFor;
}


public String getDescription() {
return this.description;
}

public void setDescription(String aDescription) {
this.description = aDescription;
}

public void setMajor(Integer major) {
this.major = major;

public String getCode() {
return this.code;
}
public void setCode(String aCode) {
this.code = aCode;
}
public OperationTarget getOpeFor() {
return this.opeFor;
}
public void setOpeFor(OperationTarget opeFor) {
this.opeFor = opeFor;
}
public String getDescription() {
return this.description;
}

public void setDescription(String aDescription) {
this.description = aDescription;
}

public Integer getMajor() {
return major;
}

public void setMajor(Integer major) {
this.major = major;
}
public Integer getLock() {
return this.lock;
}
public void setLock(Integer aLock) {
this.lock = aLock;
}
public OperationType getType() {
return this.type;
}
public void setType(OperationType aType) {
this.type = aType;
}

@Override
public boolean equals(Object anObject) {
if (this == anObject) {
return this.lock;
}

public void setLock(Integer aLock) {
this.lock = aLock;
}

public OperationType getType() {
return this.type;
}

public void setType(OperationType aType) {
this.type = aType;
}

@Override
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (!(anObject instanceof Operation)) {

if (!(anObject instanceof Operation operation)) {
return false;
}

Operation operation = (Operation)anObject;

return (this.getCode().equals(operation.getCode()) &&
this.getDescription().equalsIgnoreCase(operation.getDescription()) &&
this.getType().equals(operation.getType()) &&
this.getMajor().equals(operation.getMajor()));
}

@Override
this.getDescription().equalsIgnoreCase(operation.getDescription()) &&
this.getType().equals(operation.getType()) &&
this.getOpeFor() == operation.getOpeFor() &&
this.getMajor().equals(operation.getMajor()));
}

@Override
public int hashCode() {
if (this.hashCode == 0) {
final int m = 23;
int c = 133;

c = m * c + ((code == null) ? 0 : code.hashCode());
c = m * c + ((description == null) ? 0 : description.hashCode());
c = m * c + ((type == null) ? 0 : type.hashCode());
c = m * c + ((major == null) ? 0 : major);
c = m * c + ((lock == null) ? 0 : lock);

this.hashCode = c;
}
return this.hashCode;
}

@Override
public String toString() {
return this.description;
}
if (this.hashCode == 0) {
final int m = 23;
int c = 133;

c = m * c + ((code == null) ? 0 : code.hashCode());
c = m * c + ((description == null) ? 0 : description.hashCode());
c = m * c + ((type == null) ? 0 : type.hashCode());
c = m * c + ((opeFor == null) ? 0 : opeFor.hashCode());
c = m * c + ((major == null) ? 0 : major);
c = m * c + ((lock == null) ? 0 : lock);

this.hashCode = c;
}
return this.hashCode;
}

@Override
public String toString() {
return this.description;
}
}
Loading