-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #478 from d-tree-org/new-registration-edi-capture
New registration edi capture
- Loading branch information
Showing
13 changed files
with
435 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
opensrp-chw/src/kk/java/org/smartregister/chw/util/KKAppHealthUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.smartregister.chw.util; | ||
|
||
import android.view.View; | ||
|
||
import org.smartregister.util.AppHealthUtils; | ||
|
||
/** | ||
* Author issyzac on 27/09/2023 | ||
*/ | ||
public class KKAppHealthUtils extends AppHealthUtils { | ||
|
||
public KKAppHealthUtils(View view) { | ||
super(view); | ||
} | ||
|
||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
opensrp-chw/src/main/java/org/smartregister/chw/domain/CleanEDIStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.smartregister.chw.domain; | ||
|
||
/** | ||
* Author issyzac on 27/09/2023 | ||
*/ | ||
public enum CleanEDIStatus { | ||
|
||
CLEANED ("CLEANED"), | ||
PENDING ("PENDING"); | ||
|
||
private String value; | ||
|
||
private CleanEDIStatus(String value){ | ||
this.value = value; | ||
} | ||
|
||
public String value(){ | ||
return this.value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
opensrp-chw/src/main/java/org/smartregister/chw/job/IdentifierCleanerWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.smartregister.chw.job; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.work.WorkManager; | ||
import androidx.work.Worker; | ||
import androidx.work.WorkerParameters; | ||
|
||
import org.smartregister.CoreLibrary; | ||
import org.smartregister.chw.domain.CleanEDIStatus; | ||
import org.smartregister.chw.repository.KKEventClientRepository; | ||
|
||
import timber.log.Timber; | ||
|
||
/** | ||
* Author issyzac on 27/09/2023 | ||
*/ | ||
public class IdentifierCleanerWorker extends Worker { | ||
|
||
private Context context; | ||
public static final String TAG = "IdentifierCleanerWorker"; | ||
KKEventClientRepository repository; | ||
|
||
public IdentifierCleanerWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { | ||
super(context, workerParams); | ||
this.context = context; | ||
repository = new KKEventClientRepository(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Result doWork() { | ||
CleanEDIStatus cleanEDIStatus = null; | ||
try { | ||
cleanEDIStatus = DoClean(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
Timber.i("Doing some cleaning work"); | ||
|
||
// Remove worker if everything has been cleaned | ||
if (cleanEDIStatus != null && cleanEDIStatus.equals(CleanEDIStatus.CLEANED)) | ||
WorkManager.getInstance(context).cancelWorkById(this.getId()); | ||
|
||
return Result.success(); | ||
} | ||
|
||
private CleanEDIStatus DoClean() throws Exception { | ||
// Call repository to clean the IDs | ||
return repository.removeEdiIdsFromClients(); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
opensrp-chw/src/main/java/org/smartregister/chw/repository/EdiIdCleanUpRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.smartregister.chw.repository; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.database.Cursor; | ||
import android.util.Log; | ||
|
||
import org.smartregister.repository.BaseRepository; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import timber.log.Timber; | ||
|
||
/** | ||
* Created by Kassim Sheghembe on 2023-09-27 | ||
*/ | ||
public class EdiIdCleanUpRepository extends BaseRepository { | ||
|
||
private static final String BASE_ENTITY_ID = "baseEntityId"; | ||
|
||
public static final String CLIENTS_WITH_EDI_IDS_SQL = "WITH clients AS (" + | ||
"SELECT " + | ||
"baseEntityId, " + | ||
"COALESCE(json_extract(json, '$.identifiers.edi_id'), json_extract(json, '$.identifiers.mother_edi_id')) as edi_id " + | ||
"FROM client " + | ||
")" + | ||
"select * from clients where edi_id is not null"; | ||
|
||
public Map<String, String> clientsWithEdiIds() { | ||
|
||
Map<String, String> ediIds = new HashMap<>(); | ||
|
||
Cursor cursor = null; | ||
|
||
try { | ||
cursor = getReadableDatabase().rawQuery(CLIENTS_WITH_EDI_IDS_SQL, new String[]{}); | ||
|
||
while (cursor.moveToNext()) { | ||
@SuppressLint("Range") String baseEntityId = cursor.getString(cursor.getColumnIndex(BASE_ENTITY_ID)); | ||
@SuppressLint("Range") String ediId = cursor.getString(cursor.getColumnIndex("edi_id")); | ||
|
||
ediIds.put(baseEntityId, ediId); | ||
} | ||
|
||
} catch (Exception e) { | ||
Log.e("ERRRRORRRRR", e.getMessage()); | ||
Timber.e(e); | ||
} | ||
finally { | ||
if (cursor != null && !cursor.isClosed()) | ||
cursor.close(); | ||
} | ||
|
||
return ediIds; | ||
} | ||
} |
Oops, something went wrong.