# openmrs/openmrs-module-bedmanagement architecture

> Architecture diagram of the GitHub repository openmrs/openmrs-module-bedmanagement, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openmrs/openmrs-module-bedmanagement
- Repository: https://github.com/openmrs/openmrs-module-bedmanagement

## Overview

##### Project Type and Purpose
- The project is a modular back-end component of a larger medical record system (OpenMRS) with specific functionality for bed management.
- It combines core business logic, data access components, exposure via REST APIs, and an administrative UI (using OWA – Open Web Apps) for configuration and management.
- The README emphasizes that while the module can be used just for API/web services, the accompanying OWA module provides the admin functionality.

##### Analyzing the File Structure
- The top-level directories (api, atom-feed, omod, owa) indicate a separation of concerns:
– The "api" directory contains the core service, DAO logic, entities, exceptions, AOP validators, and activators. This is where the domain models, business logic, and database configurations (hbm.xml and liquibase) reside.
– The "atom-feed" directory shows components that likely handle asynchronous events or integrations through an Atom feed mechanism, offering a way to communicate changes or updates in bed management.
– The "omod" directory contains the REST API implementations and extensions, including resources for beds, admission locations, and related entities. This module exposes the services to external clients.
– The "owa" directory houses the administrative UI. It includes HTML, JavaScript, CSS, and tests and is responsible for the frontend representation and user interactions with the module.
- Additional files like pom.xml indicate separate Maven modules for each component, while configuration files (e.g., moduleApplicationContext.xml) further hint at Spring-based dependency management and integration.

a. Main Components:
– Core API Module: Represented by the "api" directory. This includes the data model (entities), business logic (services), DAO layer (persistence), AOP aspects (validation and event handling), and exceptions.
– Atom Feed Integration: From the "atom-feed" module. This component provides advice and event handling (with classes like BedAssignmentAdvice) to integrate bed management events with other systems.
– REST API Module: From the "omod" directory. It exposes the functionality via RESTful resources (e.g., BedDetailsResource, AdmissionLocationResource) allowing external and internal clients to interact with the system.
– Administrative UI (OWA): From the "owa" directory. This is the user interface module that offers an admin console for managing bed settings and configurations.
– Database/Persistence: Not a code module per se but represented by the Hibernate mapping files, liquibase scripts, and the underlying datastore that holds bed, admission location, and reference data.

b. Relationships and Interactions:
– The OWA (UI) communicates with the REST API (omod) via HTTP requests.
– The REST API (omod) acts as an interface to the core API logic by invoking the underlying services.
– The API module uses the DAO layer to communicate with the database for CRUD operations and data persistence, with its defined entities and mappings.
– The Atom Feed module listens to or publishes events related to bed management and ties in with the API’s AOP components to enable real-time updates or notifications.
– Data flows from user interactions (OWA) to REST endpoints (omod), then to core services (api) and finally to the database, with asynchronous event propagation via the Atom Feed as needed.

c. Architectural Patterns and Design Principles:
– Modular Design: The clear separation of API, REST, UI, and event components.
– Layered Architecture: The division into presentation (OWA), service (API), and data access (DAO with Hibernate).
– Use of AOP: As shown by the advice classes and validators which enforce business rules and event handling.
– RESTful Design: In the omod module that exposes resources for each of the bed management entities.
– Test-Driven Structure: Inclusion of extensive unit and integration tests in each module ensures robust functionality.

d. Relevant Technologies, Frameworks, or Libraries:
– Java EE/Spring Framework for dependency injection, AOP, and service management.
– Hibernate (with provided .hbm.xml files) for ORM and persistence.
– Maven for project build and modularization.
– Liquibase for database schema management.
– REST frameworks for developing the OMOD module resources.
– Frontend technologies (HTML, JavaScript, CSS) in the OWA module, along with testing frameworks like Jest (indicated by .jest.js and testing directories).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Backend Core Layer
    subgraph "Backend Core"
        APICORE["Core API Module (Business Logic, Entities, DAO)"]:::backend
        API_RESOURCES["API Config & Mappings"]:::backend
        ATOM["Atom Feed Integration (Event Handling)"]:::event
    end

    %% REST API Layer
    subgraph "REST Layer"
        REST["REST API Module (Exposes REST Endpoints)"]:::api
        REST_CONFIG["REST API Config"]:::api
    end

    %% UI Layer
    subgraph "UI Layer"
        UI["Administrative UI (OWA)"]:::ui
        OWA_APP["OWA App Files"]:::ui
        UI_CONFIG["OWA UI Configuration"]:::ui
    end

    %% Database/Persistence Layer
    DB[("Database/Persistence\n(Hibernate Mappings & Liquibase)")]:::database

    %% Primary Connections
    UI -->|"HTTPcalls"| REST
    REST -->|"ServiceInvocation"| APICORE
    APICORE -->|"CRUDOperations"| DB
    APICORE -->|"EventPropagation"| ATOM

    %% Internal Module Details (dotted connections)
    APICORE ---|"config details"| API_RESOURCES
    REST ---|"resource config"| REST_CONFIG
    UI ---|"includes"| OWA_APP
    UI ---|"includes"| UI_CONFIG

    %% Click Events for Core API Module
    click APICORE "https://github.com/openmrs/openmrs-module-bedmanagement/tree/master/api/src/main/java/org/openmrs/module/bedmanagement"
    click API_RESOURCES "https://github.com/openmrs/openmrs-module-bedmanagement/tree/master/api/src/main/resources"

    %% Click Events for Atom Feed Integration
    click ATOM "https://github.com/openmrs/openmrs-module-bedmanagement/tree/master/atom-feed/src/main/java/org/openmrs/module/bedmanagement/atomfeed"

    %% Click Events for REST API Module
    click REST "https://github.com/openmrs/openmrs-module-bedmanagement/tree/master/omod/src/main/java/org/openmrs/module/bedmanagement/rest/resource"
    click REST_CONFIG "https://github.com/openmrs/openmrs-module-bedmanagement/blob/master/omod/src/main/resources/config.xml"

    %% Click Events for Administrative UI (OWA)
    click OWA_APP "https://github.com/openmrs/openmrs-module-bedmanagement/tree/master/owa/app"
    click UI_CONFIG "https://github.com/openmrs/openmrs-module-bedmanagement/blob/master/owa/README.md"

    %% Classes and Styles
    classDef backend fill:#f4a582,stroke:#333,stroke-width:2px;
    classDef event fill:#d5f4e6,stroke:#333,stroke-width:2px;
    classDef api fill:#92c5de,stroke:#333,stroke-width:2px;
    classDef ui fill:#f7f7f7,stroke:#333,stroke-width:2px;
    classDef database fill:#fff2ae,stroke:#333,stroke-width:2px;
```
