Skip to main content
Version: Next

Android

The library provides a set of base classes, extensions and data structures to make integration to Huma platform easy.

Getting Started

How to use Huma Modules

Huma Modules can be used without any additional work. It contains the default module package. Check Readme to get the list.

To add a new module to Huma Modules check Huma Module Kit example on how to do that.

Huma Modules adds to Huma Module Kit an additional level of integration into Huma Platform. It adds a Modules Processor to process configuration to generate module instance from it.

To start working with Huma Models you need to create Module and Processor for it.

class YourProcessor(
private val context: Context,
private val scheduleConverter: ScheduleConverter,
private val aboutConverter: AboutConverter,
private val deviceName: String
) : ImportModuleProcessor(
moduleId = YourModule.MODULE_ID,
primitive = YourPrimitiveCreate::class.java,
primitiveResultToEntityMappers = YourRetrievePrimitiveResponseMapper().asList()
) {
override fun processConfig(moduleConfig: List<ModuleConfig>): List<Pair<ModuleConfigId, Module>> {
return moduleConfig.filter { it.moduleId == YourModule.MODULE_ID }
.mapNotNull { config ->
val moduleId = config.id ?: return@mapNotNull null
val scheduleData = config.schedule?.let { scheduleConverter.invoke(it) }
val aboutData = aboutConverter.invoke(config)
registerModuleConfigId(moduleId)
moduleId to YourModule(
context = context,
order = config.order ?: Int.MAX_VALUE,
version = config.version,
deviceName = deviceName,
deploymentId = DeploymentStorage.deploymentId,
moduleConfigId = moduleId,
scheduleData = scheduleData,
aboutData = aboutData,
learnArticleIds = config.learnArticleIds ?: emptyList()
)
}
}
}

After you created the processor you need to register it in HumaModuleManager:

HumaModuleManager.registerImportProcessor(processor: YourProcessor)

When the processor is registered you can call refreshModules() to fetch the config and fill your module with data and refreshData() to get data for each module.

HumaModuleManager.refreshModules() //call to refresh modules

HumaModuleManager.refreshData(vararg moduleId: String?) //call to refresh modules data

moduleId - is optional, if you set it then only this module gets data refresh, if not, all modules will be refreshed.

How to render modules list

Huma Modules provides ModuleListView that can show module cards and refresh data.

<com.huma.sdk.module.view.ModuleListView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:refreshOnCreate="everyTime"
app:swipeToRefresh="true"
app:refreshOnlyDataOnSwipe="true" />
AttributeValue
app:refreshOnCreateHow modules and data is refreshed on create
app:swipeToRefreshIs swipe to refresh enabled
app:refreshOnlyDataOnSwipeHow swipe to refresh behaves
moduleListView.refreshOnlyDataOnSwipe = true
moduleListView.swipeToRefresh = true
moduleListView.refresh() //refresh modules and data
moduleListView.refreshData() //refresh only data

Useful additions

Huma Modules provides several helper classes to reduce boilerplate code in some core cases.

Converters

AboutConverter

AboutConverter converts ModuleConfig object to AboutData that's used in AboutSection

val aboutData = AboutConverter(context).invoke(moduleConfig)

ScheduleConverter

ScheduleConverter converts ModuleSchedule object to ScheduleData that's used in ScheduleSection

val scheduleData = ScheduleConverter().invoke(moduleConfig.schedule)

Extensions

ModuleInputField

dateField() - date field timeField() - time field

SingleDefaultUnit

litersUnit() - liter units percentUnit() - percent units litersPerMinUnit() - liter per minute (L/min) units pressureUnit() - pressure (mmHg) units emptyUnit() - empty units rpmUnit() - rpm units bpmUnit() - bpm units

Form

Any.asForm() - converts any object to form. Used for modules where configBody is form

PostInputDelegateImpl

Alternative to defaultPostDelegateWithCustomRefresher where refresher using HumaModuleManager.refreshData(moduleId)

ModuleWithInput.defaultPostDelegateWithDefaultRefresher(
converter: Converter<List<Value<*>>, List<T>>,
moduleId: String,
moduleConfigId: String,
)

ModuleFilledStatusDelegate

Checks whether is module has data or not.

val filledStatusDelegate = BaseModule.filledStatusDispatcher()

filledStatusDelegate.isFilled() //true if filled

ModuleCardView

EntriesCount - creates LiveData<CardData> that returns size of entries.

override val moduleCardConfig: CardConfig
get() = CardConfig(
title = moduleName,
addButtonText = inputButtonText,
cardData = entriesCount(scheduleData)
)

LatestValue - creates LiveData<CardData> that returns last entry.

override val moduleCardConfig: CardConfig
get() = CardConfig(
title = moduleName,
addButtonText = inputButtonText,
cardData = lastEntry(scheduleData) { result, _ ->
Value.Simple(
(result as RetrievePrimitiveResponse).value
)
},
)

ChartSection

LineChartDataProvider - chart data provider for drawing line chart

ChartSection(
lineChartData(PrimitiveResultToLineChartData()),
)

BarChartDataProvider - chart data provider for drawing bar chart

ChartSection(
barChartData(PrimitiveResultToLineChartData()),
)

QuestionnaireModuleInputDelegate

Some modules are required to fill questionnaire instad of raw values. To do that use questionnaireModuleInputDelegate instead of defaultModuleInputDelegate.

private val inputDelegate by questionnaireModuleInputDelegate(form: Form)

Output of this input delegate is QuestionnaireValue(questionnaireViewData: QuestionnaireViewData)