Build Matchbox from source
This guide shows how to build and run Matchbox from its source code, e.g. to contribute a change or to build your own Docker image.
You need Java 21 (JDK), Maven, and Node.js with npm for the web interface.
Get the source
The repository contains three modules: matchbox-engine (the library), matchbox-server (the FHIR server) and
matchbox-frontend (the web interface, in Angular).
Build and run the server
The server is then available at http://localhost:8080/matchboxv3/fhir.
To run it with one of the sample configurations:
java -Dspring.config.additional-location=file:with-preload/application.yaml -jar target/matchbox.jar
To debug it, start it with the debug port 5005 open and attach your IDE:
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
Work on the web interface
Run the server (see above), then start the development server of the frontend, which forwards the API calls to
http://localhost:8080:
The web interface is then at http://localhost:4200 and reloads when you change the code.
To include your changes in the server, build the frontend into the static resources of matchbox-server and build the
server again:
Run the tests
mvn clean test # all the tests of the engine and the server
mvn -Dtest=MatchboxApiR4Test test # a single test class
cd matchbox-frontend && npm test # the tests of the frontend
Tests that need an implementation guide use the Matchbox test IG
(matchbox.health.test.ig.r4), whose package is in the test resources of both Java modules.
Build the Docker image
mvn package -DskipTests
cd matchbox-server
docker build -t matchbox .
docker run -d --name matchbox -p 8080:8080 -m 4g -v ${PWD}/with-settings:/config matchbox
Build the documentation
The documentation is in the docs directory and is built with ProperDocs
(configuration in properdocs.yml):
It is published to ahdis.github.io/matchbox when a release is tagged.
Contribute a change
Discuss it first
Report bugs and propose features in the issues; ask questions in the discussions. For a larger change, open an issue before you start, so that the approach can be agreed on.
Open a pull request
- Create a branch from
main(in your fork if you can't push toahdis/matchbox). - Make the change, with tests: the Java tests are in
src/testof each module. - Add an entry to
docs/changelog.md, under the release at the top of the file: every pull request needs one. Describe the change for the users of Matchbox, and link the issue ([#643](https://github.com/ahdis/matchbox/issues/643)). - Update the documentation if the behavior or the configuration changes. Each page belongs to one of the four
sections (Diátaxis); a new page must be added to the
navofproperdocs.yml, and a moved page needs a redirect from its old address (redirect_mapsof theredirectsplugin). -
Open the pull request against
ahdis/matchbox. The repository is a fork of the HAPI FHIR JPA server starter: make sure that GitHub doesn't proposehapifhir/hapi-fhir-jpaserver-starteras the base repository.
Don't commit the built frontend: when a change of matchbox-frontend is merged into main, a workflow builds it and
commits the result to matchbox-server/src/main/resources/static.
Follow the code style
The formatting is defined in .editorconfig, which most
IDEs apply: tabs for Java (width 3), two spaces for the other files, 120 characters per line at most. The classes copied
from HAPI FHIR and org.hl7.fhir.core (ca/uhn/fhir/** and org/hl7/fhir/**) keep the formatting of their project,
so that their patches stay easy to compare. For the frontend, run npm run lint and format with Prettier.
Pass the checks
These workflows run on every pull request to main and must pass:
| Workflow | What it checks |
|---|---|
| Unit tests | The Maven tests of matchbox-engine and matchbox-server |
| Integration tests | The tests of matchbox-int-tests, against the version being built |
| Javadoc test | That the Javadoc can be generated |
| Test the Angular GUI | That the frontend can be built |
| Security checks | The analysis of the Java code with CodeQL and of the dependencies with Trivy |
Run the tests locally before you push (see Run the tests).
Update the patched classes of the validator
Matchbox depends on org.hl7.fhir.core, the library of the HL7
validator, and patches some of its classes. The patched copies are in matchbox-engine/src/main/java/org/hl7/fhir
(and a few of HAPI FHIR in matchbox-server/src/main/java); they take precedence over the original classes on the
classpath. Each patch is marked with a matchbox patch comment.
To change a patched class, edit the copy in Matchbox and mark your change with a matchbox patch comment. Don't change
the code around it: the copies are replaced at each update of org.hl7.fhir.core.
To update org.hl7.fhir.core:
- Change
fhir.core.versionin the rootpom.xml. - Copy the new versions of the patched classes into Matchbox, which removes the patches:
./updatehapi.shcopies them from a checkout of the release tag oforg.hl7.fhir.core(and ofhapi-fhir) next to the Matchbox repository;- or
./updatehapi.ps1downloads every file ofmatchbox-engine/src/main/java/org/hl7/fhirfrom GitHub, at the version ofpom.xml(-DryRunshows what would change).
- With
git diff, re-apply eachmatchbox patchon the new code, without reverting the upstream changes. - Fix the compilation errors due to API changes, then run all the tests.
The steps and the list of patches are described in detail in
udpatecoreversion.md. When you patch a new
class, add it to updatehapi.sh.
Change the test implementation guide
Tests that need an implementation guide (profiles, examples, a package to load) use the
Matchbox test IG (matchbox.health.test.ig.r4) rather than a real
implementation guide, so that they don't depend on the content of external packages. To add what a test needs:
- Check out matchbox-test-ig next to the Matchbox repository, and add the profiles or examples (in FSH) to it.
- Raise the version in its
sushi-config.yaml, add the entry to itsCHANGELOG.md, build it with SUSHI and the IG Publisher and commit. Every package that goes into the Matchbox repository has its own version. - Run its
dist.sh: it copiesoutput/package.tgzasmatchbox.health.test.ig.r4-<version>.tgzto bothmatchbox-server/src/test/resourcesandmatchbox-engine/src/test/resources, and removes the old package. - Update the references to the version, e.g. in
application-test-r4.yaml: search formatchbox.health.test.ig.r4.
The test IG and matchbox-engine both use the latest version of hl7.terminology.r4 and hl7.fhir.uv.extensions.r4
(PACKAGE_R4_TERMINOLOGY and PACKAGE_R4_UV_EXTENSIONS in MatchboxEngine), and it has to be the same one: with
another version, the test server downloads the packages and their dependencies from the registry when it starts.
When a new version of one of the two packages is released, update both in the same pull request:
- Replace the bundled packages for R4 and R5 in
matchbox-engine/src/main/resourceswith the new ones fromhttps://packages2.fhir.org/packages/<package>/<version>, and update the constants inMatchboxEngineand the other references to the old version (search for it, e.g.hl7.terminology#inIgLoaderFromJpaPackageCache). - Build a new version of the test IG with the same dependency and add it as described above (
dist.shchecks that the dependencies are the bundled versions).