From 2e0b0be7f41f1f79b068381cea941172d6c62342 Mon Sep 17 00:00:00 2001 From: mohamedkaif356 Date: Mon, 17 Jul 2023 14:06:32 +0530 Subject: [PATCH] Blood group selection --- app/build.gradle | 2 +- .../example/hpostesting/data/DataHolder.kt | 4 + .../hpostesting/data/constant/Constants.kt | 17 ---- .../presentation/KitScanActivity.kt | 6 +- .../hpostesting/presentation/MainActivity.kt | 71 +++++++------- .../presentation/dashboard/GalleryFragment.kt | 3 - .../testRight/TestRightExpSample.kt | 35 ++++--- .../testRight/TestRightResults.kt | 98 ++++++++++++------- .../testRight/TestRightViewModel.kt | 3 - .../layout/fragment_test_right_results.xml | 28 +++++- app/src/main/res/values/strings.xml | 6 +- 11 files changed, 160 insertions(+), 113 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 7f7f01a..7025e23 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { namespace 'in.sminnovations.hpostesting' defaultConfig { - applicationId "in.sminnovations.hpostesting" + applicationId "in.sminnovations.hpostesting.prod" minSdk 21 targetSdk 33 versionCode 2 diff --git a/app/src/main/java/com/example/hpostesting/data/DataHolder.kt b/app/src/main/java/com/example/hpostesting/data/DataHolder.kt index 1ff8020..578b402 100644 --- a/app/src/main/java/com/example/hpostesting/data/DataHolder.kt +++ b/app/src/main/java/com/example/hpostesting/data/DataHolder.kt @@ -30,7 +30,11 @@ object DataHolder { var selectedTest: UserData? = null + var kitSerial: String = "" + var location: UserData.Location? = null var testExp: Boolean = true + + } \ No newline at end of file diff --git a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt index 3d5308f..bea2bc9 100644 --- a/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt +++ b/app/src/main/java/com/example/hpostesting/data/constant/Constants.kt @@ -32,26 +32,9 @@ object Constants { const val USER_ID = "usernameId" val STATICID = listOf( - "VIZ-1000-0001", - "VIZ-1000-0002", - "VIZ-1000-0003", "VIZ-1000-0004", "VIZ-1000-0005", "VIZ-1000-0006", - "VIZ-1000-0007", - "VIZ-1000-0008", - "VIZ-1000-0009", - "VIZ-1000-0010", - "VIZ-1000-0011", - "VIZ-1000-0012", - "VIZ-1000-0013", - "VIZ-1000-0014", - "VIZ-1000-0015", - "VIZ-1000-0016", - "VIZ-1000-0017", - "VIZ-1000-0018", - "VIZ-1000-0019" - ) const val password = "SMI@12345" diff --git a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt index 30d7d17..43143c4 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt @@ -42,9 +42,12 @@ class KitScanActivity : AppCompatActivity() { setContentView(binding.root) if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken){ + DataHolder.selectedTest!!.kitSerial = DataHolder.kitSerial moveToNext() } + binding.nameEditText.setText("SMI/SC/") + setSupportActionBar(binding.toolbar) binding.btnScanNow.setOnClickListener { @@ -55,7 +58,8 @@ class KitScanActivity : AppCompatActivity() { binding.btnGo.setOnClickListener { val serialNumber = binding.nameEditText.text.toString().trim() if (serialNumber.isNotEmpty() && checkDataNotNull() && isSerialValid(serialNumber)) { - DataHolder.selectedTest!!.kitSerial = binding.nameEditText.text.toString() + DataHolder.kitSerial = binding.nameEditText.text.toString() + DataHolder.selectedTest?.kitSerial = binding.nameEditText.text.toString() moveToNext() } else { Toast.makeText(this, "Invalid KIT Number", Toast.LENGTH_LONG).show() diff --git a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt index 11a9476..d7b9cab 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt @@ -64,7 +64,7 @@ class MainActivity : AppCompatActivity() { locationCallback = object : LocationCallback() { override fun onLocationResult(locationResult: LocationResult) { locationResult.lastLocation?.let { location -> - DataHolder.location = UserData.Location(location.latitude, location.longitude) + DataHolder.selectedTest!!.location = UserData.Location(location.latitude, location.longitude) Log.i("Location", DataHolder.location.toString()) } } @@ -81,10 +81,16 @@ class MainActivity : AppCompatActivity() { val availableDrivers = UsbSerialProber.getDefaultProber() .findAllDrivers(getSystemService(Context.USB_SERVICE) as UsbManager) if (availableDrivers.isNotEmpty() && availableDrivers[0].device.productId == Constants.DEVICE_PRODUCT_ID && availableDrivers[0].device.vendorId == Constants.DEVICE_VENDOR_ID) { - Log.d(TAG, "Device matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}") + Log.d( + TAG, + "Device matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}" + ) DataHolder.usbConnected.value = true } else if (availableDrivers.isNotEmpty()) { - Log.d(TAG, "Device NOT matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}") + Log.d( + TAG, + "Device NOT matched -> product = ${availableDrivers[0].device.productId}, vendor = ${availableDrivers[0].device.vendorId}" + ) Toast.makeText(this, "Device Not Compatible", Toast.LENGTH_SHORT).show() DataHolder.usbConnected.value = false } else { @@ -108,9 +114,11 @@ class MainActivity : AppCompatActivity() { DataHolder.usbConnected.observe(this) { if (it) { - myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24) + myMenu?.get(0)?.icon = + ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24) } else { - myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24) + myMenu?.get(0)?.icon = + ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24) } } } @@ -127,14 +135,11 @@ class MainActivity : AppCompatActivity() { val coarseLocationPermissionRequestCode = 101 if (ContextCompat.checkSelfPermission( - this, - coarseLocationPermission + this, coarseLocationPermission ) != PackageManager.PERMISSION_GRANTED ) { ActivityCompat.requestPermissions( - this, - arrayOf(coarseLocationPermission), - coarseLocationPermissionRequestCode + this, arrayOf(coarseLocationPermission), coarseLocationPermissionRequestCode ) } else { getLocation() @@ -146,14 +151,11 @@ class MainActivity : AppCompatActivity() { val fineLocationPermissionRequestCode = 102 if (ContextCompat.checkSelfPermission( - this, - fineLocationPermission + this, fineLocationPermission ) != PackageManager.PERMISSION_GRANTED ) { ActivityCompat.requestPermissions( - this, - arrayOf(fineLocationPermission), - fineLocationPermissionRequestCode + this, arrayOf(fineLocationPermission), fineLocationPermissionRequestCode ) } else { getLocation() @@ -165,12 +167,9 @@ class MainActivity : AppCompatActivity() { val fineLocationPermission = Manifest.permission.ACCESS_FINE_LOCATION if (ActivityCompat.checkSelfPermission( - this, - coarseLocationPermission - ) != PackageManager.PERMISSION_GRANTED && - ActivityCompat.checkSelfPermission( - this, - fineLocationPermission + this, coarseLocationPermission + ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( + this, fineLocationPermission ) != PackageManager.PERMISSION_GRANTED ) { // Handle location permission request if needed @@ -180,16 +179,14 @@ class MainActivity : AppCompatActivity() { return } - fusedLocationClient.lastLocation - .addOnSuccessListener { location: Location? -> + fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? -> location?.let { - DataHolder.location = UserData.Location(location.latitude, location.longitude) - Log.i("Location", DataHolder.location.toString()) + DataHolder.selectedTest!!.location = + UserData.Location(location.latitude, location.longitude) } ?: run { requestLocationUpdates() } - } - .addOnFailureListener { exception: Exception -> + }.addOnFailureListener { exception: Exception -> exception.printStackTrace() } } @@ -202,12 +199,9 @@ class MainActivity : AppCompatActivity() { } if (ActivityCompat.checkSelfPermission( - this, - Manifest.permission.ACCESS_COARSE_LOCATION - ) != PackageManager.PERMISSION_GRANTED && - ActivityCompat.checkSelfPermission( - this, - Manifest.permission.ACCESS_FINE_LOCATION + this, Manifest.permission.ACCESS_COARSE_LOCATION + ) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( + this, Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { return @@ -226,9 +220,7 @@ class MainActivity : AppCompatActivity() { } override fun onRequestPermissionsResult( - requestCode: Int, - permissions: Array, - grantResults: IntArray + requestCode: Int, permissions: Array, grantResults: IntArray ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) when (requestCode) { @@ -238,16 +230,19 @@ class MainActivity : AppCompatActivity() { requestFineLocationPermission() } else { // Coarse location permission denied - Toast.makeText(this, "Coarse location permission denied", Toast.LENGTH_SHORT).show() + Toast.makeText(this, "Coarse location permission denied", Toast.LENGTH_SHORT) + .show() } } + 102 -> { if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Fine location permission granted getLocation() } else { // Fine location permission denied - Toast.makeText(this, "Fine location permission denied", Toast.LENGTH_SHORT).show() + Toast.makeText(this, "Fine location permission denied", Toast.LENGTH_SHORT) + .show() } } } diff --git a/app/src/main/java/com/example/hpostesting/presentation/dashboard/GalleryFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/dashboard/GalleryFragment.kt index 3043ca5..d40a417 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/dashboard/GalleryFragment.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/dashboard/GalleryFragment.kt @@ -6,7 +6,6 @@ import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider -import com.example.hpostesting.presentation.dashboard.ui.gallery.GalleryViewModel import `in`.sminnovations.hpostesting.databinding.FragmentGalleryBinding class GalleryFragment : Fragment() { @@ -22,8 +21,6 @@ class GalleryFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View { - val galleryViewModel = - ViewModelProvider(this).get(GalleryViewModel::class.java) _binding = FragmentGalleryBinding.inflate(inflater, container, false) val root: View = binding.root diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpSample.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpSample.kt index bbfcb41..000ec30 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpSample.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpSample.kt @@ -79,18 +79,29 @@ class TestRightExpSample : Fragment() { // if (details != null) { // viewModel.patientDetails = details - UIUtils.createAlertDialog( - requireContext(), - getString(R.string.have_you_placed_sample), - getString(R.string.please_place_sample), - getString(R.string.no), - getString(R.string.yes_and_run), - object : MyDialogListener { - override fun onClickNegativeButton() {} - override fun onClickPositiveButton() { - startAcquiring() - } - }) + UIUtils.createAlertDialog( + requireContext(), + "WARNING", + "Please check if you have placed the sample of this person ${viewModel.testDetails?._id}", + getString(R.string.no), + "Yes", + object : MyDialogListener { + override fun onClickNegativeButton() {} + override fun onClickPositiveButton() { + UIUtils.createAlertDialog( + requireContext(), + getString(R.string.have_you_placed_sample), + getString(R.string.please_place_sample), + getString(R.string.no), + getString(R.string.yes_and_run), + object : MyDialogListener { + override fun onClickNegativeButton() {} + override fun onClickPositiveButton() { + startAcquiring() + } + }) + } + }) // } } diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt index 24cbc32..b107f97 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightResults.kt @@ -16,9 +16,17 @@ import com.example.hpostesting.data.model.test.TestRightResultType import com.example.hpostesting.data.model.test.TestType import com.example.hpostesting.presentation.dashboard.DashboardActivity import com.example.hpostesting.util.MyUtils.calculateAgeFromYOB +import com.google.firebase.firestore.FirebaseFirestore +import com.google.firebase.firestore.ktx.firestore +import com.google.firebase.ktx.Firebase import dagger.hilt.android.AndroidEntryPoint import `in`.sminnovations.hpostesting.R import `in`.sminnovations.hpostesting.databinding.FragmentTestRightResultsBinding +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.tasks.await +import kotlinx.coroutines.withContext @AndroidEntryPoint class TestRightResults : Fragment() { @@ -55,8 +63,9 @@ class TestRightResults : Fragment() { private fun setupListeners() { binding.ivHome.setOnClickListener { - val i = Intent(requireContext().applicationContext, DashboardActivity::class.java) - startActivity(i) + CoroutineScope(Dispatchers.IO).launch { + checkBloodGroup() + } } binding.ivNext.setOnClickListener { val i = Intent(requireContext().applicationContext, DashboardActivity::class.java) @@ -65,6 +74,29 @@ class TestRightResults : Fragment() { } } + private suspend fun checkBloodGroup() { + binding.apply { + val bloodGroup = etBloodGroup.text.toString() + if (bloodGroup.isEmpty()) { + etBloodGroup.error = "Please enter your blood group" + } else { + val db: FirebaseFirestore = Firebase.firestore + val userdata = + db.collection("patientData").whereEqualTo("_id", viewModel.testDetails?._id) + .get().await() + if (userdata.documents.isNotEmpty()) { + userdata.documents.forEach { + db.collection("patientData").document(it.id).update("bloodGroup", bloodGroup) + } + } + } + withContext(Dispatchers.Main) { + val i = Intent(requireContext().applicationContext, DashboardActivity::class.java) + startActivity(i) + } + } + } + private fun updateResults() { if (viewModel.testDetails?.name == "" && viewModel.testDetails?.birthYear == "") { binding.tvName.visibility = View.GONE @@ -81,37 +113,37 @@ class TestRightResults : Fragment() { if (DataHolder.selectedTestType == TestType.SICKLECERT) { - when (viewModel.testDetails?.result) { - TestRightResultType.NORMAL -> { - binding.resultNormal.visibility = View.VISIBLE - } - - TestRightResultType.SICKLECELLDISEASE -> { - binding.resultDisease.visibility = View.VISIBLE - } - - TestRightResultType.SICKLECELLTRAIT -> { - binding.resultTrait.visibility = View.VISIBLE - } - - TestRightResultType.POSITIVEBORDERLINE -> { - binding.resultPositiveBorderline.visibility = View.VISIBLE - binding.tvRecommended.visibility = View.VISIBLE - } - - TestRightResultType.NEGATIVEBORDERLINE -> { - binding.resultNegativeBorderline.visibility = View.VISIBLE - binding.tvRecommended.visibility = View.VISIBLE - } - - else -> { -// binding.resultUndefined.visibility = View.VISIBLE - Toast.makeText( - requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG - ).show() - moveToSamplePage() - } - } +// when (viewModel.testDetails?.result) { +// TestRightResultType.NORMAL -> { +// binding.resultNormal.visibility = View.VISIBLE +// } +// +// TestRightResultType.SICKLECELLDISEASE -> { +// binding.resultDisease.visibility = View.VISIBLE +// } +// +// TestRightResultType.SICKLECELLTRAIT -> { +// binding.resultTrait.visibility = View.VISIBLE +// } +// +// TestRightResultType.POSITIVEBORDERLINE -> { +// binding.resultPositiveBorderline.visibility = View.VISIBLE +// binding.tvRecommended.visibility = View.VISIBLE +// } +// +// TestRightResultType.NEGATIVEBORDERLINE -> { +// binding.resultNegativeBorderline.visibility = View.VISIBLE +// binding.tvRecommended.visibility = View.VISIBLE +// } +// else -> { +//// binding.resultUndefined.visibility = View.VISIBLE +// Toast.makeText( +// requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG +// ).show() +// moveToSamplePage() +// } +// } + binding.resultNormal.visibility = View.VISIBLE } else { when (viewModel.testDetails?.result) { TestRightResultType.SICKLECELLDISEASE -> { diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt index 06b96b1..b6fcd03 100644 --- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt +++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightViewModel.kt @@ -137,7 +137,6 @@ class TestRightViewModel @Inject constructor( if (isReference) DataHolder.intensityReferenceArray.clear() else intensitySampleArray.clear() - Log.d("SURYAKUMAR", fullString) val listOfString = fullString.split("\n") for (line in listOfString) { @@ -437,7 +436,6 @@ class TestRightViewModel @Inject constructor( } private fun addResultTestToDb() { - testDetails?.location = DataHolder.location testDetails?.testTime = SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale.getDefault() ).format(Calendar.getInstance().time) @@ -521,7 +519,6 @@ class TestRightViewModel @Inject constructor( } private fun bulkAddResultTestToDb(userData: UserData) { - userData.location = DataHolder.location viewModelScope.launch { userData.reportUploadTime = SimpleDateFormat( "yyyy-MM-dd HH:mm:ss", Locale.getDefault() diff --git a/app/src/main/res/layout/fragment_test_right_results.xml b/app/src/main/res/layout/fragment_test_right_results.xml index d1dcea9..3b2af12 100644 --- a/app/src/main/res/layout/fragment_test_right_results.xml +++ b/app/src/main/res/layout/fragment_test_right_results.xml @@ -117,7 +117,7 @@ android:layout_height="wrap_content" android:layout_marginHorizontal="16dp" android:background="@drawable/result_background_green" - android:text="@string/normal" + android:text="@string/test_completed" android:textAlignment="center" android:visibility="gone" app:drawableStartCompat="@drawable/ic_baseline_check_circle_24" @@ -241,6 +241,28 @@ + + + + + + + app:layout_constraintTop_toBottomOf="@id/til_blood_group" /> + app:layout_constraintTop_toBottomOf="@id/til_blood_group" /> - HPOS + HPOS Testing TestRight @@ -130,7 +130,7 @@ Scan Now Enter ABHA number manualy ABHA ID - Patient ID : %1$s + User ID : %1$s GO Click Here DashboardActivity @@ -182,5 +182,7 @@ Upload Cancel Upload done successfully + Test Completed + Select Blood Group \ No newline at end of file