Added 3 sample run for one click + updated to store patient details + fixed long(infinite) loading issue on fetchIntensityValues methods.
This commit is contained in:
@@ -16,4 +16,12 @@ object PreferenceUtility {
|
|||||||
return prefix + counter
|
return prefix + counter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun generateId(context: Context): String {
|
||||||
|
val prefs: SharedPreferences =
|
||||||
|
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
|
val counter = prefs.getInt(KEY_COUNTER, 100)
|
||||||
|
prefs.edit().putInt(KEY_COUNTER, counter + 1).apply()
|
||||||
|
return counter.toString()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,4 +24,6 @@ object Constants {
|
|||||||
|
|
||||||
const val ERROR_NORMAL = 400
|
const val ERROR_NORMAL = 400
|
||||||
const val ERROR_CRITICAL = 401
|
const val ERROR_CRITICAL = 401
|
||||||
|
|
||||||
|
const val NO_OF_TIMES_TO_RUN_SAMPLE = 3
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.hpos.domain
|
package com.example.hpos.domain
|
||||||
|
|
||||||
import com.example.hpos.data.constant.Constants
|
import com.example.hpos.data.constant.Constants
|
||||||
|
import com.example.hpos.data.model.PatientData
|
||||||
import com.example.hpos.data.model.TestRightCalculationData
|
import com.example.hpos.data.model.TestRightCalculationData
|
||||||
import com.opencsv.CSVWriter
|
import com.opencsv.CSVWriter
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -56,4 +57,28 @@ class SaveRawData {
|
|||||||
return outputString
|
return outputString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveLogWithPatientData(folderPath: String, fileName: String, calculationData: TestRightCalculationData, patientData: PatientData) {
|
||||||
|
val fileObj = File(folderPath, fileName)
|
||||||
|
val writer = FileWriter(fileObj)
|
||||||
|
|
||||||
|
writer.append(getLogStringFromObjWithPatientData(calculationData, patientData))
|
||||||
|
writer.flush()
|
||||||
|
writer.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getLogStringFromObjWithPatientData(calculationData: TestRightCalculationData, patientData: PatientData) : String {
|
||||||
|
var outputString = "Test calculation logs ==>\n"
|
||||||
|
outputString += "Name = ${patientData.name}\n"
|
||||||
|
outputString += "Age = ${patientData.age}\n"
|
||||||
|
outputString += "Gender = ${patientData.gender}\n"
|
||||||
|
outputString += "Absorbance one = ${String.format("%.3f", calculationData.absorbanceOne)}, found at wavelength = ${String.format("%.3f", calculationData.wavelengthOfAbsorbanceOne)}\n"
|
||||||
|
outputString += "Absorbance two = ${String.format("%.3f", calculationData.absorbanceTwo)}, found at wavelength = ${String.format("%.3f", calculationData.wavelengthOfAbsorbanceTwo)}\n"
|
||||||
|
|
||||||
|
outputString += "Calculated Ratio = ${String.format("%.3f", calculationData.ratioValue)}\n"
|
||||||
|
outputString += "\tlies in range min value = ${String.format("%.3f", calculationData.ratioMinRange)} & range max value = ${String.format("%.3f", calculationData.ratioMaxRange)}\n"
|
||||||
|
outputString += "Results = ${calculationData.result}\n"
|
||||||
|
|
||||||
|
return outputString
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -264,12 +264,14 @@ class TestRightExpReference : Fragment() {
|
|||||||
fullReadOutput.append(stringData)
|
fullReadOutput.append(stringData)
|
||||||
|
|
||||||
// Log.d(TAG, stringData)
|
// Log.d(TAG, stringData)
|
||||||
if (stringData.contains("OK", true)) {
|
// if (stringData.contains("OK", true)) {
|
||||||
|
if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) {
|
||||||
|
|
||||||
Log.d(TAG, "onUsbRead() called in sendCmdToFetchLightIntensities()")
|
Log.d(TAG, "onUsbRead() called in sendCmdToFetchLightIntensities()")
|
||||||
// Log.d(TAG, fullReadOutput.toString())
|
// Log.d(TAG, fullReadOutput.toString())
|
||||||
|
|
||||||
viewModel.mapIntensityValues(fullReadOutput.toString(), true)
|
viewModel.mapIntensityValues(fullReadOutput.toString(), true)
|
||||||
viewModel.saveLogTest(requireContext().applicationContext, true, fullReadOutput.toString())
|
// viewModel.saveLogTest(requireContext().applicationContext, true, fullReadOutput.toString())
|
||||||
|
|
||||||
DataHolder.isReferenceTaken = true
|
DataHolder.isReferenceTaken = true
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import android.view.ViewGroup
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.example.hpos.R
|
import com.example.hpos.R
|
||||||
|
import com.example.hpos.data.DataHolder
|
||||||
|
import com.example.hpos.data.PreferenceUtility
|
||||||
import com.example.hpos.data.constant.Constants
|
import com.example.hpos.data.constant.Constants
|
||||||
import com.example.hpos.data.constant.TestRightCommands
|
import com.example.hpos.data.constant.TestRightCommands
|
||||||
import com.example.hpos.data.model.PatientData
|
import com.example.hpos.data.model.PatientData
|
||||||
@@ -133,9 +135,10 @@ class TestRightExpSample : Fragment() {
|
|||||||
data?.let {
|
data?.let {
|
||||||
val stringData = String(it)
|
val stringData = String(it)
|
||||||
fullReadOutput.append(stringData)
|
fullReadOutput.append(stringData)
|
||||||
|
Log.d(TAG, stringData)
|
||||||
if (stringData.contains("OK", true)) {
|
// if (stringData.contains("OK", true)) {
|
||||||
// viewModel.progressBar.postValue(false)
|
// if (stringData.contains("OK", true) || fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) {
|
||||||
|
if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) {
|
||||||
Log.d(TAG, "onUsbRead() called in sendCmdToRun()")
|
Log.d(TAG, "onUsbRead() called in sendCmdToRun()")
|
||||||
Handler(Looper.getMainLooper()).postDelayed(
|
Handler(Looper.getMainLooper()).postDelayed(
|
||||||
Runnable {
|
Runnable {
|
||||||
@@ -166,14 +169,18 @@ class TestRightExpSample : Fragment() {
|
|||||||
data?.let {
|
data?.let {
|
||||||
val stringData = String(it)
|
val stringData = String(it)
|
||||||
fullReadOutput.append(stringData)
|
fullReadOutput.append(stringData)
|
||||||
// Log.d(TAG, stringData)
|
Log.d(TAG, stringData)
|
||||||
if (stringData.contains("OK", true)) {
|
// if (stringData.contains("OK", true)) {
|
||||||
|
// if (stringData.contains("OK", true) || stringData.contains("O", true) || stringData.contains("K", true)) {
|
||||||
|
// if (stringData.contains("OK", true) || fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) {
|
||||||
|
if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) {
|
||||||
Log.d(TAG, "onUsbRead() called in sendCmdToFetchLightIntensities()")
|
Log.d(TAG, "onUsbRead() called in sendCmdToFetchLightIntensities()")
|
||||||
|
|
||||||
viewModel.mapIntensityValues(fullReadOutput.toString(), false)
|
viewModel.mapIntensityValues(fullReadOutput.toString(), false)
|
||||||
viewModel.saveLogTest(requireContext().applicationContext, false, fullReadOutput.toString())
|
// viewModel.saveLogTest(requireContext().applicationContext, false, fullReadOutput.toString())
|
||||||
|
|
||||||
showResultsAfterAcquiring()
|
// showResultsAfterAcquiring()
|
||||||
|
checkIfToRunAgain()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,9 +192,34 @@ class TestRightExpSample : Fragment() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showResultsAfterAcquiring() {
|
private fun checkIfToRunAgain() {
|
||||||
|
viewModel.numberOfSampleRun++
|
||||||
|
|
||||||
|
|
||||||
viewModel.mapWavelengthToAbsorbance()
|
viewModel.mapWavelengthToAbsorbance()
|
||||||
|
// Todo: Save CSV + Test CSV
|
||||||
|
|
||||||
viewModel.calculateResults()
|
viewModel.calculateResults()
|
||||||
|
// Todo: Save Log
|
||||||
|
|
||||||
|
saveDataLocally()
|
||||||
|
|
||||||
|
if (viewModel.numberOfSampleRun < Constants.NO_OF_TIMES_TO_RUN_SAMPLE) {
|
||||||
|
Handler(Looper.getMainLooper()).postDelayed(
|
||||||
|
{
|
||||||
|
startAcquiring()
|
||||||
|
},
|
||||||
|
Constants.DELAY_BETWEEN_COMMANDS
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
viewModel.numberOfSampleRun = 0
|
||||||
|
showResultsAfterAcquiring()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showResultsAfterAcquiring() {
|
||||||
|
// viewModel.mapWavelengthToAbsorbance()
|
||||||
|
// viewModel.calculateResults()
|
||||||
|
|
||||||
viewModel.progressBar.postValue(false)
|
viewModel.progressBar.postValue(false)
|
||||||
// binding.progressBar.visibility = View.GONE
|
// binding.progressBar.visibility = View.GONE
|
||||||
@@ -195,9 +227,35 @@ class TestRightExpSample : Fragment() {
|
|||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
// fun View.setAllEnabled(enabled: Boolean) {
|
private fun saveDataLocally() {
|
||||||
// isEnabled = enabled
|
val patientName = viewModel.patientDetails.name
|
||||||
// if (this is ViewGroup) children.forEach { child -> child.setAllEnabled(enabled) }
|
// if (patientName.length > 5){
|
||||||
// }
|
// patientName = patientName.substring(0, 5)
|
||||||
|
// }
|
||||||
|
|
||||||
|
val id = PreferenceUtility.generateId(requireContext())
|
||||||
|
|
||||||
|
val prefixCsv = "HPOSSC_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||||
|
val fileExtensionCsv = ".csv"
|
||||||
|
val fileNameCsv = prefixCsv + id + fileExtensionCsv
|
||||||
|
saveCsv(fileNameCsv)
|
||||||
|
|
||||||
|
val prefixTxt = "log_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||||
|
val fileExtensionTxt = ".txt"
|
||||||
|
val fileNameTxt = prefixTxt + id + fileExtensionTxt
|
||||||
|
saveLog(fileNameTxt)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveCsv(fileName: String) {
|
||||||
|
Log.d(TAG, "saveCsv() called")
|
||||||
|
|
||||||
|
viewModel.saveCsv(requireContext().applicationContext, fileName)
|
||||||
|
viewModel.saveCsvForTesting(requireContext().applicationContext, "detailed_$fileName")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveLog(fileName: String) {
|
||||||
|
Log.d(TAG, "saveLog() called")
|
||||||
|
viewModel.saveLogWithPatient(requireContext().applicationContext, fileName)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,8 +39,8 @@ class TestRightResults : Fragment() {
|
|||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
setupListeners()
|
setupListeners()
|
||||||
updateResults()
|
updateResults()
|
||||||
saveCsv()
|
// saveCsv()
|
||||||
saveLog()
|
// saveLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupListeners() {
|
private fun setupListeners() {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class TestRightViewModel : ViewModel() {
|
|||||||
val progressBar = MutableLiveData(false)
|
val progressBar = MutableLiveData(false)
|
||||||
// val errorTriggered = MutableLiveData<String>("")
|
// val errorTriggered = MutableLiveData<String>("")
|
||||||
val errorTriggered = MutableLiveData<ErrorMessage>()
|
val errorTriggered = MutableLiveData<ErrorMessage>()
|
||||||
|
var numberOfSampleRun = 0
|
||||||
|
|
||||||
lateinit var patientDetails: PatientData
|
lateinit var patientDetails: PatientData
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ class TestRightViewModel : ViewModel() {
|
|||||||
if (isReference) DataHolder.intensityReferenceArray.clear()
|
if (isReference) DataHolder.intensityReferenceArray.clear()
|
||||||
else intensitySampleArray.clear()
|
else intensitySampleArray.clear()
|
||||||
|
|
||||||
Log.d(TAG, fullString)
|
// Log.d(TAG, fullString)
|
||||||
val listOfString = fullString.split("\n")
|
val listOfString = fullString.split("\n")
|
||||||
|
|
||||||
for (line in listOfString) {
|
for (line in listOfString) {
|
||||||
@@ -268,6 +269,23 @@ class TestRightViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveLogWithPatient(appContext: Context, fileName: String) {
|
||||||
|
var folderPath: String? = DataHolder.appFolderPath
|
||||||
|
|
||||||
|
if (DataHolder.isAppFolderCreated) {
|
||||||
|
SaveRawData().saveLogWithPatientData(folderPath!!, fileName, calculationData, patientDetails)
|
||||||
|
} else {
|
||||||
|
folderPath = MyUtils.createAppFolder(appContext)
|
||||||
|
if (folderPath != null){
|
||||||
|
DataHolder.isAppFolderCreated = true
|
||||||
|
DataHolder.appFolderPath = folderPath
|
||||||
|
SaveRawData().saveLogWithPatientData(folderPath, fileName, calculationData, patientDetails)
|
||||||
|
} else {
|
||||||
|
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun saveLogTest(appContext: Context, isReference: Boolean, fullString: String) {
|
fun saveLogTest(appContext: Context, isReference: Boolean, fullString: String) {
|
||||||
var fileName: String =
|
var fileName: String =
|
||||||
"test_log_" + SimpleDateFormat("ddMMyyyy_HHmmss").format(Date()) + ".txt"
|
"test_log_" + SimpleDateFormat("ddMMyyyy_HHmmss").format(Date()) + ".txt"
|
||||||
|
|||||||
Reference in New Issue
Block a user