Skip to content

Commit

Permalink
OP-1341 Enable Medical Type for Soft Deletion (#1458)
Browse files Browse the repository at this point in the history
* Add Medical soft deletion CORE management

* Update step_a113_medical_type_soft_deletion.sql

* Fixed number of sql file

* Added Repo method fetch non deleted medical types

* Test cased added

* fixed , isssue in demo data
  • Loading branch information
mohit10696 authored Nov 26, 2024
1 parent 30fdddc commit 402cd95
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 5 deletions.
8 changes: 4 additions & 4 deletions sql/load_demo_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2981,10 +2981,10 @@ UNLOCK TABLES;

LOCK TABLES `oh_medicaldsrtype` WRITE;
/*!40000 ALTER TABLE `oh_medicaldsrtype` DISABLE KEYS */;
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('D','Drugs',NULL,NULL,NULL,NULL,1);
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('K','Chemical',NULL,NULL,NULL,NULL,1);
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('L','Laboratory',NULL,NULL,NULL,NULL,1);
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('S','Surgery',NULL,NULL,NULL,NULL,1);
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_DELETED`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('D','Drugs','N',NULL,NULL,NULL,NULL,1);
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_DELETED`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('K','Chemical','N',NULL,NULL,NULL,NULL,1);
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_DELETED`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('L','Laboratory','N',NULL,NULL,NULL,NULL,1);
INSERT INTO `oh_medicaldsrtype` (`MDSRT_ID_A`, `MDSRT_DESC`, `MDSRT_DELETED`, `MDSRT_CREATED_BY`, `MDSRT_CREATED_DATE`, `MDSRT_LAST_MODIFIED_BY`, `MDSRT_LAST_MODIFIED_DATE`, `MDSRT_ACTIVE`) VALUES ('S','Surgery','N',NULL,NULL,NULL,NULL,1);
/*!40000 ALTER TABLE `oh_medicaldsrtype` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down
3 changes: 2 additions & 1 deletion sql/step_04_all_following_steps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ source step_a109_update_user_settings_table_constraints_and_add_usergroups_permi
source step_a110_update_operations_table_change_ope_for_to_enum.sql;
source step_a111_add_missing_lock_columns.sql;
source step_a112_users_and_groups_soft_deletion.sql;
source step_a113_alter_table_medicalinventory.sql;
source step_a113_alter_table_medicalinventory.sql;
source step_a114_medical_type_soft_deletion.sql;
2 changes: 2 additions & 0 deletions sql/step_a114_medical_type_soft_deletion.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE OH_MEDICALDSRTYPE
ADD COLUMN MDSRT_DELETED CHAR(1) NOT NULL DEFAULT 'N';
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ protected void validateMedicalType(MedicalType medicalType, boolean insert) thro
public List<MedicalType> getMedicalType() throws OHServiceException {
return ioOperations.getMedicalTypes();
}

/**
* Retrieves all the non deleted {@link MedicalType}s.
*
* @return a list of all the {@link MedicalType}s.
* @throws OHServiceException
*/
public List<MedicalType> getAllActiveMedicalType() throws OHServiceException {
return ioOperations.getMedicalTypesNotDeleted();
}

/**
* Saves the specified {@link MedicalType}.
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/isf/medtype/model/MedicalType.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.validation.constraints.NotNull;

import org.isf.utils.db.Auditable;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
Expand All @@ -48,6 +49,10 @@ public class MedicalType extends Auditable<String> {

@Column(name="MDSRT_DESC")
private String description;

@NotNull
@Column(name = "MDSRT_DELETED", columnDefinition = "char(1) default 'N'")
private char deleted = 'N'; // flag record deleted ; values are 'Y' OR 'N' default is 'N'

@Transient
private volatile int hashCode;
Expand Down Expand Up @@ -78,6 +83,15 @@ public String getDescription() {
public void setDescription(String description) {
this.description = description;
}


public char getDeleted() {
return deleted;
}

public void setDeleted(char deleted) {
this.deleted = deleted;
}

@Override
public boolean equals(Object anObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public MedicalTypeIoOperation(MedicalTypeIoOperationRepository medicalTypeIoOper
public List<MedicalType> getMedicalTypes() throws OHServiceException {
return repository.findAllByOrderByDescriptionAsc();
}


public List<MedicalType> getMedicalTypesNotDeleted() throws OHServiceException {
return repository.findByAllNotDeletedOrderByDescriptionAsc();
}

/**
* Updates the specified {@link MedicalType}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@

import org.isf.medtype.model.MedicalType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface MedicalTypeIoOperationRepository extends JpaRepository<MedicalType, String> {

List<MedicalType> findAllByOrderByDescriptionAsc();

@Query("SELECT m FROM MedicalType m WHERE m.deleted = 'N' ORDER BY m.description ASC")
List<MedicalType> findByAllNotDeletedOrderByDescriptionAsc();

}
3 changes: 3 additions & 0 deletions src/test/java/org/isf/medtype/TestMedicalType.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class TestMedicalType {

private String code = "Z";
private String description = "TestDescription";
private char deleted = 'N';

public MedicalType setup(boolean usingSet) throws OHException {
MedicalType medicalType;
Expand All @@ -48,10 +49,12 @@ public MedicalType setup(boolean usingSet) throws OHException {
public void setParameters(MedicalType medicalType) {
medicalType.setCode(code);
medicalType.setDescription(description);
medicalType.setDeleted(deleted);
}

public void check(MedicalType medicalType) {
assertThat(medicalType.getCode()).isEqualTo(code);
assertThat(medicalType.getDescription()).isEqualTo(description);
assertThat(medicalType.getDeleted()).isEqualTo(deleted);
}
}
19 changes: 19 additions & 0 deletions src/test/java/org/isf/medtype/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.isf.utils.exception.OHDataIntegrityViolationException;
import org.isf.utils.exception.OHDataValidationException;
import org.isf.utils.exception.OHException;
import org.isf.utils.exception.OHServiceException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -81,6 +82,15 @@ void testIoGetMedicalType() throws Exception {
assertThat(medicalTypes.get(medicalTypes.size() - 1).getDescription()).isEqualTo(foundMedicalType.getDescription());
}

@Test
void testIoGetAllActiveMedicalType() throws Exception {
String code = setupTestMedicalType(false);
MedicalType foundMedicalType = medicalTypeIoOperationRepository.findById(code).orElse(null);
assertThat(foundMedicalType).isNotNull();
List<MedicalType> medicalTypes = medicalTypeIoOperation.getMedicalTypesNotDeleted();
assertThat(medicalTypes.get(medicalTypes.size() - 1).getDescription()).isEqualTo(foundMedicalType.getDescription());
}

@Test
void testIoUpdateMedicalType() throws Exception {
String code = setupTestMedicalType(false);
Expand Down Expand Up @@ -125,6 +135,15 @@ void testMgrGetMedicalType() throws Exception {
assertThat(medicalTypes.get(medicalTypes.size() - 1).getDescription()).isEqualTo(foundMedicalType.getDescription());
}

@Test
void testMgrGetAllActiveMedicalType() throws Exception {
String code = setupTestMedicalType(false);
MedicalType foundMedicalType = medicalTypeIoOperationRepository.findById(code).orElse(null);
assertThat(foundMedicalType).isNotNull();
List<MedicalType> medicalTypes = medicalTypeBrowserManager.getAllActiveMedicalType();
assertThat(medicalTypes.get(medicalTypes.size() - 1).getDescription()).isEqualTo(foundMedicalType.getDescription());
}

@Test
void testMgrUpdateMedicalType() throws Exception {
String code = setupTestMedicalType(false);
Expand Down

0 comments on commit 402cd95

Please sign in to comment.