From 8983296db7b18a7bbda3087b466003816ffc3dee Mon Sep 17 00:00:00 2001 From: ManojLL Date: Sun, 27 Oct 2024 00:02:10 +0530 Subject: [PATCH 1/4] TRUNK-5830: Migrate FieldType from Hibernate Mapping XML to JPA annotations --- api/src/main/java/org/openmrs/FieldType.java | 33 ++++++++++++++++- api/src/main/resources/hibernate.cfg.xml | 1 - .../api/db/hibernate/FieldType.hbm.xml | 37 ------------------- .../org/openmrs/api/OrderServiceTest.java | 2 + 4 files changed, 33 insertions(+), 40 deletions(-) delete mode 100644 api/src/main/resources/org/openmrs/api/db/hibernate/FieldType.hbm.xml diff --git a/api/src/main/java/org/openmrs/FieldType.java b/api/src/main/java/org/openmrs/FieldType.java index 31c4d4506dd1..041f7f9aa35a 100644 --- a/api/src/main/java/org/openmrs/FieldType.java +++ b/api/src/main/java/org/openmrs/FieldType.java @@ -9,20 +9,49 @@ */ package org.openmrs; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Parameter; import org.hibernate.envers.Audited; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + /** * FieldType */ +@Entity +@Table(name = "field_type") @Audited +@AttributeOverrides(value = { + @AttributeOverride(name = "name", column = @Column(name = "name", length = 50, nullable = false)), + @AttributeOverride(name = "retired", column = @Column(name = "retired", columnDefinition = "boolean default false")) +}) public class FieldType extends BaseChangeableOpenmrsMetadata { - + + /** + * The constant serialVersionUID. + */ public static final long serialVersionUID = 35467L; // Fields - + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "field_type_id_seq") + @GenericGenerator( + name = "field_type_id_seq", + strategy = "native", + parameters = @Parameter(name = "sequence", value = "field_type_id_field_type_id_seq") + ) + @Column(name = "field_type_id", nullable = false) private Integer fieldTypeId; + @Column(name = "is_set", length = 1, nullable = false) private Boolean isSet = false; // Constructors diff --git a/api/src/main/resources/hibernate.cfg.xml b/api/src/main/resources/hibernate.cfg.xml index 60ccdf2099b0..439feeb8658f 100644 --- a/api/src/main/resources/hibernate.cfg.xml +++ b/api/src/main/resources/hibernate.cfg.xml @@ -45,7 +45,6 @@ - diff --git a/api/src/main/resources/org/openmrs/api/db/hibernate/FieldType.hbm.xml b/api/src/main/resources/org/openmrs/api/db/hibernate/FieldType.hbm.xml deleted file mode 100644 index 9d25829eb4ca..000000000000 --- a/api/src/main/resources/org/openmrs/api/db/hibernate/FieldType.hbm.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - field_type_field_type_id_seq - - - - - - - - - - - - - - - - - diff --git a/api/src/test/java/org/openmrs/api/OrderServiceTest.java b/api/src/test/java/org/openmrs/api/OrderServiceTest.java index e47ce608ad47..6a456509188f 100644 --- a/api/src/test/java/org/openmrs/api/OrderServiceTest.java +++ b/api/src/test/java/org/openmrs/api/OrderServiceTest.java @@ -35,6 +35,7 @@ import org.openmrs.DrugIngredient; import org.openmrs.DrugOrder; import org.openmrs.Encounter; +import org.openmrs.FieldType; import org.openmrs.FreeTextDosingInstructions; import org.openmrs.GlobalProperty; import org.openmrs.Location; @@ -2735,6 +2736,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th .addAnnotatedClass(DrugIngredient.class) .addAnnotatedClass(AlertRecipient.class) .addAnnotatedClass(PatientIdentifierType.class) + .addAnnotatedClass(FieldType.class) .getMetadataBuilder().build(); From d6ce6e4613c93a2a33d46ac05f868702b316eda9 Mon Sep 17 00:00:00 2001 From: ManojLL Date: Mon, 28 Oct 2024 10:41:28 +0530 Subject: [PATCH 2/4] TRUNK-5830: added date_change column to field_type table --- .../updates/liquibase-update-to-latest-2.7.x.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml b/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml index 5911cc7ef823..40e8c3483e05 100644 --- a/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml +++ b/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml @@ -169,5 +169,20 @@ referencedTableName="obs" referencedColumnNames="obs_id"/> + + + + + + + + + + + adding date change column + + + + From f9ba5f53e1a7ecfc1fd2f0a75ab45668096ee0f5 Mon Sep 17 00:00:00 2001 From: ManojLL Date: Mon, 28 Oct 2024 13:00:07 +0530 Subject: [PATCH 3/4] TRUNK-5830: added date_retired column to field_type table --- .../liquibase-update-to-latest-2.7.x.xml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml b/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml index 40e8c3483e05..d0ba6d887b9d 100644 --- a/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml +++ b/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml @@ -170,7 +170,7 @@ referencedColumnNames="obs_id"/> - + @@ -181,7 +181,22 @@ adding date change column - + + + + + + + + + + + + + + adding retired_by column + + From b056a1f35493923e488d56f0d78706db7df93fab Mon Sep 17 00:00:00 2001 From: ManojLL Date: Mon, 28 Oct 2024 15:08:34 +0530 Subject: [PATCH 4/4] TRUNK-5830: added liquibase changeSet to Filed_Type table --- .../liquibase-update-to-latest-2.7.x.xml | 96 +++++++++++++++++++ .../util/DatabaseUpdaterDatabaseIT.java | 2 +- 2 files changed, 97 insertions(+), 1 deletion(-) diff --git a/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml b/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml index d0ba6d887b9d..aa654ac2cb99 100644 --- a/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml +++ b/api/src/main/resources/org/openmrs/liquibase/updates/liquibase-update-to-latest-2.7.x.xml @@ -199,5 +199,101 @@ + + + + + + + + + + + adding retired_by column + + + + + + + + + + + + + + + adding retire_reason column + + + + + + + + + + + + + + + adding creator column + + + + + + + + + + + + + + + + + adding date_created column + + + + + + + + + + + + + + + + + adding changed_by column + + + + + + + + + + + + + + + adding retired column + + + + + + diff --git a/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java b/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java index fb7616ac9cdc..db05677f228e 100644 --- a/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java +++ b/api/src/test/java/org/openmrs/util/DatabaseUpdaterDatabaseIT.java @@ -30,7 +30,7 @@ public class DatabaseUpdaterDatabaseIT extends DatabaseIT { * This constant needs to be updated when adding new Liquibase update files to openmrs-core. */ - private static final int CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X = 899; + private static final int CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X = 907; private static final int CHANGE_SET_COUNT_FOR_2_1_X = 870;