Added control for the module sicklefind. + Updates in ratio.
This commit is contained in:
@@ -2,12 +2,12 @@ package com.example.hpos.data
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.example.hpos.data.model.TestRightDeviceConstants
|
||||
import com.example.hpos.data.model.TestType
|
||||
|
||||
object DataHolder {
|
||||
|
||||
var selectedTestType: TestType = TestType.SICKLECERT
|
||||
|
||||
// var usbConnected: Boolean = false
|
||||
// val usbConnected = MutableLiveData(false)
|
||||
val usbConnected = MutableLiveData(true)
|
||||
|
||||
var isStoragePermissionGranted = false
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.hpos.data.model
|
||||
|
||||
enum class TestType {
|
||||
SICKLECERT,
|
||||
SICKLEFIND
|
||||
}
|
||||
@@ -57,16 +57,24 @@ class ResultCalculationWithMaxImpl : TestRightResultCalculation {
|
||||
val value = absorbanceAtWaveTwo / absorbanceAtWaveOne
|
||||
testRightCalculationData.ratioValue = value
|
||||
|
||||
if (value < 0.24 || value == 0.0) {
|
||||
if (value < 0.30 || value == 0.0) {
|
||||
testRightCalculationData.ratioMinRange = 0.0
|
||||
testRightCalculationData.ratioMaxRange = 0.24
|
||||
return TestRightResultType.NORMAL
|
||||
} else if (value >= 0.24 && value < 0.30) {
|
||||
testRightCalculationData.ratioMinRange = 0.24
|
||||
testRightCalculationData.ratioMaxRange = 0.30
|
||||
return TestRightResultType.SICKLECELLTRAIT
|
||||
} else if (value >= 0.30) {
|
||||
return TestRightResultType.NORMAL
|
||||
} else if (value >= 0.30 && value < 0.31) {
|
||||
testRightCalculationData.ratioMinRange = 0.30
|
||||
testRightCalculationData.ratioMaxRange = 0.31
|
||||
return TestRightResultType.UNDEFINED
|
||||
} else if (value >= 0.31 && value < 0.52) {
|
||||
testRightCalculationData.ratioMinRange = 0.31
|
||||
testRightCalculationData.ratioMaxRange = 0.52
|
||||
return TestRightResultType.SICKLECELLTRAIT
|
||||
} else if (value >= 0.52 && value < 0.525) {
|
||||
testRightCalculationData.ratioMinRange = 0.52
|
||||
testRightCalculationData.ratioMaxRange = 0.525
|
||||
return TestRightResultType.UNDEFINED
|
||||
}else if (value >= 0.525) {
|
||||
testRightCalculationData.ratioMinRange = 0.525
|
||||
testRightCalculationData.ratioMaxRange = 999.0
|
||||
return TestRightResultType.SICKLECELLDISEASE
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.hpos.domain
|
||||
|
||||
import android.util.Log
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.PatientData
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
@@ -10,30 +11,39 @@ import java.util.Collections.sort
|
||||
|
||||
class SaveRawData {
|
||||
|
||||
private val TAG = "saverawdata"
|
||||
|
||||
fun saveCsv(folderPath: String, fileName: String, matrix: ArrayList<ArrayList<Double>>) {
|
||||
// try {
|
||||
val fullPath = "$folderPath/$fileName"
|
||||
val writer = CSVWriter(FileWriter(fullPath))
|
||||
|
||||
val fullPath = "$folderPath/$fileName"
|
||||
val writer = CSVWriter(FileWriter(fullPath))
|
||||
|
||||
sort(matrix) { one: ArrayList<Double>, two: ArrayList<Double> ->
|
||||
one[0].compareTo(two[0])
|
||||
}
|
||||
|
||||
val content = ArrayList<Array<String>>()
|
||||
content.add(arrayOf("NM", "CA"))
|
||||
|
||||
for (eachRow in matrix){
|
||||
|
||||
if (eachRow[0] >= Constants.MIN_WAVELENGTH_RANGE_TO_RECORD && eachRow[0] < Constants.MAX_WAVELENGTH_RANGE_TO_RECORD+1) {
|
||||
// val rowContent = arrayOf(String.format("%.3f", eachRow[0]), String.format("%.3f", eachRow[1]))
|
||||
val rowContent =
|
||||
arrayOf(String.format("%.10f", eachRow[0]), String.format("%.10f", eachRow[1]))
|
||||
content.add(rowContent)
|
||||
sort(matrix) { one: ArrayList<Double>, two: ArrayList<Double> ->
|
||||
one[0].compareTo(two[0])
|
||||
}
|
||||
}
|
||||
|
||||
writer.writeAll(content) // data is adding to csv
|
||||
writer.close()
|
||||
val content = ArrayList<Array<String>>()
|
||||
content.add(arrayOf("NM", "CA"))
|
||||
|
||||
for (eachRow in matrix) {
|
||||
|
||||
if (eachRow[0] >= Constants.MIN_WAVELENGTH_RANGE_TO_RECORD && eachRow[0] < Constants.MAX_WAVELENGTH_RANGE_TO_RECORD + 1) {
|
||||
// val rowContent = arrayOf(String.format("%.3f", eachRow[0]), String.format("%.3f", eachRow[1]))
|
||||
val rowContent =
|
||||
arrayOf(
|
||||
String.format("%.10f", eachRow[0]),
|
||||
String.format("%.10f", eachRow[1])
|
||||
)
|
||||
content.add(rowContent)
|
||||
}
|
||||
}
|
||||
|
||||
writer.writeAll(content) // data is adding to csv
|
||||
writer.close()
|
||||
|
||||
// } catch (e: Exception) {
|
||||
// Log.e(TAG, e.toString())
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLog(folderPath: String, fileName: String, calculationData: TestRightCalculationData) {
|
||||
@@ -45,19 +55,49 @@ class SaveRawData {
|
||||
writer.close()
|
||||
}
|
||||
|
||||
fun getLogStringFromObj(calculationData: TestRightCalculationData) : String {
|
||||
fun getLogStringFromObj(calculationData: TestRightCalculationData): String {
|
||||
var outputString = "Test calculation logs ==>\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 += "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 += "\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
|
||||
}
|
||||
|
||||
fun saveLogWithPatientData(folderPath: String, fileName: String, calculationData: TestRightCalculationData, patientData: PatientData) {
|
||||
fun saveLogWithPatientData(
|
||||
folderPath: String,
|
||||
fileName: String,
|
||||
calculationData: TestRightCalculationData,
|
||||
patientData: PatientData
|
||||
) {
|
||||
val fileObj = File(folderPath, fileName)
|
||||
val writer = FileWriter(fileObj)
|
||||
|
||||
@@ -66,18 +106,48 @@ class SaveRawData {
|
||||
writer.close()
|
||||
}
|
||||
|
||||
private fun getLogStringFromObjWithPatientData(calculationData: TestRightCalculationData, patientData: PatientData) : String {
|
||||
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 += "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 += "\tlies in range min value = ${
|
||||
String.format(
|
||||
"%.3f",
|
||||
calculationData.ratioMinRange
|
||||
)
|
||||
} & range max value = ${String.format("%.3f", calculationData.ratioMaxRange)}\n"
|
||||
outputString += "Results = ${calculationData.result}\n"
|
||||
|
||||
Log.d(TAG, outputString)
|
||||
|
||||
return outputString
|
||||
}
|
||||
|
||||
|
||||
@@ -13,21 +13,33 @@ class SaveRawDataTest {
|
||||
|
||||
fun saveCsv(folderPath: String, fileName: String, calculationData: ArrayList<CalculationVariableForTest>) {
|
||||
|
||||
val fullPath = "$folderPath/$fileName"
|
||||
val writer = CSVWriter(FileWriter(fullPath))
|
||||
val content = ArrayList<Array<String>>()
|
||||
// try {
|
||||
val fullPath = "$folderPath/$fileName"
|
||||
val writer = CSVWriter(FileWriter(fullPath))
|
||||
val content = ArrayList<Array<String>>()
|
||||
|
||||
// Header
|
||||
var rowContent = arrayOf("pixel no", "wavelength", "invertedPixelNo", "I0", "I", "absorbance")
|
||||
content.add(rowContent)
|
||||
|
||||
for (eachRow in calculationData){
|
||||
rowContent = arrayOf(eachRow.pixelNo.toString(), eachRow.wavelength.toString(), eachRow.invertedPixelNo.toString(), eachRow.I0.toString(), eachRow.I.toString(), eachRow.absorbance.toString())
|
||||
// Header
|
||||
var rowContent =
|
||||
arrayOf("pixel no", "wavelength", "invertedPixelNo", "I0", "I", "absorbance")
|
||||
content.add(rowContent)
|
||||
}
|
||||
|
||||
writer.writeAll(content) // data is adding to csv
|
||||
writer.close()
|
||||
for (eachRow in calculationData) {
|
||||
rowContent = arrayOf(
|
||||
eachRow.pixelNo.toString(),
|
||||
eachRow.wavelength.toString(),
|
||||
eachRow.invertedPixelNo.toString(),
|
||||
eachRow.I0.toString(),
|
||||
eachRow.I.toString(),
|
||||
eachRow.absorbance.toString()
|
||||
)
|
||||
content.add(rowContent)
|
||||
}
|
||||
|
||||
writer.writeAll(content) // data is adding to csv
|
||||
writer.close()
|
||||
// } catch (e: Exception){
|
||||
// Log.e(TAG, e.toString())
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLog(folderPath: String, fileName: String, isReference: Boolean, fullString: String) {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.example.hpos.domain
|
||||
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightCalculationData
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
|
||||
class SickleFindResultCaluculationWithMaxImpl : TestRightResultCalculation{
|
||||
|
||||
val testRightCalculationData = TestRightCalculationData()
|
||||
|
||||
override fun getResults(wavelengthToAbsorbance: ArrayList<ArrayList<Double>>): TestRightCalculationData {
|
||||
|
||||
val startWavelengthOne =
|
||||
Constants.WAVELENGTH_OF_INTEREST_ONE - Constants.RANGE_IN_RESULT_CALCULATIONS
|
||||
val endWavelengthOne =
|
||||
Constants.WAVELENGTH_OF_INTEREST_ONE + Constants.RANGE_IN_RESULT_CALCULATIONS + 1
|
||||
var maxAbsorbanceAtOne = -999999.0
|
||||
var wavelengthOfAbsorbanceOne = 0.0
|
||||
|
||||
val startWavelengthTwo =
|
||||
Constants.WAVELENGTH_OF_INTEREST_TWO - Constants.RANGE_IN_RESULT_CALCULATIONS
|
||||
val endWavelengthTwo =
|
||||
Constants.WAVELENGTH_OF_INTEREST_TWO + Constants.RANGE_IN_RESULT_CALCULATIONS + 1
|
||||
var maxAbsorbanceAtTwo = -999999.0
|
||||
var wavelengthOfAbsorbanceTwo = 0.0
|
||||
|
||||
for (each in wavelengthToAbsorbance) {
|
||||
if (each[0] >= startWavelengthOne && each[0] < endWavelengthOne) {
|
||||
if (each[1] > maxAbsorbanceAtOne) {
|
||||
maxAbsorbanceAtOne = each[1]
|
||||
wavelengthOfAbsorbanceOne = each[0]
|
||||
}
|
||||
}
|
||||
if (each[0] >= startWavelengthTwo && each[0] < endWavelengthTwo) {
|
||||
// maxAbsorbanceAtTwo = max(maxAbsorbanceAtTwo, each[1])
|
||||
if (each[1] > maxAbsorbanceAtTwo) {
|
||||
maxAbsorbanceAtTwo = each[1]
|
||||
wavelengthOfAbsorbanceTwo = each[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testRightCalculationData.absorbanceOne = maxAbsorbanceAtOne
|
||||
testRightCalculationData.wavelengthOfAbsorbanceOne = wavelengthOfAbsorbanceOne
|
||||
testRightCalculationData.absorbanceTwo = maxAbsorbanceAtTwo
|
||||
testRightCalculationData.wavelengthOfAbsorbanceTwo = wavelengthOfAbsorbanceTwo
|
||||
|
||||
testRightCalculationData.result = calculateResultsAndRatio(maxAbsorbanceAtOne, maxAbsorbanceAtTwo)
|
||||
return testRightCalculationData
|
||||
}
|
||||
|
||||
private fun calculateResultsAndRatio(
|
||||
absorbanceAtWaveOne: Double,
|
||||
absorbanceAtWaveTwo: Double
|
||||
): TestRightResultType {
|
||||
if (absorbanceAtWaveOne != Double.MIN_VALUE && absorbanceAtWaveTwo != Double.MIN_VALUE && absorbanceAtWaveOne != 0.0) {
|
||||
val value = absorbanceAtWaveTwo / absorbanceAtWaveOne
|
||||
testRightCalculationData.ratioValue = value
|
||||
|
||||
if (value < 0.30 || value == 0.0) {
|
||||
testRightCalculationData.ratioMinRange = 0.0
|
||||
testRightCalculationData.ratioMaxRange = 0.30
|
||||
return TestRightResultType.NORMAL
|
||||
} else if (value >= 0.30 && value < 0.31) {
|
||||
testRightCalculationData.ratioMinRange = 0.30
|
||||
testRightCalculationData.ratioMaxRange = 0.31
|
||||
return TestRightResultType.UNDEFINED
|
||||
} else if (value >= 0.31) {
|
||||
testRightCalculationData.ratioMinRange = 0.31
|
||||
testRightCalculationData.ratioMaxRange = 999.0
|
||||
return TestRightResultType.SICKLECELLDISEASE
|
||||
}
|
||||
}
|
||||
|
||||
return TestRightResultType.UNDEFINED
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.hpos.R
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestType
|
||||
import com.example.hpos.databinding.ActivityMainBinding
|
||||
import com.example.hpos.presentation.testRight.TestRightActivity
|
||||
import com.example.hpos.util.MyViewModelFactory
|
||||
@@ -86,12 +87,15 @@ class MainActivity : AppCompatActivity()
|
||||
private fun setupListeners() {
|
||||
|
||||
binding.cvItem1.setOnClickListener {
|
||||
DataHolder.selectedTestType = TestType.SICKLECERT
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
binding.cvItem2.setOnClickListener {
|
||||
Toast.makeText(this, "To be Implemented", Toast.LENGTH_SHORT).show()
|
||||
DataHolder.selectedTestType = TestType.SICKLEFIND
|
||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
|
||||
DataHolder.usbConnected.observe(this){
|
||||
|
||||
@@ -14,8 +14,10 @@ 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.TestRightCommands
|
||||
import com.example.hpos.data.model.ErrorMessage
|
||||
import com.example.hpos.data.model.PatientData
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
import com.example.hpos.data.model.TestType
|
||||
import com.example.hpos.databinding.FragmentTestRightExpSampleBinding
|
||||
import com.example.hpos.presentation.UsbServiceListener
|
||||
import com.example.hpos.presentation.utils.MyDialogListener
|
||||
@@ -158,6 +160,8 @@ class TestRightExpSample : Fragment() {
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
Log.e(TAG, "onUsbIoError() called in sendCmdToRun() -> $e")
|
||||
viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again this step", Constants.ERROR_NORMAL))
|
||||
|
||||
viewModel.progressBar.postValue(false)
|
||||
}
|
||||
})
|
||||
@@ -198,6 +202,8 @@ class TestRightExpSample : Fragment() {
|
||||
|
||||
override fun onUsbError(e: Exception?) {
|
||||
Log.e(TAG, "onUsbIoError() called in sendCmdToFetchLightIntensities() -> $e")
|
||||
viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again this step", Constants.ERROR_NORMAL))
|
||||
|
||||
viewModel.progressBar.postValue(false)
|
||||
}
|
||||
})
|
||||
@@ -210,7 +216,11 @@ class TestRightExpSample : Fragment() {
|
||||
viewModel.mapWavelengthToAbsorbance()
|
||||
// Todo: Save CSV + Test CSV
|
||||
|
||||
viewModel.calculateResults()
|
||||
if (DataHolder.selectedTestType == TestType.SICKLECERT) {
|
||||
viewModel.calculateResults()
|
||||
} else {
|
||||
viewModel.calculateResultsForSickleFind()
|
||||
}
|
||||
// Todo: Save Log
|
||||
|
||||
saveDataLocally()
|
||||
@@ -246,7 +256,12 @@ class TestRightExpSample : Fragment() {
|
||||
|
||||
val id = PreferenceUtility.generateId(requireContext())
|
||||
|
||||
val prefixCsv = "HPOSSC_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
val prefixCsv: String = if (DataHolder.selectedTestType == TestType.SICKLECERT)
|
||||
"HPOSSC_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
else
|
||||
"HPOSSF_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
|
||||
// val prefixCsv = "HPOSSC_${DataHolder.deviceSerialNumber}_${patientName}_"
|
||||
val fileExtensionCsv = ".csv"
|
||||
val fileNameCsv = prefixCsv + id + fileExtensionCsv
|
||||
saveCsv(fileNameCsv)
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpos.R
|
||||
@@ -13,6 +14,7 @@ import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.PreferenceUtility
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.TestRightResultType
|
||||
import com.example.hpos.data.model.TestType
|
||||
import com.example.hpos.databinding.FragmentTestRightResultsBinding
|
||||
import com.example.hpos.presentation.MainActivity
|
||||
import com.example.hpos.util.MyUtils
|
||||
@@ -49,16 +51,20 @@ class TestRightResults : Fragment() {
|
||||
startActivity(i)
|
||||
}
|
||||
binding.ivNext.setOnClickListener {
|
||||
if (DataHolder.sampleReadCounter > Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE) {
|
||||
DataHolder.sampleReadCounter = 0
|
||||
DataHolder.isReferenceTaken = false
|
||||
parentFragmentManager.beginTransaction()
|
||||
.replace(R.id.fl_main, TestRightExpReference())
|
||||
.commit()
|
||||
} else {
|
||||
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightExpSample())
|
||||
.commit()
|
||||
}
|
||||
moveToSamplePage()
|
||||
}
|
||||
}
|
||||
|
||||
fun moveToSamplePage() {
|
||||
if (DataHolder.sampleReadCounter > Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE) {
|
||||
DataHolder.sampleReadCounter = 0
|
||||
DataHolder.isReferenceTaken = false
|
||||
parentFragmentManager.beginTransaction()
|
||||
.replace(R.id.fl_main, TestRightExpReference())
|
||||
.commit()
|
||||
} else {
|
||||
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightExpSample())
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,22 +134,59 @@ class TestRightResults : Fragment() {
|
||||
binding.tvGender.text =
|
||||
getString(R.string.gender_in_textview, viewModel.patientDetails.gender)
|
||||
|
||||
// binding.tvResultValue.text = viewModel.patientDetails.results.toString()
|
||||
when (viewModel.patientDetails.results) {
|
||||
TestRightResultType.NORMAL -> {
|
||||
binding.resultNormal.visibility = View.VISIBLE
|
||||
if (DataHolder.selectedTestType == TestType.SICKLECERT){
|
||||
when (viewModel.patientDetails.results) {
|
||||
TestRightResultType.NORMAL -> {
|
||||
binding.resultNormal.visibility = View.VISIBLE
|
||||
}
|
||||
TestRightResultType.SICKLECELLDISEASE -> {
|
||||
binding.resultDisease.visibility = View.VISIBLE
|
||||
}
|
||||
TestRightResultType.SICKLECELLTRAIT -> {
|
||||
binding.resultTrait.visibility = View.VISIBLE
|
||||
}
|
||||
else -> {
|
||||
// binding.resultUndefined.visibility = View.VISIBLE
|
||||
Toast.makeText(requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG).show()
|
||||
moveToSamplePage()
|
||||
// val i = Intent(requireContext().applicationContext, MainActivity::class.java)
|
||||
// startActivity(i)
|
||||
}
|
||||
}
|
||||
TestRightResultType.SICKLECELLDISEASE -> {
|
||||
binding.resultDisease.visibility = View.VISIBLE
|
||||
}
|
||||
TestRightResultType.SICKLECELLTRAIT -> {
|
||||
binding.resultTrait.visibility = View.VISIBLE
|
||||
}
|
||||
else -> {
|
||||
binding.resultUndefined.visibility = View.VISIBLE
|
||||
} else {
|
||||
when (viewModel.patientDetails.results) {
|
||||
TestRightResultType.SICKLECELLDISEASE -> {
|
||||
binding.resultDisease.visibility = View.VISIBLE
|
||||
binding.resultDisease.text = "Positive"
|
||||
}
|
||||
TestRightResultType.NORMAL -> {
|
||||
binding.resultNormal.visibility = View.VISIBLE
|
||||
binding.resultNormal.text = "Negative"
|
||||
}
|
||||
else -> {
|
||||
Toast.makeText(requireContext().applicationContext, "Please Test Again", Toast.LENGTH_LONG).show()
|
||||
moveToSamplePage()
|
||||
// val i = Intent(requireContext().applicationContext, MainActivity::class.java)
|
||||
// startActivity(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// when (viewModel.patientDetails.results) {
|
||||
// TestRightResultType.NORMAL -> {
|
||||
// binding.resultNormal.visibility = View.VISIBLE
|
||||
// }
|
||||
// TestRightResultType.SICKLECELLDISEASE -> {
|
||||
// binding.resultDisease.visibility = View.VISIBLE
|
||||
// }
|
||||
// TestRightResultType.SICKLECELLTRAIT -> {
|
||||
// binding.resultTrait.visibility = View.VISIBLE
|
||||
// }
|
||||
// else -> {
|
||||
// binding.resultUndefined.visibility = View.VISIBLE
|
||||
// }
|
||||
// }
|
||||
|
||||
// Log.d(TAG, "\n\n\n\nFor intensity Reference array size = ${DataHolder.intensityReferenceArray.size}")
|
||||
// for (each in DataHolder.intensityReferenceArray){
|
||||
// Log.d(TAG, "${each}")
|
||||
|
||||
@@ -7,10 +7,7 @@ import androidx.lifecycle.ViewModel
|
||||
import com.example.hpos.data.DataHolder
|
||||
import com.example.hpos.data.constant.Constants
|
||||
import com.example.hpos.data.model.*
|
||||
import com.example.hpos.domain.ResultCalculationWithMaxImpl
|
||||
import com.example.hpos.domain.SaveRawData
|
||||
import com.example.hpos.domain.SaveRawDataTest
|
||||
import com.example.hpos.domain.TestRightResultCalculation
|
||||
import com.example.hpos.domain.*
|
||||
import com.example.hpos.util.MyUtils
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
@@ -25,7 +22,8 @@ class TestRightViewModel : ViewModel() {
|
||||
|
||||
var isServiceConnected = false
|
||||
val progressBar = MutableLiveData(false)
|
||||
// val errorTriggered = MutableLiveData<String>("")
|
||||
|
||||
// val errorTriggered = MutableLiveData<String>("")
|
||||
val errorTriggered = MutableLiveData<ErrorMessage>()
|
||||
var numberOfSampleRun = 0
|
||||
|
||||
@@ -58,12 +56,22 @@ class TestRightViewModel : ViewModel() {
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 201: In processing the data from device"
|
||||
errorTriggered.postValue(ErrorMessage("Error 201: In processing the data from device", Constants.ERROR_NORMAL))
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 201: In processing the data from device",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Todo: Throws error (showing error if empty by using a mutable error string)
|
||||
// "Error 202: Unable to fetch data from device."
|
||||
errorTriggered.postValue(ErrorMessage("Error 202: Unable to fetch data from device.", Constants.ERROR_NORMAL))
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 202: Unable to fetch data from device.",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
}
|
||||
// }
|
||||
}
|
||||
@@ -87,7 +95,12 @@ class TestRightViewModel : ViewModel() {
|
||||
} else {
|
||||
// Todo: Throws error
|
||||
// "Error 203: Unable to fetch data from device."
|
||||
errorTriggered.postValue(ErrorMessage("Error 203: Unable to fetch data from device.", Constants.ERROR_NORMAL))
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 203: Unable to fetch data from device.",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
// }
|
||||
@@ -98,7 +111,7 @@ class TestRightViewModel : ViewModel() {
|
||||
if (isReference) DataHolder.intensityReferenceArray.clear()
|
||||
else intensitySampleArray.clear()
|
||||
|
||||
// Log.d(TAG, fullString)
|
||||
Log.d("SURYAKUMAR", fullString)
|
||||
val listOfString = fullString.split("\n")
|
||||
|
||||
for (line in listOfString) {
|
||||
@@ -114,7 +127,12 @@ class TestRightViewModel : ViewModel() {
|
||||
intensitySampleArray.add(numbers[1].toDouble())
|
||||
} else {
|
||||
// "Error 204: Unable to fetch data from device."
|
||||
errorTriggered.postValue(ErrorMessage("Error 204: Unable to fetch data from device.", Constants.ERROR_NORMAL))
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 204: Unable to fetch data from device.",
|
||||
Constants.ERROR_NORMAL
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -153,7 +171,12 @@ class TestRightViewModel : ViewModel() {
|
||||
|
||||
fun mapWavelengthToAbsorbance() {
|
||||
if (DataHolder.intensityReferenceArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != DataHolder.intensityReferenceArray.size) {
|
||||
errorTriggered.postValue(ErrorMessage("Error 205: Unable to fetch data from device, please try again by reopening the app", Constants.ERROR_CRITICAL))
|
||||
errorTriggered.postValue(
|
||||
ErrorMessage(
|
||||
"Error 205: Unable to fetch data from device, please try again by reopening the app",
|
||||
Constants.ERROR_CRITICAL
|
||||
)
|
||||
)
|
||||
|
||||
throw Exception("Inconsistency in the data, size of arrays are not same. \nintensityReferenceArray.size = ${DataHolder.intensityReferenceArray.size} ; intensitySampleArray.size = ${intensitySampleArray.size} ; wavelengthToPixelArray.size = ${DataHolder.wavelengthToPixelArray.size}")
|
||||
}
|
||||
@@ -198,7 +221,8 @@ class TestRightViewModel : ViewModel() {
|
||||
// Todo: Remove
|
||||
val calculationVariableForTest = CalculationVariableForTest()
|
||||
calculationVariableForTest.pixelNo = index + 1
|
||||
calculationVariableForTest.invertedPixelNo = invertedPixelIndex+1 // 0-based indexing
|
||||
calculationVariableForTest.invertedPixelNo =
|
||||
invertedPixelIndex + 1 // 0-based indexing
|
||||
calculationVariableForTest.wavelength = wavelength
|
||||
calculationVariableForTest.I0 = i0
|
||||
calculationVariableForTest.I = i1
|
||||
@@ -220,70 +244,125 @@ class TestRightViewModel : ViewModel() {
|
||||
|
||||
}
|
||||
|
||||
fun calculateResultsForSickleFind() {
|
||||
DataHolder.sampleReadCounter++
|
||||
val resultCalculation: TestRightResultCalculation =
|
||||
SickleFindResultCaluculationWithMaxImpl()
|
||||
calculationData = resultCalculation.getResults(wavelengthToAbsorbance)
|
||||
patientDetails.results = calculationData.result
|
||||
|
||||
}
|
||||
|
||||
fun saveCsv(appContext: Context, filename: String) {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawData().saveCsv(folderPath!!, filename, wavelengthToAbsorbance)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null){
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawData().saveCsv(folderPath, filename, wavelengthToAbsorbance)
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawData().saveCsv(folderPath!!, filename, wavelengthToAbsorbance)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawData().saveCsv(folderPath, filename, wavelengthToAbsorbance)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save CSV, Please try again")
|
||||
}
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveCsvForTesting(appContext: Context, filename: String) {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawDataTest().saveCsv(folderPath!!, filename, calculationVariableList)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null){
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawDataTest().saveCsv(folderPath, filename, calculationVariableList)
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawDataTest().saveCsv(folderPath!!, filename, calculationVariableList)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawDataTest().saveCsv(folderPath, filename, calculationVariableList)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save CSV, Please try again")
|
||||
}
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLog(appContext: Context, fileName: String) {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
// try {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawData().saveLog(folderPath!!, fileName, calculationData)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null){
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawData().saveLog(folderPath, fileName, calculationData)
|
||||
if (DataHolder.isAppFolderCreated) {
|
||||
SaveRawData().saveLog(folderPath!!, fileName, calculationData)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawData().saveLog(folderPath, fileName, calculationData)
|
||||
} else {
|
||||
// errorTriggered.postValue("Unable to save Log, Please try again")
|
||||
}
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLogWithPatient(appContext: Context, fileName: String) {
|
||||
var folderPath: String? = DataHolder.appFolderPath
|
||||
// try {
|
||||
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)
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
// } catch (e: java.io.FileNotFoundException) {
|
||||
// errorTriggered.postValue(
|
||||
// ErrorMessage(
|
||||
// "File name isn't valid",
|
||||
// Constants.ERROR_CRITICAL
|
||||
// )
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
fun saveLogTest(appContext: Context, isReference: Boolean, fullString: String) {
|
||||
@@ -300,7 +379,7 @@ class TestRightViewModel : ViewModel() {
|
||||
SaveRawDataTest().saveLog(folderPath!!, fileName, isReference, fullString)
|
||||
} else {
|
||||
folderPath = MyUtils.createAppFolder(appContext)
|
||||
if (folderPath != null){
|
||||
if (folderPath != null) {
|
||||
DataHolder.isAppFolderCreated = true
|
||||
DataHolder.appFolderPath = folderPath
|
||||
SaveRawDataTest().saveLog(folderPath, fileName, isReference, fullString)
|
||||
|
||||
Reference in New Issue
Block a user