Skip to content

Commit

Permalink
USM-19: change query of getting incomplete tests to a non join approa…
Browse files Browse the repository at this point in the history
…ch (#139)

* USM-19 Change query of getting incomplete tests to a non join approach
  • Loading branch information
slubwama authored Feb 7, 2024
1 parent 85531c9 commit 0c61c42
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public interface UgandaEMRSyncService extends OpenmrsService {

/**
* Gets a list of sync task that require an action yet the action is not complete
* @param syncTaskTypeIdentifier the sync task type identifier for the sync tasks that need to be checked
* @param syncTaskTypeUuid the sync task type uuid for the sync tasks that need to be checked
* @return List<SyncTask> that are have an action that is not completed
* @throws APIException
*/
@Transactional
public List<SyncTask> getIncompleteActionSyncTask(String syncTaskTypeIdentifier) throws APIException;
public List<SyncTask> getIncompleteActionSyncTask(String syncTaskTypeUuid) throws APIException;

/**
* Get all sync task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public List getFinalResults(List<String> columns, String finalQuery) {
public List<SyncTask> getIncompleteActionSyncTask(String syncTaskTypeIdentifier) {
SQLQuery sqlQuery = getSession()
.createSQLQuery(
"select sync_task.* from sync_task inner join sync_task_type on (sync_task_type.sync_task_type_id=sync_task.sync_task_type) where sync_task_type.data_type_id='"
"select sync_task.* from sync_task inner join sync_task_type on (sync_task_type.sync_task_type_id=sync_task.sync_task_type) where sync_task_type.uuid='"
+ syncTaskTypeIdentifier
+ "' and require_action=true and action_completed=false;");
sqlQuery.addEntity(SyncTask.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public SyncTask saveSyncTask(SyncTask syncTask) throws APIException {
* @see org.openmrs.module.ugandaemrsync.api.UgandaEMRSyncService#getIncompleteActionSyncTask(java.lang.String)
*/
@Override
public List<SyncTask> getIncompleteActionSyncTask(String syncTaskTypeIdentifier) throws APIException {
return dao.getIncompleteActionSyncTask(syncTaskTypeIdentifier);
public List<SyncTask> getIncompleteActionSyncTask(String syncTaskTypeUuid) throws APIException {
return dao.getIncompleteActionSyncTask(syncTaskTypeUuid);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public class SyncConstant {

public static final String VIRAL_LOAD_LAB_REQUEST_ENCOUNTER_TYPE_UUID = "077c43ee-9745-11e9-bc42-526af7764f64";

public static final String VIRAL_LOAD_SYNC_TASK_TYPE_IDENTIFIER = "315124004";
public static final String VIRAL_LOAD_SYNC_TASK_TYPE_UUID = "3551ca84-06c0-432b-9064-fcfeefd6f4ec";

public static final String VIRAL_LOAD_SYNC_TYPE_UUID = "3551ca84-06c0-432b-9064-fcfeefd6f4ec";
public static final String VL_PROGRAM_DATA_SYNC_TYPE_UUID = "f9b2fa5d-5d37-4fd9-b20a-a0cab664f520";
public static final String FHIRSERVER_SYNC_TASK_TYPE_UUID = "3c1ce940-8ade-11ea-bc55-0242ac130003";
public static final String VIRAL_LOAD_RESULT_PULL_TYPE_UUID = "3396dcf0-2106-4e73-9b90-c63978c3a8b4";

public static final String LAB_RESULT_PULL_TYPE_UUID = "f947128e-93d7-46d5-aa32-645e38a125fe";
public static final String LAB_RESULT_PULL_SYNC_TASK_TYPE_UUID = "d4a3ebbb-e793-4e56-867c-0cf998e51f56";

public static final String SEND_MER_REPORTS_SYNC_TASK_TYPE_UUID = "6ebd85c8-127b-4c88-8a40-27defef367a9";
public static final String SEND_HMIS_REPORTS_SYNC_TASK_TYPE_UUID = "c5f00f18-c0f6-4917-b973-2b7c1d2d4a81";
Expand Down Expand Up @@ -468,7 +468,7 @@ public class SyncConstant {

public static final String VIRAL_LOAD_ENCOUNTER_QUERY = "select * from encounter inner join encounter_type on (encounter.encounter_type=encounter_type.encounter_type_id) where encounter_type.uuid='077c43ee-9745-11e9-bc42-526af7764f64'";

public static final String VIRAL_LOAD_ORDERS_QUERY = "select orders.order_id from orders inner join test_order on (test_order.order_id=orders.order_id) inner JOIN concept ON (orders.concept_id = concept.concept_id) inner join concept_reference_map on (concept.concept_id = concept_reference_map.concept_id) inner join concept_reference_term on (concept_reference_map.concept_reference_term_id = concept_reference_term.concept_reference_term_id) where accession_number!=\"\" AND specimen_source!=\"\" AND orders.instructions=\"REFER TO cphl\" AND code=\"" + VIRAL_LOAD_SYNC_TASK_TYPE_IDENTIFIER + "\"";
public static final String VIRAL_LOAD_ORDERS_QUERY = "select orders.order_id from orders inner join test_order on (test_order.order_id=orders.order_id) inner JOIN concept ON (orders.concept_id = concept.concept_id) inner join concept_reference_map on (concept.concept_id = concept_reference_map.concept_id) inner join concept_reference_term on (concept_reference_map.concept_reference_term_id = concept_reference_term.concept_reference_term_id) where accession_number!=\"\" AND specimen_source!=\"\" AND orders.instructions=\"REFER TO cphl\" AND code=\"" + VIRAL_LOAD_SYNC_TASK_TYPE_UUID + "\"";

public static final String VIRAL_LOAD_ORDER_QUERY = "select orders.order_id from orders inner join test_order on (test_order.order_id=orders.order_id) where accession_number=\"%s\"";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void execute() {
return;
}

for (SyncTask syncTask : ugandaEMRSyncService.getIncompleteActionSyncTask(LAB_RESULT_PULL_TYPE_UUID)) {
for (SyncTask syncTask : ugandaEMRSyncService.getIncompleteActionSyncTask(LAB_RESULT_PULL_SYNC_TASK_TYPE_UUID)) {

Order order = getOrder(syncTask.getSyncTask());
Map results = new HashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.openmrs.module.ugandaemrsync.model.SyncTask;
import org.openmrs.module.ugandaemrsync.model.SyncTaskType;
import org.openmrs.module.ugandaemrsync.api.UgandaEMRHttpURLConnection;
import org.openmrs.module.ugandaemrsync.util.UgandaEMRSyncUtil;
import org.openmrs.scheduler.tasks.AbstractTask;

import java.util.*;
Expand All @@ -29,8 +28,7 @@ public void execute() {
return;
}

for (SyncTask syncTask : ugandaEMRSyncService.getIncompleteActionSyncTask(VIRAL_LOAD_SYNC_TASK_TYPE_IDENTIFIER)) {

for (SyncTask syncTask : ugandaEMRSyncService.getIncompleteActionSyncTask(VIRAL_LOAD_SYNC_TASK_TYPE_UUID)) {
Order order = getOrder(syncTask.getSyncTask());

String dataOutput = generateVLFHIRResultRequestBody(VL_RECEIVE_RESULT_FHIR_JSON_STRING, ugandaEMRSyncService.getHealthCenterCode(), ugandaEMRSyncService.getPatientIdentifier(order.getEncounter().getPatient(), PATIENT_IDENTIFIER_TYPE), String.valueOf(syncTask.getSyncTask())).get("json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void getSyncTaskTypeByUUID_shouldReturnSyncTaskTypeThatMatchesUUID() {
public void getSyncT_shouldReturnSyncTaskTypeThatMatchesUUID() {
UgandaEMRSyncService ugandaEMRSyncService = Context.getService(UgandaEMRSyncService.class);
SyncTaskType syncTaskType = ugandaEMRSyncService.getSyncTaskTypeByUUID(VIRAL_LOAD_SYNC_TYPE_UUID);
List<SyncTask> syncTasks = ugandaEMRSyncService.getIncompleteActionSyncTask(syncTaskType.getDataTypeId());
List<SyncTask> syncTasks = ugandaEMRSyncService.getIncompleteActionSyncTask(syncTaskType.getUuid());

Assert.assertNotEquals(0, syncTasks.size());
Assert.assertEquals(VIRAL_LOAD_SYNC_TYPE_UUID, syncTasks.get(0).getSyncTaskType().getUuid());
Expand Down

0 comments on commit 0c61c42

Please sign in to comment.