Skip to content

Commit

Permalink
TRUNK-4202 Convert Order.orderer to be a Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
k-joseph committed Jan 8, 2014
1 parent 7ab4014 commit e2b4c86
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
6 changes: 3 additions & 3 deletions api/src/main/java/org/openmrs/Order.java
Expand Up @@ -67,7 +67,7 @@ public enum Action {

private Encounter encounter;

private User orderer;
private Provider orderer;

private Date dateStopped;

Expand Down Expand Up @@ -262,14 +262,14 @@ public void setAccessionNumber(String accessionNumber) {
/**
* @return Returns the orderer.
*/
public User getOrderer() {
public Provider getOrderer() {
return orderer;
}

/**
* @param orderer The orderer to set.
*/
public void setOrderer(User orderer) {
public void setOrderer(Provider orderer) {
this.orderer = orderer;
}

Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.openmrs.Program;
import org.openmrs.ProgramWorkflow;
import org.openmrs.ProgramWorkflowState;
import org.openmrs.Provider;
import org.openmrs.Relationship;
import org.openmrs.RelationshipType;
import org.openmrs.User;
Expand Down Expand Up @@ -130,13 +131,13 @@ public String exportXml(Cohort ps) throws DAOException {
return ret.toString();
}

private String formatUserName(User u) {
return u.getPersonName().toString();
private String formatProviderName(Provider p) {

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jan 9, 2014

Here you should do p.getName()

return p.getPerson().toString();
}

private String formatUser(User u) {
private String formatProvider(Provider p) {
StringBuilder ret = new StringBuilder();
ret.append(u.getUserId() + "^" + formatUserName(u));
ret.append(p.getProviderId() + "^" + formatProviderName(p));
return ret.toString();
}

Expand Down Expand Up @@ -384,7 +385,7 @@ public String exportXml(Integer patientId) throws DAOException {
orderNode.setAttribute("auto_expire_date", df.format(order.getAutoExpireDate()));
}
if (order.getOrderer() != null) {
orderNode.setAttribute("orderer", formatUser(order.getOrderer()));
orderNode.setAttribute("orderer", formatProvider(order.getOrderer()));
}
if (order.getDateStopped() != null) {
orderNode.setAttribute("date_stopped", df.format(order.getDateStopped()));
Expand Down
26 changes: 26 additions & 0 deletions api/src/main/resources/liquibase-update-to-latest.xml
Expand Up @@ -6805,5 +6805,31 @@
<comment>Removing discontinued_by from orders</comment>
<dropColumn tableName="orders" columnName="discontinued_by" />
</changeSet>

<changeSet id="201401081823-TRUNK-4202" author="k-joseph">

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jan 9, 2014

Did you actually try test this out by running the webapp and confirm that your change sets execute successfully?

<preConditions onFail="MARK_RAN">
<columnExists tableName="orders" columnName="orderer" />
</preConditions>
<comment>Creating provider accounts for all users who have placed
orders for patients and have no associated provider accounts
</comment>
<sql>
INSERT INTO provider(person_id, identifier, creator, date_created, retired, uuid)
SELECT orders.orderer, CONCAT('providerAccount', SUBSTRING(person.uuid, 5)), 1,
CURRENT_TIMESTAMP, false, CONCAT('providerAccount', SUBSTRING(person.uuid, 5))
WHERE orders.patient_id IS NOT NULL AND orders.orderer NOT IN (SELECT person_id FROM provider)
</sql>
</changeSet>

<changeSet id="201401081850-TRUNK-4202" author="k-joseph">
<preConditions onFail="MARK_RAN">

This comment has been minimized.

Copy link
@dkayiwa

dkayiwa Jan 9, 2014

These change sets are not correctly written, did you try test them out?

This comment has been minimized.

Copy link
@k-joseph

k-joseph Jan 9, 2014

Author Owner

i guess it will be better to go over them, again, i request you to help me while we go over them, so that i can correct wherever there's a mistake, i tested the sql and they were resulting into some errors :(

<columnExists tableName="provider" columnName="provider_id" />
</preConditions>
<comment>Migrating data in orders.orderer column to be provider_ids</comment>
<sql>
UPDATE orders SET orderer = (SELECT provider_id FROM provider WHERE provider_id = orders.orderer)
WHERE users.user_id IN (SELECT orders.orderer FROM orders)
</sql>
</changeSet>

</databaseChangeLog>
Expand Up @@ -70,8 +70,8 @@
<column name="discontinued_reason" />
</many-to-one>

<!-- bi-directional many-to-one association to User -->
<many-to-one name="orderer" class="org.openmrs.User">
<!-- bi-directional many-to-one association to Provider -->
<many-to-one name="orderer" class="org.openmrs.Provider">
<column name="orderer" />
</many-to-one>

Expand Down

0 comments on commit e2b4c86

Please sign in to comment.