Change the project into Testing app

This commit is contained in:
mohamedkaif356
2023-06-28 12:41:18 +05:30
parent 69df710006
commit 0c063583ca
118 changed files with 1729 additions and 2760 deletions

View File

@@ -0,0 +1,89 @@
package com.example.hpostesting.util
import android.content.Context
import android.os.Environment
import com.example.hpostesting.data.model.patient.PatientDetails
import `in`.sminnovations.hpostesting.R
import java.io.File
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
object MyUtils {
fun createAppFolder(context: Context) : String? {
val folderPath = getAppFolderPath(context)
val file = File(folderPath)
return if (!file.exists()) {
if (!file.mkdirs()) {
null
} else {
folderPath
}
} else {
folderPath
}
}
fun getAppFolderPath(context: Context) : String {
return Environment.getExternalStorageDirectory().absolutePath + "/" + context.resources.getString(R.string.app_name) + "/"
}
fun isInternetConnected(): Boolean {
val runtime = Runtime.getRuntime()
try {
val ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8")
val exitValue = ipProcess.waitFor()
return exitValue == 0
} catch (e: IOException) {
e.printStackTrace()
} catch (e: InterruptedException) {
e.printStackTrace()
}
return false
}
fun generateTestIdForPatient(patientId: String): String {
val dateFormat = SimpleDateFormat("HHmm_ddMMyyyy", Locale.getDefault())
return patientId + "_" + dateFormat.format(Date())
}
fun String.mapToGender(): PatientDetails.Gender {
return if (this.lowercase() == "m"|| this.lowercase() == "male") {
PatientDetails.Gender.MALE
} else if (this.lowercase() == "f"|| this.lowercase() == "female") {
PatientDetails.Gender.FEMALE
} else {
PatientDetails.Gender.OTHER
}
}
fun String.mapToCategory(): PatientDetails.Category {
return when (this.lowercase()){
"gen" -> PatientDetails.Category.GENERAL
"general" -> PatientDetails.Category.GENERAL
"obc" -> PatientDetails.Category.OBC
"sc" -> PatientDetails.Category.SC
"st" -> PatientDetails.Category.ST
else -> {PatientDetails.Category.GENERAL}
}
}
fun String.fetchYOBFromDOB(): Int {
val startIndex = if (this.length >= 4) this.length - 4 else 0
return this.substring(startIndex).toInt()
}
fun Int.calculateAgeFromYOB(): Int {
val currentY = SimpleDateFormat("yyyy").format(Date()).toInt()
return (currentY - this)
}
fun String.mapYesNoStringToBool(): Boolean {
return this.lowercase() == "yes"
}
}