|
| 1 | +# Bahmni Clinical Frontend Setup Guide |
| 2 | + |
| 3 | +This guide provides comprehensive instructions for setting up the Bahmni Clinical Frontend application for both development and production environments. |
| 4 | + |
| 5 | +## Introduction |
| 6 | + |
| 7 | +Bahmni Clinical Frontend is a React TypeScript application for the Bahmni Clinical module, built with Webpack and Carbon Design System. It includes Progressive Web App (PWA) support for offline capabilities. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +Before you begin, ensure you have the following installed: |
| 12 | + |
| 13 | +- **Node.js** (v22.x or later recommended) |
| 14 | + - [Download Node.js](https://nodejs.org/en/download/) |
| 15 | + - Verify installation: `node --version` |
| 16 | + |
| 17 | +- **Yarn** (v1.22.x or later recommended) |
| 18 | + - [Installation instructions](https://yarnpkg.com/getting-started/install) |
| 19 | + - Verify installation: `yarn --version` |
| 20 | + |
| 21 | +- **Docker** and **Docker Compose** |
| 22 | + - [Install Docker](https://docs.docker.com/get-docker/) |
| 23 | + - [Install Docker Compose](https://docs.docker.com/compose/install/) |
| 24 | + - Verify installation: `docker --version` and `docker compose --version` |
| 25 | + |
| 26 | +- **Git** |
| 27 | + - [Install Git](https://git-scm.com/downloads) |
| 28 | + - Verify installation: `git --version` |
| 29 | + |
| 30 | +### GitHub Personal Access Token (PAT) |
| 31 | + |
| 32 | +You'll need a GitHub Personal Access Token to access the GitHub Container Registry: |
| 33 | + |
| 34 | +1. Go to your GitHub account settings: [https://github.com/settings/tokens](https://github.com/settings/tokens) |
| 35 | +2. Click "Generate new token" (classic) |
| 36 | +3. Give your token a descriptive name |
| 37 | +4. Select the following scopes: |
| 38 | + - `repo` (Full control of private repositories) |
| 39 | + - `read:packages` (Download packages from GitHub Package Registry) |
| 40 | +5. Click "Generate token" |
| 41 | +6. **Important**: Copy and save your token immediately as it won't be shown again |
| 42 | + |
| 43 | +## Environment Setup |
| 44 | + |
| 45 | +### 1. Clone Required Repositories |
| 46 | + |
| 47 | +```bash |
| 48 | +# Clone the Bahmni Docker repository |
| 49 | +git clone https://github.com/bahnew/bahmni-docker.git |
| 50 | +cd bahmni-docker |
| 51 | + |
| 52 | +# Clone the Bahmni Clinical Frontend repository (in a separate terminal) |
| 53 | +git clone https://github.com/bahnew/bahmni-clinical-frontend.git |
| 54 | +``` |
| 55 | + |
| 56 | +### 2. Authenticate with GitHub Container Registry |
| 57 | + |
| 58 | +```bash |
| 59 | +export GITHUB_PAT=<your-token-here> |
| 60 | +# Login to GitHub Container Registry using your Personal Access Token |
| 61 | +echo $GITHUB_PAT | docker login ghcr.io -u YOUR_GITHUB_USERNAME --password-stdin |
| 62 | +``` |
| 63 | + |
| 64 | +Replace `GITHUB_PAT` with your GitHub Personal Access Token and `YOUR_GITHUB_USERNAME` with your GitHub username. |
| 65 | + |
| 66 | +### 3. Bring Up EMR Components |
| 67 | + |
| 68 | +After setting up the repositories and authenticating with GitHub Container Registry, you need to start the EMR components: |
| 69 | + |
| 70 | +```bash |
| 71 | +# Navigate to the bahmni-docker directory |
| 72 | +cd bahmni-docker |
| 73 | + |
| 74 | +# Start all EMR components with the latest images |
| 75 | +docker compose --env-file .env.dev up -d |
| 76 | +``` |
| 77 | + |
| 78 | +This command will pull the latest images for all EMR components and start them in detached mode. You can verify that the containers are running with: |
| 79 | + |
| 80 | +```bash |
| 81 | +docker ps |
| 82 | +``` |
| 83 | + |
| 84 | +Wait for all services to start up completely before proceeding with the development setup. |
| 85 | + |
| 86 | +## Development Setup Options |
| 87 | + |
| 88 | +There are two methods for local development. Choose the one that best fits your workflow: |
| 89 | + |
| 90 | +### Method 1: Mounting the Built Artifact (Docker-based) |
| 91 | + |
| 92 | +This method allows you to build the application locally and mount it into the Docker container: |
| 93 | + |
| 94 | +1. **Update Environment Variables**: |
| 95 | + |
| 96 | + In the `bahmni-docker` directory, edit the `.env.dev` file to point to your local bahmni-clinical-frontend repository: |
| 97 | + |
| 98 | + ```bash |
| 99 | + # Open the .env.dev file |
| 100 | + nano .env.dev |
| 101 | + |
| 102 | + # Update the BAHMNI_CLINICAL_FRONTEND_PATH variable |
| 103 | + BAHMNI_CLINICAL_FRONTEND_PATH=/path/to/your/bahmni-clinical-frontend |
| 104 | + ``` |
| 105 | + |
| 106 | +2. **Uncomment Volumes in Docker Compose**: |
| 107 | + |
| 108 | + Edit the Docker Compose file to uncomment the volumes section for the clinical-frontend service. |
| 109 | + |
| 110 | +3. **Build the Application**: |
| 111 | + |
| 112 | + In your bahmni-clinical-frontend directory: |
| 113 | + |
| 114 | + ```bash |
| 115 | + # Install dependencies |
| 116 | + yarn |
| 117 | + |
| 118 | + # Build the application |
| 119 | + yarn build |
| 120 | + ``` |
| 121 | + |
| 122 | +4. **Start the Docker Services**: |
| 123 | + |
| 124 | + In the bahmni-docker directory: |
| 125 | + |
| 126 | + ```bash |
| 127 | + # Start all EMR components with the latest images |
| 128 | + docker compose --env-file .env.dev up -d |
| 129 | + |
| 130 | + # Or, to update only the clinical-frontend service |
| 131 | + docker compose --env-file .env.dev up -d clinical-frontend |
| 132 | + ``` |
| 133 | + |
| 134 | +5. **Access the Application**: |
| 135 | + |
| 136 | + Open your browser and navigate to the Bahmni EMR URL (typically http://localhost:8080/bahmni-new/). |
| 137 | + |
| 138 | +6. **Development Workflow**: |
| 139 | + |
| 140 | + With this setup, every time you rebuild the application, the changes will be automatically available in the browser without restarting the Docker container. |
| 141 | + |
| 142 | +### Method 2: Using Hot Reload (Local Development Server) |
| 143 | + |
| 144 | +This method provides a faster development experience with hot reloading: |
| 145 | + |
| 146 | +1. **Start the Development Server**: |
| 147 | + |
| 148 | + In your bahmni-clinical-frontend directory: |
| 149 | + |
| 150 | + ```bash |
| 151 | + # Install dependencies (if not already done) |
| 152 | + yarn |
| 153 | + |
| 154 | + # Start the development server |
| 155 | + yarn start |
| 156 | + ``` |
| 157 | + |
| 158 | + This will start the development server and automatically open your browser at [http://localhost:3000](http://localhost:3000). |
| 159 | + |
| 160 | +2. **Set Up Authentication**: |
| 161 | + |
| 162 | + To authorize API requests to the backend: |
| 163 | + |
| 164 | + a. Login to Bahmni EMR in another browser tab (typically http://localhost:8080/bahmni/home) |
| 165 | + |
| 166 | + b. After successful login, open browser developer tools (F12 or right-click > Inspect) |
| 167 | + |
| 168 | + c. Go to the Application tab > Cookies |
| 169 | + |
| 170 | + d. Find and copy the value of the `JSESSIONID` cookie |
| 171 | + |
| 172 | + e. In your localhost:3000 tab, use developer tools to create a new cookie: |
| 173 | + - Name: `JSESSIONID` |
| 174 | + - Value: (paste the copied value) |
| 175 | + - Domain: localhost |
| 176 | + |
| 177 | +3. **Development Workflow**: |
| 178 | + |
| 179 | + With this setup, any changes you make to the source code will be immediately reflected in the browser. |
| 180 | + |
| 181 | +## Additional Commands |
| 182 | + |
| 183 | +### Building for Production |
| 184 | + |
| 185 | +```bash |
| 186 | +# Build the application for production |
| 187 | +yarn build |
| 188 | +``` |
| 189 | + |
| 190 | +The build artifacts will be stored in the `dist/` directory. |
| 191 | + |
| 192 | +### Linting and Formatting |
| 193 | + |
| 194 | +```bash |
| 195 | +# Run ESLint to check for code quality issues |
| 196 | +yarn lint |
| 197 | + |
| 198 | +# Fix ESLint issues automatically |
| 199 | +yarn lint:fix |
| 200 | + |
| 201 | +# Check formatting with Prettier |
| 202 | +yarn prettier:check |
| 203 | + |
| 204 | +# Fix formatting issues with Prettier |
| 205 | +yarn prettier:fix |
| 206 | +``` |
| 207 | + |
| 208 | +### Testing |
| 209 | + |
| 210 | +```bash |
| 211 | +# Run tests |
| 212 | +yarn test |
| 213 | + |
| 214 | +# Run tests in watch mode |
| 215 | +yarn test:watch |
| 216 | +``` |
| 217 | + |
| 218 | +## Troubleshooting |
| 219 | + |
| 220 | +### Common Issues |
| 221 | + |
| 222 | +1. **Authentication Failures with GitHub Container Registry**: |
| 223 | + - Ensure your Personal Access Token has the correct scopes |
| 224 | + - Check that your token hasn't expired |
| 225 | + - Verify you're using the correct username |
| 226 | + |
| 227 | +2. **Docker Compose Errors**: |
| 228 | + - Ensure all required environment variables are set in `.env.dev` |
| 229 | + - Check for port conflicts with other running services |
| 230 | + |
| 231 | +3. **API Authorization Issues**: |
| 232 | + - Verify the JSESSIONID cookie is correctly set |
| 233 | + - Ensure the Bahmni backend services are running |
| 234 | + |
| 235 | +### Getting Help |
| 236 | + |
| 237 | +If you encounter issues not covered in this guide: |
| 238 | + |
| 239 | +- Check the [GitHub repository issues](https://github.com/bahnew/bahmni-clinical-frontend/issues) |
| 240 | +- Consult the [Bahmni community forums](https://talk.openmrs.org/c/software/bahmni/35) |
| 241 | + |
| 242 | +## Additional Resources |
| 243 | + |
| 244 | +- [React Documentation](https://react.dev/) |
| 245 | +- [TypeScript Documentation](https://www.typescriptlang.org/docs/) |
| 246 | +- [Carbon Design System](https://carbondesignsystem.com/) |
| 247 | +- [Webpack Documentation](https://webpack.js.org/concepts/) |
| 248 | +- [Docker Documentation](https://docs.docker.com/) |
| 249 | +- [Bahmni Documentation](https://bahmni.atlassian.net/wiki/spaces/BAH/overview) |
0 commit comments