Compare commits
11 Commits
dev-Adding
...
dev-molbio
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b059bc953 | ||
|
|
320ceae26a | ||
|
|
08a781a706 | ||
|
|
8c4fedfe28 | ||
|
|
71818e1115 | ||
|
|
d7c1508397 | ||
|
|
d701ee4f6d | ||
|
|
e4b237bb9a | ||
|
|
3913aedefc | ||
|
|
b554f64b51 | ||
|
|
95bb428041 |
@@ -13,6 +13,12 @@ interface HemoCubeDao {
|
|||||||
@Query("SELECT * from hemo_cube_test_table")
|
@Query("SELECT * from hemo_cube_test_table")
|
||||||
fun getAll(): LiveData<List<HemoCubeTestData>>
|
fun getAll(): LiveData<List<HemoCubeTestData>>
|
||||||
|
|
||||||
|
@Query("SELECT * from hemo_cube_test_table WHERE molbioFlag=false")
|
||||||
|
fun getMolbioPending(): List<HemoCubeTestData>
|
||||||
|
|
||||||
|
@Query("SELECT * from hemo_cube_test_table WHERE localFlag=false")
|
||||||
|
fun getFirebasePending():List<HemoCubeTestData>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(hemoCubeTestData: HemoCubeTestData)
|
suspend fun insertAll(hemoCubeTestData: HemoCubeTestData)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.example.hpostesting.encryption
|
||||||
|
|
||||||
|
import android.util.Base64
|
||||||
|
import javax.crypto.Cipher
|
||||||
|
import javax.crypto.SecretKeyFactory
|
||||||
|
import javax.crypto.spec.IvParameterSpec
|
||||||
|
import javax.crypto.spec.PBEKeySpec
|
||||||
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
|
object Encryption {
|
||||||
|
private const val AES_MODE = "AES/CBC/PKCS5Padding"
|
||||||
|
private const val KEY_SPEC_ALGORITHM = "PBKDF2WithHmacSHA1"
|
||||||
|
private const val SALT = "Bigtec"
|
||||||
|
private const val ITERATION_COUNT = 10000
|
||||||
|
private const val KEY_LENGTH = 256
|
||||||
|
private val FIXED_IV = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
|
||||||
|
|
||||||
|
fun encrypt(textToEncrypt: String, password: String): String {
|
||||||
|
val salt = SALT.toByteArray()
|
||||||
|
val factory = SecretKeyFactory.getInstance(KEY_SPEC_ALGORITHM)
|
||||||
|
val spec = PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH)
|
||||||
|
val tmp = factory.generateSecret(spec)
|
||||||
|
val key = SecretKeySpec(tmp.encoded, "AES")
|
||||||
|
val cipher = Cipher.getInstance(AES_MODE)
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, key, IvParameterSpec(FIXED_IV))
|
||||||
|
val encryptedBytes = cipher.doFinal(textToEncrypt.toByteArray(Charsets.UTF_8))
|
||||||
|
return Base64.encodeToString(encryptedBytes, Base64.NO_WRAP)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun decrypt(encryptedText: String, password: String): String {
|
||||||
|
val salt = SALT.toByteArray()
|
||||||
|
val encryptedBytes = Base64.decode(encryptedText, Base64.NO_WRAP)
|
||||||
|
val factory = SecretKeyFactory.getInstance(KEY_SPEC_ALGORITHM)
|
||||||
|
val spec = PBEKeySpec(password.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH)
|
||||||
|
val tmp = factory.generateSecret(spec)
|
||||||
|
val key = SecretKeySpec(tmp.encoded, "AES")
|
||||||
|
val cipher = Cipher.getInstance(AES_MODE)
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, key, IvParameterSpec(FIXED_IV))
|
||||||
|
val decryptedBytes = cipher.doFinal(encryptedBytes)
|
||||||
|
return String(decryptedBytes, Charsets.UTF_8)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,16 +25,12 @@ class ActivitiesFragment : Fragment() {
|
|||||||
private lateinit var binding: FragmentActivitiesBinding
|
private lateinit var binding: FragmentActivitiesBinding
|
||||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||||
private lateinit var adapter: OfflineUserListAdapter
|
private lateinit var adapter: OfflineUserListAdapter
|
||||||
private lateinit var sharedPreference: SharedPreferences
|
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||||
): View {
|
): View {
|
||||||
binding = FragmentActivitiesBinding.inflate(inflater, container, false)
|
binding = FragmentActivitiesBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
sharedPreference = requireContext().getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
|
||||||
DataHolder.selectedTest = null
|
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import android.net.Uri
|
|||||||
import android.os.BatteryManager
|
import android.os.BatteryManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Environment
|
||||||
|
import android.provider.Settings
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -28,6 +30,7 @@ import androidx.fragment.app.activityViewModels
|
|||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.example.hpostesting.data.constant.DataHolder
|
import com.example.hpostesting.data.constant.DataHolder
|
||||||
import com.example.hpostesting.util.Result
|
import com.example.hpostesting.util.Result
|
||||||
|
import com.example.hpostesting.presentation.utils.DeviceCommunicationHandler
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.login.LoginRequest
|
import com.example.hpostesting.data.model.login.LoginRequest
|
||||||
@@ -39,7 +42,7 @@ import com.example.hpostesting.data.model.patient.HemoCubeTestData
|
|||||||
import com.example.hpostesting.data.model.patient.UserData
|
import com.example.hpostesting.data.model.patient.UserData
|
||||||
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
import com.example.hpostesting.data.model.updates.CheckUpdateRequest
|
||||||
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
|
||||||
import com.example.hpostesting.presentation.utils.DeviceCommunicationHandler
|
import com.example.hpostesting.encryption.Encryption
|
||||||
import com.example.hpostesting.presentation.KitScanActivity
|
import com.example.hpostesting.presentation.KitScanActivity
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
import com.example.hpostesting.presentation.adapter.OfflineUserListAdapter
|
||||||
@@ -56,6 +59,7 @@ import com.google.firebase.perf.ktx.performance
|
|||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import `in`.sminnovations.hpostesting.R
|
import `in`.sminnovations.hpostesting.R
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentHomeBinding
|
||||||
|
import kotlinx.coroutines.tasks.await
|
||||||
import okhttp3.ResponseBody
|
import okhttp3.ResponseBody
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
@@ -121,8 +125,6 @@ class HomeFragment : Fragment() {
|
|||||||
userData.forEach {
|
userData.forEach {
|
||||||
if (it.testStatus == false) {
|
if (it.testStatus == false) {
|
||||||
userList.add(it)
|
userList.add(it)
|
||||||
}else if(it.testStatus == true){
|
|
||||||
userList.removeAll(userData)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
val bm = requireContext().getSystemService(BATTERY_SERVICE) as BatteryManager
|
||||||
@@ -152,22 +154,20 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now re-subscribe to allUserData
|
// Now re-subscribe to allUserData
|
||||||
hemoCubeViewModel.allLocalData.observe(viewLifecycleOwner) { originalUserDataList ->
|
/* hemoCubeViewModel.allLocalData.observe(viewLifecycleOwner) { originalUserDataList ->
|
||||||
|
|
||||||
Log.d("LOCAL_DB OBSERVE", "OBSERVE CALLED")
|
Log.d("LOCAL_DB OBSERVE", "OBSERVE CALLED")
|
||||||
|
|
||||||
val resultList = MolbioV2ResultRequest(mutableListOf())
|
val resultList = MolbioV2ResultRequest(mutableListOf())
|
||||||
originalUserDataList.forEach { userData ->
|
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()
|
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||||
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
||||||
if(accessToken.isNotEmpty()) {
|
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(
|
val currentTimeFormatted = SimpleDateFormat(
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
Locale.getDefault()
|
Locale.getDefault()
|
||||||
@@ -180,9 +180,11 @@ class HomeFragment : Fragment() {
|
|||||||
rawData = userData,
|
rawData = userData,
|
||||||
analysisId = userData._id,
|
analysisId = userData._id,
|
||||||
analysisDate = currentTimeFormatted,
|
analysisDate = currentTimeFormatted,
|
||||||
analysisStatus = userData.classificationResult ?: "defaultStatus", // Handle possible nulls
|
analysisStatus = userData.classificationResult
|
||||||
|
?: "defaultStatus", // Handle possible nulls
|
||||||
thresholds = bufferIntensityThreshold,
|
thresholds = bufferIntensityThreshold,
|
||||||
interpretation = userData.classificationResult ?: "defaultInterpretation", // Handle possible nulls
|
interpretation = userData.classificationResult
|
||||||
|
?: "defaultInterpretation", // Handle possible nulls
|
||||||
testId = userData._id,
|
testId = userData._id,
|
||||||
testTime = currentTimeFormatted,
|
testTime = currentTimeFormatted,
|
||||||
collectionTime = currentTimeFormatted,
|
collectionTime = currentTimeFormatted,
|
||||||
@@ -192,14 +194,18 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("USER DATA LIST SIZE", resultList.results?.count().toString())
|
Log.d("USER DATA LIST SIZE", resultList.results?.count().toString())
|
||||||
|
|
||||||
resultList.results?.forEach { result ->
|
resultList.results?.forEach { result ->
|
||||||
val userData = result.rawData
|
val userData = result.rawData
|
||||||
Log.d("UserData", userData.toString())
|
Log.d("UserData", userData.toString())
|
||||||
|
if (userData != null) {
|
||||||
|
if (!userData.localFlag) {
|
||||||
|
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
resultList.results?.forEach { result ->
|
resultList.results?.forEach { result ->
|
||||||
result.rawData?.let { sanitizeDoubleValues(it) }
|
result.rawData?.let { sanitizeDoubleValues(it) }
|
||||||
}
|
}
|
||||||
@@ -210,7 +216,9 @@ class HomeFragment : Fragment() {
|
|||||||
Log.d("resultcount1", "Uploading sanitized results")
|
Log.d("resultcount1", "Uploading sanitized results")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
hemoCubeViewModel.sendDataToMolbio()
|
||||||
|
hemoCubeViewModel.sendDataToFirebase()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
binding.internetAvailableCL.visibility = View.GONE
|
binding.internetAvailableCL.visibility = View.GONE
|
||||||
@@ -241,28 +249,27 @@ class HomeFragment : Fragment() {
|
|||||||
binding.uploadData.setOnClickListener {
|
binding.uploadData.setOnClickListener {
|
||||||
// showUploadDialog(requireContext())
|
// showUploadDialog(requireContext())
|
||||||
}
|
}
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userData ->
|
||||||
if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") {
|
//
|
||||||
val btnSaveLocalVisibility =
|
// val btnSaveLocalVisibility =
|
||||||
if (userData.any { it.testStatus == true }) View.VISIBLE else View.GONE
|
// if (userData.any { it.testStatus == true }) View.GONE else View.GONE
|
||||||
binding.downloadCSV.visibility = btnSaveLocalVisibility
|
//
|
||||||
binding.downloadCSV.setOnClickListener {
|
// binding.downloadCSV.visibility = btnSaveLocalVisibility
|
||||||
if (btnSaveLocalVisibility == View.VISIBLE) {
|
//
|
||||||
// Execute the action when the button is visible (testStatus is true for at least one user)
|
// binding.downloadCSV.setOnClickListener {
|
||||||
showDownloadDialog(requireContext())
|
// if (btnSaveLocalVisibility == View.VISIBLE) {
|
||||||
} else {
|
// // Execute the action when the button is visible (testStatus is true for at least one user)
|
||||||
// Handle the case when the button is not visible
|
// showDownloadDialog(requireContext())
|
||||||
Toast.makeText(
|
// } else {
|
||||||
requireContext(),
|
// // Handle the case when the button is not visible
|
||||||
"No test details stored locally",
|
// Toast.makeText(
|
||||||
Toast.LENGTH_SHORT
|
// requireContext(),
|
||||||
).show()
|
// "No test details stored locally",
|
||||||
}
|
// Toast.LENGTH_SHORT
|
||||||
}
|
// ).show()
|
||||||
}else{
|
// }
|
||||||
binding.downloadCSV.visibility = View.GONE
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
binding.btnNewKit.setOnClickListener {
|
binding.btnNewKit.setOnClickListener {
|
||||||
@@ -272,7 +279,7 @@ class HomeFragment : Fragment() {
|
|||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
startActivity(Intent(requireContext(), KitScanActivity::class.java))
|
startActivity(Intent(requireContext(), KitScanActivity::class.java))
|
||||||
// requireActivity().finish()
|
requireActivity().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -306,6 +313,10 @@ class HomeFragment : Fragment() {
|
|||||||
var password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
var password = sharedPreference.getString(Constants.DEVICE_PASSWORD_API, "").toString()
|
||||||
var userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
var userID = sharedPreference.getString(Constants.DEVICE_ID_API, "").toString()
|
||||||
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
||||||
|
|
||||||
|
val target = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||||
|
val file = File(target, "credentials.txt") //this file contains userID and password to communicate with API.
|
||||||
|
|
||||||
if (userID.isNotEmpty() && password.isNotEmpty()) {
|
if (userID.isNotEmpty() && password.isNotEmpty()) {
|
||||||
Log.d("istoken", isTokenAvailable.toString())
|
Log.d("istoken", isTokenAvailable.toString())
|
||||||
if (!isTokenAvailable) {
|
if (!isTokenAvailable) {
|
||||||
@@ -326,6 +337,28 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
} else if (userID == "deviceIDAPI" && password == "devicePasswordAPI" && deviceId.isNotEmpty()) {
|
} else if (userID == "deviceIDAPI" && password == "devicePasswordAPI" && deviceId.isNotEmpty()) {
|
||||||
fetchDeviceCredentials()
|
fetchDeviceCredentials()
|
||||||
|
} else if (file.exists()) {
|
||||||
|
val encryptedString = file.readText()
|
||||||
|
val encryptionKey =
|
||||||
|
Settings.Secure.getString(context?.contentResolver, Settings.Secure.ANDROID_ID)
|
||||||
|
val decryptedMessage: String = Encryption.decrypt(encryptedString, encryptionKey)
|
||||||
|
val credentials = decryptedMessage.split("\n")
|
||||||
|
userID = credentials[0]
|
||||||
|
password = credentials[1]
|
||||||
|
Toast.makeText(context, "DECRYPTED: $credentials", Toast.LENGTH_SHORT).show()
|
||||||
|
if (!isTokenAvailable) {
|
||||||
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
|
isTokenAvailable = true
|
||||||
|
|
||||||
|
} else if (isTokenAvailable) {
|
||||||
|
isTokenAvailable = true
|
||||||
|
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||||
|
hemoCubeViewModel.checkUpdate(createCheckUpdateRequestData())
|
||||||
|
} else {
|
||||||
|
if (isTokenExpired(accessToken)) {
|
||||||
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
@@ -374,7 +407,11 @@ class HomeFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Toast.makeText(activity, "Molbio Result is successfully uploaded", Toast.LENGTH_LONG)
|
Toast.makeText(
|
||||||
|
activity,
|
||||||
|
"Molbio Result is successfully uploaded",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -430,7 +467,8 @@ class HomeFragment : Fragment() {
|
|||||||
context?.let { ctx ->
|
context?.let { ctx ->
|
||||||
val packageInfo = ctx.packageManager.getPackageInfo(ctx.packageName, 0)
|
val packageInfo = ctx.packageManager.getPackageInfo(ctx.packageName, 0)
|
||||||
val versionName = packageInfo.versionName
|
val versionName = packageInfo.versionName
|
||||||
val versionCode: Long = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
val versionCode: Long =
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
// From Android P (API level 28), versionCode is deprecated and you should use longVersionCode instead.
|
// From Android P (API level 28), versionCode is deprecated and you should use longVersionCode instead.
|
||||||
packageInfo.longVersionCode
|
packageInfo.longVersionCode
|
||||||
} else {
|
} else {
|
||||||
@@ -439,7 +477,10 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use versionName and versionCode as needed
|
// Use versionName and versionCode as needed
|
||||||
Log.d("AppInfo", "Version Name: $versionName, Version Code: $versionCode")
|
Log.d(
|
||||||
|
"AppInfo",
|
||||||
|
"Version Name: $versionName, Version Code: $versionCode"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Log.d("versionnow", currentversion.toString())
|
Log.d("versionnow", currentversion.toString())
|
||||||
Log.d("versionnow", updatedversion.toString())
|
Log.d("versionnow", updatedversion.toString())
|
||||||
@@ -487,14 +528,19 @@ class HomeFragment : Fragment() {
|
|||||||
|
|
||||||
val downloadDirectory = "NATS"
|
val downloadDirectory = "NATS"
|
||||||
val fileName = "nats_certificate.zip"
|
val fileName = "nats_certificate.zip"
|
||||||
val unzipDirectoryPath = requireContext().getExternalFilesDir(null)?.absolutePath + "/$downloadDirectory"
|
val unzipDirectoryPath =
|
||||||
|
requireContext().getExternalFilesDir(null)?.absolutePath + "/$downloadDirectory"
|
||||||
|
|
||||||
// Check if the directory with extracted files exists.
|
// Check if the directory with extracted files exists.
|
||||||
val directory = File(unzipDirectoryPath)
|
val directory = File(unzipDirectoryPath)
|
||||||
if (directory.exists() && directory.isDirectory) {
|
if (directory.exists() && directory.isDirectory) {
|
||||||
// Assuming if the directory exists, the certificate has been downloaded and extracted.
|
// Assuming if the directory exists, the certificate has been downloaded and extracted.
|
||||||
// You can add more specific checks here, e.g., checking for specific files within the directory.
|
// You can add more specific checks here, e.g., checking for specific files within the directory.
|
||||||
Toast.makeText(requireContext(), "NATS certificate already downloaded and extracted.", Toast.LENGTH_SHORT).show()
|
Toast.makeText(
|
||||||
|
requireContext(),
|
||||||
|
"NATS certificate already downloaded and extracted.",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
return@observe
|
return@observe
|
||||||
}
|
}
|
||||||
val file = downloadFile(url, requireContext(), fileName, downloadDirectory)
|
val file = downloadFile(url, requireContext(), fileName, downloadDirectory)
|
||||||
@@ -879,15 +925,11 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkUnprocessedCSVData() {
|
private fun checkUnprocessedCSVData() {
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
if (sharedPreference.getString(Constants.USER_ID, "").toString() == "ADMIN") {
|
// val downloadDataVisibility =
|
||||||
val downloadDataVisibility =
|
// if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.GONE else View.GONE
|
||||||
if (userDataList.any { !it.isCSVCreated && it.testStatus == true }) View.VISIBLE else View.GONE
|
// binding.downloadCSV.visibility = downloadDataVisibility
|
||||||
binding.downloadCSV.visibility = downloadDataVisibility
|
// }
|
||||||
}else{
|
|
||||||
binding.downloadCSV.visibility = View.GONE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
|
private fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
|
||||||
@@ -904,7 +946,6 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun showUploadDialog(context: Context) {
|
private fun showUploadDialog(context: Context) {
|
||||||
val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
builder.setTitle(R.string.upload_db_registration_title)
|
builder.setTitle(R.string.upload_db_registration_title)
|
||||||
@@ -922,22 +963,22 @@ class HomeFragment : Fragment() {
|
|||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showDownloadDialog(context: Context) {
|
// private fun showDownloadDialog(context: Context) {
|
||||||
val builder = AlertDialog.Builder(context)
|
// val builder = AlertDialog.Builder(context)
|
||||||
builder.setTitle(R.string.download_db_registration_title)
|
// builder.setTitle(R.string.download_db_registration_title)
|
||||||
builder.setMessage(R.string.download_db_registration_message)
|
// builder.setMessage(R.string.download_db_registration_message)
|
||||||
|
//
|
||||||
builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
// builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
||||||
downloadLocalDBData(dialog)
|
// downloadLocalDBData(dialog)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
// builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||||
dialog.dismiss()
|
// dialog.dismiss()
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
val dialog = builder.create()
|
// val dialog = builder.create()
|
||||||
dialog.show()
|
// dialog.show()
|
||||||
}
|
// }
|
||||||
|
|
||||||
private fun uploadLocalDBData(dialog: DialogInterface) {
|
private fun uploadLocalDBData(dialog: DialogInterface) {
|
||||||
// viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
// viewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
@@ -999,25 +1040,27 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun downloadLocalDBData(dialog: DialogInterface) {
|
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
// hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||||
val downloadList = mutableListOf<HemoCubeTestData>()
|
// val downloadList = mutableListOf<HemoCubeTestData>()
|
||||||
|
//
|
||||||
userDataList.forEach { userData ->
|
// userDataList.forEach { userData ->
|
||||||
if (!userData.isCSVCreated) {
|
// if (!userData.isCSVCreated) {
|
||||||
downloadList.add(userData) // Add the userData to downloadList
|
// downloadList.add(userData) // Add the userData to downloadList
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (downloadList.isNotEmpty()) {
|
// if (downloadList.isNotEmpty()) {
|
||||||
// Call ViewModel function to create CSV with filtered data
|
// // Call ViewModel function to create CSV with filtered data
|
||||||
hemoCubeViewModel.createCSV(downloadList, requireContext())
|
// hemoCubeViewModel.createCSV(downloadList, requireContext())
|
||||||
Toast.makeText(requireContext(), "Done", Toast.LENGTH_SHORT).show()
|
// Toast.makeText(requireContext(), "Done", Toast.LENGTH_SHORT).show()
|
||||||
}
|
// } else {
|
||||||
|
// Toast.makeText(requireContext(), "Failed", Toast.LENGTH_SHORT).show()
|
||||||
dialog.dismiss()
|
// }
|
||||||
}
|
//
|
||||||
}
|
// dialog.dismiss()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private fun deleteIncompleteRegistrations(userDataList: List<UserData>) {
|
private fun deleteIncompleteRegistrations(userDataList: List<UserData>) {
|
||||||
userDataList.forEach { userData ->
|
userDataList.forEach { userData ->
|
||||||
@@ -1053,22 +1096,22 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun showDownloadDialog(context: Context) {
|
private fun showDownloadDialog(context: Context) {
|
||||||
// val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
// builder.setTitle(R.string.download_db_registration_title)
|
builder.setTitle(R.string.download_db_registration_title)
|
||||||
// builder.setMessage(R.string.download_db_registration_message)
|
builder.setMessage(R.string.download_db_registration_message)
|
||||||
//
|
|
||||||
// builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
builder.setPositiveButton(R.string.downloadcsv) { dialog, _ ->
|
||||||
// downloadLocalDBData(dialog)
|
// downloadLocalDBData(dialog)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
builder.setNegativeButton(R.string.cancel) { dialog, _ ->
|
||||||
// dialog.dismiss()
|
dialog.dismiss()
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// val dialog = builder.create()
|
val dialog = builder.create()
|
||||||
// dialog.show()
|
dialog.show()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||||
// var csvDownloaded = false
|
// var csvDownloaded = false
|
||||||
@@ -1125,7 +1168,8 @@ class HomeFragment : Fragment() {
|
|||||||
val receivedData = String(it, Charset.forName("UTF-8"))
|
val receivedData = String(it, Charset.forName("UTF-8"))
|
||||||
Log.d("HomeFragment", "USB data" + receivedData)
|
Log.d("HomeFragment", "USB data" + receivedData)
|
||||||
// Assuming the device ID is the full content of the received data. Adjust if needed.
|
// Assuming the device ID is the full content of the received data. Adjust if needed.
|
||||||
deviceId = extractDeviceId(receivedData) // Implement this method based on your data format.
|
deviceId =
|
||||||
|
extractDeviceId(receivedData) // Implement this method based on your data format.
|
||||||
if (deviceId.isNotEmpty()) {
|
if (deviceId.isNotEmpty()) {
|
||||||
// Store the deviceId in SharedPreferences
|
// Store the deviceId in SharedPreferences
|
||||||
with(sharedPreference.edit()) {
|
with(sharedPreference.edit()) {
|
||||||
@@ -1154,6 +1198,7 @@ class HomeFragment : Fragment() {
|
|||||||
val matchResult = regex.find(receivedData)
|
val matchResult = regex.find(receivedData)
|
||||||
return matchResult?.groups?.get(1)?.value ?: ""
|
return matchResult?.groups?.get(1)?.value ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SuspiciousIndentation")
|
@SuppressLint("SuspiciousIndentation")
|
||||||
private fun checkForUpdate() {
|
private fun checkForUpdate() {
|
||||||
try {
|
try {
|
||||||
@@ -1175,7 +1220,8 @@ class HomeFragment : Fragment() {
|
|||||||
val updatePathGlobal = deviceData.updatePath
|
val updatePathGlobal = deviceData.updatePath
|
||||||
|
|
||||||
|
|
||||||
db.collection("devices").whereEqualTo("deviceId", deviceId).get().addOnSuccessListener { documentSnapshotNew ->
|
db.collection("devices").whereEqualTo("deviceId", deviceId).get()
|
||||||
|
.addOnSuccessListener { documentSnapshotNew ->
|
||||||
if (documentSnapshotNew.documents.isNotEmpty()) {
|
if (documentSnapshotNew.documents.isNotEmpty()) {
|
||||||
documentSnapshotNew.documents.forEach {
|
documentSnapshotNew.documents.forEach {
|
||||||
val documentIn = it.toObject(DeviceData::class.java)
|
val documentIn = it.toObject(DeviceData::class.java)
|
||||||
@@ -1186,16 +1232,23 @@ class HomeFragment : Fragment() {
|
|||||||
val updatePath = documentIn.updatePath
|
val updatePath = documentIn.updatePath
|
||||||
if (globalUpdateIgnore) {
|
if (globalUpdateIgnore) {
|
||||||
if (deviceUpdateAvailable) {
|
if (deviceUpdateAvailable) {
|
||||||
val update = db.collection("devices").document(it.id).update("deviceUpdateAvailable",false)
|
val update = db.collection("devices").document(it.id)
|
||||||
|
.update("deviceUpdateAvailable", false)
|
||||||
update.addOnSuccessListener {
|
update.addOnSuccessListener {
|
||||||
Log.d("HomeFragmentUpdate","Device local update done")
|
Log.d(
|
||||||
|
"HomeFragmentUpdate",
|
||||||
|
"Device local update done"
|
||||||
|
)
|
||||||
|
|
||||||
initiateUpdate(updatePath)
|
initiateUpdate(updatePath)
|
||||||
}.addOnFailureListener {
|
}.addOnFailureListener {
|
||||||
Log.e("fetchDeviceUpdate", "update fail.")
|
Log.e("fetchDeviceUpdate", "update fail.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d("HomeFragmentUpdate","Device update not available")
|
Log.d(
|
||||||
|
"HomeFragmentUpdate",
|
||||||
|
"Device update not available"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (deviceUpdateAvailableGlobal) {
|
if (deviceUpdateAvailableGlobal) {
|
||||||
@@ -1263,7 +1316,8 @@ class HomeFragment : Fragment() {
|
|||||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||||
request.setDestinationInExternalFilesDir(requireActivity(), "Updates", "update.apk")
|
request.setDestinationInExternalFilesDir(requireActivity(), "Updates", "update.apk")
|
||||||
|
|
||||||
val downloadManager = requireActivity().getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
val downloadManager =
|
||||||
|
requireActivity().getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||||
downloadId = downloadManager.enqueue(request)
|
downloadId = downloadManager.enqueue(request)
|
||||||
|
|
||||||
// Register a BroadcastReceiver to receive the download complete event
|
// Register a BroadcastReceiver to receive the download complete event
|
||||||
@@ -1273,12 +1327,15 @@ class HomeFragment : Fragment() {
|
|||||||
requireActivity().registerReceiver(downloadReceiver, filter, RECEIVER_EXPORTED)
|
requireActivity().registerReceiver(downloadReceiver, filter, RECEIVER_EXPORTED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun extractApkUrl(responseBody: ResponseBody): String {
|
private fun extractApkUrl(responseBody: ResponseBody): String {
|
||||||
return responseBody.string()
|
return responseBody.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isValidHttpUrl(url: String): Boolean {
|
private fun isValidHttpUrl(url: String): Boolean {
|
||||||
return url.startsWith("http://") || url.startsWith("https://")
|
return url.startsWith("http://") || url.startsWith("https://")
|
||||||
}
|
}
|
||||||
|
|
||||||
private val downloadReceiver = object : BroadcastReceiver() {
|
private val downloadReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
|
val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
|
||||||
@@ -1292,7 +1349,10 @@ class HomeFragment : Fragment() {
|
|||||||
val file = File(requireActivity().getExternalFilesDir("Updates"), "update.apk")
|
val file = File(requireActivity().getExternalFilesDir("Updates"), "update.apk")
|
||||||
file.setReadable(true, false) // Ensure the file is readable
|
file.setReadable(true, false) // Ensure the file is readable
|
||||||
|
|
||||||
val pInfo = requireActivity().baseContext.packageManager.getPackageInfo(requireActivity().baseContext.packageName, 0)
|
val pInfo = requireActivity().baseContext.packageManager.getPackageInfo(
|
||||||
|
requireActivity().baseContext.packageName,
|
||||||
|
0
|
||||||
|
)
|
||||||
Log.d("HomeFragmentShowInfo", pInfo.packageName.toString())
|
Log.d("HomeFragmentShowInfo", pInfo.packageName.toString())
|
||||||
val uri: Uri = FileProvider.getUriForFile(
|
val uri: Uri = FileProvider.getUriForFile(
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Environment
|
||||||
|
import android.provider.Settings
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@@ -17,11 +19,15 @@ import com.example.hpostesting.data.constant.Constants
|
|||||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
||||||
import com.example.hpostesting.data.model.patient.DeviceData
|
import com.example.hpostesting.data.model.patient.DeviceData
|
||||||
|
import com.example.hpostesting.encryption.Encryption
|
||||||
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
import com.example.hpostesting.presentation.utils.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
|
import com.google.android.gms.ads.identifier.AdvertisingIdClient
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
import com.google.firebase.ktx.Firebase
|
import com.google.firebase.ktx.Firebase
|
||||||
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
class DeviceProvisionFragment : Fragment() {
|
class DeviceProvisionFragment : Fragment() {
|
||||||
private var resultData: String = ""
|
private var resultData: String = ""
|
||||||
@@ -122,6 +128,10 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
deviceUpdateAvailable = false
|
deviceUpdateAvailable = false
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
encryptAndSaveToFile(
|
||||||
|
response.data.data?.credentials?.username.toString(),
|
||||||
|
response.data.data?.credentials?.password.toString()
|
||||||
|
)
|
||||||
// viewModel.addDeviceId(DeviceData(deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()))
|
// viewModel.addDeviceId(DeviceData(deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()))
|
||||||
Log.e("idpass", response.toString())
|
Log.e("idpass", response.toString())
|
||||||
Log.e("idpass", response.data.data?.credentials?.username.toString())
|
Log.e("idpass", response.data.data?.credentials?.username.toString())
|
||||||
@@ -221,4 +231,25 @@ class DeviceProvisionFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun encryptAndSaveToFile(username: String, password: String) {
|
||||||
|
val messageToEncrypt = "$username\n$password"
|
||||||
|
val encryptionKey =
|
||||||
|
Settings.Secure.getString(context?.contentResolver, Settings.Secure.ANDROID_ID)
|
||||||
|
val encryptedString = Encryption.encrypt(messageToEncrypt, encryptionKey)
|
||||||
|
Log.d("DEVICE ID/encryptionKey", encryptionKey)
|
||||||
|
val target = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||||
|
val file = File(target, "credentials.txt")
|
||||||
|
|
||||||
|
if (!file.exists()) {
|
||||||
|
file.createNewFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
file.writeText(encryptedString)
|
||||||
|
|
||||||
|
Log.d("Encrypted Message", encryptedString)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import com.example.hpostesting.data.repository.Repository
|
|||||||
import com.example.hpostesting.domain.CheckUpdateWorker
|
import com.example.hpostesting.domain.CheckUpdateWorker
|
||||||
import com.example.hpostesting.domain.LogFileManager
|
import com.example.hpostesting.domain.LogFileManager
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
@@ -152,6 +153,89 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun sendDataToMolbio() = viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
|
||||||
|
Log.d("molbio","getting in sendMolbio")
|
||||||
|
val resultList = MolbioV2ResultRequest(mutableListOf())
|
||||||
|
val pendingData = hemoCubeDao.getMolbioPending()
|
||||||
|
Log.d("molbio","pending size"+pendingData.size)
|
||||||
|
pendingData.forEach{
|
||||||
|
userData ->
|
||||||
|
val currentTimeFormatted = SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
|
Locale.getDefault()
|
||||||
|
).format(Calendar.getInstance().time)
|
||||||
|
val bufferIntensityThreshold =
|
||||||
|
Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId]?.toString()
|
||||||
|
?: "defaultThreshold" // Handle possible nulls safely
|
||||||
|
resultList.results?.add(
|
||||||
|
MolbioV2Result(
|
||||||
|
rawData = userData,
|
||||||
|
analysisId = userData._id,
|
||||||
|
analysisDate = currentTimeFormatted,
|
||||||
|
analysisStatus = userData.classificationResult
|
||||||
|
?: "defaultStatus", // Handle possible nulls
|
||||||
|
thresholds = bufferIntensityThreshold,
|
||||||
|
interpretation = userData.classificationResult
|
||||||
|
?: "defaultInterpretation", // Handle possible nulls
|
||||||
|
testId = userData._id,
|
||||||
|
testTime = currentTimeFormatted,
|
||||||
|
collectionTime = currentTimeFormatted,
|
||||||
|
expiryTime = currentTimeFormatted
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
resultList.results?.forEach { result ->
|
||||||
|
result.rawData?.let { sanitizeDoubleValues(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultList.results?.isNotEmpty() == true) {
|
||||||
|
uploadMoblioBulkResults(resultList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun uploadMoblioBulkResults(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
||||||
|
Log.d("molbio","upload called")
|
||||||
|
repository.uploadResults(molbioV2ResultRequest).let {
|
||||||
|
when (it) {
|
||||||
|
is Result.Success -> {
|
||||||
|
it.data.data?.forEach { id ->
|
||||||
|
id.rawData?.let { it1 ->
|
||||||
|
updateMolbioFlag(
|
||||||
|
it1._id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is Result.Error -> {
|
||||||
|
Log.d("result","result upload error")
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Log.d("result","result upload else")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun sendDataToFirebase() = viewModelScope.launch ( Dispatchers.IO ) {
|
||||||
|
val pendingData = hemoCubeDao.getFirebasePending()
|
||||||
|
pendingData.forEach{
|
||||||
|
userData ->
|
||||||
|
if (userData != null) {
|
||||||
|
if (!userData.localFlag) {
|
||||||
|
bulkAddResultTestToDb(userData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun checkUpdate(checkUpdateRequest: CheckUpdateRequest) = viewModelScope.launch {
|
fun checkUpdate(checkUpdateRequest: CheckUpdateRequest) = viewModelScope.launch {
|
||||||
checkUpdate.postValue(Result.Loading())
|
checkUpdate.postValue(Result.Loading())
|
||||||
repository.checkUpdate(checkUpdateRequest).let {
|
repository.checkUpdate(checkUpdateRequest).let {
|
||||||
|
|||||||
Reference in New Issue
Block a user