Android
The library provides a set of base classes, extensions and data structures to make integration to Huma platform easy.
Getting Started
- Example
- Installing
- Readme
- Changelog
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" />
Attribute | Value |
---|---|
app:refreshOnCreate | How modules and data is refreshed on create |
app:swipeToRefresh | Is swipe to refresh enabled |
app:refreshOnlyDataOnSwipe | How 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)
implementation("com.huma.sdk:module:latest-version")
HumaModuleManager
require dependencies to be initialized before it in theApplication
class
HumaUtilsManager.init(/*..*/)
HumaUiManager.init(/*..*/)
HumaSharedManager.init(/*..*/)
HumaCachingManager.init(/*..*/)
HumaModuleKitManager.init(/*..*/)
HumaObjectStorageManager.init(/*..*/)
HumaPermissionsManager.init(/*..*/)
HumaPreferredUnitsManager.init()
HumaGoogleFitManager.init()
val questionnaireManager = HumaQuestionnaireManager.init(/*..*/)
HumaModuleManager.init(questionnaireManager)
Processor - the class that is dedicated to processing ModuleConfig
and outputting instance of Module
Supported modules:
- BloodGlucose
- BloodPressure
- BMI
- BodyMeasurement
- Breathlessness
- Covid19DailyCheckIn
- Covid19RiskScore
- CVDRiskScore
- DailyCheckIn
- DiabetesDistressScore
- FJSHip
- FJSKnee
- GeneralAnxietyDisorder
- HighFrequencyHeartRate
- HighFrequencyStep
- HeartRate
- Journal
- KCCQ
- KOOS
- Medications
- MedicationTracker
- NORFOLK
- OxygenSaturation
- PeakFlow
- Photo
- PulseOximetry
- Questionnaire
- RespiratoryRate
- RestingHeartRate
- RestingBreathingRate
- SF36
- Symptom
- Step
- Temperature
- Weight
Documentation
API Reference
[0.1.29]
- #195 Weight module added
- #118 Created Body Measurement module
- #115 Added Temperature module
- #114 Added Symptom module. Added documentation for Symptom module
- #110 Added Resting Heart Rate module
- #109 Created Respiration Rate module
- #107 Added Pulse Oximetry module
- #106 Added Peak Flow module
- #105 Created Oxygen Saturation module
- #104 Medications module; questionnaire module refactoring; improvements
- #103 Medication tracker module + refactoring
- #102 Added Diabetes Distress Score
- #101 Added Daily Check In module. Fixed titles of History section view. Inactive “No entries added yet” button
- #100 Added Breathlessness module
- #96 Added Daily Check In module. Fixed titles of History section view. Inactive “No entries added yet” button
- #94 Added BMI module
- #92 Hsdk 886
- #91 Hsdk 886
- #90 BloodGlucose module, Chart Details Screen
- #86 Journal Unit Tests
- #84 Created Photo module
- #83 hsdk 684
- #81 refactor interface hierarchy
- #79 hsdk 684
- #78 hsdk 684
- #73 Core and Journal
- #72 Added Module List View
- #71 Added CVDRiskScore module support
- #70 Added KCCQ module support
- #69 Added KOOS module support
- #68 Added Norfolk module support
- #67 Added SF36 module support
- #66 Added FJSKnee support
- #64 Added FJSHip module support
- #54 Added Resting Breathing Rate module
- #51 Added Questionnaire module
- #50 Added High Frequency Heart Rate
- #48 Added General Anxiety Disorder module
- #47 Added Covid 19 Risk Score module support
- #44 Added Covid19DailyCheckIn module support
- #43 Added CalculatedQuestionnaire support