open-index/open-npm huggingface dataset:
npm package: @hisp-amr/api
Description: DHIS2 base API functions
Latest version: 0.0.8

# api

## Installation

```bash
yarn add @hisp-amr/api
# or
npm i @hisp-amr/api
```

## Environment variables
`REACT_APP_DHIS2_BASE_URL` and `REACT_APP_DHIS2_API_VERSION` needs to be set.

### Example
```dotenv
# [root_dir]/.env
REACT_APP_DHIS2_API_VERSION=30
```

```dotenv
# [root_dir]/.env.development
REACT_APP_DHIS2_BASE_URL=https://amrtest.icmr.org.in/amr
```

```dotenv
# [root_dir]/.env.production
REACT_APP_DHIS2_BASE_URL=../../..
```

## Usage
Coming soon...
npm package: @hisp-amr/assign-value-rule-engine
Description: DHIS2 program rule engine for assign data value actions
Latest version: 0.0.4

# assign-value-rule-engine

## Installation

```bash
yarn add @hisp-amr/assign-value-rule-engine
# or
npm i @hisp-amr/assign-value-rule-engine
```

## Usage
You need to pass along some metadata. In the example app the bellow query was used with [@dhis2/app-runtime](https://runtime.dhis2.nu/#/hooks/useDataQuery). See [AppContent.js](../../examples/whonet-program/src/components/AppContent.js)
```js
const query = {
    metadata: {
        resource: 'metadata',
        params: {
            optionGroups: 'true', // not strictly needed, but was used to find the correct program based on organism
            programs: 'true',
            programRules: 'true',
            programRuleVariables: 'true',
            fields: [
                'id',
                'options[code,displayName]',
                'dataElement',
                'name',
                'condition',
                'programRuleActions[programRuleActionType,dataElement,data]',
                'programStages[id,programStageDataElements]',
                'program',
            ],
        },
    },
}
```

See [RuleRunner.js](../../examples/whonet-program/src/components/RuleRunner/RuleRunner.js)

```js
import { runAssignValueRules } from '@hisp-amr/assign-value-rule-engine'

const newDataValues = runAssignValueRules(
    event.dataValues,
    programStage.programStageDataElements, // programStage of the event
    {
        programRules: metadata.programRules.filter(
            ({ program }) => program.id === programId
        ),
        programRuleVariables: metadata.programRuleVariables,
    }
)
```
npm package: @hisp-amr/org-unit-tree
Description: DHIS2 single select organisation unit tree
Latest version: 0.0.17

# org-unit-tree

## Installation

```bash
yarn add @hisp-amr/org-unit-tree
# or
npm i @hisp-amr/org-unit-tree
```

## Usage
`REACT_APP_DHIS2_BASE_URL` needs to be set.

```bash
# [root_dir]/.env.development
REACT_APP_DHIS2_BASE_URL=https://amrtest.icmr.org.in/amr
```

```bash
# [root_dir]/.env.production
REACT_APP_DHIS2_BASE_URL=../../..
```

```jsx
import React from 'react'
import { OrgUnitTree } from '@hisp-amr/org-unit-tree'

const onError = error => console.error(error)
const onSelect = selected => console.log(selected)

const App = () => (
    <>
        {/* Other components */}
        <OrgUnitTree
            onSelect={onSelect}
            onError={onError}
        />
    </>
)
```