Skip to content

Commit

Permalink
Renaming start_date in order to date_activated
Browse files Browse the repository at this point in the history
  • Loading branch information
Miss Beens authored and rkorytkowski committed Aug 4, 2014
1 parent 515a4ef commit cc8882c
Show file tree
Hide file tree
Showing 34 changed files with 179 additions and 167 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/DrugOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ protected DrugOrder cloneForRevisionHelper(DrugOrder target) {
public String toString() {
String prefix = Action.DISCONTINUE == getAction() ? "DC " : "";
return prefix + "DrugOrder(" + getDose() + getDoseUnits() + " of "
+ (getDrug() != null ? getDrug().getName() : "[no drug]") + " from " + getStartDate() + " to "
+ (getDrug() != null ? getDrug().getName() : "[no drug]") + " from " + getDateActivated() + " to "
+ (isDiscontinuedRightNow() ? getDateStopped() : getAutoExpireDate()) + ")";
}

Expand Down
30 changes: 15 additions & 15 deletions api/src/main/java/org/openmrs/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.openmrs.util.OpenmrsUtil;

/**
* Dates should be interpreted as follows: If startDate is null then the order has been going on
* "since the beginning of time" Otherwise the order starts on startDate If discontinued is non-null
* Dates should be interpreted as follows: If dateActivated is null then the order has been going on
* "since the beginning of time" Otherwise the order starts on dateActivated If discontinued is non-null
* and true, then the following fields should be ignored: autoExpireDate if dateStopped is null then
* the order was discontinued "the instant after it began" otherwise it was given from its starting
* date until dateStopped Otherwise (discontinued is null or false) if autoExpireDate is null, the
Expand Down Expand Up @@ -64,7 +64,7 @@ public enum Action {

private String instructions;

private Date startDate;
private Date dateActivated;

private Date autoExpireDate;

Expand Down Expand Up @@ -136,7 +136,7 @@ protected Order copyHelper(Order target) {
target.setOrderType(getOrderType());
target.setConcept(getConcept());
target.setInstructions(getInstructions());
target.setStartDate(getStartDate());
target.setDateActivated(getDateActivated());
target.setAutoExpireDate(getAutoExpireDate());
target.setEncounter(getEncounter());
target.setOrderer(getOrderer());
Expand Down Expand Up @@ -301,17 +301,17 @@ public void setOrderId(Integer orderId) {
}

/**
* @return Returns the startDate.
* @return Returns the dateActivated.
*/
public Date getStartDate() {
return startDate;
public Date getDateActivated() {
return dateActivated;
}

/**
* @param startDate The startDate to set.
* @param dateActivated The dateActivated to set.
*/
public void setStartDate(Date startDate) {
this.startDate = startDate;
public void setDateActivated(Date dateActivated) {
this.dateActivated = dateActivated;
}

/**
Expand Down Expand Up @@ -358,13 +358,13 @@ public boolean isCurrent(Date checkDate) {
checkDate = new Date();
}

if (startDate != null && checkDate.before(startDate)) {
if (dateActivated != null && checkDate.before(dateActivated)) {
return false;
}

if (isDiscontinuedRightNow()) {
if (dateStopped == null)
return checkDate.equals(startDate);
return checkDate.equals(dateActivated);
else
return checkDate.before(dateStopped);

Expand All @@ -386,7 +386,7 @@ public boolean isFuture(Date checkDate) {
if (checkDate == null)
checkDate = new Date();

return startDate != null && checkDate.before(startDate);
return dateActivated != null && checkDate.before(dateActivated);
}

public boolean isFuture() {
Expand All @@ -405,7 +405,7 @@ public boolean isDiscontinued(Date checkDate) {
if (checkDate == null)
checkDate = new Date();

if (startDate == null || checkDate.before(startDate)) {
if (dateActivated == null || checkDate.before(dateActivated)) {
return false;
}
if (dateStopped != null && dateStopped.after(checkDate)) {
Expand Down Expand Up @@ -607,7 +607,7 @@ protected Order cloneForRevisionHelper(Order target) {
if (getAction() == Action.DISCONTINUE) {
target.setAction(Action.DISCONTINUE);
target.setPreviousOrder(getPreviousOrder());
target.setStartDate(getStartDate());
target.setDateActivated(getDateActivated());
} else {
target.setAction(Action.REVISE);
target.setPreviousOrder(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public List<Order> getOrders(OrderType orderType, List<Patient> patients, List<C
if (encounters.size() > 0)
crit.add(Restrictions.in("encounter", encounters));

crit.addOrder(org.hibernate.criterion.Order.desc("startDate"));
crit.addOrder(org.hibernate.criterion.Order.desc("dateActivated"));

return crit.list();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ public String exportXml(Integer patientId) throws DAOException {
if (order.getInstructions() != null) {

This comment has been minimized.

Copy link
@wluyima

wluyima Aug 7, 2014

Member

I believe there is more things to change in this class

This comment has been minimized.

Copy link
@wluyima

wluyima Aug 7, 2014

Member

E.g in getCurrentDrugOrders(..) method, i will probably make the changes as i merge the code

orderNode.setAttribute("instructions", order.getInstructions());
}
if (order.getStartDate() != null) {
orderNode.setAttribute("start_date", df.format(order.getStartDate()));
if (order.getDateActivated() != null) {
orderNode.setAttribute("date_activated", df.format(order.getDateActivated()));
}
if (order.getAutoExpireDate() != null) {
orderNode.setAttribute("auto_expire_date", df.format(order.getAutoExpireDate()));
Expand Down Expand Up @@ -1790,7 +1790,7 @@ public Map<Integer, Collection<Integer>> getActiveDrugIds(Collection<Integer> pa
List<String> whereClauses = new ArrayList<String>();
whereClauses.add("o.voided = false");
if (toDate != null) {
whereClauses.add("o.start_date <= :toDate");
whereClauses.add("o.date_activated <= :toDate");
}
if (fromDate != null) {
whereClauses.add("(o.auto_expire_date is null or o.auto_expire_date > :fromDate)");
Expand Down
18 changes: 9 additions & 9 deletions api/src/main/java/org/openmrs/api/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public synchronized Order saveOrder(Order order, OrderContext orderContext) thro
if (order.getOrderId() != null) {
throw new APIException("Cannot edit an existing order, you need to revise it instead");
}
if (order.getStartDate() == null) {
order.setStartDate(new Date());
if (order.getDateActivated() == null) {
order.setDateActivated(new Date());
}
//Reject if there is an active order for the same orderable
boolean isDrugOrder = DrugOrder.class.isAssignableFrom(getActualType(order));
Expand Down Expand Up @@ -160,7 +160,7 @@ public synchronized Order saveOrder(Order order, OrderContext orderContext) thro
if (previousOrder == null) {
throw new APIException("Previous Order is required for a revised order");
}
stopOrder(previousOrder, order.getStartDate());
stopOrder(previousOrder, order.getDateActivated());
} else if (DISCONTINUE == order.getAction()) {
discontinueExistingOrdersIfNecessary(order);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ private Order saveOrderInternal(Order order, OrderContext orderContext) {

//DC orders should auto expire upon creating them
if (DISCONTINUE == order.getAction()) {
order.setAutoExpireDate(order.getStartDate());
order.setAutoExpireDate(order.getDateActivated());
}
}

Expand Down Expand Up @@ -279,7 +279,7 @@ private void discontinueExistingOrdersIfNecessary(Order order) {
//Mark previousOrder as discontinued if it is not already
Order previousOrder = order.getPreviousOrder();
if (previousOrder != null) {
stopOrder(previousOrder, order.getStartDate());
stopOrder(previousOrder, order.getDateActivated());
return;
}

Expand All @@ -306,7 +306,7 @@ private void discontinueExistingOrdersIfNecessary(Order order) {

if (shouldMarkAsDiscontinued) {
order.setPreviousOrder(activeOrder);
stopOrder(activeOrder, order.getStartDate());
stopOrder(activeOrder, order.getDateActivated());
break;
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ public Order unvoidOrder(Order order) throws APIException {
final String action = DISCONTINUE == order.getAction() ? "discontinuation" : "revision";
throw new APIException("Cannot unvoid a " + action + " order if the previous order is no longer active");
}
stopOrder(previousOrder, order.getStartDate());
stopOrder(previousOrder, order.getDateActivated());
}

return saveOrderInternal(order, null);
Expand Down Expand Up @@ -616,7 +616,7 @@ public Order discontinueOrder(Order orderToDiscontinue, Concept reasonCoded, Dat
if (discontinueDate == null) {
discontinueDate = new Date();
}
newOrder.setStartDate(discontinueDate);
newOrder.setDateActivated(discontinueDate);
return saveOrderInternal(newOrder, null);
}

Expand All @@ -635,7 +635,7 @@ public Order discontinueOrder(Order orderToDiscontinue, String reasonNonCoded, D
if (discontinueDate == null) {
discontinueDate = new Date();
}
newOrder.setStartDate(discontinueDate);
newOrder.setDateActivated(discontinueDate);
return saveOrderInternal(newOrder, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ public Date getEarliestDrugStart(String drugSetName) {
}
Date earliest = null;
for (DrugOrder o : patientOrders) {
if (earliest == null || OpenmrsUtil.compareWithNullAsLatest(o.getStartDate(), earliest) < 0) {
earliest = o.getStartDate();
if (earliest == null || OpenmrsUtil.compareWithNullAsLatest(o.getDateActivated(), earliest) < 0) {
earliest = o.getDateActivated();
}
}
return earliest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void createDiscontinueOrders(JdbcConnection connection, List<Discontinue
insertStatement = connection
.prepareStatement("Insert into orders(previous_order_id, concept_id, patient_id, encounter_id, "
+ "creator, date_created, discontinued_reason, discontinued_reason_non_coded, "
+ "uuid, order_action, orderer, order_number, order_type_id, start_date, auto_expire_date) "
+ "uuid, order_action, orderer, order_number, order_type_id, date_activated, auto_expire_date) "
+ "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
for (DiscontinuedOrder discontinuedOrder : discontinuedOrders) {
insertStatement.setInt(1, discontinuedOrder.previousOrderId);
Expand All @@ -78,8 +78,8 @@ private void createDiscontinueOrders(JdbcConnection connection, List<Discontinue
setIntOrNull(insertStatement, 11, discontinuedOrder.discontinuedById);
insertStatement.setString(12, discontinuedOrder.orderNumber);
insertStatement.setInt(13, discontinuedOrder.orderTypeId);
insertStatement.setDate(14, discontinuedOrder.dateStarted);
insertStatement.setDate(15, discontinuedOrder.dateStarted);
insertStatement.setDate(14, discontinuedOrder.dateActivated);
insertStatement.setDate(15, discontinuedOrder.dateActivated);
insertStatement.addBatch();

if (index % batchSize == 0) {
Expand Down Expand Up @@ -182,7 +182,7 @@ private static class DiscontinuedOrder {

public String discontinuedReasonNonCoded;

public Date dateStarted;
public Date dateActivated;

public int discontinuedById;

Expand All @@ -205,7 +205,7 @@ private DiscontinuedOrder(int orderId, int conceptId, int patientId, int encount
this.encounterId = encounterId;
this.discontinuedReasonId = discontinuedReasonId;
this.discontinuedReasonNonCoded = discontinuedReasonNonCoded;
this.dateStarted = dateStopped;
this.dateActivated = dateStopped;
this.discontinuedById = discontinuedById;
this.dateCreated = dateStopped;
this.orderNumber = String.valueOf(orderId).concat("-DC");
Expand Down
18 changes: 9 additions & 9 deletions api/src/main/java/org/openmrs/validator/OrderValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void validate(Object obj, Errors errors) {

validateSamePatientInOrderAndEncounter(order, errors);
validateOrderTypeClass(order, errors);
validateStartDate(order, errors);
validateDateActivated(order, errors);
validateScheduledDate(order, errors);
}
}
Expand All @@ -102,27 +102,27 @@ private void validateOrderTypeClass(Order order, Errors errors) {
}
}

private void validateStartDate(Order order, Errors errors) {
Date startDate = order.getStartDate();
private void validateDateActivated(Order order, Errors errors) {
Date startDate = order.getDateActivated();
if (startDate != null) {
if (startDate.after(new Date())) {
errors.rejectValue("startDate", "Order.error.startDateInFuture");
errors.rejectValue("dateActivated", "Order.error.dateActivatedInFuture");
return;
}
Date dateStopped = order.getDateStopped();
if (dateStopped != null && startDate.after(dateStopped)) {
errors.rejectValue("startDate", "Order.error.startDateAfterDiscontinuedDate");
errors.rejectValue("dateStopped", "Order.error.startDateAfterDiscontinuedDate");
errors.rejectValue("dateActivated", "Order.error.dateActivatedAfterDiscontinuedDate");
errors.rejectValue("dateStopped", "Order.error.dateActivatedAfterDiscontinuedDate");
}
Date autoExpireDate = order.getAutoExpireDate();
if (autoExpireDate != null && startDate.after(autoExpireDate)) {
errors.rejectValue("startDate", "Order.error.startDateAfterAutoExpireDate");
errors.rejectValue("autoExpireDate", "Order.error.startDateAfterAutoExpireDate");
errors.rejectValue("dateActivated", "Order.error.dateActivatedAfterAutoExpireDate");
errors.rejectValue("autoExpireDate", "Order.error.dateActivatedAfterAutoExpireDate");
}
Encounter encounter = order.getEncounter();
if (encounter != null && encounter.getEncounterDatetime() != null
&& encounter.getEncounterDatetime().after(startDate)) {
errors.rejectValue("startDate", "Order.error.startDateAfterEncounterDatetime");
errors.rejectValue("dateActivated", "Order.error.dateActivatedAfterEncounterDatetime");
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/resources/liquibase-update-to-latest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8422,5 +8422,13 @@
<comment>Dropping default value for drug_order.drug_inventory_id </comment>
<dropDefaultValue tableName="drug_order" columnName="drug_inventory_id" columnDataType="int" />
</changeSet>
<changeSet id="20140801-TRUNK-4443-rename_order_start_date_to_date_activated" author="bharti">
<preConditions onFail="MARK_RAN">
<columnExists columnName="start_date" tableName="orders" />

This comment has been minimized.

Copy link
@wluyima

wluyima Aug 7, 2014

Member

When renaming a column, it is good to also check that no existing column has the new column name

</preConditions>
<comment>Renaming the start_date in order table to date_activated</comment>
<renameColumn tableName="orders" newColumnName="date_activated" oldColumnName="start_date" columnDataType="datetime" />
</changeSet>


</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
column="uuid" length="38" unique="true" />

<property name="instructions" type="java.lang.String" column="instructions" length="65535"/>
<property name="startDate" type="java.util.Date" column="start_date" length="19" not-null="true"/>
<property name="dateActivated" type="java.util.Date" column="date_activated" length="19" not-null="true"/>
<property name="autoExpireDate" type="java.util.Date" column="auto_expire_date" length="19"/>
<property name="dateStopped" type="java.util.Date" column="date_stopped" length="19" access="field"/>
<property name="accessionNumber" type="java.lang.String" column="accession_number" length="255" />
Expand Down
6 changes: 3 additions & 3 deletions api/src/test/java/org/openmrs/DrugOrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void cloneForRevision_shouldSetAllTheRelevantFields() throws Exception {
drugOrder.setDrug(drug);
OrderTest.assertThatAllFieldsAreCopied(drugOrder, "cloneForRevision", "creator", "dateCreated", "action",
"changedBy", "dateChanged", "voided", "dateVoided", "voidedBy", "voidReason", "encounter", "orderNumber",
"orderer", "previousOrder", "startDate", "dateStopped", "accessionNumber");
"orderer", "previousOrder", "dateActivated", "dateStopped", "accessionNumber");
}

/**
Expand All @@ -98,15 +98,15 @@ public void cloneForRevision_shouldSetTheRelevantFieldsForADCOrder() throws Exce
Order order = new DrugOrder();
order.setAction(Order.Action.DISCONTINUE);
Date date = new Date();
order.setStartDate(date);
order.setDateActivated(date);
order.setAutoExpireDate(date);
order.setAccessionNumber("some number");
OrderUtilTest.setDateStopped(order, date);
order.setPreviousOrder(new Order());

Order clone = order.cloneForRevision();
assertEquals(Order.Action.DISCONTINUE, clone.getAction());
assertEquals(order.getStartDate(), clone.getStartDate());
assertEquals(order.getDateActivated(), clone.getDateActivated());
assertEquals(order.getPreviousOrder(), clone.getPreviousOrder());
assertNull(clone.getAutoExpireDate());
assertNull(clone.getDateStopped());
Expand Down

0 comments on commit cc8882c

Please sign in to comment.