Skip to content

Commit

Permalink
issue 2822: launch dialler with phone number (#2856)
Browse files Browse the repository at this point in the history
* added LAUNCH_DIALER workflow to which will be triggered by the ON_CLICK trigger attached to the clickable phone number COMPOUND_TEXT

* add LAUNCH_DIALER functionality to ConfigExtensions. reset to unedited configurations/app

* added tests to check that startactivity is called. check correct prefix for the telephone number. check that the correct action_dial is sent in the intent

* add modified fakePatient to dialler test to allow addition of telecom values

* fixed Test Bug: interpolatedParams received an empty list. fixed by complete extraction of phone number into computed values. also added action parameters to the action config

* test to make sure startActivity is called successfully and no errors are thrown

* spotless apply & check

* merge main into my branch && change dialer to dialler for consistent spelling && spotless checks

* config(test) changes. add phoneNumber parameters and extraction rules to fix failing CI test

* add verification that startActivity was called and added assertions to enfocrce Intent.ACTION_DIAL and correct data

* CI spotless
  • Loading branch information
kelvin-ngure authored Nov 20, 2023
1 parent 4a55f61 commit 0ec96d7
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ enum class ApplicationWorkflow {

/** A workflow for changing a managing entity */
CHANGE_MANAGING_ENTITY,

/** A workflow that launches the dialer with the phone number ready to place a call */
LAUNCH_DIALLER,
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.smartregister.fhircore.quest.util.extensions

import android.content.Intent
import android.net.Uri
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.navigation.NavController
import androidx.navigation.NavOptions
Expand Down Expand Up @@ -142,6 +145,13 @@ fun List<ActionConfig>.handleClickEvent(
MainNavigationScreen.GeoWidget.route,
bundleOf(NavigationArg.CONFIG_ID to actionConfig.id),
)
ApplicationWorkflow.LAUNCH_DIALLER -> {
val actionParameter = interpolatedParams.first()
val patientPhoneNumber = actionParameter.value
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:$patientPhoneNumber")
ContextCompat.startActivity(navController.context, intent, null)
}
else -> return
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@
"actions": [
"data.put('patientId', fhirPath.extractValue(Patient, 'Patient.identifier[0].value'))"
]
},
{
"name": "patientPhoneNumber",
"condition": "true",
"actions": [
"data.put('patientPhoneNumber', fhirPath.extractValue(Patient, 'Patient.telecom[0].value'))"
]
},
{
"name": "phoneNumberAvailable",
"condition": "true",
"actions": [
"data.put('phoneNumberAvailable', !empty(data.get('patientPhoneNumber')))"
]
}
],
"views": [
Expand All @@ -58,6 +72,38 @@
"primaryText": "ID: @{patientId}",
"primaryTextColor": "#000000"
},
{
"viewType": "SPACER",
"height": 10,
"visible": "@{phoneNumberAvailable}"
},
{
"viewType": "COMPOUND_TEXT",
"primaryTextColor": "#000000",
"primaryText": "PHONE NUMBER",
"visible": "@{phoneNumberAvailable}"
},
{
"viewType": "COMPOUND_TEXT",
"primaryText": "@{patientPhoneNumber}",
"primaryTextColor": "#0077CC",
"fontSize": 14,
"visible": "@{phoneNumberAvailable}",
"clickable": "true",
"primaryTextActions": [
{
"trigger": "ON_CLICK",
"workflow": "LAUNCH_DIALLER",
"params": [
{
"paramType": "PARAMDATA",
"key": "patientPhoneNumber",
"value": "@{patientPhoneNumber}"
}
]
}
]
},
{
"viewType": "ROW",
"children": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package org.smartregister.fhircore.quest.util.extensions

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.core.content.ContextCompat.startActivity
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.NavOptions
Expand All @@ -27,6 +30,7 @@ import io.mockk.mockk
import io.mockk.slot
import io.mockk.verify
import kotlin.test.assertEquals
import org.hl7.fhir.r4.model.ContactPoint
import org.hl7.fhir.r4.model.ResourceType
import org.junit.Assert
import org.junit.Before
Expand Down Expand Up @@ -282,6 +286,63 @@ class ConfigExtensionsTest : RobolectricTest() {
Assert.assertEquals("geoWidgetId", slotBundle.captured.getString(NavigationArg.CONFIG_ID))
}

@Test
fun testLaunchDiallerOnClick() {
val patientWithPhoneNumber = patient.copy()
patientWithPhoneNumber.apply {
addTelecom(
ContactPoint().apply { this.value = "0700000000" },
)
}

val computedValuesWithPhoneNumberMutable = resourceData.computedValuesMap.toMutableMap()
computedValuesWithPhoneNumberMutable["patientPhoneNumber"] =
patientWithPhoneNumber.telecom.first().value
val computedValuesWithPhoneNumber = computedValuesWithPhoneNumberMutable.toMap()

val resourceDataWithPhoneNumber =
ResourceData(
baseResourceId = patient.logicalId,
baseResourceType = ResourceType.Patient,
computedValuesMap = computedValuesWithPhoneNumber,
)

val clickAction =
ActionConfig(
id = "diallerId",
trigger = ActionTrigger.ON_CLICK,
workflow = ApplicationWorkflow.LAUNCH_DIALLER.name,
params =
listOf(
ActionParameter(
key = "patientPhoneNumber",
value = "@{patientPhoneNumber}",
paramType = ActionParameterType.PARAMDATA,
),
),
)

listOf(clickAction)
.handleClickEvent(
navController = navController,
resourceData = resourceDataWithPhoneNumber,
) // make a clicking action

// make sure no errors thrown when the new activity is started. should return nothing
every { context.startActivity(any()) } returns Unit

// make sure correct function with correct signature is called
verify {
context.startActivity(
withArg {
assertEquals(it.action, Intent.ACTION_DIAL)
assertEquals(it.data, Uri.parse("tel:0700000000"))
},
null,
)
}
}

@Test
fun testNavigateBackToHomeWhenCurrentAndPreviousDestinationIdsAreNull() {
val clickAction =
Expand Down

0 comments on commit 0ec96d7

Please sign in to comment.