|
|
|
|
@@ -121,6 +121,8 @@ class HomeFragment : Fragment() {
|
|
|
|
|
userData.forEach {
|
|
|
|
|
if (it.testStatus == false) {
|
|
|
|
|
userList.add(it)
|
|
|
|
|
}else if(it.testStatus == true){
|
|
|
|
|
userList.removeAll(userData)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
|
|
|
|
@@ -156,14 +158,16 @@ class HomeFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
val resultList = MolbioV2ResultRequest(mutableListOf())
|
|
|
|
|
originalUserDataList.forEach { userData ->
|
|
|
|
|
Log.d(
|
|
|
|
|
": USER DATA",
|
|
|
|
|
originalUserDataList.count().toString() + " : " + userData._id
|
|
|
|
|
)
|
|
|
|
|
Log.d(": USER DATA", originalUserDataList.count().toString() + " : " + userData._id)
|
|
|
|
|
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
|
|
|
|
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
|
|
|
|
if(accessToken.isNotEmpty()) {
|
|
|
|
|
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
|
|
|
|
|
|
|
|
|
if (!userData.localFlag && userData.testStatus == true) {
|
|
|
|
|
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION && userData.testStatus == true) {
|
|
|
|
|
val currentTimeFormatted = SimpleDateFormat(
|
|
|
|
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
|
|
|
|
Locale.getDefault()
|
|
|
|
|
@@ -176,11 +180,9 @@ class HomeFragment : Fragment() {
|
|
|
|
|
rawData = userData,
|
|
|
|
|
analysisId = userData._id,
|
|
|
|
|
analysisDate = currentTimeFormatted,
|
|
|
|
|
analysisStatus = userData.classificationResult
|
|
|
|
|
?: "defaultStatus", // Handle possible nulls
|
|
|
|
|
analysisStatus = userData.classificationResult ?: "defaultStatus", // Handle possible nulls
|
|
|
|
|
thresholds = bufferIntensityThreshold,
|
|
|
|
|
interpretation = userData.classificationResult
|
|
|
|
|
?: "defaultInterpretation", // Handle possible nulls
|
|
|
|
|
interpretation = userData.classificationResult ?: "defaultInterpretation", // Handle possible nulls
|
|
|
|
|
testId = userData._id,
|
|
|
|
|
testTime = currentTimeFormatted,
|
|
|
|
|
collectionTime = currentTimeFormatted,
|
|
|
|
|
@@ -190,23 +192,19 @@ class HomeFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d("USER DATA LIST SIZE", resultList.results?.count().toString())
|
|
|
|
|
|
|
|
|
|
resultList.results?.forEach { result ->
|
|
|
|
|
val userData = result.rawData
|
|
|
|
|
Log.d("UserData", userData.toString())
|
|
|
|
|
if (userData != null) {
|
|
|
|
|
if (!userData.localFlag) {
|
|
|
|
|
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resultList.results?.forEach { result ->
|
|
|
|
|
result.rawData?.let { sanitizeDoubleValues(it) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then, check if there are any results to upload.
|
|
|
|
|
// Then, check if there are any results to upload.
|
|
|
|
|
if (resultList.results?.isNotEmpty() == true) {
|
|
|
|
|
hemoCubeViewModel.uploadResult(resultList)
|
|
|
|
|
Log.d("resultcount1", "Uploading sanitized results")
|
|
|
|
|
@@ -243,27 +241,28 @@ class HomeFragment : Fragment() {
|
|
|
|
|
binding.uploadData.setOnClickListener {
|
|
|
|
|
// showUploadDialog(requireContext())
|
|
|
|
|
}
|
|
|
|
|
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
|
|
|
|
//
|
|
|
|
|
// val btnSaveLocalVisibility =
|
|
|
|
|
// if (userData.any { it.testStatus == true }) View.GONE else View.GONE
|
|
|
|
|
//
|
|
|
|
|
// binding.downloadCSV.visibility = btnSaveLocalVisibility
|
|
|
|
|
//
|
|
|
|
|
// binding.downloadCSV.setOnClickListener {
|
|
|
|
|
// if (btnSaveLocalVisibility == View.VISIBLE) {
|
|
|
|
|
// // Execute the action when the button is visible (testStatus is true for at least one user)
|
|
|
|
|
// showDownloadDialog(requireContext())
|
|
|
|
|
// } else {
|
|
|
|
|
// // Handle the case when the button is not visible
|
|
|
|
|
// Toast.makeText(
|
|
|
|
|
// requireContext(),
|
|
|
|
|
// "No test details stored locally",
|
|
|
|
|
// Toast.LENGTH_SHORT
|
|
|
|
|
// ).show()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
|
|
|
|
if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") {
|
|
|
|
|
val btnSaveLocalVisibility =
|
|
|
|
|
if (userData.any { it.testStatus == true }) View.VISIBLE else View.GONE
|
|
|
|
|
binding.downloadCSV.visibility = btnSaveLocalVisibility
|
|
|
|
|
binding.downloadCSV.setOnClickListener {
|
|
|
|
|
if (btnSaveLocalVisibility == View.VISIBLE) {
|
|
|
|
|
// Execute the action when the button is visible (testStatus is true for at least one user)
|
|
|
|
|
showDownloadDialog(requireContext())
|
|
|
|
|
} else {
|
|
|
|
|
// Handle the case when the button is not visible
|
|
|
|
|
Toast.makeText(
|
|
|
|
|
requireContext(),
|
|
|
|
|
"No test details stored locally",
|
|
|
|
|
Toast.LENGTH_SHORT
|
|
|
|
|
).show()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
binding.downloadCSV.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.btnNewKit.setOnClickListener {
|
|
|
|
|
@@ -880,11 +879,15 @@ class HomeFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun checkUnprocessedCSVData() {
|
|
|
|
|
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
|
|
|
|
// val downloadDataVisibility =
|
|
|
|
|
// if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.GONE else View.GONE
|
|
|
|
|
// binding.downloadCSV.visibility = downloadDataVisibility
|
|
|
|
|
// }
|
|
|
|
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
|
|
|
|
if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") {
|
|
|
|
|
val downloadDataVisibility =
|
|
|
|
|
if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.VISIBLE else View.GONE
|
|
|
|
|
binding.downloadCSV.visibility = downloadDataVisibility
|
|
|
|
|
}else{
|
|
|
|
|
binding.downloadCSV.visibility = View.GONE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
|
|
|
|
|
@@ -919,22 +922,22 @@ class HomeFragment : Fragment() {
|
|
|
|
|
dialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private fun showDownloadDialog(context: Context) {
|
|
|
|
|
// val builder = AlertDialog.Builder(context)
|
|
|
|
|
// builder.setTitle(R.string.download_db_registration_title)
|
|
|
|
|
// builder.setMessage(R.string.download_db_registration_message)
|
|
|
|
|
//
|
|
|
|
|
// builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
|
|
|
|
// downloadLocalDBData(dialog)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
|
|
|
|
// dialog.dismiss()
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// val dialog = builder.create()
|
|
|
|
|
// dialog.show()
|
|
|
|
|
// }
|
|
|
|
|
private fun showDownloadDialog(context: Context) {
|
|
|
|
|
val builder = AlertDialog.Builder(context)
|
|
|
|
|
builder.setTitle(R.string.download_db_registration_title)
|
|
|
|
|
builder.setMessage(R.string.download_db_registration_message)
|
|
|
|
|
|
|
|
|
|
builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
|
|
|
|
downloadLocalDBData(dialog)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
|
|
|
|
dialog.dismiss()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val dialog = builder.create()
|
|
|
|
|
dialog.show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun uploadLocalDBData(dialog: DialogInterface) {
|
|
|
|
|
// viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
|
|
|
|
@@ -996,27 +999,25 @@ class HomeFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
|
|
|
|
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
|
|
|
|
// val downloadList = mutableListOf<HemoCubeTestData>()
|
|
|
|
|
//
|
|
|
|
|
// userDataList.forEach { userData ->
|
|
|
|
|
// if (!userData.isCSVCreated) {
|
|
|
|
|
// downloadList.add(userData) // Add the userData to downloadList
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (downloadList.isNotEmpty()) {
|
|
|
|
|
// // Call ViewModel function to create CSV with filtered data
|
|
|
|
|
// hemoCubeViewModel.createCSV(downloadList, requireContext())
|
|
|
|
|
// Toast.makeText(requireContext(), "Done", Toast.LENGTH_SHORT).show()
|
|
|
|
|
// } else {
|
|
|
|
|
// Toast.makeText(requireContext(), "Failed", Toast.LENGTH_SHORT).show()
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// dialog.dismiss()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
private fun downloadLocalDBData(dialog: DialogInterface) {
|
|
|
|
|
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
|
|
|
|
val downloadList = mutableListOf<HemoCubeTestData>()
|
|
|
|
|
|
|
|
|
|
userDataList.forEach { userData ->
|
|
|
|
|
if (!userData.isCSVCreated) {
|
|
|
|
|
downloadList.add(userData) // Add the userData to downloadList
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (downloadList.isNotEmpty()) {
|
|
|
|
|
// Call ViewModel function to create CSV with filtered data
|
|
|
|
|
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
|
|
|
|
Toast.makeText(requireContext(), "Done", Toast.LENGTH_SHORT).show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dialog.dismiss()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun deleteIncompleteRegistrations(userDataList: List<UserData>) {
|
|
|
|
|
userDataList.forEach { userData ->
|
|
|
|
|
@@ -1052,22 +1053,22 @@ class HomeFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun showDownloadDialog(context: Context) {
|
|
|
|
|
val builder = AlertDialog.Builder(context)
|
|
|
|
|
builder.setTitle(R.string.download_db_registration_title)
|
|
|
|
|
builder.setMessage(R.string.download_db_registration_message)
|
|
|
|
|
|
|
|
|
|
builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
|
|
|
|
// private fun showDownloadDialog(context: Context) {
|
|
|
|
|
// val builder = AlertDialog.Builder(context)
|
|
|
|
|
// builder.setTitle(R.string.download_db_registration_title)
|
|
|
|
|
// builder.setMessage(R.string.download_db_registration_message)
|
|
|
|
|
//
|
|
|
|
|
// builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
|
|
|
|
// downloadLocalDBData(dialog)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
|
|
|
|
dialog.dismiss()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val dialog = builder.create()
|
|
|
|
|
dialog.show()
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
|
|
|
|
// dialog.dismiss()
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// val dialog = builder.create()
|
|
|
|
|
// dialog.show()
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
|
|
|
|
// var csvDownloaded = false
|
|
|
|
|
|