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

TRUNK-6149: Add 'discontinue_reason' and 'discontinue_reason_non_coded' to Order object #4565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions api/src/main/java/org/openmrs/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public enum FulfillerStatus {

private String formNamespaceAndPath;

private Concept discontinueReason;

private String discontinueReasonNonCoded;

/**
* Allows the orders if ordered as an orderGroup, to maintain a sequence of how members are
* added in the group ex - for two orders of isoniazid and ampicillin, the sequence of 1 and 2
Expand Down Expand Up @@ -204,6 +208,8 @@ protected Order copyHelper(Order target) {
target.setFulfillerComment(getFulfillerComment());
target.setFulfillerStatus(getFulfillerStatus());
target.setFormNamespaceAndPath(getFormNamespaceAndPath());
target.setDiscontinueReason(getDiscontinueReason());
target.setDiscontinueReasonNonCoded(getDiscontinueReasonNonCoded());
return target;
}

Expand Down Expand Up @@ -777,6 +783,8 @@ protected Order cloneForRevisionHelper(Order target) {
target.setFulfillerStatus(getFulfillerStatus());
target.setFulfillerComment(getFulfillerComment());
target.setFormNamespaceAndPath(getFormNamespaceAndPath());
target.setDiscontinueReason(getDiscontinueReason());
target.setDiscontinueReasonNonCoded(getDiscontinueReasonNonCoded());

return target;
}
Expand Down Expand Up @@ -951,4 +959,40 @@ public String getFormFieldPath() {
public void setFormField(String namespace, String formFieldPath) {
formNamespaceAndPath = BaseFormRecordableOpenmrsData.getFormNamespaceAndPath(namespace, formFieldPath);
}

/**
* @return Returns the discontinueReason
*
* @since 2.7.0
*/
public Concept getDiscontinueReason() {
return discontinueReason;
}

/**
* @param discontinueReason The discontinueReason to set
*
* @since 2.7.0
*/
public void setDiscontinueReason(Concept discontinueReason) {
this.discontinueReason = discontinueReason;
}

/**
* @return Returns the discontinueReasonNonCoded
*
* @since 2.7.0
*/
public String getDiscontinueReasonNonCoded() {
return discontinueReasonNonCoded;
}

/**
* @param discontinueReasonNonCoded the discontinueReasonNonCoded to set
*
* @since 2.7.0
*/
public void setDiscontinueReasonNonCoded(String discontinueReasonNonCoded) {
this.discontinueReasonNonCoded = discontinueReasonNonCoded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
public class ImmutableOrderInterceptor extends ImmutableEntityInterceptor {

private static final String[] MUTABLE_PROPERTY_NAMES = new String[] { "dateStopped", "voided", "dateVoided", "voidedBy",
"voidReason", "patient", "fulfillerStatus", "fulfillerComment", "accessionNumber"};
"voidReason", "patient", "fulfillerStatus", "fulfillerComment", "accessionNumber", "discontinueReasonNonCoded",
"discontinueReason" };

/**
* @see ImmutableEntityInterceptor#getSupportedType()
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Dat
if (discontinueDate == null) {
discontinueDate = aMomentBefore(new Date());
}
setProperty(orderToDiscontinue, "discontinueReason", reasonCoded);
stopOrder(orderToDiscontinue, discontinueDate, false);
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
newOrder.setOrderReason(reasonCoded);
Expand All @@ -806,6 +807,7 @@ public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, D
if (discontinueDate == null) {
discontinueDate = aMomentBefore(new Date());
}
setProperty(orderToDiscontinue, "discontinueReasonNonCoded", reasonNonCoded);
stopOrder(orderToDiscontinue, discontinueDate, false);
Order newOrder = orderToDiscontinue.cloneForDiscontinuing();
newOrder.setOrderReasonNonCoded(reasonNonCoded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<property name="sortWeight" type="java.lang.Double" column="sort_weight"/>
<property name="fulfillerComment" type="java.lang.String" column="fulfiller_comment" length="1024"/>
<property name="formNamespaceAndPath" type="java.lang.String" column="form_namespace_and_path" length="255" />
<property name="discontinueReasonNonCoded" column="discontinue_reason_non_coded" type="java.lang.String" length="255"/>

<property name="urgency" column="urgency" length="50" not-null="true">
<type name="org.hibernate.type.EnumType">
Expand Down Expand Up @@ -95,6 +96,8 @@
<!-- bi-directional many-to-one association to User -->
<many-to-one name="creator" class="org.openmrs.User" not-null="true" />

<many-to-one name="discontinueReason" column="discontinue_reason" class="org.openmrs.Concept" not-null="false" />

<set name="attributes" lazy="true" inverse="true" batch-size="100" cascade="all-delete-orphan" order-by="voided asc">
<key column="order_id" />
<one-to-many class="org.openmrs.OrderAttribute" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,32 @@
CREATE FUNCTION UUID() RETURNS UUID LANGUAGE SQL AS $$ SELECT uuid_generate_v1() $$;
</sql>
</changeSet>

<changeSet id="TRUNK-6149-2024-02-20-1001" author="mujuzi">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="orders" columnName="discontinue_reason" />
</not>
</preConditions>
<comment>Adding property 'discontinue_reason' to 'orders' table</comment>
<addColumn tableName="orders">
<column name="discontinue_reason" type="INT" />
</addColumn>
<addForeignKeyConstraint constraintName="order_discontinue_reason_fk"
baseTableName="orders" baseColumnNames="discontinue_reason"
referencedTableName="concept" referencedColumnNames="concept_id" />
</changeSet>

<changeSet id="TRUNK-6149-2024-02-20-1002" author="mujuzi">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="orders" columnName="discontinue_reason_non_coded" />
</not>
</preConditions>
<comment>Adding property 'discontinue_reason_non_coded' to 'orders' table</comment>
<addColumn tableName="orders">
<column name="discontinue_reason_non_coded" type="VARCHAR(255)" />
</addColumn>
</changeSet>

</databaseChangeLog>
44 changes: 44 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,50 @@ public void discontinueOrder_shouldNotPassForADiscontinuedOrder() {
assertThat(exception.getMessage(), is(messageSourceService.getMessage("Order.cannot.discontinue.inactive")));
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(Order, Concept, Date, Provider, Encounter)
*/
@Test
public void discontinueOrder_shouldSetCorrectValuesForTheExistingOrderDiscontinueReason() {
executeDataSet("org/openmrs/include/standardTestDataset.xml");

Order order = orderService.getOrderByOrderNumber("111");
assertTrue(OrderUtilTest.isActiveOrder(order, null));
Date discontinueDate = new Date();
Concept discontinueReason = conceptService.getConcept(3);

Order discontinueOrder = orderService.discontinueOrder(order, discontinueReason, discontinueDate, order.getOrderer(), order.getEncounter());

assertEquals(order.getDateStopped(), discontinueDate);
assertNotNull(order.getDiscontinueReason());
assertEquals(order.getDiscontinueReason(), discontinueReason);

assertNotNull(discontinueOrder);
assertEquals(discontinueOrder.getOrderReason(), discontinueReason);
}

/**
* @see org.openmrs.api.OrderService#discontinueOrder(Order, String, Date, Provider, Encounter)
*/
@Test
public void discontinueOrder_shouldSetCorrectValuesForTheExistingOrderDiscontinueReasonNonCoded() {
executeDataSet("org/openmrs/include/standardTestDataset.xml");

Order order = orderService.getOrderByOrderNumber("111");
assertTrue(OrderUtilTest.isActiveOrder(order, null));
Date discontinueDate = new Date();
String discontinueReasonNonCoded = "Test if I can discontinue this";

Order discontinueOrder = orderService.discontinueOrder(order, discontinueReasonNonCoded, discontinueDate, order.getOrderer(), order.getEncounter());

assertEquals(order.getDateStopped(), discontinueDate);
assertNotNull(order.getDiscontinueReasonNonCoded());
assertEquals(order.getDiscontinueReasonNonCoded(), discontinueReasonNonCoded);

assertNotNull(discontinueOrder);
assertEquals(discontinueOrder.getOrderReasonNonCoded(), discontinueReasonNonCoded);
}

/**
* @see OrderService#saveOrder(org.openmrs.Order, OrderContext)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DatabaseUpdaterDatabaseIT extends H2DatabaseIT {
* 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 = 897;
private static final int CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X = 899;

private static final int CHANGE_SET_COUNT_FOR_2_1_X = 870;

Expand Down
Loading