Compare commits
7 Commits
dev-Adding
...
DEV_UAT
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5e03e3fab | ||
|
|
a97fd86c86 | ||
|
|
41a66766d1 | ||
|
|
3f9d1d110f | ||
|
|
af3f152e26 | ||
|
|
339a2d0d70 | ||
|
|
8fd91e0961 |
@@ -19,8 +19,8 @@ android {
|
||||
applicationId "in.sminnovations.hpostesting.dev"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 112
|
||||
versionName "2.1.112"
|
||||
versionCode 114
|
||||
versionName "2.1.114"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -116,15 +116,18 @@
|
||||
android:name="com.example.hpostesting.presentation.testRight.UsbService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.SplashActivity"
|
||||
android:exported="true"
|
||||
android:noHistory="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<!-- <category android:name="android.intent.category.HOME" />-->
|
||||
<!-- <category android:name="android.intent.category.DEFAULT" />-->
|
||||
<!-- <category android:name="android.intent.category.MONKEY"/>-->
|
||||
<!-- <category android:name="android.intent.category.LAUNCHER_APP" />-->
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
|
||||
@@ -8,7 +8,7 @@ object Constants {
|
||||
|
||||
const val ABHA_APP_PACKAGE = "in.ndhm.phr"
|
||||
|
||||
const val MOLBIO_INTEGRATION = false
|
||||
const val MOLBIO_INTEGRATION = true
|
||||
const val deviceProvisionEmail = "HPOS_provisioner@bigtec.co.in"
|
||||
const val deviceProvisionPassword = "f2ab0e7f9d69"
|
||||
const val DEVICE_ID_API = "deviceIDAPI"
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.example.hpostesting.data.encryption
|
||||
|
||||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyProperties
|
||||
import android.util.Base64
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
|
||||
object AESCrypt {
|
||||
private const val ALGORITHM = "AES"
|
||||
private const val KEY = "your_secret_key"
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun encrypt(value: String): String {
|
||||
val keySpec = SecretKeySpec(KEY.toByteArray(), ALGORITHM)
|
||||
val cipher = Cipher.getInstance(ALGORITHM)
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec)
|
||||
val encryptedBytes = cipher.doFinal(value.toByteArray())
|
||||
return Base64.encodeToString(encryptedBytes, Base64.DEFAULT)
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun decrypt(encrypted: String?): String {
|
||||
val keySpec = SecretKeySpec(KEY.toByteArray(), ALGORITHM)
|
||||
val cipher = Cipher.getInstance(ALGORITHM)
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec)
|
||||
val encryptedBytes = Base64.decode(encrypted, Base64.DEFAULT)
|
||||
val decryptedBytes = cipher.doFinal(encryptedBytes)
|
||||
return String(decryptedBytes)
|
||||
}
|
||||
|
||||
//generates a secret key for the encryption functions to use
|
||||
//TODO: Generating keys requires a higher API level. ask someone if this is okay.
|
||||
}
|
||||
@@ -161,7 +161,8 @@ class AssuranceControlsFragment : Fragment() {
|
||||
""
|
||||
}
|
||||
DataHolder.hemoCubeTestData!!._id = currentUnixTime.toString() + "SMI"
|
||||
DataHolder.hemoCubeTestData!!.name =
|
||||
DataHolder.hemoCubeTestData!!.solution = binding.spinnerSolutions.selectedItem.toString()
|
||||
DataHolder.hemoCubeTestData!!.name = binding.spinnerConcentration.selectedItem.toString()
|
||||
"${DataHolder.hemoCubeTestData!!.solution} ${DataHolder.hemoCubeTestData!!.concentration} ${DataHolder.hemoCubeTestData!!.volume}"
|
||||
|
||||
DataHolder.selectedTest = UserData()
|
||||
|
||||
@@ -72,6 +72,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
|
||||
binding = ActivityDashboardBinding.inflate(layoutInflater)
|
||||
sharedPreferences = this.getSharedPreferences("HEMOCUBE", Context.MODE_PRIVATE)
|
||||
setContentView(binding.root)
|
||||
|
||||
@@ -58,9 +58,11 @@ import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
|
||||
@AndroidEntryPoint
|
||||
class HomeFragment : Fragment() {
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
@@ -83,6 +85,7 @@ class HomeFragment : Fragment() {
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
Log.d("OnCreate Home Fragment", "HomeFragment calls")
|
||||
|
||||
// Check if _binding is null
|
||||
if (_binding == null) {
|
||||
@@ -133,6 +136,7 @@ class HomeFragment : Fragment() {
|
||||
|
||||
}
|
||||
viewModel.networkStatusLiveData?.observe(viewLifecycleOwner) { isConnected ->
|
||||
Log.d("NETWORK OBSERVE", "OBSERVE CALLED")
|
||||
if (isConnected) {
|
||||
binding.internetAvailableCL.visibility = View.VISIBLE
|
||||
binding.internetNotAvailableCL.visibility = View.GONE
|
||||
@@ -144,39 +148,62 @@ class HomeFragment : Fragment() {
|
||||
checkForTokenAndUpdate()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { originalUserDataList ->
|
||||
|
||||
Log.d("LOCAL_DB OBSERVE", "OBSERVE CALLED")
|
||||
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf())
|
||||
originalUserDataList.forEach { userData ->
|
||||
Log.d(
|
||||
": USER DATA",
|
||||
originalUserDataList.count().toString() + " : " + userData._id
|
||||
)
|
||||
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
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 = "2024-02-08 16:33:56",//userData.testTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
analysisDate = currentTimeFormatted,
|
||||
analysisStatus = userData.classificationResult
|
||||
?: "defaultStatus", // Handle possible nulls
|
||||
thresholds = bufferIntensityThreshold,
|
||||
interpretation = userData.classificationResult
|
||||
?: "defaultInterpretation", // Handle possible nulls
|
||||
testId = userData._id,
|
||||
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
||||
testTime = currentTimeFormatted,
|
||||
collectionTime = currentTimeFormatted,
|
||||
expiryTime = currentTimeFormatted
|
||||
)
|
||||
)
|
||||
}
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
|
||||
}
|
||||
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)
|
||||
userData.localFlag = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
||||
if (resultList.results?.isNotEmpty() == true) {
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
binding.internetAvailableCL.visibility = View.GONE
|
||||
binding.pendingTest.visibility = View.GONE
|
||||
@@ -287,7 +314,31 @@ class HomeFragment : Fragment() {
|
||||
hemoCubeViewModel.uploadLogs()
|
||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
}
|
||||
} else {
|
||||
}
|
||||
// } else if (fis.available()>0){
|
||||
// val buffer = ByteArray(fis.available())
|
||||
// fis.read(buffer)
|
||||
// fis.close()
|
||||
// val encryptedData = String(buffer)
|
||||
// val parts = encryptedData.split(",".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
// .toTypedArray()
|
||||
// val deviceID = parts[0]
|
||||
// val decryptedUsername = decrypt(parts[1])
|
||||
// val decryptedPassword = decrypt(parts[2])
|
||||
// if (accessToken.isEmpty()) {
|
||||
// hemoCubeViewModel.login(createLoginRequestData(decryptedUsername, decryptedPassword))
|
||||
//}
|
||||
// else {
|
||||
// // Continue with your existing logic if the token is not empty.
|
||||
// isTokenAvailable = true
|
||||
// hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
|
||||
// hemoCubeViewModel.uploadLogs()
|
||||
// hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||
// }
|
||||
|
||||
|
||||
//}
|
||||
else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
"Contact Help and get your device provision done",
|
||||
@@ -397,6 +448,7 @@ class HomeFragment : Fragment() {
|
||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||
when (it) {
|
||||
is Result.Success -> {
|
||||
Log.d("MOLBIO UPLOAD", "RESULT SUCCESS")
|
||||
it.data.data?.forEach { id ->
|
||||
id.rawData?.let { it1 ->
|
||||
hemoCubeViewModel.updateMolbioFlag(
|
||||
@@ -404,18 +456,22 @@ class HomeFragment : Fragment() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
is Result.Error -> {
|
||||
binding.btnSubmit.visibility = View.VISIBLE
|
||||
//Remove this line of code while deploying to IOCL
|
||||
|
||||
it.exception.let { message ->
|
||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
else -> {}
|
||||
else -> {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -824,39 +880,6 @@ class HomeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = "2024-02-08 16:33:56", //userData.reportUploadTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allKitTestData.observe(viewLifecycleOwner) { kitDataList ->
|
||||
kitDataList.forEach { userData ->
|
||||
if (!userData.localFlag) {
|
||||
@@ -867,36 +890,6 @@ class HomeFragment : Fragment() {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
hemoCubeViewModel.allUserData.observe(viewLifecycleOwner) { userDataList ->
|
||||
val resultList = MolbioV2ResultRequest(mutableListOf(MolbioV2Result()))
|
||||
userDataList.forEach { userData ->
|
||||
if (!userData.molbioFlag && isTokenAvailable) {
|
||||
resultList.results?.add(
|
||||
MolbioV2Result(
|
||||
rawData = userData,
|
||||
analysisId = userData._id,
|
||||
analysisDate = "2024-02-08 16:33:56",//userData.testTime,
|
||||
analysisStatus = userData.classificationResult,
|
||||
thresholds = Constants.BUFFER_INTENSITY_THRESHOLDS[userData.deviceId].toString(),
|
||||
interpretation = userData.classificationResult,
|
||||
testId = userData._id,
|
||||
testTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
collectionTime = "2024-02-08 16:33:56",//userData.testTime,
|
||||
expiryTime = "2024-02-08 16:33:56"//userData.testTime,
|
||||
)
|
||||
)
|
||||
userData.molbioFlag = true
|
||||
hemoCubeViewModel.uploadResult(resultList)
|
||||
}
|
||||
|
||||
if (!userData.localFlag) {
|
||||
userData.localFlag = true
|
||||
hemoCubeViewModel.bulkAddResultTestToDb(userData)
|
||||
}
|
||||
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
// private fun downloadLocalDBData(dialog: DialogInterface) {
|
||||
|
||||
@@ -93,7 +93,6 @@ class DeviceProvisionActivity : AppCompatActivity(), DeviceCommunicationHandler
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
setupListener()
|
||||
connectUsb(false)
|
||||
|
||||
}
|
||||
|
||||
private fun setupListener() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpostesting.data.Result
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.encryption.AESCrypt
|
||||
import com.example.hpostesting.data.model.deviceprovision.DeviceProvisionRequest
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
@@ -23,6 +24,7 @@ import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import `in`.sminnovations.hpostesting.databinding.FragmentDeviceProvisionBinding
|
||||
|
||||
|
||||
class DeviceProvisionFragment : Fragment() {
|
||||
private var resultData: String = ""
|
||||
private lateinit var binding: FragmentDeviceProvisionBinding
|
||||
@@ -123,6 +125,9 @@ class DeviceProvisionFragment : Fragment() {
|
||||
Log.e("idpass", response.toString())
|
||||
Log.e("idpass", response.data.data?.credentials?.username.toString())
|
||||
Log.e("idpass", deviceProvisionResponse)
|
||||
|
||||
saveDataToLocalFile(response.data.data?.credentials?.username.toString(), response.data.data?.credentials?.password.toString())
|
||||
|
||||
} else {
|
||||
Toast.makeText(
|
||||
activity,
|
||||
@@ -218,4 +223,18 @@ class DeviceProvisionFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//saves username and password to a local file after encrypting it.
|
||||
private fun saveDataToLocalFile( username : String, password : String){
|
||||
val deviceID = sharedPreferences.getString(Constants.DEVICE_ID, "").toString();
|
||||
val encryptedUsername = AESCrypt.encrypt(username)
|
||||
val encryptedPassword = AESCrypt.encrypt(password)
|
||||
val encryptedData = deviceID + "\n" + encryptedUsername + "\n" + encryptedPassword
|
||||
|
||||
val fileOutputStream = requireContext().openFileOutput("credentials.txt", Context.MODE_PRIVATE)
|
||||
fileOutputStream.write(encryptedData.toByteArray())
|
||||
fileOutputStream.close()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -137,6 +137,7 @@ class HemoCubeViewModel @Inject constructor(
|
||||
|
||||
fun uploadResult(molbioV2ResultRequest: MolbioV2ResultRequest) = viewModelScope.launch {
|
||||
resultUpload.postValue(Result.Loading())
|
||||
Log.d("API CALL", "UPLOADED RESULT")
|
||||
repository.uploadResults(molbioV2ResultRequest).let {
|
||||
resultUpload.postValue(it)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user