Skip to content

Commit

Permalink
remove attribute for appointments.
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-fdeniger committed May 3, 2024
1 parent 1093bf1 commit 9be355b
Show file tree
Hide file tree
Showing 38 changed files with 1,171 additions and 174 deletions.
47 changes: 26 additions & 21 deletions README.md
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.



44 changes: 7 additions & 37 deletions backend/README.md
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
10 changes: 5 additions & 5 deletions backend/distro.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ omod.metadatamapping=${metadatamapping.version}
omod.metadatasharing=${metadatasharing.version}
omod.openconceptlab=${openconceptlab.version}
omod.owa=${owa.version}
omod.referencedemodata=${referencedemodata.version}
#omod.referencedemodata=${referencedemodata.version}
omod.attachments=${attachments.version}
omod.queue=${queue.version}
#omod.appointments=${appointments.version}
#omod.appointments.groupId=org.bahmni.module
#omod.teleconsultation=${teleconsultation.version}
#omod.teleconsultation.groupId=org.bahmni.module
omod.appointments=${appointments.version}
omod.appointments.groupId=org.bahmni.module
omod.teleconsultation=${teleconsultation.version}
omod.teleconsultation.groupId=org.bahmni.module
omod.cohort=${cohort.version}
omod.reporting=${reporting.version}
omod.reportingrest=${reportingrest.version}
Expand Down
3 changes: 3 additions & 0 deletions backend/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Logger name="org.openmrs" level="WARN" />
<Logger name="org.openmrs.module.initializer" level="INFO" />
<Logger name="org.openmrs.module.referencedemodata" level="INFO" />
<Logger name="org.openmrs.module.createusers" level="INFO" />
<Logger name="org.openmrs.module.initializer.api.OrderedFile" level="ERROR" />
<Logger name="liquibase" level="INFO" />
<!--
Expand All @@ -52,6 +53,8 @@
<Logger name="org.springframework.context.support.ResourceBundleMessageSource" level="ERROR" />
<Logger name="org.springframework.beans.factory.support.DefaultListableBeanFactory" level="ERROR" />
<Logger name="org.hibernate.orm.deprecation" additivity="false" level="ERROR"/>
<Logger name="org.hibernate.SQL" additivity="false" level="DEBUG"/>
<Logger name="org.hibernate.type.descriptor.sql.BasicBinder" additivity="false" level="TRACE"/>
<Root level="WARN">
<AppenderRef ref="CONSOLE" />
</Root>
Expand Down
31 changes: 31 additions & 0 deletions backend/module-create-users/README.md
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.
9 changes: 2 additions & 7 deletions backend/module-create-users/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
<version>1.0.0-SNAPSHOT</version>
</parent>


<artifactId>create-users-api</artifactId>
<packaging>jar</packaging>
<name>create-users API</name>
<description>API project for create-users</description>
<dependencies>
<dependency>
<groupId>org.openmrs.api</groupId>
<artifactId>openmrs-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
*/
package org.openmrs.module.createusers;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.liquibase.ChangeSetExecutorCallback;
import org.openmrs.module.BaseModuleActivator;
import org.openmrs.util.DatabaseUpdateException;
import org.openmrs.util.DatabaseUpdater;
import org.openmrs.util.InputRequiredException;

/**
* This class contains the logic that is run every time this module is either started or shutdown
Expand All @@ -27,14 +25,16 @@ public class CreateUsersActivator extends BaseModuleActivator {
/**
* @see #started()
*/
@Override
public void started() {
log.warn("Started Create.users");
log.warn("Normally oauth2 module should manage datafilter inputs as well: To be improved.");
try {
DatabaseUpdater.executeChangelog("liquibase-add-default-users.xml", MapUtils.EMPTY_MAP);
} catch (DatabaseUpdateException | InputRequiredException e) {
DatabaseUpdater.executeChangelog("liquibase-add-default-users.xml", (ChangeSetExecutorCallback) null);
} catch (Exception e) {
log.error(e);
}
new ReferenceDemoDataCreator().create();
}

/**
Expand Down
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;
}
}
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);
}
}
Loading

0 comments on commit 9be355b

Please sign in to comment.