Change the project into Testing app
This commit is contained in:
89
app/src/main/java/com/example/hpostesting/util/MyUtils.kt
Normal file
89
app/src/main/java/com/example/hpostesting/util/MyUtils.kt
Normal 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"
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user