Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catalog, show questionnaire response when submit questionnaire button get clicked. #1097

Merged
merged 45 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b797bc4
Sdc gallery app landing page
santosh-pingle Dec 28, 2021
94df10b
Rename file name.
santosh-pingle Dec 28, 2021
2b3030c
Merge branch 'master' into sp/988-landing-page
santosh-pingle Dec 28, 2021
c129e57
Update components and layouts vector icons.
santosh-pingle Jan 3, 2022
b1525b5
Merge branch 'master' into sp/988-landing-page
santosh-pingle Jan 3, 2022
c67b949
Sdc gallery app single choice workflow.
santosh-pingle Jan 4, 2022
05f8a44
Update it as boolean choice.
santosh-pingle Jan 5, 2022
45d59cb
Address review comments.
santosh-pingle Jan 5, 2022
52121cf
Boolean choice component icon.
santosh-pingle Jan 5, 2022
6efe4b9
Merge branch 'sp/988-landing-page' into sp/992-single-choice
santosh-pingle Jan 5, 2022
d76da21
Spotless apply
santosh-pingle Jan 5, 2022
2e68631
Merge branch 'master' into sp/988-landing-page
santosh-pingle Jan 5, 2022
0dfebad
Build failures
santosh-pingle Jan 5, 2022
9ca677d
Delete gallery drawables.
santosh-pingle Jan 5, 2022
98bba50
fix package name in nav graph
santosh-pingle Jan 5, 2022
2b9e33f
Merge branch 'sp/988-landing-page' into sp/992-single-choice
santosh-pingle Jan 5, 2022
4357509
Spotless apply.
santosh-pingle Jan 5, 2022
f697147
Delete gallery color resource
santosh-pingle Jan 5, 2022
83c3c45
Merge branch 'master' into sp/988-landing-page
santosh-pingle Jan 6, 2022
0adae63
Merge branch 'sp/988-landing-page' into sp/992-single-choice
santosh-pingle Jan 7, 2022
96e30a6
Merge branch 'master' into sp/988-landing-page
santosh-pingle Jan 7, 2022
b050ce4
Merge branch 'sp/988-landing-page' into sp/992-single-choice
santosh-pingle Jan 7, 2022
3664435
theme attributes for color value.
santosh-pingle Jan 10, 2022
2384a9a
bottom view margin
santosh-pingle Jan 10, 2022
38be418
Merge branch 'master' into sp/988-landing-page
santosh-pingle Jan 10, 2022
68486e1
Merge branch 'sp/988-landing-page' into sp/992-single-choice
santosh-pingle Jan 10, 2022
177935f
Merge branch 'master' into sp/992-single-choice
santosh-pingle Jan 13, 2022
b97e26b
default layout workflow.
santosh-pingle Jan 20, 2022
3263a7d
apply layout theme
santosh-pingle Jan 25, 2022
40e871f
Merge branch 'master' into sp/1049-default-layout
santosh-pingle Jan 27, 2022
4ce99bc
Add filename field to the layout enum.
santosh-pingle Jan 27, 2022
5d506cf
Update catalog title in toolbar when user navigate back from defalult…
santosh-pingle Jan 27, 2022
451b22a
Merge branch 'master' into sp/1049-default-layout
santosh-pingle Jan 31, 2022
82d399c
Display questionnaire response.
santosh-pingle Feb 1, 2022
a55310e
Merge branch 'master' into sp/1081-q-response
santosh-pingle Feb 11, 2022
fc7cb59
Review comment.
santosh-pingle Feb 16, 2022
61f32fe
Remove commented code
santosh-pingle Feb 16, 2022
e580f7d
Merge branch 'master' into sp/1081-q-response
santosh-pingle Feb 16, 2022
93f85a5
Add submit menu to overflow menu.
santosh-pingle Feb 18, 2022
4e04eaf
Merge branch 'master' into sp/1081-q-response
santosh-pingle Feb 18, 2022
81caac9
Merge branch 'master' into sp/1081-q-response
santosh-pingle Feb 21, 2022
73977f0
Address review comments.
santosh-pingle Feb 21, 2022
7937287
Address review comment.
santosh-pingle Feb 22, 2022
204d059
Merge branch 'master' into sp/1081-q-response
santosh-pingle Feb 22, 2022
0ce52c6
Merge branch 'master' into sp/1081-q-response
santosh-pingle Feb 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sdc gallery app single choice workflow.
  • Loading branch information
santosh-pingle committed Jan 4, 2022
commit c67b94996bc1aadedf24a8395cef7a705efba40a
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"resourceType": "Questionnaire",
"item": [
{
"extension": [
{
"url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http:https://hl7.org/fhir/questionnaire-item-control",
"code": "radio-button",
"display": "Radio Button"
}
]
}
}
],
"linkId": "1",
"text": "Have you taken a pregnancy test?",
"type": "boolean",
"answerOption": [
{
"valueCoding": {
"system": "http:https://terminology.hl7.org/CodeSystem/v2-0532",
"code": "Y",
"display": "Yes"
}
},
{
"valueCoding": {
"system": "http:https://terminology.hl7.org/CodeSystem/v2-0532",
"code": "N",
"display": "No"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"resourceType": "Questionnaire",
"item": [
{
"extension": [
{
"url": "http:https://hl7.org/fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "http:https://hl7.org/fhir/questionnaire-item-control",
"code": "radio-button",
"display": "Radio Button"
}
]
}
}
],
"linkId": "1",
"text": "Have you taken a pregnancy test?",
"type": "boolean"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
package com.google.android.fhir.datacapture.gallery

import android.os.Bundle
import android.view.Gravity
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView

Expand All @@ -32,11 +36,47 @@ class ComponentsFragment : Fragment(R.layout.fragment_components) {
setUpComponentsRecyclerView()
}

override fun onResume() {
super.onResume()
setUpActionBar()
(activity as MainActivity).showBottomNavigationView(View.VISIBLE)
}

private fun setUpActionBar() {
(requireActivity() as AppCompatActivity).supportActionBar?.apply {
setDisplayHomeAsUpEnabled(false)
}
(activity as MainActivity).setActionBar(
getString(R.string.toolbar_text),
Gravity.CENTER_HORIZONTAL
)
setHasOptionsMenu(true)
}

private fun setUpComponentsRecyclerView() {
val adapter = ComponentsRecyclerViewAdapter()
val adapter = ComponentsRecyclerViewAdapter(::onItemClick)
val recyclerView = view?.findViewById<RecyclerView>(R.id.componentsRecyclerView)
recyclerView?.adapter = adapter
recyclerView?.layoutManager = GridLayoutManager(context, 2)
adapter.submitList(viewModel.getComponentsList())
}

private fun onItemClick(component: ComponentsLayoutsViewModel.Components) {
// TODO Remove check when all components questionnaire json are updated.
if (viewModel.getQuestionnaire(component).isEmpty()) {
return
}
launchQuestionnaireFragment(component)
}

private fun launchQuestionnaireFragment(component: ComponentsLayoutsViewModel.Components) {
findNavController()
.navigate(
ComponentsFragmentDirections.actionComponentsFragmentToGalleryQuestionnaireFragment(
context?.getString(component.textId) ?: "",
viewModel.getQuestionnaire(component),
null
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ class ComponentsLayoutsViewModel(application: Application, private val state: Sa
return SdcLayouts.values().toList()
}

fun getQuestionnaire(component: Components): String {
return when (component) {
Components.MULTIPLE_CHOICE -> ""
// Components.SINGLE_CHOICE -> "single_choice_questionnaire.json"
Components.SINGLE_CHOICE -> "single_choice_questionnaire_boolean.json"
Components.OPEN_CHOICE -> ""
Components.TEXT_FIELD -> ""
Components.DATE_PICKER -> ""
Components.TIME_PICKER -> ""
Components.MODAL -> ""
Components.SLIDER -> ""
Components.DROPDOWN -> ""
Components.IMAGE -> ""
Components.DATE_OF_BIRTH -> ""
Components.DATE_RANGE_PICKER -> ""
Components.UNIT_OPTIONS -> ""
}
}

// TODO update components icons
enum class Components(@DrawableRes val iconId: Int, @StringRes val textId: Int) {
MULTIPLE_CHOICE(R.drawable.ic_multiplechoice, R.string.multiple_choice),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.google.android.fhir.datacapture.gallery.databinding.LandingPageItemBinding

class ComponentsRecyclerViewAdapter() :
class ComponentsRecyclerViewAdapter(
private val onItemClick: (ComponentsLayoutsViewModel.Components) -> Unit
) :
ListAdapter<ComponentsLayoutsViewModel.Components, SdcComponentsViewHolder>(
ComponentsDiffUtil()
) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SdcComponentsViewHolder {
return SdcComponentsViewHolder(
LandingPageItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
LandingPageItemBinding.inflate(LayoutInflater.from(parent.context), parent, false),
onItemClick
)
}

Expand All @@ -38,12 +41,15 @@ class ComponentsRecyclerViewAdapter() :
}
}

class SdcComponentsViewHolder(private val binding: LandingPageItemBinding) :
RecyclerView.ViewHolder(binding.root) {
class SdcComponentsViewHolder(
private val binding: LandingPageItemBinding,
private val onItemClick: (ComponentsLayoutsViewModel.Components) -> Unit
) : RecyclerView.ViewHolder(binding.root) {
fun bind(component: ComponentsLayoutsViewModel.Components) {
binding.componentLayoutIconImageview.setImageResource(component.iconId)
binding.componentLayoutTextView.text =
binding.componentLayoutTextView.context.getString(component.textId)
binding.root.setOnClickListener { onItemClick(component) }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.fhir.datacapture.gallery

import android.os.Bundle
import android.view.Gravity
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.navArgs
import com.google.android.fhir.datacapture.QuestionnaireFragment
import kotlinx.coroutines.launch

class GalleryQuestionnaireFragment : Fragment(R.layout.fragment_gallery_questionnaire) {
private val viewModel: GalleryQuestionnaireViewModel by viewModels()
private val args: GalleryQuestionnaireFragmentArgs by navArgs()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
updateArguments()
if (savedInstanceState == null) {
addQuestionnaireFragment()
}
}

override fun onResume() {
super.onResume()
(requireActivity() as MainActivity).showBottomNavigationView(View.GONE)
setUpActionBar()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
NavHostFragment.findNavController(this).navigateUp()
true
}
else -> super.onOptionsItemSelected(item)
}
}

private fun setUpActionBar() {
(requireActivity() as AppCompatActivity).supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
}
(requireActivity() as MainActivity).setActionBar(args.questionnaireTitleKey, Gravity.TOP)
setHasOptionsMenu(true)
}

private fun updateArguments() {
requireArguments()
.putString(
QuestionnaireContainerFragment.QUESTIONNAIRE_FILE_PATH_KEY,
args.questionnaireFilePathKey
)
}

private fun addQuestionnaireFragment() {
val fragment = QuestionnaireFragment()
viewLifecycleOwner.lifecycleScope.launch {
fragment.arguments =
bundleOf(
QuestionnaireFragment.EXTRA_QUESTIONNAIRE_JSON_STRING to viewModel.getQuestionnaireJson()
)
childFragmentManager.commit { add(R.id.container, fragment, QUESTIONNAIRE_FRAGMENT_TAG) }
}
}

companion object {
const val QUESTIONNAIRE_FRAGMENT_TAG = "questionnaire-fragment-tag"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.fhir.datacapture.gallery

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.withContext

class GalleryQuestionnaireViewModel(application: Application, private val state: SavedStateHandle) :
AndroidViewModel(application) {
private val backgroundContext = viewModelScope.coroutineContext
private var questionnaireJson: String? = null

suspend fun getQuestionnaireJson(): String {
return withContext(backgroundContext) {
if (questionnaireJson == null) {
questionnaireJson =
readFileFromAssets(state[QuestionnaireContainerFragment.QUESTIONNAIRE_FILE_PATH_KEY]!!)
}
questionnaireJson!!
}
}

private suspend fun readFileFromAssets(filename: String) =
withContext(backgroundContext) {
getApplication<Application>().assets.open(filename).bufferedReader().use { it.readText() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import androidx.recyclerview.widget.RecyclerView
class LayoutsFragment : Fragment(R.layout.fragment_layouts) {
private val viewModel: ComponentsLayoutsViewModel by viewModels()

override fun onResume() {
super.onResume()
(requireActivity() as MainActivity).setNavigationUp(false)
(requireActivity() as MainActivity).showBottomNavigationView(View.VISIBLE)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setUpLayoutsRecyclerView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package com.google.android.fhir.datacapture.gallery

import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import com.google.android.material.bottomnavigation.BottomNavigationView
Expand All @@ -29,6 +31,22 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
setUpBottomNavigationView()
}

fun showBottomNavigationView(value: Int) {
findViewById<BottomNavigationView>(R.id.bottom_navigation_view).visibility = value
}

fun setNavigationUp(value: Boolean) {
supportActionBar?.apply { setDisplayHomeAsUpEnabled(value) }
}

fun setActionBar(title: String, gravity: Int) {
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
val titleTextView = toolbar.findViewById<TextView>(R.id.toolbarTitle)
titleTextView.text = title
titleTextView.gravity = gravity
}

private fun setUpBottomNavigationView() {
val navController = Navigation.findNavController(this, R.id.nav_host_fragment)
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation_view)
Expand Down
5 changes: 5 additions & 0 deletions datacapturegallery/src/main/res/color/checked_text_color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http:https://schemas.android.com/apk/res/android">
<item android:color="@color/blue_600" android:state_checked="true" />
<item android:color="?attr/colorPrimary" />
</selector>
Loading