-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1093bf1
commit 9be355b
Showing
38 changed files
with
1,171 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
# openmrs-distro-keycloak | ||
reference openmrs distro datafilter, oauth2 module using Keycloak with default users configured: | ||
- The users list is given by `keycloak/users.csv` | ||
- The default password is setup in a env variables, see `env.default` | ||
# Why | ||
The goal of this distribution is to enable the effortless initiation of an OpenMRS Distro with Single Sign-On (SSO) and DataFilter activated through a single command line (utilizing Docker). | ||
|
||
# How to start | ||
1. Copy the file `.env.default` to `.env` | ||
2. Edit .env and provide default username, password | ||
3. Start Using published images: | ||
`docker compose -f docker-compose.yml up -d --build` | ||
4. to build images locally and start: `docker compose up -d --build` | ||
# ICRC Customization | ||
|
||
This distribution is a customized version of https://github.com/openmrs/openmrs-distro-referenceapplication to: | ||
- integrate Oauth2 Module: [openmrs-module-oauth2login](https://github.com/openmrs/openmrs-module-oauth2login) | ||
- integrate DataFilter Module: [openmrs-module-datafilter](https://github.com/openmrs/openmrs-module-datafilter) | ||
- Generate default users and populate the database with patient data. | ||
|
||
# Login to ghrc | ||
# Components | ||
|
||
- [database](./database/README.md) is used to create a MariaDB Docker Image with an "initial" OpenMRS Dump. | ||
- [frontend](./frontend/README.md) activate oauth2 login in the frontend | ||
- [backend](./backend/README.md) create an OpenMRS distribution incorporating OAuth2, DataFilter modules, and a custom module for generating default users and patients. | ||
- [keycloak](./keycloak/README.md) start and configure automatically Keycloak | ||
|
||
```bash | ||
export CR_PAT=YOUR_TOKEN | ||
echo $CR_PAT | docker login ghcr.io -u <yourAccount> --password-stdin | ||
``` | ||
# How to build and start | ||
|
||
1. Copy the file `.env.default` to `.env` | ||
2. Edit .env and provide default username, password | ||
3. Start dockers with: `docker compose up -d --build` | ||
4. Go to http://localhost | ||
5. You should be redirected to Keycloak. | ||
6. Sign in using a user selected from the provided list [keycloak/users.csv](./keycloak/users.csv) and the password defined in `.env` | ||
|
||
See https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry | ||
To login you can use the username (before @). For instance to log as `[email protected]`, you can use `doctor.many` in sso login page. | ||
|
||
# Useful command | ||
# How to use images: | ||
A default docker-compose file is available here: | ||
https://github.com/icrc/openmrs-android-fhir/docker-compose.yml | ||
|
||
- `docker compose down -v` to restart all from scratch | ||
- `docker compose up -d` to start quickly | ||
A `.env` is always required to define passwords and sso admin username. | ||
|
||
# Other Resources | ||
|
||
- [database](./database/README.md) is used to ceate a MariaDB Docker Image with an OpenMRS Dump. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,9 @@ | ||
_Packages a distribution of configs, metadata and binaries to run OpenMRS_ | ||
ICRC Customization of https://github.com/openmrs/openmrs-distro-referenceapplication to: | ||
- integrate Oauth2 Module: [openmrs-module-oauth2login](https://github.com/openmrs/openmrs-module-oauth2login) | ||
- integrate DataFilter Module: [openmrs-module-datafilter](https://github.com/openmrs/openmrs-module-datafilter) | ||
- activate Location Based identifier ( see related configuration in `openmrs_custom_config` folder) | ||
- 4 Locations are activated: `Location 1`,`Location 2`,`Location 3`,`Location 4`. See [openmrs_custom_config/locations/locations-core_demo_with_code.csv](./openmrs_custom_config/locations/locations-core_demo_with_code.csv) | ||
- Create Default user via the intern module `module-create-users` (to be improved): see [module-create-users/README.md](./module-create-users/README.md) | ||
|
||
----- | ||
|
||
```bash | ||
mvn clean package | ||
``` | ||
|
||
Output: | ||
|
||
`target/openmrs-distro-package/openmrs-distro-package-$version.zip` | ||
|
||
Package contents: | ||
|
||
|File or Directory|Description| | ||
|-----------------|-----------| | ||
|`openmrs_config` |The OpenMRS configuration, particularly including any files to be processed by the [Initializer module](https://github.com/mekomsolutions/openmrs-module-initializer). An example configuration can be found [here](https://github.com/mekomsolutions/openmrs-config-haiti). | ||
|`openmrs_core` |The main OpenMRS WAR file.| | ||
|`openmrs_module` |The modules (OMODs) to be run in this OpenMRS instance.| | ||
|`spa` |The compiled SPA for the 3.x frontend.| | ||
|`spa_config` |Any configuration files used by the SPA.| | ||
|`openmrs-distro.properties`|The distro.properties used to generate this package.| | ||
|
||
---- | ||
|
||
### Specifying dependencies | ||
#### OpenMRS modules | ||
`omod`s are specified as Maven `<dependency>` in the [pom.xml](pom.xml) file. | ||
|
||
#### OpenMRS Configuration (Initializer) | ||
OpenMRS config can be set in [openmrs-config/configuration/](openmrs-config/configuration/) folder | ||
|
||
#### Micro Frontends | ||
ESMs are set in the [spa-config.json](spa-config.json) file. | ||
|
||
#### Micro Frontends configuration | ||
MF Config can be set in [spa-config/configuration/](spa-config/configuration/) folder | ||
|
||
---- | ||
O |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
|
||
# Users configured accordingly to Datafilter filter (location based filter) | ||
|
||
Will run liquibase scripts at startup to create users attached to one or several locations. | ||
The liquibase scripts are in [api/src/main/resources](./api/src/main/resources) | ||
|
||
- The users `l1` will be assigned to the location `l1`, etc | ||
- The users `many` will be assigned to the locations `l1`, `l2` and `l3` | ||
|
||
These users will be also created in keycloak. See [../../keycloak/README.md](../../keycloak/README.md). So the users | ||
created in liquibase should be also present in [../../keycloak/users.csv](../../keycloak/users.csv). | ||
|
||
# TODO | ||
|
||
improve/configure oauth2 module to automatically create users based on their role/location defined in keycloak Oauth2 | ||
module can auto-create users in OpenMRS if not present. | ||
|
||
|
||
# Patients / Visits Created. | ||
|
||
this module is based on [openmrs-module-referencedemodata](https://github.com/openmrs/openmrs-module-referencedemodata) to create patients, visits... | ||
|
||
Modifications are done to: | ||
- create patients on all locations and not only one location | ||
- use the patient location to create visits,... | ||
- try to avoid hardcoded configuration ( providers,...) | ||
- use thread to create visits in parallel ( otherwise startup is too long) | ||
|
||
## TODO | ||
to be improved and pushed back in `referencedemodata` module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...rs/api/src/main/java/org/openmrs/module/createusers/DemoPatientGeneratorWithLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* <p> | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.createusers; | ||
|
||
import org.openmrs.Location; | ||
import org.openmrs.Patient; | ||
import org.openmrs.PatientIdentifier; | ||
import org.openmrs.PatientIdentifierType; | ||
import org.openmrs.api.APIException; | ||
import org.openmrs.api.PatientService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.idgen.service.IdentifierSourceService; | ||
import org.openmrs.module.referencedemodata.patient.DemoPersonGenerator; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import static org.openmrs.module.referencedemodata.ReferenceDemoDataConstants.OPENMRS_ID_NAME; | ||
|
||
public class DemoPatientGeneratorWithLocation { | ||
|
||
Logger log = LoggerFactory.getLogger(DemoPatientGeneratorWithLocation.class); | ||
|
||
private final IdentifierSourceService iss; | ||
|
||
public DemoPatientGeneratorWithLocation(IdentifierSourceService iss) { | ||
this.iss = iss; | ||
} | ||
|
||
/** | ||
* Main entry point to create patients. Creates the specified number of patients and returns a | ||
* list of database IDs for those patients. | ||
* | ||
* @param patientCount number of patients to create | ||
* @return a list of the primary keys for each patient created | ||
*/ | ||
public List<Integer> createDemoPatients(int patientCount) { | ||
List<Integer> patientIds = new ArrayList<>(patientCount); | ||
|
||
PatientService ps = Context.getPatientService(); | ||
List<Location> locations = Context.getLocationService().getRootLocations(false); | ||
int nbPatientsPerLocation = (int) Math.ceil((double) patientCount / locations.size()); | ||
PatientIdentifierType patientIdentifierType = ps.getPatientIdentifierTypeByName(OPENMRS_ID_NAME); | ||
|
||
if (patientIdentifierType == null) { | ||
throw new APIException("Could not find identifier type " + OPENMRS_ID_NAME); | ||
} | ||
for (Location location : locations) { | ||
try { | ||
Context.getUserContext().setLocation(location); | ||
for (int i = 0; i < nbPatientsPerLocation; i++) { | ||
|
||
Patient patient = createDemoPatient(ps, patientIdentifierType, location); | ||
log.info("created demo patient: {} {} {} age: {}", | ||
new Object[]{patient.getPatientIdentifier(), patient.getGivenName(), patient.getFamilyName(), | ||
patient.getAge()}); | ||
patientIds.add(patient.getId()); | ||
} | ||
} catch (Exception e) { | ||
log.error("Cant create patient for {}", location.getName(), e); | ||
} | ||
} | ||
|
||
|
||
return patientIds; | ||
} | ||
|
||
private Patient createDemoPatient(PatientService ps, PatientIdentifierType patientIdentifierType, Location location) { | ||
Patient patient = new Patient(); | ||
|
||
DemoPersonGenerator.populatePerson(patient); | ||
|
||
PatientIdentifier patientIdentifier = new PatientIdentifier(); | ||
patientIdentifier.setIdentifier(iss.generateIdentifier(patientIdentifierType, "DemoData")); | ||
patientIdentifier.setIdentifierType(patientIdentifierType); | ||
patientIdentifier.setDateCreated(new Date()); | ||
patientIdentifier.setLocation(location); | ||
patient.addIdentifier(patientIdentifier); | ||
|
||
patient = ps.savePatient(patient); | ||
return patient; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...s/api/src/main/java/org/openmrs/module/createusers/DemoProviderGeneratorWithLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.openmrs.module.createusers; | ||
|
||
import org.openmrs.Provider; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.referencedemodata.Randomizer; | ||
import org.openmrs.module.referencedemodata.providers.DemoProviderGenerator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Generate data with other provider to user provider linked to a location. | ||
*/ | ||
public class DemoProviderGeneratorWithLocation extends DemoProviderGenerator { | ||
|
||
private List<Provider> clinicians = null; | ||
|
||
private List<Provider> labTechs = null; | ||
|
||
@Override | ||
public Provider getRandomClinician() { | ||
if (clinicians == null) { | ||
clinicians = new ArrayList<>(Context.getProviderService().getAllProviders(false)); | ||
} | ||
return Randomizer.randomListEntry(clinicians); | ||
} | ||
|
||
@Override | ||
public Provider getRandomLabTech() { | ||
if (labTechs == null) { | ||
labTechs = new ArrayList<>(Context.getProviderService().getAllProviders(false)); | ||
} | ||
return Randomizer.randomListEntry(labTechs); | ||
} | ||
} |
Oops, something went wrong.