Skip to content

Commit

Permalink
Implemneted disease parsing into human-readable text (eu-digital-gree…
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrsarapulovgl authored Jun 4, 2021
1 parent 25e8614 commit 3e13505
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class PersonModel(
)

data class VaccinationModel(
override val disease: String,
override val disease: DiseaseType,
val vaccine: String,
val medicinalProduct: String,
val manufacturer: String,
Expand All @@ -51,7 +51,7 @@ data class VaccinationModel(
) : CertificateData

data class TestModel(
override val disease: String,
override val disease: DiseaseType,
val typeOfTest: String,
val testName: String?,
val testNameAndManufacturer: String?,
Expand All @@ -70,8 +70,13 @@ enum class TestResult(val value: String) {
NOT_DETECTED("NOT DETECTED")
}

enum class DiseaseType(val value: String) {
COVID_19("COVID-19"),
UNDEFINED("UNDEFINED")
}

data class RecoveryModel(
override val disease: String,
override val disease: DiseaseType,
val dateOfFirstPositiveTest: String,
val countryOfVaccination: String,
val certificateIssuer: String,
Expand All @@ -81,5 +86,5 @@ data class RecoveryModel(
) : CertificateData

interface CertificateData {
val disease: String
val disease: DiseaseType
}
27 changes: 19 additions & 8 deletions app/src/main/java/dgca/verifier/app/android/model/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

package dgca.verifier.app.android.model

import dgca.verifier.app.decoder.model.GreenCertificate
import dgca.verifier.app.decoder.model.Person
import dgca.verifier.app.decoder.model.RecoveryStatement
import dgca.verifier.app.decoder.model.Test
import dgca.verifier.app.decoder.model.Vaccination
import dgca.verifier.app.decoder.model.*

fun GreenCertificate.toCertificateModel(): CertificateModel {
return CertificateModel(
Expand All @@ -40,7 +36,7 @@ fun GreenCertificate.toCertificateModel(): CertificateModel {

fun RecoveryStatement.toRecoveryModel(): RecoveryModel {
return RecoveryModel(
disease = disease,
disease = disease.toDiseaseCode().toDiseaseType(),
dateOfFirstPositiveTest = dateOfFirstPositiveTest,
countryOfVaccination = countryOfVaccination,
certificateIssuer = certificateIssuer,
Expand All @@ -52,7 +48,7 @@ fun RecoveryStatement.toRecoveryModel(): RecoveryModel {

fun Test.toTestModel(): TestModel {
return TestModel(
disease = disease,
disease = disease.toDiseaseCode().toDiseaseType(),
typeOfTest = typeOfTest,
testName = testName,
testNameAndManufacturer = testNameAndManufacturer,
Expand All @@ -74,9 +70,14 @@ fun Test.TestResult.toTestResult(): TestResult {
}
}

fun DiseaseCode.toDiseaseType(): DiseaseType = when (this) {
DiseaseCode.COVID_19 -> DiseaseType.COVID_19
else -> DiseaseType.UNDEFINED
}

fun Vaccination.toVaccinationModel(): VaccinationModel {
return VaccinationModel(
disease = disease,
disease = disease.toDiseaseCode().toDiseaseType(),
vaccine = vaccine,
medicinalProduct = medicinalProduct,
manufacturer = manufacturer,
Expand All @@ -96,4 +97,14 @@ fun Person.toPersonModel(): PersonModel {
standardisedGivenName = standardisedGivenName,
givenName = givenName
)
}

fun String.toDiseaseCode(): DiseaseCode = when (this) {
DiseaseCode.COVID_19.value -> DiseaseCode.COVID_19
else -> DiseaseCode.UNDEFINED
}

enum class DiseaseCode(val value: String) {
COVID_19("840539006"),
UNDEFINED("")
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import dgca.verifier.app.android.parseFromTo
class RecoveryViewHolder(private val binding: ItemRecoveryBinding) : RecyclerView.ViewHolder(binding.root) {

fun bind(data: RecoveryModel) {
binding.diseaseValue.text = data.disease
binding.diseaseValue.text = data.disease.value
binding.validFromValue.text = data.certificateValidFrom.parseFromTo(YEAR_MONTH_DAY, FORMATTED_YEAR_MONTH_DAY)
binding.validUntilValue.text = data.certificateValidUntil.parseFromTo(YEAR_MONTH_DAY, FORMATTED_YEAR_MONTH_DAY)
binding.dateOfPositiveValue.text = data.dateOfFirstPositiveTest.parseFromTo(YEAR_MONTH_DAY, FORMATTED_YEAR_MONTH_DAY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TestViewHolder(private val binding: ItemTestBinding) : RecyclerView.ViewHo
binding.dateOfTestResultValue.text = this
}
binding.dateOfTestResultValue.visibility = if(dateOfTestResultString?.isNotEmpty() == true) View.VISIBLE else View.GONE
binding.diseaseValue.text = data.disease
binding.diseaseValue.text = data.disease.value
binding.typeOfTestValue.text = data.typeOfTest
binding.countryValue.text = data.countryOfVaccination
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class VaccinationViewHolder(private val binding: ItemVaccinationBinding) : Recyc

fun bind(data: VaccinationModel) {
binding.dateValue.text = data.dateOfVaccination.parseFromTo(YEAR_MONTH_DAY, FORMATTED_YEAR_MONTH_DAY)
binding.diseaseValue.text = data.disease
binding.diseaseValue.text = data.disease.value
binding.doseTotalNumberValue.text = data.totalSeriesOfDoses.toString()
binding.doseSequenceValue.text = data.doseNumber.toString()
binding.countryValue.text = data.countryOfVaccination
Expand Down

0 comments on commit 3e13505

Please sign in to comment.