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-4202] Convert Order.orderer to be a Provider #563

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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 Expand Up @@ -2224,4 +2225,8 @@ public Cohort getPatients(Integer start, Integer size) {
return new Cohort("Batch of " + size + " patients starting at " + start, "", ids);
}

private String formatProvider(Provider p) {
return p.getName();
}

}
25 changes: 25 additions & 0 deletions api/src/main/resources/liquibase-update-to-latest.xml
Expand Up @@ -7033,5 +7033,30 @@
referencedColumnNames="user_id"
referencedTableName="users"/>
</changeSet>

<changeSet id="201401161532-TRUNK-4202" author="k-joseph" dbms="mysql">
<preConditions onFail="MARK_RAN">
<not><sqlCheck expectedResult="0">select count(*) from orders</sqlCheck></not>
</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 u.person_id, u.system_id , (select user_id from users where uuid = "A4F30A1B-5EB9-11DF-A648-37A07F9C90FB"), CURRENT_TIMESTAMP , u.retired, UUID()
FROM users as u JOIN orders AS o ON o.orderer = u.user_id
WHERE u.person_id NOT IN (SELECT DISTINCT person_id FROM provider)
</sql>
</changeSet>

<changeSet id="201401202238-TRUNK-4202" author="k-joseph" dbms="mysql">
<preConditions onFail="MARK_RAN">
<not><sqlCheck expectedResult="0">select count(*) from orders</sqlCheck></not>
</preConditions>
<comment>Migrating data in orders.orderer column to be provider_ids instead of user_ids</comment>
<sql>
UPDATE orders AS o INNER JOIN users u ON o.orderer = u.user_id
INNER JOIN provider p ON u.user_id = p.provider_id
SET o.orderer = p.provider_id
</sql>
</changeSet>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test to Database1_9To1_10UpgradeTest to ensure that this works as expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wluyima : i have checked whether i could see any documentation inform of parhaps wiki pages about; "unit testing for our changesets" and i didn't get one, it looks to me like this is still under development as can be seen @{https://tickets.openmrs.org/browse/TRUNK-4052}, in case am not right in this manner, then i request to be directed to that way in which i can have my changeset tested according to openmrs standards

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Database1_9To1_10UpgradeTest.java and add your tests to it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am challenged to write a changeset that; shouldMigrateDataInOrdererColumnToBeProviderIdsInsteadOfUserIds, since am not sure of which way to use in order to run my changeset inside the testcase to update the datasets available within openmrs now that this is under development

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the tests in that class, yours will be very similar

</databaseChangeLog>
Expand Up @@ -68,8 +68,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
Expand Up @@ -159,7 +159,6 @@ public void shouldPassIfAllExistingDrugOrderUnitsAndFrequenciesAreMappedToConcep
}

@Test
@Ignore
public void shouldConvertOrderersToBeingProvidersInsteadOfUsers() throws Exception {
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/standardTest-1.9.7-dataSet.xml");
upgradeTestUtil.executeDataset("/org/openmrs/util/databasechange/database1_9To1_10UpgradeTest-dataSet.xml");
Expand Down