From 5e30a5a788005644893d97d661371e7989f25705 Mon Sep 17 00:00:00 2001 From: Himabindu T Date: Fri, 31 May 2024 17:29:11 +0530 Subject: [PATCH 01/15] Bindu, Kavitha | Merge code from Bahmni-IPD-master branch to main branch (#56) * [Ritesh] | BAH-3148 | Create and fetch medication task (#1) * [Ritesh] | 1. Repo set up. 2. Created Slot and Schedule entity 3.Saving IPD Medication Schedule without creating slots. * [Ritesh] | 1. Update package name 2. Added Dao and Service layer for reference 3. Minor fixes * [Ritesh] | 1.Rename Schedule Strategy to MedicationFrequency * [Ritesh] | 1. Migration for slot. 2. Slot creation from schedule * [Ritesh] | 1. Refactor SlotTimeCreationService * [Ritesh] | 1. Handle time zone issue while creating slots and schedule. * [Ritesh] | 1. Changing the url of saving medication * [Ritesh] | 1. Returning slots * [Ritesh] | Get schedule for Drug chart * [Ritesh] | Fix date time issue in slots response * [Ritesh] | Refactoring and Added test * [Ritesh] | 1. Change for reference id to subject reference id and by reference id to actor reference id. 2. Also added pre-condition before adding medication concept for ipd. * [Ritesh] | 1. Refactoring ServiceType * [Ritesh] | 1. Bug Fix return empty list if now slots are not present for a patient on specific day. * [Ritesh] | 1. Updated README file * [Ritesh] | 1. Fixed time zone issue in test * add. endpoint to get list of IPD medications scheduled for a patient * refactor. endpoint and updated tests in DAO and service classes * refactor. namings for schedule DAO methods * fix. test failures in ScheduleImpl --------- Co-authored-by: Arjun-Go Co-authored-by: Arjun G <91885483+Arjun-Go@users.noreply.github.com> * A-1205974389432443 | Feedbacks on Medication Schedule (#3) * [Ritesh] | 1. Repo set up. 2. Created Slot and Schedule entity 3.Saving IPD Medication Schedule without creating slots. * [Ritesh] | 1. Update package name 2. Added Dao and Service layer for reference 3. Minor fixes * [Ritesh] | 1.Rename Schedule Strategy to MedicationFrequency * [Ritesh] | 1. Migration for slot. 2. Slot creation from schedule * [Ritesh] | 1. Refactor SlotTimeCreationService * [Ritesh] | 1. Handle time zone issue while creating slots and schedule. * [Ritesh] | 1. Changing the url of saving medication * [Ritesh] | 1. Returning slots * [Ritesh] | Get schedule for Drug chart * [Ritesh] | Fix date time issue in slots response * [Ritesh] | Refactoring and Added test * [Ritesh] | 1. Change for reference id to subject reference id and by reference id to actor reference id. 2. Also added pre-condition before adding medication concept for ipd. * [Ritesh] | 1. Refactoring ServiceType * [Ritesh] | 1. Bug Fix return empty list if now slots are not present for a patient on specific day. * [Ritesh] | 1. Updated README file * [Ritesh] | 1. Fixed time zone issue in test * add. endpoint to get list of IPD medications scheduled for a patient * refactor. endpoint and updated tests in DAO and service classes * refactor. namings for schedule DAO methods * fix. test failures in ScheduleImpl * add. changes to create one schedule for a patient * update. columns in Schedule and Slot table * update. set end date as null * fix tests for Slot and Schedule Hiberate and DAOs. Updated responses for GET calls * fix tests Schedule DAO * remove unnecessary fields * API Change to accomodate Editable Remaining day slot start time for medication --------- Co-authored-by: Ritesh Ghiya Co-authored-by: Kalaiyarasan Raja * add. changes to automate omod publish for Bahmni-IPD-master branch (#4) * Arjun | Fix deployment workflow (#5) * test. ipd publish workflow * revert. testing changes in deploy workflow * test changes with maven wrapper * revert. deploy for test branch * Medication Administration Feature (#7) * [Ritesh] | 1. Repo set up. 2. Created Slot and Schedule entity 3.Saving IPD Medication Schedule without creating slots. * [Ritesh] | 1. Update package name 2. Added Dao and Service layer for reference 3. Minor fixes * [Ritesh] | 1.Rename Schedule Strategy to MedicationFrequency * [Ritesh] | 1. Migration for slot. 2. Slot creation from schedule * [Ritesh] | 1. Refactor SlotTimeCreationService * [Ritesh] | 1. Handle time zone issue while creating slots and schedule. * [Ritesh] | 1. Changing the url of saving medication * [Ritesh] | 1. Returning slots * [Ritesh] | Get schedule for Drug chart * [Ritesh] | Fix date time issue in slots response * [Ritesh] | Refactoring and Added test * [Ritesh] | 1. Change for reference id to subject reference id and by reference id to actor reference id. 2. Also added pre-condition before adding medication concept for ipd. * [Ritesh] | 1. Refactoring ServiceType * [Ritesh] | 1. Bug Fix return empty list if now slots are not present for a patient on specific day. * [Ritesh] | 1. Updated README file * [Ritesh] | 1. Fixed time zone issue in test * add. endpoint to get list of IPD medications scheduled for a patient * refactor. endpoint and updated tests in DAO and service classes * refactor. namings for schedule DAO methods * fix. test failures in ScheduleImpl * add. changes to create one schedule for a patient * update. columns in Schedule and Slot table * update. set end date as null * fix tests for Slot and Schedule Hiberate and DAOs. Updated responses for GET calls * fix tests Schedule DAO * remove unnecessary fields * API Change to accomodate Editable Remaining day slot start time for medication * Kavitha|Kalai Add Change for Medication Administration Save * Kavitha|Kalai - Medication Administration Create API Changes * Kavitha|Kalai - Medication Administration Create API Changes * Kavitha, Kalai | refactored patient reference param * Kavitha|Kalai - Medication Administration Create API Changes * Kavitha|Kalai - Medication Administration Create API Changes * Kavitha|Kalai - Medication Administration Create API Changes * Kavitha|Kalai - Medication Administration Create API Changes * Kavitha, Kalai | add medication administration reference in slot db and api * Kavitha|Kalai - Medication Administration Create API Changes * Kavitha, Kalai | added provider mapper and time converter * Kavitha | add adhoc and refactored scheduled medication administration * refactored schedule from medication administration request * Kavitha | refactored medication administration request and response * Kavitha | refactored annotation to medicationAdministrationNote * Kavitha | removed unused methods --------- Co-authored-by: Ritesh Ghiya Co-authored-by: Arjun-Go Co-authored-by: Kalaiyarasan Raja * IPD Treatment Display Control Get API Changes & Edit Drug Chart API Changes (#8) * IPD Drug Order Fetch API changes * IPD Drug Order schedule update API changes * IPD Drug Order schedule update API changes * IPD Drug Order schedule update API changes * IPD Drug Order schedule update API changes * Fix to convert time to UTC intead of Local Time * Kavitha | refactored treatments API to include emergency medications * Kavitha,Kalai | add provider as part of drug order response --------- Co-authored-by: Kavitha S * A-1206156796138532 | Abi | add. functionality to return slot information based on given time frame * Abi | fix. method name based on functionality * Abi | fix. filter non-voided slots for the iven time frame (#10) * Changes to accomodate Drugchart view where we need to intended and actual administered time Changes to accomodate Drugchart view where we need to intended and actual administered time * BAH-3460 | Kavitha | refactor save adhoc medications (#13) * Changes to stop/void slots associated with drugorder when its stopped (#12) Changes to stop/void slots associated with drugorder when its stopped * BAH-3460 | fix provider uuid issue for schedule creation (#14) * Nursing task enhancement (#15) * Abi | fix. schedule notes issue (#17) * Provider acknowledge flow changes - Update API Introduced for Medication Administration Provider acknowledge flow changes - Update API Introduced for Medication Administration * Kavitha | fix slot creation logic for 1 day (#19) * Kavitha | add void condition in fetching slots (#20) * Abi | update. status as Stopped once administered and stopped a medicine (#21) * Changes to bring drug order one visit previous to current visit Changes to bring drug order one visit previous to current visit * update. shift api to return slots based on visitUuid * add. check to avoid multiple save (#23) * update. filter slots for drugChart based on visit uuid * Test Case Fix for new change added * API to save/schedule the placeholder Tasks for PRN (#24) * add. logic for creating placeholder for as needed medications * add. test for getting medications in given time frame * add. logic to fetch medications of particular service type * update. name of variable * update. modify imports to have static imports * pendingSlotsAvailable Key added to know whether any pending slots is available for drug Order * condition added to check if slotstart time is after current time (#27) * [Sri/kalai] - get the pending slots after the current time in drug order schedule response * Change to consider MedicationRequest as a default serviceType if is not sent in payload * MAde Visit UUid as non-mandatory Param, if visit is not send consider Active Visit of the patient * Change to consider MedicationRequest as a default serviceType if is not sent in payload (#29) * Change to consider MedicationRequest as a default serviceType if is not sent in payload * MAde Visit UUid as non-mandatory Param, if visit is not send consider Active Visit of the patient * Backend changed to accomodate prn slots * added First Slot Start time to response in DrugOrderSchedule * Kavitha | add api to fetch slots by patient list with custom includes (#32) * Ward Level DashBoard API Changes (#30) * Ward Level DashBoard API Changes * Kavitha | add null check to get slots for list of patients (#34) * Search functionality API added & Refactor get patients API (#33) * Add boolean key to show if all slots are attended (#35) * Add totalPatient in Patient List & Search API response * Add missing classes * Kavitha | refactored slot creation logic for continuous medication (#38) * add. scheduler to mark non-administered slots as missed (#39) * Bookmarking API - API To Create Care Team & its Participants (#37) Bookmarking API - API To Create Care Team & its Participants (#37) * Adds careTeam information to AdmittedPatient (#40) * Adds visitDetails to AdmittedPatientResponse * Removed starttime,endtime & provider in update flow (#42) * Adds provider details and time check for getAdmittedPatients * Change LocalDateTime to Date * Rename methods * Adds ability to sort by Bed Number * CareTeam info added to search API as well (#44) CareTeam info added to search API as well (#44) * Removed CareTeam Particpants join condition (#45) Removed CareTeam Particpants join condition (#45) * Changes Inner join to left outer join * Makes sortBy optional parameter * Add a check in generateGroupByClauseForSorting to handle null values * Extract ORDER BY from GROUP BY * Add myPatient count for provider in summary API * Include void check for provider patients * Include currentDateTime for provider shift validation * BAH-3723|Kavitha| Event handling model & create task for admit event (#48) * BAH-3723|Kavitha| add event handling model and create task for admit event * Kavitha| add null check for event type * Kavitha | update fhir2 extension module version * Add scheduler, liquibase and handleEvent for shift start task * Move Events to api, refactor and include shift start task scheduler * Update api pom.xml * Add scheduler task for rollover medication tasks * Gets rollover tasks from fhir task service using task names and status * Add migration top add scheduler for rollover tasks * Create start shift scheduler and roll over tasks * Update and Refactor the rollover and shift start task * Remove the emrapi dependency * Refactor the method names * Rename the scheduler name * Add filters on drugorder while showing count (#51) * [Ashish]Add. Two new frequencies are added to medications * Abi | add. privilege checks for endpoints (#54) * Changes to Show the medication of Immediate Previous Visit Only if it is an OPD Visit Changes to Show the medication of Immediate Previous Visit Only if it is an OPD Visit * Upgrade Fhir2 version & Fhir2 Extension Version (#57) * Bindu | Remove feature branch from workflow --------- Co-authored-by: Ritesh Ghiya Co-authored-by: Arjun-Go Co-authored-by: Arjun G <91885483+Arjun-Go@users.noreply.github.com> Co-authored-by: Ritesh Ghiya Co-authored-by: Kalaiyarasan Raja Co-authored-by: kavitha-sundararajan <90255023+kavitha-sundararajan@users.noreply.github.com> Co-authored-by: kalai-tw <104360355+kalai-tw@users.noreply.github.com> Co-authored-by: Kavitha S Co-authored-by: Abinaya U <77735030+abinaya-u@users.noreply.github.com> Co-authored-by: Abinaya U Co-authored-by: Soorya Kumaran C <90232857+SooryaKumaranC-tw@users.noreply.github.com> Co-authored-by: srinithishg <81152520+srinithishg@users.noreply.github.com> Co-authored-by: srinithishg Co-authored-by: Umair Fayaz Co-authored-by: Umair Fayaz <59157924+umair-fayaz@users.noreply.github.com> Co-authored-by: AshishkurianTw Co-authored-by: AshishkurianTw <119398030+AshishkurianTw@users.noreply.github.com> --- .github/workflows/build_publish.yaml | 25 + .github/workflows/validate_pr.yml | 22 + .gitignore | 22 + .mvn/wrapper/maven-wrapper.properties | 18 + LICENSE | 661 ++++++++++++++++++ README.md | 14 + api/pom.xml | 219 ++++++ .../openmrs/module/ipd/api/IPDActivator.java | 22 + .../module/ipd/api/dao/CareTeamDAO.java | 14 + .../module/ipd/api/dao/ReferenceDAO.java | 15 + .../module/ipd/api/dao/ScheduleDAO.java | 17 + .../openmrs/module/ipd/api/dao/SlotDAO.java | 45 ++ .../openmrs/module/ipd/api/dao/WardDAO.java | 19 + .../api/dao/impl/HibernateCareTeamDAO.java | 41 ++ .../api/dao/impl/HibernateReferenceDAO.java | 44 ++ .../api/dao/impl/HibernateScheduleDAO.java | 47 ++ .../ipd/api/dao/impl/HibernateSlotDAO.java | 247 +++++++ .../ipd/api/dao/impl/HibernateWardDAO.java | 240 +++++++ .../module/ipd/api/events/ConfigLoader.java | 41 ++ .../ipd/api/events/IPDEventManager.java | 36 + .../module/ipd/api/events/IPDEventUtils.java | 22 + .../api/events/factory/IPDEventFactory.java | 8 + .../factory/impl/IPDEventFactoryImpl.java | 38 + .../api/events/handler/IPDEventHandler.java | 7 + .../impl/PatientAdmitEventHandler.java | 52 ++ .../impl/RolloverTaskEventHandler.java | 57 ++ .../impl/ShiftStartTaskEventHandler.java | 60 ++ .../ipd/api/events/model/ConfigDetail.java | 19 + .../module/ipd/api/events/model/IPDEvent.java | 18 + .../ipd/api/events/model/IPDEventType.java | 7 + .../ipd/api/events/model/TaskDetail.java | 16 + .../module/ipd/api/model/AdmittedPatient.java | 27 + .../module/ipd/api/model/CareTeam.java | 105 +++ .../ipd/api/model/CareTeamParticipant.java | 99 +++ .../ipd/api/model/IPDPatientDetails.java | 17 + .../ipd/api/model/IPDWardPatientDetails.java | 17 + .../module/ipd/api/model/Reference.java | 40 ++ .../module/ipd/api/model/Schedule.java | 63 ++ .../module/ipd/api/model/ServiceType.java | 18 + .../openmrs/module/ipd/api/model/Slot.java | 99 +++ .../ipd/api/model/WardPatientsSummary.java | 18 + .../scheduler/tasks/MarkSlotsAsMissed.java | 36 + .../tasks/RollOverNonMedicationTasks.java | 30 + .../api/scheduler/tasks/ShiftStartTasks.java | 29 + .../ipd/api/service/CareTeamService.java | 18 + .../ipd/api/service/ReferenceService.java | 20 + .../ipd/api/service/ScheduleService.java | 20 + .../module/ipd/api/service/SlotService.java | 55 ++ .../module/ipd/api/service/WardService.java | 20 + .../api/service/impl/CareTeamServiceImpl.java | 39 ++ .../service/impl/ReferenceServiceImpl.java | 39 ++ .../api/service/impl/ScheduleServiceImpl.java | 43 ++ .../ipd/api/service/impl/SlotServiceImpl.java | 139 ++++ .../ipd/api/service/impl/WardServiceImpl.java | 62 ++ ...nAdministrationToSlotStatusTranslator.java | 22 + .../module/ipd/api/util/DateTimeUtil.java | 29 + .../module/ipd/api/util/IPDConstants.java | 7 + api/src/main/resources/liquibase.xml | 530 ++++++++++++++ .../resources/moduleApplicationContext.xml | 38 + .../module/ipd/api/BaseIntegrationTest.java | 6 + .../HibernateCareTeamDAOIntegrationTest.java | 92 +++ .../HibernateReferenceDAOIntegrationTest.java | 36 + .../HibernateScheduleDAOIntegrationTest.java | 138 ++++ .../impl/HibernateSlotDAOIntegrationTest.java | 484 +++++++++++++ .../impl/HibernateWardDAOIntegrationTest.java | 34 + .../service/impl/CareTeamServiceImplTest.java | 59 ++ .../impl/ReferenceServiceImplTest.java | 50 ++ .../service/impl/ScheduleServiceImplTest.java | 69 ++ .../api/service/impl/SlotServiceImplTest.java | 221 ++++++ .../module/ipd/api/util/DateTimeUtilTest.java | 58 ++ .../test/resources/CareTeamDAOTestData.xml | 22 + .../resources/TestingApplicationContext.xml | 12 + api/src/test/resources/WardDAOTestData.xml | 181 +++++ .../resources/scheduleMedicationsTestData.xml | 41 ++ mvnw | 308 ++++++++ mvnw.cmd | 205 ++++++ omod/pom.xml | 191 +++++ .../openmrs/module/ipd/ModuleDescriptor.java | 3 + .../ipd/contract/AdmittedPatientResponse.java | 33 + .../contract/CareTeamParticipantRequest.java | 24 + .../contract/CareTeamParticipantResponse.java | 30 + .../module/ipd/contract/CareTeamRequest.java | 15 + .../module/ipd/contract/CareTeamResponse.java | 28 + .../contract/DrugOrderScheduleResponse.java | 37 + .../ipd/contract/IPDDrugOrderResponse.java | 40 ++ .../contract/IPDPatientDetailsResponse.java | 23 + .../ipd/contract/IPDTreatmentsResponse.java | 28 + .../IPDWardPatientDetailsResponse.java | 24 + .../IPDWardPatientSummaryResponse.java | 23 + .../module/ipd/contract/IPDWardResponse.java | 25 + .../MedicationAdministrationNoteRequest.java | 26 + .../MedicationAdministrationNoteResponse.java | 31 + ...icationAdministrationPerformerRequest.java | 21 + ...cationAdministrationPerformerResponse.java | 28 + .../MedicationAdministrationRequest.java | 38 + .../MedicationAdministrationResponse.java | 78 +++ .../contract/MedicationScheduleResponse.java | 43 ++ .../ipd/contract/MedicationSlotResponse.java | 60 ++ .../PatientMedicationSummaryResponse.java | 35 + .../PrescribedOrderSlotSummaryResponse.java | 36 + .../contract/ScheduleMedicationRequest.java | 55 ++ .../contract/ScheduleMedicationResponse.java | 35 + .../ipd/controller/IPDCareTeamController.java | 47 ++ ...IPDMedicationAdministrationController.java | 92 +++ .../ipd/controller/IPDScheduleController.java | 180 +++++ .../ipd/controller/IPDVisitController.java | 57 ++ .../ipd/controller/IPDWardController.java | 89 +++ .../module/ipd/factory/CareTeamFactory.java | 65 ++ .../MedicationAdministrationFactory.java | 91 +++ .../module/ipd/factory/ScheduleFactory.java | 55 ++ .../module/ipd/factory/SlotFactory.java | 91 +++ .../module/ipd/model/DrugOrderSchedule.java | 21 + .../module/ipd/model/IPDDrugOrder.java | 23 + .../ipd/model/PatientMedicationSummary.java | 19 + .../ipd/model/PrescribedOrderSlotSummary.java | 20 + .../postprocessor/IPDTransactionHandler.java | 36 + .../ipd/service/IPDCareTeamService.java | 12 + .../IPDMedicationAdministrationService.java | 14 + .../ipd/service/IPDScheduleService.java | 26 + .../module/ipd/service/IPDVisitService.java | 14 + .../module/ipd/service/IPDWardService.java | 18 + .../service/impl/IPDCareTeamServiceImpl.java | 49 ++ ...PDMedicationAdministrationServiceImpl.java | 121 ++++ .../service/impl/IPDScheduleServiceImpl.java | 247 +++++++ .../ipd/service/impl/IPDVisitServiceImpl.java | 194 +++++ .../ipd/service/impl/IPDWardServiceImpl.java | 77 ++ .../service/impl/SlotTimeCreationService.java | 145 ++++ .../module/ipd/util/PrivilegeConstants.java | 19 + .../src/main/resources/application.properties | 3 + omod/src/main/resources/config.xml | 21 + .../resources/webModuleApplicationContext.xml | 12 + .../module/ipd/BaseIntegrationTest.java | 7 + .../module/ipd/BaseWebControllerTest.java | 176 +++++ .../IPDScheduleControllerIntegrationTest.java | 57 ++ omod/src/test/resources/config.xml | 21 + .../resources/webModuleApplicationContext.xml | 11 + pom.xml | 435 ++++++++++++ 137 files changed, 9383 insertions(+) create mode 100644 .github/workflows/build_publish.yaml create mode 100644 .github/workflows/validate_pr.yml create mode 100644 .gitignore create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 LICENSE create mode 100644 api/pom.xml create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/IPDActivator.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/CareTeamDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/ReferenceDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/ScheduleDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/SlotDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/WardDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventManager.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/factory/IPDEventFactory.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/factory/impl/IPDEventFactoryImpl.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/handler/IPDEventHandler.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEvent.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEventType.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/AdmittedPatient.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/CareTeam.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/CareTeamParticipant.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/IPDPatientDetails.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/IPDWardPatientDetails.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/Reference.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/Schedule.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/ServiceType.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/Slot.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/model/WardPatientsSummary.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/MarkSlotsAsMissed.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/RollOverNonMedicationTasks.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/ShiftStartTasks.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/CareTeamService.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/ReferenceService.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/ScheduleService.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/SlotService.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/WardService.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImpl.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImpl.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImpl.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImpl.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/service/impl/WardServiceImpl.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/translators/MedicationAdministrationToSlotStatusTranslator.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/util/DateTimeUtil.java create mode 100644 api/src/main/java/org/openmrs/module/ipd/api/util/IPDConstants.java create mode 100644 api/src/main/resources/liquibase.xml create mode 100644 api/src/main/resources/moduleApplicationContext.xml create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/BaseIntegrationTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAOIntegrationTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAOIntegrationTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAOIntegrationTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAOIntegrationTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImplTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImplTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImplTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImplTest.java create mode 100644 api/src/test/java/org/openmrs/module/ipd/api/util/DateTimeUtilTest.java create mode 100644 api/src/test/resources/CareTeamDAOTestData.xml create mode 100644 api/src/test/resources/TestingApplicationContext.xml create mode 100644 api/src/test/resources/WardDAOTestData.xml create mode 100644 api/src/test/resources/scheduleMedicationsTestData.xml create mode 100755 mvnw create mode 100644 mvnw.cmd create mode 100644 omod/pom.xml create mode 100644 omod/src/main/java/org/openmrs/module/ipd/ModuleDescriptor.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/AdmittedPatientResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantRequest.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamRequest.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/DrugOrderScheduleResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/IPDDrugOrderResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/IPDPatientDetailsResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/IPDTreatmentsResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientDetailsResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientSummaryResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteRequest.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerRequest.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationRequest.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationScheduleResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/MedicationSlotResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/PatientMedicationSummaryResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/PrescribedOrderSlotSummaryResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationRequest.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationResponse.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/controller/IPDCareTeamController.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/controller/IPDWardController.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/factory/CareTeamFactory.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/factory/ScheduleFactory.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/factory/SlotFactory.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/model/DrugOrderSchedule.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/model/IPDDrugOrder.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/model/PatientMedicationSummary.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/model/PrescribedOrderSlotSummary.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/IPDCareTeamService.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/IPDMedicationAdministrationService.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/IPDScheduleService.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/IPDVisitService.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/IPDWardService.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDCareTeamServiceImpl.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDMedicationAdministrationServiceImpl.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDScheduleServiceImpl.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDVisitServiceImpl.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/service/impl/SlotTimeCreationService.java create mode 100644 omod/src/main/java/org/openmrs/module/ipd/util/PrivilegeConstants.java create mode 100644 omod/src/main/resources/application.properties create mode 100644 omod/src/main/resources/config.xml create mode 100644 omod/src/main/resources/webModuleApplicationContext.xml create mode 100644 omod/src/test/java/org/openmrs/module/ipd/BaseIntegrationTest.java create mode 100644 omod/src/test/java/org/openmrs/module/ipd/BaseWebControllerTest.java create mode 100644 omod/src/test/java/org/openmrs/module/ipd/controller/IPDScheduleControllerIntegrationTest.java create mode 100644 omod/src/test/resources/config.xml create mode 100644 omod/src/test/resources/webModuleApplicationContext.xml create mode 100644 pom.xml diff --git a/.github/workflows/build_publish.yaml b/.github/workflows/build_publish.yaml new file mode 100644 index 0000000..8a164f2 --- /dev/null +++ b/.github/workflows/build_publish.yaml @@ -0,0 +1,25 @@ +name: Build and Publish package +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build-publish-package: + name: Build and Publish package + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + server-id: nexus-sonatype + server-username: NEXUS_USERNAME + server-password: NEXUS_PASSWORD + - name: Build and deploy with Maven + run: ./mvnw --no-transfer-progress clean -U deploy + env: + NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} + NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} diff --git a/.github/workflows/validate_pr.yml b/.github/workflows/validate_pr.yml new file mode 100644 index 0000000..5a0c37b --- /dev/null +++ b/.github/workflows/validate_pr.yml @@ -0,0 +1,22 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Maven + run: mvn clean package diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef96046 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +*.class +.settings +.project +.classpath +.talismanrc +target + +# Package Files # +*.jar +*.marker +*.war +*.ear +.idea +.DS_Store + +/omod/target/* +/api/target/* +*.iml +*/logs/* +logs/* +classes/ +.mvn/wrapper/*.jar diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..ac18401 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ad25db --- /dev/null +++ b/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/README.md b/README.md index 7833d3f..aa72fd3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # openmrs-module-ipd Openmrs module for Bahmni IPD Care and Monitoring + +OpenMRS Module Bahmni-events Backend +================================= +This repository handles Bahmni IPD Care and Monitoring. + +## Packaging +```mvn clean package``` + +### Prerequisite + JDK 1.8 + +## Deploy + +Copy ```openmrs-module-ipd/omod/target/bahmni-ipd-1.0.0-SNAPSHOT.omod``` into OpenMRS modules directory and restart OpenMRS \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml new file mode 100644 index 0000000..ecc0868 --- /dev/null +++ b/api/pom.xml @@ -0,0 +1,219 @@ + + + 4.0.0 + + org.bahmni.module + bahmni-ipd + 1.0.0-SNAPSHOT + + + bahmni-ipd-api + jar + Bahmni IPD API + Bahmni IPD API contains all backend APIs for IPD + + + + + src/main/resources + true + + + + + + src/test/resources + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + test-jar + + + + + + + + + + + org.openmrs.api + openmrs-api + provided + + + org.projectlombok + lombok + provided + + + org.openmrs.module + bedmanagement-api + provided + + + org.openmrs.web + openmrs-web + provided + + + org.openmrs.module + webservices.rest-omod-common + provided + + + + org.openmrs.module + webservices.rest-omod-2.0 + provided + + + + org.openmrs.module + fhir2-api + provided + + + + org.openmrs.module + fhir2-omod + provided + + + + org.bahmni.module + fhir2Extension-api + provided + + + + org.bahmni.module + fhir2Extension-omod + provided + + + + org.bahmni.module + medication-administration-api + provided + + + + org.openmrs.module + webservices.rest-omod-common + test-jar + test + + + org.openmrs.test + openmrs-test + pom + + + org.openmrs.web + openmrs-web + test-jar + test + + + org.openmrs.api + openmrs-api + test-jar + test + + + org.powermock + powermock-api-mockito2 + test + + + org.mockito + mockito-core + test + + + org.powermock + powermock-module-junit4 + test + + + junit + junit + + + org.hamcrest + hamcrest-core + + + test + + + + + + diff --git a/api/src/main/java/org/openmrs/module/ipd/api/IPDActivator.java b/api/src/main/java/org/openmrs/module/ipd/api/IPDActivator.java new file mode 100644 index 0000000..730babb --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/IPDActivator.java @@ -0,0 +1,22 @@ +package org.openmrs.module.ipd.api; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.module.BaseModuleActivator; + +/** + * This class contains the logic that is run every time this module is either started or shutdown + */ +public class IPDActivator extends BaseModuleActivator { + + private final Log log = LogFactory.getLog(this.getClass()); + + public void startup() { + log.info("Starting Basic Module"); + } + + public void shutdown() { + log.info("Shutting down Basic Module"); + } + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/CareTeamDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/CareTeamDAO.java new file mode 100644 index 0000000..f07d2e8 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/CareTeamDAO.java @@ -0,0 +1,14 @@ +package org.openmrs.module.ipd.api.dao; + +import org.openmrs.Visit; +import org.openmrs.api.db.DAOException; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.api.model.Schedule; + +public interface CareTeamDAO { + + CareTeam saveCareTeam(CareTeam careTeam) throws DAOException; + + CareTeam getCareTeamByVisit(Visit visit) throws DAOException; + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/ReferenceDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/ReferenceDAO.java new file mode 100644 index 0000000..983d639 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/ReferenceDAO.java @@ -0,0 +1,15 @@ +package org.openmrs.module.ipd.api.dao; + +import org.openmrs.api.db.DAOException; +import org.openmrs.module.ipd.api.model.Reference; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface ReferenceDAO { + + Optional getReferenceByTypeAndTargetUUID(String type, String targetUUID) throws DAOException; + + Reference saveReference(Reference reference) throws DAOException; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/ScheduleDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/ScheduleDAO.java new file mode 100644 index 0000000..7d85035 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/ScheduleDAO.java @@ -0,0 +1,17 @@ +package org.openmrs.module.ipd.api.dao; + +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.api.db.DAOException; +import org.springframework.stereotype.Repository; + + +@Repository +public interface ScheduleDAO { + + Schedule getSchedule(Integer scheduleId) throws DAOException; + + Schedule saveSchedule(Schedule schedule) throws DAOException; + + Schedule getScheduleByVisit(Visit visit) throws DAOException; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/SlotDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/SlotDAO.java new file mode 100644 index 0000000..e28cca8 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/SlotDAO.java @@ -0,0 +1,45 @@ +package org.openmrs.module.ipd.api.dao; + +import org.openmrs.Concept; +import org.openmrs.Order; +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.api.db.DAOException; +import org.springframework.stereotype.Repository; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +@Repository +public interface SlotDAO { + + Slot getSlot(Integer slotId) throws DAOException; + + Slot getSlotByUUID(String uuid) throws DAOException; + + Slot saveSlot(Slot slot) throws DAOException; + + List getSlotsBySubjectReferenceIdAndForDateAndServiceType(Reference subject, LocalDate forDate, Concept serviceType); + + List getSlotsBySubjectReferenceIdAndServiceType(Reference subject, Concept serviceType); + + List getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(Reference subject, Concept serviceType, List orderUuids); + + List getSlotsByPatientAndVisitAndServiceType(Reference subject, Visit visit, Concept serviceType); + + List getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit, Concept serviceType); + + List getSlotsBySubjectIncludingAdministeredTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit); + + List getSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate, LocalDateTime localEndDate); + + List getImmediatePreviousSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate); + + List getSlotDurationForPatientsByOrder(List orders, List serviceTypes); + + List getLastSlotForAnOrder(LocalDateTime dateTime); + + List getScheduledSlots(List orders); +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/WardDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/WardDAO.java new file mode 100644 index 0000000..c08b66a --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/WardDAO.java @@ -0,0 +1,19 @@ +package org.openmrs.module.ipd.api.dao; + +import org.openmrs.Location; +import org.openmrs.Provider; +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.openmrs.module.ipd.api.model.WardPatientsSummary; + +import java.util.Date; +import java.util.List; + +public interface WardDAO { + + List searchAdmittedPatients(Location location, List searchKeys, String searchValue, String sortBy); + + List getAdmittedPatients(Location location, Provider provider, Date currentDateTime, String sortBy); + + WardPatientsSummary getWardPatientSummary(Location location, Provider provider, Date currentDateTime); + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAO.java new file mode 100644 index 0000000..f696dbc --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAO.java @@ -0,0 +1,41 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.hibernate.query.Query; +import org.openmrs.Visit; +import org.openmrs.api.db.DAOException; +import org.openmrs.module.ipd.api.dao.CareTeamDAO; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class HibernateCareTeamDAO implements CareTeamDAO { + + private static final Logger log = LoggerFactory.getLogger(HibernateCareTeamDAO.class); + private final SessionFactory sessionFactory; + + @Autowired + public HibernateCareTeamDAO(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Override + public CareTeam saveCareTeam(CareTeam careTeam) throws DAOException { + sessionFactory.getCurrentSession().saveOrUpdate(careTeam); + return careTeam; + } + + @Override + public CareTeam getCareTeamByVisit(Visit visit) throws DAOException { + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM CareTeam careteam " + + "WHERE careteam.visit = :visit "); + + query.setParameter("visit", visit); + + return (CareTeam) query.uniqueResult(); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAO.java new file mode 100644 index 0000000..9557690 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAO.java @@ -0,0 +1,44 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.hibernate.query.Query; +import org.openmrs.api.db.DAOException; +import org.openmrs.module.ipd.api.dao.ReferenceDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public class HibernateReferenceDAO implements ReferenceDAO { + + private static final Logger log = LoggerFactory.getLogger(HibernateReferenceDAO.class); + + private final SessionFactory sessionFactory; + + @Autowired + public HibernateReferenceDAO(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Override + public Optional getReferenceByTypeAndTargetUUID(String type, String targetUuid) throws DAOException { + + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM Reference ref WHERE ref.type=:type and ref.targetUuid=:targetUuid"); + + query.setParameter("type", type); + query.setParameter("targetUuid", targetUuid); + + return query.uniqueResultOptional(); + } + + @Override + public Reference saveReference(Reference reference) throws DAOException { + sessionFactory.getCurrentSession().saveOrUpdate(reference); + return reference; + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAO.java new file mode 100644 index 0000000..5a15768 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAO.java @@ -0,0 +1,47 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.hibernate.query.Query; +import org.openmrs.Visit; +import org.openmrs.api.db.DAOException; +import org.openmrs.module.ipd.api.dao.ScheduleDAO; +import org.openmrs.module.ipd.api.model.Schedule; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +@Repository +public class HibernateScheduleDAO implements ScheduleDAO { + + private static final Logger log = LoggerFactory.getLogger(HibernateScheduleDAO.class); + private final SessionFactory sessionFactory; + + @Autowired + public HibernateScheduleDAO(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Override + public Schedule getSchedule(Integer scheduleId) throws DAOException { + return sessionFactory.getCurrentSession().get(Schedule.class, scheduleId); + } + + @Override + public Schedule saveSchedule(Schedule schedule) throws DAOException { + sessionFactory.getCurrentSession().saveOrUpdate(schedule); + return schedule; + } + + @Override + public Schedule getScheduleByVisit(Visit visit) throws DAOException { + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM Schedule schedule " + + "WHERE schedule.visit = :visit " + + "and active = 1"); + + query.setParameter("visit", visit); + + return (Schedule) query.uniqueResult(); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAO.java new file mode 100644 index 0000000..845e49a --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAO.java @@ -0,0 +1,247 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.query.Query; +import org.openmrs.Concept; +import org.openmrs.Order; +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.dao.SlotDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Slot; +import org.hibernate.SessionFactory; +import org.openmrs.api.db.DAOException; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.List; + +@Repository +public class HibernateSlotDAO implements SlotDAO { + + private static final Logger log = LoggerFactory.getLogger(HibernateSlotDAO.class); + + private final SessionFactory sessionFactory; + + @Autowired + public HibernateSlotDAO(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + @Override + public Slot getSlot(Integer slotId) throws DAOException { + return sessionFactory.getCurrentSession().get(Slot.class, slotId); + } + + @Override + public Slot getSlotByUUID(String uuid) throws DAOException { + Slot s = (Slot)this.sessionFactory.getCurrentSession().createQuery("from Slot s where s.uuid = :uuid").setString("uuid", uuid).uniqueResult(); + return s; + } + + @Override + public Slot saveSlot(Slot slot) throws DAOException { + sessionFactory.getCurrentSession().saveOrUpdate(slot); + return slot; + } + + @Override + public List getSlotsBySubjectReferenceIdAndForDateAndServiceType(Reference subject, LocalDate forDate, Concept serviceType) { + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM Slot slot WHERE slot.schedule.subject=:subject and YEAR(slot.startDateTime)=:forYear and MONTH(slot.startDateTime)=:forMonth and DAY(slot.startDateTime)=:forDay and slot.serviceType=:serviceType and slot.voided=0"); + + query.setParameter("subject", subject); + query.setParameter("forYear", forDate.getYear()); + query.setParameter("forMonth", forDate.getMonthValue()); + query.setParameter("forDay", forDate.getDayOfMonth()); + query.setParameter("serviceType", serviceType); + + return query.getResultList(); + } + + @Override + public List getSlotsBySubjectReferenceIdAndServiceType(Reference subject, Concept serviceType) { + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM Slot slot WHERE slot.schedule.subject=:subject and slot.serviceType=:serviceType and slot.voided=0"); + + query.setParameter("subject", subject); + query.setParameter("serviceType", serviceType); + + return query.getResultList(); + } + + @Override + public List getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(Reference subject, Concept serviceType, List orderUuids) { + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM Slot slot " + + "WHERE slot.schedule.subject=:subject and " + + "slot.serviceType=:serviceType and" + + " slot.order.uuid IN :orderUuids and " + + "slot.voided = 0"); + + query.setParameter("subject", subject); + query.setParameter("serviceType", serviceType); + query.setParameter("orderUuids", orderUuids); + + return query.getResultList(); + } + + @Override + public List getSlotsByPatientAndVisitAndServiceType(Reference subject, Visit visit, Concept serviceType) { + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM Slot slot WHERE slot.schedule.subject=:subject and slot.schedule.visit=:visit and slot.serviceType=:serviceType"); + + query.setParameter("subject", subject); + query.setParameter("visit", visit); + query.setParameter("serviceType", serviceType); + + return query.getResultList(); + } + @Override + public List getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit, Concept serviceType){ + Query query = sessionFactory.getCurrentSession() + .createQuery("FROM Slot slot WHERE slot.schedule.subject=:subject and ((slot.startDateTime BETWEEN :startDate and :endDate) or (slot.serviceType = :serviceType)) and slot.voided=0 and slot.schedule.visit=:visit"); + + query.setParameter("subject", subject); + query.setParameter("startDate", localStartDate); + query.setParameter("endDate", localEndDate); + query.setParameter("visit", visit); + query.setParameter("serviceType", serviceType); + + return query.getResultList(); + } + + @Override + public List getSlotsBySubjectIncludingAdministeredTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit) { + Query query = sessionFactory.getCurrentSession() + .createQuery("SELECT slot FROM Slot slot " + + "LEFT JOIN slot.medicationAdministration medAdmin " + + "WHERE (slot.schedule.subject = :subject) AND slot.voided = 0 AND slot.schedule.visit=:visit AND " + + "(((slot.startDateTime BETWEEN :startDateTime AND :endDateTime) AND " + + "(medAdmin.administeredDateTime BETWEEN :startDate AND :endDate or medAdmin is null)) OR " + + "(medAdmin is not null AND " + + "(medAdmin.administeredDateTime BETWEEN :startDate AND :endDate)))"); + + query.setParameter("subject", subject); + query.setParameter("visit", visit); + query.setParameter("startDateTime", localStartDate); + query.setParameter("endDateTime", localEndDate); + query.setParameter("startDate", DateTimeUtil.convertLocalDateTimeDate(localStartDate)); + query.setParameter("endDate", DateTimeUtil.convertLocalDateTimeDate(localEndDate)); + + return query.getResultList(); + } + + @Override + public List getSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate, LocalDateTime localEndDate) { + Query query = sessionFactory.getCurrentSession() + .createQuery("SELECT slot FROM Slot slot \n" + + "INNER JOIN slot.schedule.subject reference \n" + + "INNER JOIN slot.schedule.visit visit \n" + + "WHERE (slot.startDateTime BETWEEN :startDate and :endDate) \n" + + "and slot.voided=0 \n" + + "and visit.stopDatetime is NULL \n" + + "and reference.type = 'org.openmrs.Patient' \n" + + "and reference.targetUuid in (:patientUuidList)"); + + query.setParameterList("patientUuidList", patientUuidList); + query.setParameter("startDate", localStartDate); + query.setParameter("endDate", localEndDate); + + return query.getResultList(); + } + + @Override + public List getImmediatePreviousSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate) { + String maxDateTimeSubquery = "SELECT s.order, MAX(s.startDateTime) AS maxStartDateTime " + + "FROM Slot s " + + "INNER JOIN s.schedule.subject reference " + + "INNER JOIN s.schedule.visit visit " + + "WHERE s.startDateTime < :startDate " + + "AND s.voided = 0 " + + "AND visit.stopDatetime IS NULL " + + "AND reference.type = 'org.openmrs.Patient' " + + "AND reference.targetUuid IN (:patientUuidList) " + + "GROUP BY s.order"; + + String latestPreviousSlotsQuery = "SELECT slot " + + "FROM Slot slot " + + "INNER JOIN slot.schedule.subject reference " + + "INNER JOIN slot.schedule.visit visit " + + "WHERE slot.startDateTime < :startDate " + + "AND slot.voided = 0 " + + "AND visit.stopDatetime IS NULL " + + "AND reference.type = 'org.openmrs.Patient' " + + "AND reference.targetUuid IN (:patientUuidList) " + + "AND (slot.order, slot.startDateTime) IN " + + "( " + maxDateTimeSubquery + " ) "; + + Query query = sessionFactory.getCurrentSession() + .createQuery(latestPreviousSlotsQuery); + + query.setParameterList("patientUuidList", patientUuidList); + query.setParameter("startDate", localStartDate); + + return query.getResultList(); + } + + @Override + public List getSlotDurationForPatientsByOrder(List orders, List serviceTypes) { + Query query = sessionFactory.getCurrentSession() + .createQuery("SELECT \n" + + " slot.order AS order,\n" + + " MIN(slot.startDateTime) AS minStartDateTime,\n" + + " MAX(slot.startDateTime) AS maxStartDateTime\n" + + "FROM\n" + + " Slot slot\n" + + "INNER JOIN\n" + + " slot.schedule.subject reference\n" + + "INNER JOIN\n" + + " slot.schedule.visit visit \n" + + "WHERE\n" + + " slot.voided = 0\n" + + " AND slot.serviceType IN (:serviceTypes)\n" + + " AND visit.stopDatetime is NULL \n" + + " AND slot.order IN (:orders)\n" + + "GROUP BY\n" + + " slot.order"); + + query.setParameterList("orders", orders); + query.setParameterList("serviceTypes", serviceTypes); + return query.getResultList(); + } + + @Override + public List getLastSlotForAnOrder(LocalDateTime localStartDateTime){ + Query query = sessionFactory.getCurrentSession() + .createQuery("SELECT s from Slot s\n" + + "where s.startDateTime IN (SELECT MAX(s1.startDateTime) \n" + + "from Slot s1 WHERE \n" + + "s1.startDateTime>:previousDate \n" + + "and s1.startDateTime<=:currentDate \n" + + "and s1.order IS NOT NULL \n" + + "and s1.order = s.order \n" + + "and s1.voided = 0 \n" + + "GROUP by s1.order \n) " + + "and s.voided = 0 \n" + + "GROUP by s.order"); + + query.setParameter("currentDate", localStartDateTime); + query.setParameter("previousDate", localStartDateTime.minus(1, ChronoUnit.DAYS)); + return query.getResultList(); + } + + @Override + public List getScheduledSlots(List orders){ + Query query = sessionFactory.getCurrentSession() + .createQuery("From Slot slot WHERE slot.order IN (:order) and slot.status=:status and slot.voided=0"); + + query.setParameter("order", orders); + query.setParameter("status", Slot.SlotStatus.SCHEDULED); + return query.getResultList(); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java new file mode 100644 index 0000000..599ffa3 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java @@ -0,0 +1,240 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.openmrs.Location; +import org.openmrs.Provider; +import org.openmrs.module.ipd.api.dao.WardDAO; +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.openmrs.module.ipd.api.model.WardPatientsSummary; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import org.hibernate.query.Query; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Repository +public class HibernateWardDAO implements WardDAO { + + private static final Logger log = LoggerFactory.getLogger(HibernateWardDAO.class); + + private final SessionFactory sessionFactory; + + @Autowired + public HibernateWardDAO(SessionFactory sessionFactory) { + this.sessionFactory = sessionFactory; + } + + private static String generateOrderByClauseForSorting(String sortBy) { + String orderBy = " "; + + sortBy = sortBy != null ? sortBy : "default"; + + switch (sortBy) { + case "bedNumber": + orderBy += "ORDER BY assignment.bed.bedNumber "; + break; + default: + orderBy += "ORDER BY assignment.startDatetime desc "; + break; + } + return orderBy; + } + + @Override + public List getAdmittedPatients(Location location, Provider provider, Date dateTime, String sortBy) { + Session session = this.sessionFactory.getCurrentSession(); + try { + String queryString = "select NEW org.openmrs.module.ipd.api.model.AdmittedPatient(assignment," + + "(COUNT(DISTINCT o.orderId) - COUNT (DISTINCT s.order.orderId)), careTeam)" + + "from org.openmrs.module.bedmanagement.entity.BedPatientAssignment assignment " + + "JOIN org.openmrs.Visit v on v.patient = assignment.patient " + + "JOIN org.openmrs.Encounter e on e.visit = v " + + "LEFT JOIN CareTeam careTeam on careTeam.visit = v " + + "JOIN org.openmrs.module.bedmanagement.entity.BedLocationMapping locmap on locmap.bed = assignment.bed " + + "JOIN org.openmrs.Location l on locmap.location = l " + + "LEFT JOIN careTeam.participants ctp ON ctp.voided = 0 " + + "LEFT JOIN org.openmrs.Order o on o.encounter = e and o.dateStopped is null and o.action!='DISCONTINUE' and o.careSetting.careSettingId = 2 " + + "LEFT JOIN Slot s on s.order = o " + + "where assignment.endDatetime is null and v.stopDatetime is null "; + + if(location != null){ + queryString += "and l.parentLocation = :location "; + } + + if (provider != null) { + queryString += "and ctp.provider = :provider "; + } + + if (dateTime != null) { + queryString += "and :dateTime between ctp.startTime and ctp.endTime "; + } + + String groupBy = " GROUP BY assignment.patient, v "; + + String orderBy = generateOrderByClauseForSorting(sortBy); + + String finalQuery = queryString + groupBy + orderBy; + + Query query = session.createQuery(finalQuery); + + if(location != null) { + query.setParameter("location", location); + } + + if (provider != null) { + query.setParameter("provider", provider); + } + + if (dateTime != null) { + query.setParameter("dateTime", dateTime); + } + + return query.getResultList(); + } + catch (Exception ex){ + log.error("Exception at WardDAO getAdmittedPatients ",ex.getStackTrace()); + } + return new ArrayList<>(); + } + + @Override + public WardPatientsSummary getWardPatientSummary(Location location, Provider provider, Date dateTime) { + Session session = this.sessionFactory.getCurrentSession(); + try { + Query totalPatientsQuery = session.createQuery( + "SELECT COUNT(assignment) " + + "FROM org.openmrs.module.bedmanagement.entity.BedPatientAssignment assignment " + + "JOIN org.openmrs.module.bedmanagement.entity.BedLocationMapping locmap ON locmap.bed = assignment.bed " + + "JOIN org.openmrs.Location l ON locmap.location = l " + + "JOIN org.openmrs.Visit v ON v.patient = assignment.patient " + + "WHERE assignment.endDatetime IS NULL AND v.stopDatetime IS NULL AND l.parentLocation = :location" + ); + + totalPatientsQuery.setParameter("location", location); + + Long totalPatients = (Long) totalPatientsQuery.uniqueResult(); + + Query totalProviderPatientsQuery = session.createQuery( + "SELECT COUNT(DISTINCT CASE WHEN ctp.provider = :provider THEN assignment.patient ELSE null END) " + + "FROM org.openmrs.module.bedmanagement.entity.BedPatientAssignment assignment " + + "JOIN org.openmrs.module.bedmanagement.entity.BedLocationMapping locmap ON locmap.bed = assignment.bed " + + "JOIN org.openmrs.Location l ON locmap.location = l " + + "JOIN org.openmrs.Visit v ON v.patient = assignment.patient " + + "LEFT JOIN CareTeam careTeam ON careTeam.patient = v.patient " + + "LEFT JOIN careTeam.participants ctp ON ctp.voided = 0 " + + "WHERE assignment.endDatetime IS NULL AND v.stopDatetime IS NULL AND l.parentLocation = :location " + + "AND (ctp.provider = :provider AND :dateTime BETWEEN ctp.startTime AND ctp.endTime)" + ); + + totalProviderPatientsQuery.setParameter("location", location); + totalProviderPatientsQuery.setParameter("provider", provider); + totalProviderPatientsQuery.setParameter("dateTime", dateTime); + + Long totalProviderPatients = (Long) totalProviderPatientsQuery.uniqueResult(); + + return new WardPatientsSummary(totalPatients, totalProviderPatients); + } catch (Exception e) { + log.error("Exception at WardDAO getAdmittedPatients ", e); + } + + return new WardPatientsSummary(); + } + + @Override + public List searchAdmittedPatients(Location location, List searchKeys, String searchValue, String sortBy) { + try { + Session session = sessionFactory.getCurrentSession(); + + String selectQuery = "select NEW org.openmrs.module.ipd.api.model.AdmittedPatient(assignment," + + "(COUNT(DISTINCT o.orderId) - COUNT (DISTINCT s.order.orderId)),careTeam) " + + "from org.openmrs.module.bedmanagement.entity.BedPatientAssignment assignment " + + "JOIN org.openmrs.Visit v on v.patient = assignment.patient " + + "JOIN org.openmrs.Patient p on assignment.patient = p " + + "JOIN org.openmrs.Person pr on pr.personId=p.patientId " + + "JOIN org.openmrs.Encounter e on e.visit = v " + + "LEFT JOIN CareTeam careTeam on careTeam.visit = v "+ + "JOIN org.openmrs.module.bedmanagement.entity.BedLocationMapping locmap on locmap.bed = assignment.bed " + + "JOIN org.openmrs.Location l on locmap.location = l " + + "LEFT JOIN org.openmrs.Order o on o.encounter = e " + + "LEFT JOIN Slot s on s.order = o "; + + // Construct additional joins and where clause based on search keys + StringBuilder additionalJoins = new StringBuilder(""); + StringBuilder whereClause = new StringBuilder(""); + generateSQLSearchConditions(searchKeys,additionalJoins,whereClause); + + // Construct group by clause + String groupBy = " GROUP BY assignment.patient, v "; + + String orderBy = generateOrderByClauseForSorting(sortBy); + + // Create query + Query query = session.createQuery(selectQuery + additionalJoins + whereClause + groupBy + orderBy); + + // Set parameters + query.setParameter("location", location); + setQueryParameters(query, searchKeys, searchValue); + + return query.getResultList(); + } catch (Exception ex) { + log.error("Exception at WardDAO searching ", ex.getMessage()); + return new ArrayList<>(); + } + } + + private void generateSQLSearchConditions(List searchKeys,StringBuilder additionalJoins,StringBuilder whereClause) { + whereClause.append("where (assignment.endDatetime is null and v.stopDatetime is null and l.parentLocation = :location)"); + if (searchKeys != null && !searchKeys.isEmpty()) { + whereClause.append(" and ("); + for (int i = 0; i < searchKeys.size(); i++) { + switch (searchKeys.get(i)) { + case "bedNumber": + whereClause.append(" assignment.bed.bedNumber LIKE :bedNumber "); + break; + case "patientIdentifier": + additionalJoins.append(" JOIN p.identifiers pi "); + whereClause.append(" pi.identifier LIKE :patientIdentifier "); + break; + case "patientName": + additionalJoins.append(" JOIN pr.names prn "); + whereClause.append(" (prn.givenName LIKE :patientName or prn.middleName LIKE :patientName or prn.familyName LIKE :patientName) "); + break; + } + if (i < searchKeys.size() - 1) { + whereClause.append(" or "); + } + } + whereClause.append(" ) "); + } + } + + private void setQueryParameters(Query query, List searchKeys, String searchValue) { + if (searchKeys != null && searchValue != null && !searchValue.isEmpty()) { + if (searchKeys.contains("bedNumber")) { + query.setParameter("bedNumber", "%" + searchValue + "%"); + } + if (searchKeys.contains("patientIdentifier")) { + query.setParameter("patientIdentifier", "%" + searchValue + "%"); + } + if (searchKeys.contains("patientName")) { + query.setParameter("patientName", "%" + searchValue + "%"); + } + } + } + + private StringBuilder appendORIfMoreSearchKeysPresent(int i,int size,StringBuilder whereClause){ + if (size==(i+1)){ + return whereClause; + } + return whereClause.append(" or "); + } + + + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java b/api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java new file mode 100644 index 0000000..fc58629 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/ConfigLoader.java @@ -0,0 +1,41 @@ +package org.openmrs.module.ipd.api.events; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.openmrs.module.ipd.api.events.model.ConfigDetail; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.FileSystemResource; +import org.springframework.stereotype.Component; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +@Component +@Slf4j +public class ConfigLoader { + private List configs = new ArrayList<>(); + + private ObjectMapper objectMapper = new ObjectMapper(); + + @Value("${config-file.path}") + private String routeConfigurationFileLocation; + + public List getConfigs() { + if (configs.isEmpty()) { + loadConfiguration(); + } + return this.configs; + } + + private void loadConfiguration() { + try { + File routeConfigurationFile = new FileSystemResource(routeConfigurationFileLocation).getFile(); + this.configs = objectMapper.readValue(routeConfigurationFile, new TypeReference>() {}); + } catch (IOException exception) { + log.error("Failed to load configuration for file : " + routeConfigurationFileLocation, exception); + } + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventManager.java b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventManager.java new file mode 100644 index 0000000..d98f77e --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventManager.java @@ -0,0 +1,36 @@ +package org.openmrs.module.ipd.api.events; + +import org.openmrs.module.ipd.api.events.model.IPDEvent; +import org.openmrs.module.ipd.api.events.factory.IPDEventFactory; +import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; +import org.openmrs.module.ipd.api.events.model.IPDEventType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class IPDEventManager { + @Autowired + ConfigLoader configLoader; + + @Autowired + IPDEventFactory eventFactory; + + public IPDEventType getEventTypeForEncounter(String type) { + switch (type) { + case "ADMISSION": + return IPDEventType.PATIENT_ADMIT; + case "SHIFT_START_TASK": + return IPDEventType.SHIFT_START_TASK; + case "ROLLOVER_TASK": + return IPDEventType.ROLLOVER_TASK; + default: + return null; + } + } + + public void processEvent(IPDEvent event) { + IPDEventHandler handler = eventFactory.createEventHandler(event.getIpdEventType()); + handler.handleEvent(event); + } + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java new file mode 100644 index 0000000..b9da7ab --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java @@ -0,0 +1,22 @@ +package org.openmrs.module.ipd.api.events; + +import org.openmrs.module.fhir2.model.FhirTask; +import org.openmrs.module.fhirExtension.web.contract.TaskRequest; +import org.openmrs.module.ipd.api.events.model.IPDEvent; + +import java.util.Date; + +public class IPDEventUtils { + + public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, String name, String taskType) { + TaskRequest taskRequest = new TaskRequest(); + taskRequest.setName(name); + taskRequest.setTaskType(taskType); + taskRequest.setEncounterUuid(ipdEvent.getEncounterUuid()); + taskRequest.setPatientUuid(ipdEvent.getPatientUuid()); + taskRequest.setRequestedStartTime(new Date()); + taskRequest.setIntent(FhirTask.TaskIntent.ORDER); + taskRequest.setStatus(FhirTask.TaskStatus.REQUESTED); + return taskRequest; + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/factory/IPDEventFactory.java b/api/src/main/java/org/openmrs/module/ipd/api/events/factory/IPDEventFactory.java new file mode 100644 index 0000000..125fe81 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/factory/IPDEventFactory.java @@ -0,0 +1,8 @@ +package org.openmrs.module.ipd.api.events.factory; + +import org.openmrs.module.ipd.api.events.model.IPDEventType; +import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; + +public interface IPDEventFactory { + IPDEventHandler createEventHandler(IPDEventType eventType); +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/factory/impl/IPDEventFactoryImpl.java b/api/src/main/java/org/openmrs/module/ipd/api/events/factory/impl/IPDEventFactoryImpl.java new file mode 100644 index 0000000..cb13de8 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/factory/impl/IPDEventFactoryImpl.java @@ -0,0 +1,38 @@ +package org.openmrs.module.ipd.api.events.factory.impl; + +import org.openmrs.module.ipd.api.events.handler.impl.ShiftStartTaskEventHandler; +import org.openmrs.module.ipd.api.events.model.IPDEventType; +import org.openmrs.module.ipd.api.events.factory.IPDEventFactory; +import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; +import org.openmrs.module.ipd.api.events.handler.impl.PatientAdmitEventHandler; +import org.openmrs.module.ipd.api.events.handler.impl.RolloverTaskEventHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class IPDEventFactoryImpl implements IPDEventFactory { + + @Autowired + PatientAdmitEventHandler patientAdmitEventHandler; + + @Autowired + ShiftStartTaskEventHandler shiftStartTaskEventHandler; + + @Autowired + RolloverTaskEventHandler rolloverTaskEventHandler; + + @Override + public IPDEventHandler createEventHandler(IPDEventType eventType) { + switch (eventType) { + case PATIENT_ADMIT: + return patientAdmitEventHandler; + case SHIFT_START_TASK: + return shiftStartTaskEventHandler; + case ROLLOVER_TASK: + return rolloverTaskEventHandler; + default: + throw new IllegalArgumentException("Unsupported event type: " + eventType); + } + } + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/IPDEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/IPDEventHandler.java new file mode 100644 index 0000000..4c75fdf --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/IPDEventHandler.java @@ -0,0 +1,7 @@ +package org.openmrs.module.ipd.api.events.handler; + +import org.openmrs.module.ipd.api.events.model.IPDEvent; + +public interface IPDEventHandler { + void handleEvent(IPDEvent event); +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java new file mode 100644 index 0000000..9828da5 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java @@ -0,0 +1,52 @@ +package org.openmrs.module.ipd.api.events.handler.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.module.fhirExtension.model.Task; +import org.openmrs.module.fhirExtension.service.TaskService; +import org.openmrs.module.fhirExtension.web.contract.TaskRequest; +import org.openmrs.module.fhirExtension.web.mapper.TaskMapper; +import org.openmrs.module.ipd.api.events.ConfigLoader; +import org.openmrs.module.ipd.api.events.IPDEventUtils; +import org.openmrs.module.ipd.api.events.model.ConfigDetail; +import org.openmrs.module.ipd.api.events.model.IPDEvent; +import org.openmrs.module.ipd.api.events.model.TaskDetail; +import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class PatientAdmitEventHandler implements IPDEventHandler { + + private final Log log = LogFactory.getLog(this.getClass()); + + @Autowired + ConfigLoader configLoader; + + @Autowired + private TaskMapper taskMapper; + + @Autowired + private TaskService taskService; + + @Override + public void handleEvent(IPDEvent event) { + List configList = configLoader.getConfigs(); + ConfigDetail eventConfig = configList.stream() + .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .findFirst() + .orElse(null); + if (eventConfig != null) { + for(TaskDetail taskDetail : eventConfig.getTasks()) { + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), "nursing_activity_system"); + Task task = taskMapper.fromRequest(taskRequest); + taskService.saveTask(task); + log.info("Task created " + taskDetail.getName()); + } + } + + + } +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java new file mode 100644 index 0000000..16ce44d --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java @@ -0,0 +1,57 @@ +package org.openmrs.module.ipd.api.events.handler.impl; + +import org.openmrs.module.fhir2.model.FhirTask; +import org.openmrs.module.fhirExtension.dao.TaskRequestedPeriodDao; +import org.openmrs.module.fhirExtension.model.FhirTaskRequestedPeriod; +import org.openmrs.module.fhirExtension.model.Task; +import org.openmrs.module.fhirExtension.model.TaskSearchRequest; +import org.openmrs.module.fhirExtension.service.TaskService; +import org.openmrs.module.ipd.api.events.ConfigLoader; +import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; +import org.openmrs.module.ipd.api.events.model.ConfigDetail; +import org.openmrs.module.ipd.api.events.model.IPDEvent; +import org.openmrs.module.ipd.api.events.model.TaskDetail; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@Component +public class RolloverTaskEventHandler implements IPDEventHandler { + + @Autowired + ConfigLoader configLoader; + @Autowired + private TaskService taskService; + @Autowired + private TaskRequestedPeriodDao taskRequestedPeriodDao; + private static final String TASK_STATUS = "REQUESTED"; + + @Override + public void handleEvent(IPDEvent event) { + List configList = configLoader.getConfigs(); + ConfigDetail eventConfig = configList.stream() + .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .findFirst() + .orElse(null); + + List taskNames = eventConfig.getTasks().stream() + .map(TaskDetail::getName) + .collect(Collectors.toList()); + List taskStatuses= Arrays.asList(FhirTask.TaskStatus.REQUESTED); + List rolloverTasks = taskService.searchTasks(new TaskSearchRequest(taskNames,taskStatuses)); + List fhirTaskRequestedPeriods = new ArrayList(); + for (Task task : rolloverTasks) { + if (task.getFhirTaskRequestedPeriod() != null) { + FhirTaskRequestedPeriod fhirTaskRequestedPeriod = task.getFhirTaskRequestedPeriod(); + fhirTaskRequestedPeriod.setRequestedStartTime(new Date()); + fhirTaskRequestedPeriods.add(fhirTaskRequestedPeriod); + } + } + taskRequestedPeriodDao.update(fhirTaskRequestedPeriods); + } +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java new file mode 100644 index 0000000..e97d620 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java @@ -0,0 +1,60 @@ +package org.openmrs.module.ipd.api.events.handler.impl; + +import org.openmrs.module.fhirExtension.model.Task; +import org.openmrs.module.fhirExtension.service.TaskService; +import org.openmrs.module.fhirExtension.web.contract.TaskRequest; +import org.openmrs.module.fhirExtension.web.mapper.TaskMapper; +import org.openmrs.module.ipd.api.events.ConfigLoader; +import org.openmrs.module.ipd.api.events.IPDEventUtils; +import org.openmrs.module.ipd.api.events.handler.IPDEventHandler; +import org.openmrs.module.ipd.api.events.model.ConfigDetail; +import org.openmrs.module.ipd.api.events.model.IPDEvent; +import org.openmrs.module.ipd.api.events.model.TaskDetail; +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.openmrs.module.ipd.api.service.WardService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class ShiftStartTaskEventHandler implements IPDEventHandler { + + @Autowired + ConfigLoader configLoader; + @Autowired + private TaskMapper taskMapper; + @Autowired + private TaskService taskService; + @Autowired + private WardService wardService; + + @Override + public void handleEvent(IPDEvent event) { + List admittedPatients = wardService.getAdmittedPatients(); + ConfigDetail eventConfig = getEventConfig(event); + List tasks = new ArrayList(); + for(AdmittedPatient admittedPatient: admittedPatients){ + String patientUuid = admittedPatient.getBedPatientAssignment().getPatient().getUuid(); + IPDEvent ipdEvent = new IPDEvent(null, patientUuid, event.getIpdEventType()); + for(TaskDetail taskDetail : eventConfig.getTasks()) { + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), "nursing_activity_system"); + Task task = taskMapper.fromRequest(taskRequest); + tasks.add(task); + } + } + if(tasks.size() > 0){ + taskService.saveTask(tasks); + } + } + + private ConfigDetail getEventConfig(IPDEvent event){ + List configList = configLoader.getConfigs(); + ConfigDetail eventConfig = configList.stream() + .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .findFirst() + .orElse(null); + return eventConfig; + } +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java new file mode 100644 index 0000000..284f2a5 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java @@ -0,0 +1,19 @@ +package org.openmrs.module.ipd.api.events.model; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class ConfigDetail { + private String type; + private List tasks; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEvent.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEvent.java new file mode 100644 index 0000000..dc5cf9b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEvent.java @@ -0,0 +1,18 @@ +package org.openmrs.module.ipd.api.events.model; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class IPDEvent { + private String encounterUuid; + private String patientUuid; + private IPDEventType ipdEventType; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEventType.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEventType.java new file mode 100644 index 0000000..e74030c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/IPDEventType.java @@ -0,0 +1,7 @@ +package org.openmrs.module.ipd.api.events.model; + +public enum IPDEventType { + PATIENT_ADMIT, + SHIFT_START_TASK, + ROLLOVER_TASK; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java new file mode 100644 index 0000000..7b1426f --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java @@ -0,0 +1,16 @@ +package org.openmrs.module.ipd.api.events.model; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class TaskDetail { + private String name; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/AdmittedPatient.java b/api/src/main/java/org/openmrs/module/ipd/api/model/AdmittedPatient.java new file mode 100644 index 0000000..5210ed5 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/AdmittedPatient.java @@ -0,0 +1,27 @@ +package org.openmrs.module.ipd.api.model; + +import org.openmrs.module.bedmanagement.entity.BedPatientAssignment; + +public class AdmittedPatient { + + private BedPatientAssignment bedPatientAssignment; + private Long newTreatments; + private CareTeam careTeam; + + + public AdmittedPatient(BedPatientAssignment bedPatientAssignment, Long newTreatments, CareTeam careTeam){ + this.bedPatientAssignment=bedPatientAssignment; + this.newTreatments=newTreatments; + this.careTeam=careTeam; + } + + public BedPatientAssignment getBedPatientAssignment() { + return bedPatientAssignment; + } + + public Long getNewTreatments() { + return newTreatments; + } + + public CareTeam getCareTeam() { return careTeam; } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/CareTeam.java b/api/src/main/java/org/openmrs/module/ipd/api/model/CareTeam.java new file mode 100644 index 0000000..9f6f47c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/CareTeam.java @@ -0,0 +1,105 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.openmrs.BaseChangeableOpenmrsData; +import org.openmrs.Concept; +import org.openmrs.Patient; +import org.openmrs.Visit; + +import javax.persistence.*; +import java.util.Date; +import java.util.Set; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) +@Entity +@Table(name = "care_team") +public class CareTeam extends BaseChangeableOpenmrsData { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "care_team_id") + private Integer careTeamId; + + /** + * FHIR:subject + * Patient for Whom care team is for + */ + @ManyToOne(optional = true) + @JoinColumn(name = "patient_id") + private Patient patient; + + @OneToOne + @JoinColumn(name = "visit_id", referencedColumnName = "visit_id") + private Visit visit; + + /** + * FHIR:period.start + * Starting time with inclusive boundary + */ + @Column(name = "start_time") + private Date startTime; + + /** + * FHIR:period.end + * Ending time with inclusive boundary, if not ongoing + */ + @Column(name = "end_time") + private Date endTime; + + /** + * FHIR:performer + * @see + * https://build.fhir.org/careteam-definitions.html#CareTeam.participant + * Identifies all people and organizations who are expected to be involved in the care team. + */ + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "care_team_id") + private Set participants; + + + @Override + public Integer getId() { + return this.careTeamId; + } + + @Override + public void setId(Integer careTeamId) { + this.careTeamId=careTeamId; + } + + public Patient getPatient() { + return patient; + } + + public void setPatient(Patient patient) { + this.patient = patient; + } + + public Visit getVisit() { + return visit; + } + + public void setVisit(Visit visit) { + this.visit = visit; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/CareTeamParticipant.java b/api/src/main/java/org/openmrs/module/ipd/api/model/CareTeamParticipant.java new file mode 100644 index 0000000..6cb82cc --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/CareTeamParticipant.java @@ -0,0 +1,99 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.openmrs.BaseChangeableOpenmrsData; +import org.openmrs.Provider; + +import javax.persistence.*; +import java.util.Date; +import java.util.Objects; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) +@Entity +@Table(name = "care_team_participant") +public class CareTeamParticipant extends BaseChangeableOpenmrsData { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "care_team_participant_id") + private Integer careTeamParticipantId; + + /** + * FHIR:member + * Indicates Who is involved . + */ + @OneToOne(optional = false) + @JoinColumn(name = "provider_id") + private Provider provider; + + /** + * FHIR:coverage.coveragePeriod.start + * Starting time with inclusive boundary + */ + @Column(name = "start_time") + private Date startTime; + + /** + * FHIR:coverage.coveragePeriod.end + * Ending time with inclusive boundary, if not ongoing + */ + @Column(name = "end_time") + private Date endTime; + + @Override + public Integer getId() { + return getCareTeamParticipantId(); + } + + @Override + public void setId(Integer careTeamParticipantId) { + this.careTeamParticipantId=careTeamParticipantId; + } + + public Provider getProvider() { + return provider; + } + + public void setProvider(Provider provider) { + this.provider = provider; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if (obj != null && this.getClass() == obj.getClass()) { + CareTeamParticipant other = (CareTeamParticipant) obj; + return Objects.equals(this.getUuid(), other.getUuid()); + } else { + return false; + } + } + + public int hashCode() { + int hash = Objects.hash(new Object[]{this.getUuid()}); + return hash; + } + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/IPDPatientDetails.java b/api/src/main/java/org/openmrs/module/ipd/api/model/IPDPatientDetails.java new file mode 100644 index 0000000..2805000 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/IPDPatientDetails.java @@ -0,0 +1,17 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class IPDPatientDetails { + + private List admittedPatients; + private Integer patientCount; + +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/IPDWardPatientDetails.java b/api/src/main/java/org/openmrs/module/ipd/api/model/IPDWardPatientDetails.java new file mode 100644 index 0000000..63f4a52 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/IPDWardPatientDetails.java @@ -0,0 +1,17 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class IPDWardPatientDetails { + + private List activePatients; + private WardPatientsSummary ipdWardWardPatientsSummary; + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/Reference.java b/api/src/main/java/org/openmrs/module/ipd/api/model/Reference.java new file mode 100644 index 0000000..2889cac --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/Reference.java @@ -0,0 +1,40 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import org.openmrs.BaseOpenmrsMetadata; +import org.openmrs.OpenmrsObject; + +import javax.persistence.*; + +@Getter +@Setter +@Entity +@Table(name = "ipd_reference") +public class Reference extends BaseOpenmrsMetadata { + + private static final long serialVersionUID = 1L; + + public Reference() { + setName(""); + } + + public Reference(String type, String targetUuid) { + this.type = type; + this.targetUuid = targetUuid; + this.setName(type + "/" + targetUuid); + } + + @EqualsAndHashCode.Include + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "reference_id") + private Integer id; + + @Column(name = "target_type", nullable = false) + private String type; + + @Column(name = "target_uuid", nullable = false) + private String targetUuid; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/Schedule.java b/api/src/main/java/org/openmrs/module/ipd/api/model/Schedule.java new file mode 100644 index 0000000..691c24d --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/Schedule.java @@ -0,0 +1,63 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.openmrs.BaseChangeableOpenmrsData; +import org.openmrs.Concept; +import org.openmrs.Visit; + +import javax.persistence.*; +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) +@Entity +@Table(name = "ipd_schedule") +public class Schedule extends BaseChangeableOpenmrsData { + + private static final long serialVersionUID = 1L; + + @EqualsAndHashCode.Include + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "schedule_id") + private Integer id; + + /** + * Should we rename it to "subject" + * This can have reference for which the schedule is being created + */ + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "subject_reference_id", referencedColumnName = "reference_id", nullable = false) + private Reference subject; + + /** + * Should we rename it to "carer/executor/ actor" + * This can have reference which execute the schedule is being created + */ + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "actor_reference_id", referencedColumnName = "reference_id", nullable = false) + private Reference actor; + + @Column(name = "active", nullable = false) + private boolean active = Boolean.TRUE; + + @OneToOne + @JoinColumn(name = "service_type_id", referencedColumnName = "concept_id", nullable = false) + private Concept serviceType; + + @OneToOne + @JoinColumn(name = "visit_id", referencedColumnName = "visit_id") + private Visit visit; + + @Column(name = "start_date", nullable = false) + private LocalDateTime startDate; + + @Column(name = "end_date") + private LocalDateTime endDate; + + @Column(name = "comments") + private String comments; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/ServiceType.java b/api/src/main/java/org/openmrs/module/ipd/api/model/ServiceType.java new file mode 100644 index 0000000..90de59c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/ServiceType.java @@ -0,0 +1,18 @@ +package org.openmrs.module.ipd.api.model; + +public enum ServiceType { + MEDICATION_REQUEST("MedicationRequest"), + EMERGENCY_MEDICATION_REQUEST("EmergencyMedicationRequest"), + AS_NEEDED_MEDICATION_REQUEST("AsNeededMedicationRequest"), + AS_NEEDED_PLACEHOLDER("AsNeededPlaceholder"); + + private final String conceptName; + + ServiceType(String medicationRequest) { + this.conceptName = medicationRequest; + } + + public String conceptName() { + return conceptName; + } +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/Slot.java b/api/src/main/java/org/openmrs/module/ipd/api/model/Slot.java new file mode 100644 index 0000000..4cc0b3a --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/Slot.java @@ -0,0 +1,99 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.openmrs.BaseChangeableOpenmrsData; +import org.openmrs.Order; +import org.openmrs.Location; +import org.openmrs.Concept; + +import javax.persistence.*; +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) +@Entity +@Table(name = "ipd_slot") +public class Slot extends BaseChangeableOpenmrsData { + + private static final long serialVersionUID = 1L; + + public enum SlotStatus { + SCHEDULED, + NOT_DONE, + COMPLETED, + STOPPED, + MISSED + } + + @EqualsAndHashCode.Include + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "slot_id") + private Integer id; + + /** + * The location Where schedule occurs + */ + @ManyToOne + @JoinColumn(name = "location_id", referencedColumnName = "location_id") + private Location location; // bed location for patient + + /** + * The Service Type of the Schedule + */ + @OneToOne + @JoinColumn(name = "service_type_id", referencedColumnName = "concept_id", nullable = false) + private Concept serviceType; // as per schedule service type + + /** + * The entity that belongs to a Schedule + */ + @ManyToOne + @JoinColumn(name = "schedule_id", referencedColumnName = "schedule_id", nullable = false) + private Schedule schedule; + + /** + * Order with respect to the Slot + */ + @OneToOne + @JoinColumn(name = "order_id", referencedColumnName = "order_id") + private Order order; + + /** + * The Start Date the Slot + */ + @Column(name = "start_date_time", nullable = false) + private LocalDateTime startDateTime; // slot start time + + /** + * The End Date the Slot + */ + @Column(name = "end_date_time") + private LocalDateTime endDateTime; // can be null for now + + /** + * The current status of the slot. + */ + @Column(name = "status", nullable = false) + @Enumerated(EnumType.STRING) + private SlotStatus status = SlotStatus.SCHEDULED; + + /** + * The reference of medication administration if the medication is administered + */ + @OneToOne + @JoinColumn(name = "medication_administration_id", referencedColumnName = "medication_administration_id") + private MedicationAdministration medicationAdministration; + + @Column(name = "comments") + private String notes; + + public Boolean isStopped() { + return this.status !=null && this.status == SlotStatus.STOPPED; + } +} + + diff --git a/api/src/main/java/org/openmrs/module/ipd/api/model/WardPatientsSummary.java b/api/src/main/java/org/openmrs/module/ipd/api/model/WardPatientsSummary.java new file mode 100644 index 0000000..d2da22c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/model/WardPatientsSummary.java @@ -0,0 +1,18 @@ +package org.openmrs.module.ipd.api.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@NoArgsConstructor +@AllArgsConstructor +@Setter +@Getter +public class WardPatientsSummary { + private Long totalPatients = 0L; + private Long totalProviderPatients = 0L; + + // to be added in future +// private Integer toBeDischargedPatients; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/MarkSlotsAsMissed.java b/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/MarkSlotsAsMissed.java new file mode 100644 index 0000000..aae3b05 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/MarkSlotsAsMissed.java @@ -0,0 +1,36 @@ +package org.openmrs.module.ipd.api.scheduler.tasks; + +import lombok.extern.slf4j.Slf4j; +import org.openmrs.Order; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.service.SlotService; +import org.openmrs.scheduler.tasks.AbstractTask; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Slf4j +public class MarkSlotsAsMissed extends AbstractTask { + @Override + public void execute() { + + SlotService slotService = Context.getService(SlotService.class); + LocalDateTime currentDateTime = LocalDateTime.now(); + List lastSlotForAnOrder = slotService.getLastSlotForAnOrder(currentDateTime); + List orders = new ArrayList<>(); + Map maxTimeForAnOrder = new HashMap<>(); + if (!lastSlotForAnOrder.isEmpty()) { + lastSlotForAnOrder.stream().forEach(slot -> { + maxTimeForAnOrder.put(slot.getOrder(), slot.getStartDateTime()); + orders.add(slot.getOrder()); + }); + List scheduledSlots = slotService.getScheduledSlots(orders); + slotService.markSlotsAsMissed(scheduledSlots, maxTimeForAnOrder); + } + } + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/RollOverNonMedicationTasks.java b/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/RollOverNonMedicationTasks.java new file mode 100644 index 0000000..4f2615e --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/RollOverNonMedicationTasks.java @@ -0,0 +1,30 @@ +package org.openmrs.module.ipd.api.scheduler.tasks; + +import org.openmrs.module.ipd.api.events.IPDEventManager; +import org.openmrs.module.ipd.api.events.model.IPDEvent; +import org.openmrs.module.ipd.api.events.model.IPDEventType; +import org.openmrs.scheduler.tasks.AbstractTask; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class RollOverNonMedicationTasks extends AbstractTask implements ApplicationContextAware { + + private static ApplicationContext context; + + @Override + public void execute() { + IPDEventManager eventManager = context.getBean(IPDEventManager.class); + IPDEventType eventType = eventManager.getEventTypeForEncounter(String.valueOf(IPDEventType.ROLLOVER_TASK)); + if (eventType != null) { + IPDEvent ipdEvent = new IPDEvent(null, null, eventType); + eventManager.processEvent(ipdEvent); + } + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + this.context = applicationContext; + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/ShiftStartTasks.java b/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/ShiftStartTasks.java new file mode 100644 index 0000000..59ce500 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/scheduler/tasks/ShiftStartTasks.java @@ -0,0 +1,29 @@ +package org.openmrs.module.ipd.api.scheduler.tasks; + +import org.openmrs.module.ipd.api.events.IPDEventManager; +import org.openmrs.module.ipd.api.events.model.IPDEvent; +import org.openmrs.module.ipd.api.events.model.IPDEventType; +import org.openmrs.scheduler.tasks.AbstractTask; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class ShiftStartTasks extends AbstractTask implements ApplicationContextAware { + + private static ApplicationContext context; + @Override + public void execute() { + IPDEventManager eventManager = context.getBean(IPDEventManager.class); + IPDEventType eventType = eventManager.getEventTypeForEncounter(String.valueOf(IPDEventType.SHIFT_START_TASK)); + if (eventType != null) { + IPDEvent ipdEvent = new IPDEvent(null, null, eventType); + eventManager.processEvent(ipdEvent); + } + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + this.context = applicationContext; + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/CareTeamService.java b/api/src/main/java/org/openmrs/module/ipd/api/service/CareTeamService.java new file mode 100644 index 0000000..83b235c --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/CareTeamService.java @@ -0,0 +1,18 @@ +package org.openmrs.module.ipd.api.service; + +import org.openmrs.Visit; +import org.openmrs.api.APIException; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.api.model.Schedule; +import org.springframework.stereotype.Service; +import org.openmrs.api.OpenmrsService; + + +@Service +public interface CareTeamService extends OpenmrsService { + + CareTeam saveCareTeam(CareTeam careTeam) throws APIException; + + CareTeam getCareTeamByVisit(Visit visit) throws APIException; + +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/ReferenceService.java b/api/src/main/java/org/openmrs/module/ipd/api/service/ReferenceService.java new file mode 100644 index 0000000..a006d08 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/ReferenceService.java @@ -0,0 +1,20 @@ +package org.openmrs.module.ipd.api.service; + +import org.openmrs.api.APIException; +import org.openmrs.api.OpenmrsService; +import org.openmrs.api.db.DAOException; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Slot; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +public interface ReferenceService extends OpenmrsService { + + // @Authorized({ PrivilegeConstants.EDIT_IPD_SCHEDULES }) + Optional getReferenceByTypeAndTargetUUID(String type, String targetUuid) throws APIException; + + // @Authorized({ PrivilegeConstants.EDIT_IPD_SCHEDULES }) + Reference saveReference(Reference reference) throws APIException; +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/ScheduleService.java b/api/src/main/java/org/openmrs/module/ipd/api/service/ScheduleService.java new file mode 100644 index 0000000..a370215 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/ScheduleService.java @@ -0,0 +1,20 @@ +package org.openmrs.module.ipd.api.service; + +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.api.APIException; +import org.openmrs.api.OpenmrsService; +import org.springframework.stereotype.Service; + + +@Service +public interface ScheduleService extends OpenmrsService { + +// @Authorized({ PrivilegeConstants.EDIT_IPD_SCHEDULES }) + Schedule getSchedule(Integer scheduleId) throws APIException; + +// @Authorized({ PrivilegeConstants.EDIT_IPD_SCHEDULES }) + Schedule saveSchedule(Schedule schedule) throws APIException; + + Schedule getScheduleByVisit(Visit visit); +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/SlotService.java b/api/src/main/java/org/openmrs/module/ipd/api/service/SlotService.java new file mode 100644 index 0000000..05856ab --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/SlotService.java @@ -0,0 +1,55 @@ +package org.openmrs.module.ipd.api.service; + +import org.openmrs.Concept; +import org.openmrs.Order; +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.api.APIException; +import org.openmrs.api.OpenmrsService; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; + +@Service +public interface SlotService extends OpenmrsService { + +// @Authorized({ PrivilegeConstants.EDIT_IPD_SLOTS }) + Slot getSlot(Integer slotId) throws APIException; + + // @Authorized({ PrivilegeConstants.EDIT_IPD_SLOTS }) + Slot getSlotByUUID(String uuid) throws APIException; + +// @Authorized({ PrivilegeConstants.EDIT_IPD_SLOTS }) + Slot saveSlot(Slot slot) throws APIException; + + List getSlotsBySubjectReferenceIdAndForDateAndServiceType(Reference subject, LocalDate forDate, Concept serviceType); + + List getSlotsBySubjectReferenceIdAndServiceType(Reference subject, Concept serviceType); + + List getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(Reference subject, Concept serviceType, List orderUuids); + + void voidSlot(Slot slot,String voidReason); + + List getSlotsByPatientAndVisitAndServiceType(Reference subject, Visit visit, Concept serviceType); + + List getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference reference, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit); + + List getSlotsBySubjectReferenceIncludingAdministeredTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit); + + List getSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate, LocalDateTime localEndDate); + + List getImmediatePreviousSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate); + + List getSlotDurationForPatientsByOrder(List orders, List serviceTypes); + + + List getLastSlotForAnOrder(LocalDateTime currentDay); + + List getScheduledSlots(List orders); + + void markSlotsAsMissed(List markSlotStatusAsMissed, Map slotsForADay); +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/WardService.java b/api/src/main/java/org/openmrs/module/ipd/api/service/WardService.java new file mode 100644 index 0000000..070999a --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/WardService.java @@ -0,0 +1,20 @@ +package org.openmrs.module.ipd.api.service; + +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.openmrs.module.ipd.api.model.WardPatientsSummary; + +import java.util.List; + + +public interface WardService { + + WardPatientsSummary getIPDWardPatientSummary(String wardUuid, String providerUuid); + + List getWardPatientsByUuid(String wardUuid, String sortBy); + + List searchWardPatients(String wardUuid, List searchKeys, String searchValue, String sortBy); + + List getPatientsByWardAndProvider(String wardUuid, String providerUuid, String sortBy); + + List getAdmittedPatients(); +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImpl.java b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImpl.java new file mode 100644 index 0000000..84c253e --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImpl.java @@ -0,0 +1,39 @@ +package org.openmrs.module.ipd.api.service.impl; + + +import org.openmrs.Visit; +import org.openmrs.api.APIException; +import org.openmrs.api.impl.BaseOpenmrsService; +import org.openmrs.module.ipd.api.dao.CareTeamDAO; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.service.CareTeamService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class CareTeamServiceImpl extends BaseOpenmrsService implements CareTeamService { + + private static final Logger log = LoggerFactory.getLogger(CareTeamServiceImpl.class); + + private final CareTeamDAO careTeamDAO; + + @Autowired + public CareTeamServiceImpl(CareTeamDAO careTeamDAO) { + this.careTeamDAO = careTeamDAO; + } + + @Override + public CareTeam saveCareTeam(CareTeam careTeam) throws APIException { + return careTeamDAO.saveCareTeam(careTeam); + } + + @Override + public CareTeam getCareTeamByVisit(Visit visit) throws APIException { + return careTeamDAO.getCareTeamByVisit(visit); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImpl.java b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImpl.java new file mode 100644 index 0000000..9895276 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImpl.java @@ -0,0 +1,39 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.openmrs.api.APIException; +import org.openmrs.api.impl.BaseOpenmrsService; +import org.openmrs.module.ipd.api.dao.ReferenceDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.service.ReferenceService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +@Service +@Transactional +public class ReferenceServiceImpl extends BaseOpenmrsService implements ReferenceService { + + private static final Logger log = LoggerFactory.getLogger(ReferenceServiceImpl.class); + + private final ReferenceDAO referenceDAO; + + @Autowired + public ReferenceServiceImpl(ReferenceDAO referenceDAO) { + this.referenceDAO = referenceDAO; + } + + @Override + @Transactional(readOnly = true) + public Optional getReferenceByTypeAndTargetUUID(String type, String targetUuid) throws APIException { + return referenceDAO.getReferenceByTypeAndTargetUUID(type, targetUuid); + } + + @Override + public Reference saveReference(Reference reference) throws APIException { + return referenceDAO.saveReference(reference); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImpl.java b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImpl.java new file mode 100644 index 0000000..7521211 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImpl.java @@ -0,0 +1,43 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.dao.ScheduleDAO; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.service.ScheduleService; +import org.openmrs.api.APIException; +import org.openmrs.api.impl.BaseOpenmrsService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class ScheduleServiceImpl extends BaseOpenmrsService implements ScheduleService { + + private static final Logger log = LoggerFactory.getLogger(ScheduleServiceImpl.class); + + private final ScheduleDAO scheduleDAO; + + @Autowired + public ScheduleServiceImpl(ScheduleDAO scheduleDAO) { + this.scheduleDAO = scheduleDAO; + } + + @Override + @Transactional(readOnly = true) + public Schedule getSchedule(Integer scheduleId) throws APIException { + return scheduleDAO.getSchedule(scheduleId); + } + + @Override + public Schedule saveSchedule(Schedule schedule) throws APIException { + return scheduleDAO.saveSchedule(schedule); + } + + @Override + public Schedule getScheduleByVisit(Visit visit) { + return scheduleDAO.getScheduleByVisit(visit); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImpl.java b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImpl.java new file mode 100644 index 0000000..2f94af5 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImpl.java @@ -0,0 +1,139 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.openmrs.Concept; +import org.openmrs.Order; +import org.openmrs.Visit; +import org.openmrs.api.APIException; +import org.openmrs.api.ConceptService; +import org.openmrs.api.context.Context; +import org.openmrs.api.impl.BaseOpenmrsService; +import org.openmrs.module.ipd.api.dao.SlotDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.service.SlotService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Service +@Transactional +public class SlotServiceImpl extends BaseOpenmrsService implements SlotService { + + private static final Logger log = LoggerFactory.getLogger(SlotServiceImpl.class); + + private final SlotDAO slotDAO; + private ConceptService conceptService; + + @Autowired + public SlotServiceImpl(SlotDAO slotDAO, ConceptService conceptService) { + + this.slotDAO = slotDAO; + this.conceptService = conceptService; + } + + + @Override + @Transactional(readOnly = true) + public Slot getSlot(Integer slotId) throws APIException { + return slotDAO.getSlot(slotId); + } + + @Override + public Slot getSlotByUUID(String uuid) throws APIException { + return slotDAO.getSlotByUUID(uuid); + } + + @Override + public Slot saveSlot(Slot slot) throws APIException { + return slotDAO.saveSlot(slot); + } + + @Override + @Transactional(readOnly = true) + public List getSlotsBySubjectReferenceIdAndForDateAndServiceType(Reference subject, LocalDate forDate, Concept serviceType) { + return slotDAO.getSlotsBySubjectReferenceIdAndForDateAndServiceType(subject, forDate, serviceType); + } + + @Override + public List getSlotsBySubjectReferenceIdAndServiceType(Reference subject, Concept serviceType) { + return slotDAO.getSlotsBySubjectReferenceIdAndServiceType(subject, serviceType); + } + + @Override + public List getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(Reference subject, Concept serviceType, List orderUuids) { + return slotDAO.getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(subject, serviceType, orderUuids); + } + + @Override + public void voidSlot(Slot slot, String voidReason) throws APIException { + slot.setVoided(true); + slot.setVoidedBy(Context.getAuthenticatedUser()); + slot.setDateVoided(new Date()); + slot.setVoidReason(voidReason); + slotDAO.saveSlot(slot); + } + + + @Override + public List getSlotsByPatientAndVisitAndServiceType(Reference subject, Visit visit, Concept serviceType) { + return slotDAO.getSlotsByPatientAndVisitAndServiceType(subject, visit, serviceType); + } + @Override + public List getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit){ + Concept asNeededPlaceholderServiceType = conceptService.getConceptByName(ServiceType.AS_NEEDED_PLACEHOLDER.conceptName()); + return slotDAO.getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(subject, localStartDate, localEndDate, visit, asNeededPlaceholderServiceType); + } + + @Override + public List getSlotsBySubjectReferenceIncludingAdministeredTimeFrame(Reference subject, LocalDateTime localStartDate, LocalDateTime localEndDate, Visit visit) { + return slotDAO.getSlotsBySubjectIncludingAdministeredTimeFrame(subject, localStartDate, localEndDate, visit); + } + + @Override + public List getSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate, LocalDateTime localEndDate) { + return slotDAO.getSlotsForPatientListByTime(patientUuidList, localStartDate, localEndDate); + } + + @Override + public List getImmediatePreviousSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate) { + return slotDAO.getImmediatePreviousSlotsForPatientListByTime(patientUuidList, localStartDate); + } + + public List getSlotDurationForPatientsByOrder(List orders, List serviceTypes) { + return slotDAO.getSlotDurationForPatientsByOrder(orders, serviceTypes); + } + @Override + public List getLastSlotForAnOrder(LocalDateTime startDateTime) { + return slotDAO.getLastSlotForAnOrder(startDateTime); + } + + @Override + public List getScheduledSlots(List orders) { + return slotDAO.getScheduledSlots(orders); + } + + @Override + public void markSlotsAsMissed(List scheduledSlots, Map maxTimeForAnOrder) { + List slotsToBeMarkedAsMissed = new ArrayList<>(); + + scheduledSlots.stream().forEach(slot -> { + if (slot.getStartDateTime().compareTo(maxTimeForAnOrder.get(slot.getOrder())) < 0) + slotsToBeMarkedAsMissed.add(slot); + }); + + slotsToBeMarkedAsMissed.forEach(slot -> { + slot.setStatus(Slot.SlotStatus.MISSED); + slotDAO.saveSlot(slot); + }); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/service/impl/WardServiceImpl.java b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/WardServiceImpl.java new file mode 100644 index 0000000..72dc5dd --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/service/impl/WardServiceImpl.java @@ -0,0 +1,62 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.openmrs.Location; +import org.openmrs.Provider; +import org.openmrs.api.LocationService; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.dao.WardDAO; +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.openmrs.module.ipd.api.model.WardPatientsSummary; +import org.openmrs.module.ipd.api.service.WardService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; + +@Service +@Transactional +public class WardServiceImpl implements WardService { + + private final WardDAO wardDAO; + + @Autowired + public WardServiceImpl(WardDAO wardDAO) { + this.wardDAO = wardDAO; + } + + + @Override + public WardPatientsSummary getIPDWardPatientSummary(String wardUuid, String providerUuid) { + Location location= Context.getService(LocationService.class).getLocationByUuid(wardUuid); + Provider provider = Context.getProviderService().getProviderByUuid(providerUuid); + Date currentDateTime = new Date(); + return wardDAO.getWardPatientSummary(location, provider, currentDateTime); + } + + @Override + public List getWardPatientsByUuid(String wardUuid, String sortBy) { + Location location= Context.getService(LocationService.class).getLocationByUuid(wardUuid); + return wardDAO.getAdmittedPatients(location,null, null, sortBy); + } + + @Override + public List getPatientsByWardAndProvider(String wardUuid, String providerUuid, String sortBy) { + Location location = Context.getService(LocationService.class).getLocationByUuid(wardUuid); + Provider provider = Context.getProviderService().getProviderByUuid(providerUuid); + Date currentDateTime = new Date(); + return wardDAO.getAdmittedPatients(location, provider, currentDateTime, sortBy); + } + + @Override + public List searchWardPatients(String wardUuid, List searchKeys, String searchValue, String sortBy) { + Location location= Context.getService(LocationService.class).getLocationByUuid(wardUuid); + return wardDAO.searchAdmittedPatients(location,searchKeys,searchValue,sortBy); + } + + @Override + public List getAdmittedPatients() { + return wardDAO.getAdmittedPatients(null,null, null, null); + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/translators/MedicationAdministrationToSlotStatusTranslator.java b/api/src/main/java/org/openmrs/module/ipd/api/translators/MedicationAdministrationToSlotStatusTranslator.java new file mode 100644 index 0000000..f1d0079 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/translators/MedicationAdministrationToSlotStatusTranslator.java @@ -0,0 +1,22 @@ +package org.openmrs.module.ipd.api.translators; + +import org.hl7.fhir.r4.model.MedicationAdministration; +import org.openmrs.module.ipd.api.model.Slot; +import org.springframework.stereotype.Component; + +@Component +public class MedicationAdministrationToSlotStatusTranslator { + + public Slot.SlotStatus toSlotStatus(MedicationAdministration.MedicationAdministrationStatus medicationAdministrationStatus){ + if (medicationAdministrationStatus.equals(MedicationAdministration.MedicationAdministrationStatus.COMPLETED)){ + return Slot.SlotStatus.COMPLETED; + } + if (medicationAdministrationStatus.equals(MedicationAdministration.MedicationAdministrationStatus.NOTDONE)){ + return Slot.SlotStatus.NOT_DONE; + } + if (medicationAdministrationStatus.equals(MedicationAdministration.MedicationAdministrationStatus.STOPPED)){ + return Slot.SlotStatus.STOPPED; + } + return null; + } +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/util/DateTimeUtil.java b/api/src/main/java/org/openmrs/module/ipd/api/util/DateTimeUtil.java new file mode 100644 index 0000000..7588d4b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/util/DateTimeUtil.java @@ -0,0 +1,29 @@ +package org.openmrs.module.ipd.api.util; + +import java.time.*; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +public class DateTimeUtil { + public static LocalDateTime convertEpocUTCToLocalTimeZone(long utcTime) { + return Instant.ofEpochSecond(utcTime).atZone(ZoneOffset.systemDefault()).toLocalDateTime(); + } + + public static long convertLocalDateTimeToUTCEpoc(LocalDateTime localDateTime) { + return localDateTime.atZone(ZoneId.systemDefault()).withZoneSameInstant(ZoneId.of("UTC")).toEpochSecond(); + } + + public static LocalDateTime convertDateToLocalDateTime(Date date) { + return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); + } + + public static Date convertLocalDateTimeDate(LocalDateTime localDateTime) { + return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + } + + public static Date convertEpochTimeToDate(Long utcTime) { + return new Date(TimeUnit.SECONDS.toMillis(utcTime)); + } + + +} \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ipd/api/util/IPDConstants.java b/api/src/main/java/org/openmrs/module/ipd/api/util/IPDConstants.java new file mode 100644 index 0000000..cf264fe --- /dev/null +++ b/api/src/main/java/org/openmrs/module/ipd/api/util/IPDConstants.java @@ -0,0 +1,7 @@ +package org.openmrs.module.ipd.api.util; + +public class IPDConstants { + + public static final String IPD_VIEW_DRUG_CHART = "drugChart"; + +} diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml new file mode 100644 index 0000000..df5fc2f --- /dev/null +++ b/api/src/main/resources/liquibase.xml @@ -0,0 +1,530 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT COUNT(*) FROM concept where short_name='MedicationRequest' and description='MedicationRequest'; + + + Add concept Medication Request + + insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created, + changed_by, date_changed, uuid) + values (0, 'MedicationRequest', 'MedicationRequest', + (select concept_datatype_id from concept_datatype where name = 'Text'), + (select concept_class_id from concept_class where name = 'Misc'), + 0, 1, now(), 1, now(), uuid()); + + + + + + + SELECT COUNT(*) FROM concept_name where name ='MedicationRequest'; + + + Add concept-name Medication Request + + insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created, + concept_name_type, voided, uuid) + values ((select concept_id from concept where short_name='MedicationRequest'), + 'MedicationRequest', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid()); + + + + + + + + + + + + + + + + + + + + + + + + + ALTER TABLE ipd_schedule MODIFY COLUMN end_date datetime NULL; + + + + + + + + + + + + + + SELECT COUNT(*) FROM concept where short_name='EmergencyMedicationRequest' and description='EmergencyMedicationRequest'; + + + SELECT COUNT(*) FROM concept_name where name ='EmergencyMedicationRequest'; + + + Add concept for Emergency Medication Request + + insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created, + changed_by, date_changed, uuid) + values (0, 'EmergencyMedicationRequest', 'EmergencyMedicationRequest', + (select concept_datatype_id from concept_datatype where name = 'Text'), + (select concept_class_id from concept_class where name = 'Misc'), + 0, 1, now(), 1, now(), uuid()); + insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created, + concept_name_type, voided, uuid) + values ((select concept_id from concept where short_name='EmergencyMedicationRequest'), + 'EmergencyMedicationRequest', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid()); + + + + + + + SELECT COUNT(*) FROM concept where short_name='AsNeededMedicationRequest' and description='AsNeededMedicationRequest'; + + + SELECT COUNT(*) FROM concept_name where name ='AsNeededMedicationRequest'; + + + Add concept for As Needed Medication Request + + insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created, + changed_by, date_changed, uuid) + values (0, 'AsNeededMedicationRequest', 'AsNeededMedicationRequest', + (select concept_datatype_id from concept_datatype where name = 'Text'), + (select concept_class_id from concept_class where name = 'Misc'), + 0, 1, now(), 1, now(), uuid()); + insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created, + concept_name_type, voided, uuid) + values ((select concept_id from concept where short_name='AsNeededMedicationRequest'), + 'AsNeededMedicationRequest', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid()); + + + + + + + SELECT COUNT(*) FROM concept where short_name='AsNeededPlaceholder' and description='AsNeededPlaceholder'; + + + SELECT COUNT(*) FROM concept_name where name ='AsNeededPlaceholder'; + + + Add concept for As Needed Medication Request + + insert into concept (retired, short_name, description, datatype_id, class_id, is_set, creator, date_created, + changed_by, date_changed, uuid) + values (0, 'AsNeededPlaceholder', 'AsNeededPlaceholder', + (select concept_datatype_id from concept_datatype where name = 'Text'), + (select concept_class_id from concept_class where name = 'Misc'), + 0, 1, now(), 1, now(), uuid()); + insert into concept_name (concept_id, name, locale, locale_preferred, creator, date_created, + concept_name_type, voided, uuid) + values ((select concept_id from concept where short_name='AsNeededPlaceholder'), + 'AsNeededPlaceholder', 'en', 1, 1, now(), 'FULLY_SPECIFIED', 0, uuid()); + + + + + + + + + + Creating care_team table + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SELECT COUNT(*) FROM scheduler_task_config WHERE name = "Mark Slots As Missed"; + + + + INSERT INTO + scheduler_task_config(name, description, schedulable_class, start_time, start_time_pattern, repeat_interval, + start_on_startup, created_by, date_created, uuid) + VALUES + ('Mark Slots As Missed', 'Mark Slots As Missed', 'org.openmrs.module.ipd.api.scheduler.tasks.MarkSlotsAsMissed', + TIMESTAMP(CURDATE(), "23:59"), 'MM/dd/yyyy HH:mm:ss', 86400, false, 1, NOW(), UUID()); + + + + + + + SELECT COUNT(*) FROM scheduler_task_config WHERE name = "Shift Start Tasks First"; + + + + INSERT INTO + scheduler_task_config(name, description, schedulable_class, start_time, start_time_pattern, repeat_interval, + start_on_startup, created_by, date_created, uuid) + VALUES + ('Shift Start Tasks First', 'Shift start tasks first shift', 'org.openmrs.module.ipd.api.scheduler.tasks.ShiftStartTasks', + '2024-04-11 08:00:00', 'MM/dd/yyyy HH:mm:ss', 86400, true, 1, NOW(), UUID()); + + + + + + + SELECT COUNT(*) FROM scheduler_task_config WHERE name = "Shift Start Tasks Second"; + + + + INSERT INTO + scheduler_task_config(name, description, schedulable_class, start_time, start_time_pattern, repeat_interval, + start_on_startup, created_by, date_created, uuid) + VALUES + ('Shift Start Tasks Second', 'Shift start tasks second shift', 'org.openmrs.module.ipd.api.scheduler.tasks.ShiftStartTasks', + '2024-04-11 19:00:00', 'MM/dd/yyyy HH:mm:ss', 86400, true, 1, NOW(), UUID()); + + + + + + + SELECT COUNT(*) FROM scheduler_task_config WHERE name = "Shift Rollover Tasks First"; + + + + INSERT INTO + scheduler_task_config(name, description, schedulable_class, start_time, start_time_pattern, repeat_interval, + start_on_startup, created_by, date_created, uuid) + VALUES + ('Shift Rollover Tasks First', 'Shift Rollover tasks first shift', 'org.openmrs.module.ipd.api.scheduler.tasks.RollOverNonMedicationTasks', + '2024-04-11 08:00:00', 'MM/dd/yyyy HH:mm:ss', 86400, true, 1, NOW(), UUID()); + + + + + + + SELECT COUNT(*) FROM scheduler_task_config WHERE name = "Shift Rollover Tasks Second"; + + + + INSERT INTO + scheduler_task_config(name, description, schedulable_class, start_time, start_time_pattern, repeat_interval, + start_on_startup, created_by, date_created, uuid) + VALUES + ('Shift Rollover Tasks Second', 'Shift Rollover tasks second shift', 'org.openmrs.module.ipd.api.scheduler.tasks.RollOverNonMedicationTasks', + '2024-04-11 19:00:00', 'MM/dd/yyyy HH:mm:ss', 86400, true, 1, NOW(), UUID()); + + + + + select count(*) from privilege where privilege = 'Edit Medication Tasks' + + + + + + + + + + select count(*) from privilege where privilege = 'Delete Medication Tasks' + + + + + + + + + + select count(*) from privilege where privilege = 'Edit adhoc medication tasks' + + + + + + + + + + select count(*) from privilege where privilege = 'Edit Medication Administration' + + + + + + + + + + select count(*) from privilege where privilege = 'Get Medication Administration' + + + + + + + + + + select count(*) from privilege where privilege = 'Get Medication Tasks' + + + + + + + + diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml new file mode 100644 index 0000000..0dde695 --- /dev/null +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.openmrs.module.ipd.api.service.SlotService + + + + + + \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/BaseIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/BaseIntegrationTest.java new file mode 100644 index 0000000..1e6033b --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/BaseIntegrationTest.java @@ -0,0 +1,6 @@ +package org.openmrs.module.ipd.api; +import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; + +@org.springframework.test.context.ContextConfiguration(locations = {"classpath:TestingApplicationContext.xml"}) +public abstract class BaseIntegrationTest extends BaseModuleWebContextSensitiveTest { +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAOIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAOIntegrationTest.java new file mode 100644 index 0000000..f2003ea --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateCareTeamDAOIntegrationTest.java @@ -0,0 +1,92 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.openmrs.*; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.BaseIntegrationTest; +import org.openmrs.module.ipd.api.dao.CareTeamDAO; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.api.model.CareTeamParticipant; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +public class HibernateCareTeamDAOIntegrationTest extends BaseIntegrationTest { + + @Autowired + private CareTeamDAO careTeamDAO; + + @Autowired + private SessionFactory sessionFactory; + + @Test + public void shouldSaveTheCareTeamCreatedForPatientGivenPatientVisit() { + + executeDataSet("CareTeamDAOTestData.xml"); + + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + Visit visit=Context.getVisitService().getVisitByUuid("84d8b838-1111-11e3-b47b-c6959a448789"); + Provider provider=Context.getProviderService().getProviderByUuid("2bdc3f7d-d911-401a-84e9-5494dda83e8e"); + + + CareTeamParticipant participant = new CareTeamParticipant(); + participant.setStartTime(visit.getStartDatetime()); + participant.setProvider(provider); + Set participantSet=new HashSet<>(); + participantSet.add(participant); + + CareTeam careTeam = new CareTeam(); + careTeam.setPatient(visit.getPatient()); + careTeam.setStartTime(visit.getStartDatetime()); + careTeam.setVisit(visit); + careTeam.setParticipants(participantSet); + + CareTeam savedCareTeam = careTeamDAO.saveCareTeam(careTeam); + + List participantsList = new ArrayList<>(savedCareTeam.getParticipants()); + + Assertions.assertEquals(visit.getPatient().getPatientId(), savedCareTeam.getPatient().getPatientId()); + Assertions.assertEquals(provider, participantsList.get(0).getProvider()); + Assertions.assertEquals(visit, savedCareTeam.getVisit()); + + sessionFactory.getCurrentSession().delete(savedCareTeam); + } + + + @Test + public void shouldGetCareTeamGivenPatientVisit() { + + executeDataSet("CareTeamDAOTestData.xml"); + + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + Visit visit=Context.getVisitService().getVisitByUuid("84d8b838-1111-11e3-b47b-c6959a448789"); + Provider provider=Context.getProviderService().getProviderByUuid("2bdc3f7d-d911-401a-84e9-5494dda83e8e"); + + + CareTeamParticipant participant = new CareTeamParticipant(); + participant.setStartTime(visit.getStartDatetime()); + participant.setProvider(provider); + Set participantSet=new HashSet<>(); + participantSet.add(participant); + + CareTeam careTeam = new CareTeam(); + careTeam.setPatient(visit.getPatient()); + careTeam.setStartTime(visit.getStartDatetime()); + careTeam.setVisit(visit); + careTeam.setParticipants(participantSet); + + CareTeam savedCareTeam=careTeamDAO.saveCareTeam(careTeam); + + CareTeam careTeamByVisit= careTeamDAO.getCareTeamByVisit(visit); + + Assertions.assertEquals(savedCareTeam.getCareTeamId(),careTeamByVisit.getCareTeamId()); + Assertions.assertEquals(visit,careTeamByVisit.getVisit()); + Assertions.assertEquals(1,careTeam.getParticipants().size()); + + sessionFactory.getCurrentSession().delete(savedCareTeam); + } + + +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAOIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAOIntegrationTest.java new file mode 100644 index 0000000..46aa98d --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateReferenceDAOIntegrationTest.java @@ -0,0 +1,36 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.openmrs.Patient; +import org.openmrs.module.ipd.api.BaseIntegrationTest; +import org.openmrs.module.ipd.api.dao.ReferenceDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Optional; + +public class HibernateReferenceDAOIntegrationTest extends BaseIntegrationTest { + + @Autowired + private ReferenceDAO referenceDAO; + + @Autowired + private SessionFactory sessionFactory; + + @Test + public void shouldSaveAndGetThePatientReference() { + Reference openmrsReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference reference = referenceDAO.saveReference(openmrsReference); + + Optional savedReference = referenceDAO.getReferenceByTypeAndTargetUUID(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + + Assertions.assertTrue(savedReference.isPresent()); + Assertions.assertEquals("2c33920f-7aa6-0000-998a-60412d8ff7d5", savedReference.get().getTargetUuid()); + Assertions.assertEquals("org.openmrs.Patient", savedReference.get().getType()); + Assertions.assertEquals("org.openmrs.Patient/2c33920f-7aa6-0000-998a-60412d8ff7d5", savedReference.get().getName()); + + sessionFactory.getCurrentSession().delete(reference); + } +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAOIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAOIntegrationTest.java new file mode 100644 index 0000000..a6806e5 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateScheduleDAOIntegrationTest.java @@ -0,0 +1,138 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.openmrs.Concept; +import org.openmrs.DrugOrder; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.api.context.Context; +import org.openmrs.api.db.VisitDAO; +import org.openmrs.module.ipd.api.BaseIntegrationTest; +import org.openmrs.module.ipd.api.dao.ScheduleDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.springframework.beans.factory.annotation.Autowired; + +import java.time.LocalDateTime; +import java.util.Date; + +public class HibernateScheduleDAOIntegrationTest extends BaseIntegrationTest { + + @Autowired + private ScheduleDAO scheduleDAO; + + @Autowired + private SessionFactory sessionFactory; + + @Autowired + private VisitDAO visitDAO; + + @Test + public void shouldSaveTheScheduledCreatedForPatientGivenPatientSchedule() { + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9142"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + + Patient patient = Context.getPatientService().getPatientByUuid("2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Visit visit = new Visit(); + visit.setPatient(patient); + visit.setStartDatetime(new Date()); + visit.setVisitType(Context.getVisitService().getVisitType(1)); + + Schedule schedule = new Schedule(); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setServiceType(testConcept); + schedule.setVisit(visit); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + Assertions.assertEquals(patientReference, schedule.getSubject()); + Assertions.assertEquals(providerReference, schedule.getActor()); + Assertions.assertEquals(startDate, schedule.getStartDate()); + Assertions.assertEquals(testConcept, schedule.getServiceType()); + Assertions.assertEquals(visit, schedule.getVisit()); + + sessionFactory.getCurrentSession().delete(savedSchedule); + } + + @Test + public void shouldGetTheSavedScheduledCreatedForPatientGivenPatientSchedule() { + + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9142"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + + Patient patient = Context.getPatientService().getPatientByUuid("2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Visit visit = new Visit(); + visit.setPatient(patient); + visit.setStartDatetime(new Date()); + visit.setVisitType(Context.getVisitService().getVisitType(1)); + + + Schedule schedule = new Schedule(); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setServiceType(testConcept); + schedule.setVisit(visit); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + Schedule scheduleById = scheduleDAO.getSchedule(savedSchedule.getId()); + + Assertions.assertEquals(patientReference, scheduleById.getSubject()); + Assertions.assertEquals(providerReference, scheduleById.getActor()); + Assertions.assertEquals(startDate, scheduleById.getStartDate()); + Assertions.assertEquals(testConcept, scheduleById.getServiceType()); + Assertions.assertEquals(visit, scheduleById.getVisit()); + + sessionFactory.getCurrentSession().delete(savedSchedule); + } + + @Test + public void shouldGetTheSavedScheduleCreatedForPatientGivenVisit() { + + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9142"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + + Visit visit = new Visit(); + visit.setPatient(new Patient(2)); + visit.setStartDatetime(new Date()); + visit.setVisitType(Context.getVisitService().getVisitType(1)); + Visit savedVisit = visitDAO.saveVisit(visit); + + Schedule schedule = new Schedule(); + schedule.setDateCreated(new Date()); + schedule.setActive(true); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setServiceType(testConcept); + schedule.setVisit(savedVisit); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + Schedule scheduleByVisit = scheduleDAO.getScheduleByVisit(visit); + + Assertions.assertEquals(patientReference, scheduleByVisit.getSubject()); + Assertions.assertEquals(providerReference, scheduleByVisit.getActor()); + Assertions.assertEquals(startDate, scheduleByVisit.getStartDate()); + Assertions.assertEquals(testConcept, scheduleByVisit.getServiceType()); + Assertions.assertEquals(visit, scheduleByVisit.getVisit()); + + sessionFactory.getCurrentSession().delete(savedSchedule); + sessionFactory.getCurrentSession().delete(savedVisit); + } +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java new file mode 100644 index 0000000..231d5b2 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java @@ -0,0 +1,484 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.openmrs.Concept; +import org.openmrs.DrugOrder; +import org.openmrs.Order; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.VisitType; +import org.openmrs.api.context.Context; +import org.openmrs.module.fhir2.apiext.dao.FhirMedicationAdministrationDao; +import org.openmrs.module.ipd.api.BaseIntegrationTest; +import org.openmrs.module.ipd.api.dao.ScheduleDAO; +import org.openmrs.module.ipd.api.dao.SlotDAO; +import org.openmrs.module.ipd.api.model.MedicationAdministration; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.springframework.beans.factory.annotation.Autowired; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class HibernateSlotDAOIntegrationTest extends BaseIntegrationTest { + + @Autowired + private ScheduleDAO scheduleDAO; + + @Autowired + private SlotDAO slotDAO; + + @Autowired + private SessionFactory sessionFactory; + + @Autowired + private FhirMedicationAdministrationDao medicationAdministrationDao; + + @Test + public void shouldSaveTheSlotForPatientGivenPatientSchedule() { + + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9142"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + LocalDateTime endDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate()); + + Schedule schedule = new Schedule(); +// schedule.setOrder(drugOrder); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setEndDate(endDate); + schedule.setServiceType(testConcept); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + LocalDateTime slotStartTime = LocalDateTime.now(); + + Slot slot = new Slot(); + slot.setSchedule(savedSchedule); + slot.setServiceType(testConcept); + slot.setStartDateTime(slotStartTime); + + Slot savedSlot = slotDAO.saveSlot(slot); + + sessionFactory.getCurrentSession().delete(savedSlot); + sessionFactory.getCurrentSession().delete(savedSchedule); + } + + @Test + public void shouldGetTheSavedSlotForPatientGivenPatientSchedule() { + + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9142"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + LocalDateTime endDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate()); + + Schedule schedule = new Schedule(); +// schedule.setOrder(drugOrder); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setEndDate(endDate); + schedule.setServiceType(testConcept); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + LocalDateTime slotStartTime = LocalDateTime.now(); + + Slot slot = new Slot(); + slot.setSchedule(savedSchedule); + slot.setServiceType(testConcept); + slot.setStartDateTime(slotStartTime); + + Slot savedSlot = slotDAO.saveSlot(slot); + Slot getSlotById = slotDAO.getSlot(savedSlot.getId()); + + sessionFactory.getCurrentSession().delete(savedSlot); + sessionFactory.getCurrentSession().delete(savedSchedule); + } + + @Test + public void shouldGetTheSavedSlotsForPatientByForReferenceIdAndForDateAndServiceTypeGivenPatientSchedule() { + + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9142"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + LocalDateTime endDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate()); + + Schedule schedule = new Schedule(); +// schedule.setOrder(drugOrder); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setEndDate(endDate); + schedule.setServiceType(testConcept); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + LocalDateTime slotStartTime = LocalDateTime.now(); + + Slot slot1 = new Slot(); + slot1.setSchedule(savedSchedule); + slot1.setServiceType(testConcept); + slot1.setStartDateTime(slotStartTime); + + Slot slot2 = new Slot(); + slot2.setSchedule(savedSchedule); + slot2.setServiceType(testConcept); + slot2.setStartDateTime(slotStartTime.plusDays(1)); + + Slot savedSlot1 = slotDAO.saveSlot(slot1); + Slot savedSlot2 = slotDAO.saveSlot(slot2); + + List slotsAgainstSchedule = slotDAO.getSlotsBySubjectReferenceIdAndForDateAndServiceType(patientReference, slotStartTime.toLocalDate(), testConcept); + + Assertions.assertEquals(1, slotsAgainstSchedule.size()); + + sessionFactory.getCurrentSession().delete(savedSlot1); + sessionFactory.getCurrentSession().delete(savedSlot2); + sessionFactory.getCurrentSession().delete(savedSchedule); + } + + @Test + public void shouldGetTheSavedSlotsForPatientByForReferenceIdAndServiceTypeAndOrderUuid() { + + String orderUuid = "921de0a3-05c4-444a-be03-e01b4c4b9142"; + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid(orderUuid); + DrugOrder drugOrder2 = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9143"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + LocalDateTime endDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate()); + + Schedule schedule = new Schedule(); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setEndDate(endDate); + schedule.setServiceType(testConcept); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + LocalDateTime slotStartTime = LocalDateTime.now(); + + Slot slot1 = new Slot(); + slot1.setSchedule(savedSchedule); + slot1.setServiceType(testConcept); + slot1.setStartDateTime(slotStartTime); + slot1.setOrder(drugOrder); + + Slot slot2 = new Slot(); + slot2.setSchedule(savedSchedule); + slot2.setServiceType(testConcept); + slot2.setStartDateTime(slotStartTime.plusDays(1)); + slot2.setOrder(drugOrder2); + + Slot savedSlot1 = slotDAO.saveSlot(slot1); + Slot savedSlot2 = slotDAO.saveSlot(slot2); + + List orderUuidList = new ArrayList<>(); + orderUuidList.add(orderUuid); + + List slotsBySubjectReferenceIdAndServiceTypeAndOrderUuids = slotDAO.getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(patientReference, testConcept, orderUuidList); + + Assertions.assertEquals(1, slotsBySubjectReferenceIdAndServiceTypeAndOrderUuids.size()); + + sessionFactory.getCurrentSession().delete(savedSlot1); + sessionFactory.getCurrentSession().delete(savedSlot2); + sessionFactory.getCurrentSession().delete(savedSchedule); + } + + @Test + public void shouldGetTheSavedSlotsForPatientByForReferenceIdAndServiceType() { + + String orderUuid = "921de0a3-05c4-444a-be03-e01b4c4b9142"; + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid(orderUuid); + DrugOrder drugOrder2 = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9143"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + LocalDateTime endDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate()); + + Schedule schedule = new Schedule(); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setEndDate(endDate); + schedule.setServiceType(testConcept); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + LocalDateTime slotStartTime = LocalDateTime.now(); + + Slot slot1 = new Slot(); + slot1.setSchedule(savedSchedule); + slot1.setServiceType(testConcept); + slot1.setStartDateTime(slotStartTime); + slot1.setOrder(drugOrder); + + Slot slot2 = new Slot(); + slot2.setSchedule(savedSchedule); + slot2.setServiceType(testConcept); + slot2.setStartDateTime(slotStartTime.plusDays(1)); + slot2.setOrder(drugOrder2); + + Slot savedSlot1 = slotDAO.saveSlot(slot1); + Slot savedSlot2 = slotDAO.saveSlot(slot2); + + List slotsBySubjectReferenceIdAndServiceType = slotDAO.getSlotsBySubjectReferenceIdAndServiceType(patientReference, testConcept); + + Assertions.assertEquals(2, slotsBySubjectReferenceIdAndServiceType.size()); + + sessionFactory.getCurrentSession().delete(savedSlot1); + sessionFactory.getCurrentSession().delete(savedSlot2); + sessionFactory.getCurrentSession().delete(savedSchedule); + } + + @Test + public void shouldGetTheSavedSlotsForPatientByAdministeredTime() { + + String orderUuid = "921de0a3-05c4-444a-be03-e01b4c4b9142"; + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid(orderUuid); + DrugOrder drugOrder2 = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9143"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + + Visit visit = new Visit(1); + visit.setPatient(new Patient(123)); + visit.setStartDatetime(new Date()); + visit.setVisitType(new VisitType(321)); + + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + LocalDateTime endDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate()); + + Schedule schedule = new Schedule(); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setEndDate(endDate); + schedule.setServiceType(testConcept); + schedule.setVisit(visit); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + LocalDateTime startTime = LocalDateTime.now(); + LocalDateTime slot1StartTime = LocalDateTime.now().plusHours(1); + LocalDateTime slot2StartTime = LocalDateTime.now().plusDays(-1); + LocalDateTime medicationAdministeredTime= LocalDateTime.now().plusHours(3); + LocalDateTime medicationAdministeredTime2= LocalDateTime.now().plusDays(3); + + + MedicationAdministration medicationAdministration=new MedicationAdministration(); + medicationAdministration.setStatus(testConcept); + medicationAdministration.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime)); + MedicationAdministration savedMedicationAdministration= medicationAdministrationDao.createOrUpdate(medicationAdministration); + + MedicationAdministration medicationAdministration2=new MedicationAdministration(); + medicationAdministration2.setStatus(testConcept); + medicationAdministration2.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime2)); + MedicationAdministration savedMedicationAdministration2= medicationAdministrationDao.createOrUpdate(medicationAdministration2); + + Slot slot1 = new Slot(); + slot1.setSchedule(savedSchedule); + slot1.setServiceType(testConcept); + slot1.setStartDateTime(slot1StartTime); + slot1.setOrder(drugOrder); + + Slot slot2 = new Slot(); + slot2.setSchedule(savedSchedule); + slot2.setServiceType(testConcept); + slot2.setStartDateTime(slot2StartTime); + slot2.setMedicationAdministration(savedMedicationAdministration); + slot2.setOrder(drugOrder2); + + Slot slot3 = new Slot(); + slot3.setSchedule(savedSchedule); + slot3.setServiceType(testConcept); + slot3.setStartDateTime(slot2StartTime); + slot3.setOrder(drugOrder); + + Slot slot4 = new Slot(); + slot4.setSchedule(savedSchedule); + slot4.setServiceType(testConcept); + slot4.setStartDateTime(slot1StartTime); + slot4.setMedicationAdministration(savedMedicationAdministration2); + slot4.setOrder(drugOrder); + + Slot savedSlot1 = slotDAO.saveSlot(slot1); + Slot savedSlot2 = slotDAO.saveSlot(slot2); + Slot savedSlot3 = slotDAO.saveSlot(slot3); + Slot savedSlot4 = slotDAO.saveSlot(slot4); + + + List slotsBySubjectReferenceIdAndServiceType = slotDAO.getSlotsBySubjectIncludingAdministeredTimeFrame(patientReference,startTime,startTime.plusHours(6),visit); + + Assertions.assertEquals(2, slotsBySubjectReferenceIdAndServiceType.size()); + + sessionFactory.getCurrentSession().delete(savedMedicationAdministration); + sessionFactory.getCurrentSession().delete(savedMedicationAdministration2); + sessionFactory.getCurrentSession().delete(savedSlot1); + sessionFactory.getCurrentSession().delete(savedSlot2); + sessionFactory.getCurrentSession().delete(savedSlot3); + sessionFactory.getCurrentSession().delete(savedSlot4); + sessionFactory.getCurrentSession().delete(savedSchedule); + sessionFactory.getCurrentSession().delete(visit); + + } + + @Test + public void shouldGetTheSavedSlotsForPatientBySubjectReferenceAndAGivenTimeFrame() { + + String orderUuid = "921de0a3-05c4-444a-be03-e01b4c4b9142"; + DrugOrder drugOrder = (DrugOrder) Context.getOrderService().getOrderByUuid(orderUuid); + DrugOrder drugOrder2 = (DrugOrder) Context.getOrderService().getOrderByUuid("921de0a3-05c4-444a-be03-e01b4c4b9143"); + Reference patientReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference providerReference = new Reference(Patient.class.getTypeName(), "d869ad24-d2a0-4747-a888-fe55048bb7ce"); + Concept testConcept = Context.getConceptService().getConceptByName("UNKNOWN"); + LocalDateTime startDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate()); + LocalDateTime endDate = DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate()); + + Visit visit = new Visit(1); + visit.setPatient(new Patient(123)); + visit.setStartDatetime(new Date()); + visit.setVisitType(new VisitType(321)); + + Schedule schedule = new Schedule(); + schedule.setSubject(patientReference); + schedule.setActor(providerReference); + schedule.setStartDate(startDate); + schedule.setVisit(visit); + schedule.setEndDate(endDate); + schedule.setServiceType(testConcept); + + Schedule savedSchedule = scheduleDAO.saveSchedule(schedule); + + LocalDateTime startTime = LocalDateTime.now(); + LocalDateTime slot1StartTime = LocalDateTime.now().plusHours(1); + LocalDateTime slot2StartTime = LocalDateTime.now().plusDays(-1); + LocalDateTime medicationAdministeredTime= LocalDateTime.now().plusHours(3); + LocalDateTime medicationAdministeredTime2= LocalDateTime.now().plusDays(3); + + + MedicationAdministration medicationAdministration=new MedicationAdministration(); + medicationAdministration.setStatus(testConcept); + medicationAdministration.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime)); + MedicationAdministration savedMedicationAdministration= medicationAdministrationDao.createOrUpdate(medicationAdministration); + + MedicationAdministration medicationAdministration2=new MedicationAdministration(); + medicationAdministration2.setStatus(testConcept); + medicationAdministration2.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime2)); + MedicationAdministration savedMedicationAdministration2= medicationAdministrationDao.createOrUpdate(medicationAdministration2); + + Slot slot1 = new Slot(); + slot1.setSchedule(savedSchedule); + slot1.setServiceType(testConcept); + slot1.setStartDateTime(slot1StartTime); + slot1.setOrder(drugOrder); + + Slot slot2 = new Slot(); + slot2.setSchedule(savedSchedule); + slot2.setServiceType(testConcept); + slot2.setStartDateTime(slot2StartTime); + slot2.setMedicationAdministration(savedMedicationAdministration); + slot2.setOrder(drugOrder2); + + Slot slot3 = new Slot(); + slot3.setSchedule(savedSchedule); + slot3.setServiceType(testConcept); + slot3.setStartDateTime(slot2StartTime); + slot3.setOrder(drugOrder); + + Slot slot4 = new Slot(); + slot4.setSchedule(savedSchedule); + slot4.setServiceType(testConcept); + slot4.setStartDateTime(slot1StartTime); + slot4.setOrder(drugOrder); + + Slot savedSlot1 = slotDAO.saveSlot(slot1); + Slot savedSlot2 = slotDAO.saveSlot(slot2); + Slot savedSlot3 = slotDAO.saveSlot(slot3); + Slot savedSlot4 = slotDAO.saveSlot(slot4); + + + List slotsBySubjectReferenceIdAndServiceType = slotDAO.getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(patientReference,startTime,startTime.plusHours(6),visit,testConcept); + + Assertions.assertEquals(4, slotsBySubjectReferenceIdAndServiceType.size()); + + sessionFactory.getCurrentSession().delete(savedMedicationAdministration); + sessionFactory.getCurrentSession().delete(savedMedicationAdministration2); + sessionFactory.getCurrentSession().delete(savedSlot1); + sessionFactory.getCurrentSession().delete(savedSlot2); + sessionFactory.getCurrentSession().delete(savedSlot3); + sessionFactory.getCurrentSession().delete(savedSlot4); + sessionFactory.getCurrentSession().delete(savedSchedule); + sessionFactory.getCurrentSession().delete(visit); + + } + + @Test + public void shouldGetSlotsForPatientListByTime() { + executeDataSet("scheduleMedicationsTestData.xml"); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime startTime = LocalDateTime.parse("2024-01-28 11:00:00", formatter); + LocalDateTime endTime = LocalDateTime.parse("2024-01-29 11:00:00", formatter); + List patientUuids = new ArrayList<>(); + patientUuids.add("75e04d42-3ca8-11e3-bf2b-0800271c1b75"); + + List slotsForPatientListByTime = slotDAO.getSlotsForPatientListByTime(patientUuids, startTime, endTime); + + Assertions.assertEquals(3, slotsForPatientListByTime.size()); + } + + @Test + public void shouldGetImmediatePreviousSlotsForPatientListByTime() { + executeDataSet("scheduleMedicationsTestData.xml"); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime startTime = LocalDateTime.parse("2024-01-28 11:00:00", formatter); + List patientUuids = new ArrayList<>(); + patientUuids.add("75e04d42-3ca8-11e3-bf2b-0800271c1b75"); + + List previousSlots = slotDAO.getImmediatePreviousSlotsForPatientListByTime(patientUuids, startTime); + + Assertions.assertEquals(1, previousSlots.size()); + } + + @Test + public void shouldGetSlotDurationForPatientsByOrder() { + executeDataSet("scheduleMedicationsTestData.xml"); + + List orders = new ArrayList<>(); + Order order = Context.getOrderService().getOrderByUuid("6d0ae386-707a-4629-9850-f15206e63ab0"); + orders.add(order); + List serviceTypes = new ArrayList<>(); + serviceTypes.add(Context.getConceptService().getConceptByName("MedicationRequest")); + + List slotsDuration = slotDAO.getSlotDurationForPatientsByOrder(orders, serviceTypes); + + Assertions.assertEquals(1, slotsDuration.size()); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime startTime = LocalDateTime.parse("2024-01-27 20:00:00", formatter); + LocalDateTime endTime = LocalDateTime.parse("2024-01-29 08:00:00", formatter); + + Assertions.assertEquals(startTime, slotsDuration.get(0)[1]); + Assertions.assertEquals(endTime, slotsDuration.get(0)[2]); + } +} diff --git a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAOIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAOIntegrationTest.java new file mode 100644 index 0000000..a932f79 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAOIntegrationTest.java @@ -0,0 +1,34 @@ +package org.openmrs.module.ipd.api.dao.impl; + +import org.hibernate.SessionFactory; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.openmrs.Location; +import org.openmrs.api.LocationService; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.BaseIntegrationTest; +import org.openmrs.module.ipd.api.dao.WardDAO; +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +public class HibernateWardDAOIntegrationTest extends BaseIntegrationTest { + + @Autowired + private WardDAO wardDAO; + + @Autowired + private SessionFactory sessionFactory; + + + @Test + public void shouldGetAdmittedPatientsByLocation() { + + Location location= Context.getService(LocationService.class).getLocationByUuid("7779d653-393b-4118-9c83-a3715b82d4ac"); + List admittedPatients= wardDAO.getAdmittedPatients(location, null, null, null); + + Assertions.assertEquals(0, admittedPatients.size()); + + } +} diff --git a/api/src/test/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImplTest.java b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImplTest.java new file mode 100644 index 0000000..468423b --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/CareTeamServiceImplTest.java @@ -0,0 +1,59 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.openmrs.Concept; +import org.openmrs.ConceptName; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.dao.CareTeamDAO; +import org.openmrs.module.ipd.api.dao.ScheduleDAO; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Schedule; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +@RunWith(MockitoJUnitRunner.class) +public class CareTeamServiceImplTest { + + @InjectMocks + private CareTeamServiceImpl careTeamService; + + @Mock + private CareTeamDAO careTeamDAO; + + @Test + public void shouldInvokeSaveCareTeamWithGivenCareTeam() { + CareTeam careTeam = new CareTeam(); + CareTeam expectedCareTeam = new CareTeam(); + expectedCareTeam.setId(1); + + Mockito.when(careTeamDAO.saveCareTeam(careTeam)).thenReturn(expectedCareTeam); + + careTeamService.saveCareTeam(careTeam); + + Mockito.verify(careTeamDAO, Mockito.times(1)).saveCareTeam(careTeam); + } + + @Test + public void shouldInvokeGetCareTeamWithGivenVisit() { + CareTeam expectedCareTeam = new CareTeam(); + Visit visit = new Visit(); + expectedCareTeam.setId(1); + + Mockito.when(careTeamDAO.getCareTeamByVisit(visit)).thenReturn(expectedCareTeam); + + careTeamService.getCareTeamByVisit(visit); + + Mockito.verify(careTeamDAO, Mockito.times(1)).getCareTeamByVisit(visit); + } + +} diff --git a/api/src/test/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImplTest.java b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImplTest.java new file mode 100644 index 0000000..26332a8 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/ReferenceServiceImplTest.java @@ -0,0 +1,50 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.openmrs.Patient; +import org.openmrs.module.ipd.api.dao.ReferenceDAO; +import org.openmrs.module.ipd.api.model.Reference; + +import java.util.Optional; + +@RunWith(MockitoJUnitRunner.class) +public class ReferenceServiceImplTest { + + @InjectMocks + private ReferenceServiceImpl referenceService; + + @Mock + private ReferenceDAO referenceDAO; + + @Test + public void shouldInvokeSaveReferenceWithGivenReference() { + Reference openmrsReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + Reference expectedOpenmrsReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + expectedOpenmrsReference.setId(1); + + Mockito.when(referenceDAO.saveReference(openmrsReference)).thenReturn(expectedOpenmrsReference); + + referenceService.saveReference(openmrsReference); + + Mockito.verify(referenceDAO, Mockito.times(1)).saveReference(openmrsReference); + } + + @Test + public void shouldInvokeGetReferenceByTargetUUIDAndTypeWithGivenTargetUUIDAndType() { + String typeName = Patient.class.getTypeName(); + String targetUuid = "2c33920f-7aa6-0000-998a-60412d8ff7d5"; + Reference expectedOpenmrsReference = new Reference(Patient.class.getTypeName(), "2c33920f-7aa6-0000-998a-60412d8ff7d5"); + expectedOpenmrsReference.setId(1); + + Mockito.when(referenceDAO.getReferenceByTypeAndTargetUUID(typeName, targetUuid)).thenReturn(Optional.of(expectedOpenmrsReference)); + + referenceService.getReferenceByTypeAndTargetUUID(typeName, targetUuid); + + Mockito.verify(referenceDAO, Mockito.times(1)).getReferenceByTypeAndTargetUUID(typeName, targetUuid); + } +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImplTest.java b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImplTest.java new file mode 100644 index 0000000..ee897c3 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/ScheduleServiceImplTest.java @@ -0,0 +1,69 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.openmrs.Concept; +import org.openmrs.ConceptName; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.dao.ScheduleDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Schedule; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +@RunWith(MockitoJUnitRunner.class) +public class ScheduleServiceImplTest { + + @InjectMocks + private ScheduleServiceImpl scheduleService; + + @Mock + private ScheduleDAO scheduleDAO; + + @Test + public void shouldInvokeSaveScheduleWithGivenSchedule() { + Schedule schedule = new Schedule(); + Schedule expectedSchedule = new Schedule(); + expectedSchedule.setId(1); + + Mockito.when(scheduleDAO.saveSchedule(schedule)).thenReturn(expectedSchedule); + + scheduleService.saveSchedule(schedule); + + Mockito.verify(scheduleDAO, Mockito.times(1)).saveSchedule(schedule); + } + + @Test + public void shouldInvokeGetScheduleWithGivenScheduleId() { + Schedule expectedSchedule = new Schedule(); + expectedSchedule.setId(1); + + Mockito.when(scheduleDAO.getSchedule(1)).thenReturn(expectedSchedule); + + scheduleService.getSchedule(1); + + Mockito.verify(scheduleDAO, Mockito.times(1)).getSchedule(1); + } + + @Test + public void shouldInvokeGetScheduleWithGivenVisit() { + Schedule expectedSchedule = new Schedule(); + Visit visit = new Visit(); + expectedSchedule.setId(1); + + Mockito.when(scheduleDAO.getScheduleByVisit(visit)).thenReturn(expectedSchedule); + + scheduleService.getScheduleByVisit(visit); + + Mockito.verify(scheduleDAO, Mockito.times(1)).getScheduleByVisit(visit); + } + +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImplTest.java b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImplTest.java new file mode 100644 index 0000000..8a08728 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/service/impl/SlotServiceImplTest.java @@ -0,0 +1,221 @@ +package org.openmrs.module.ipd.api.service.impl; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.openmrs.Concept; +import org.openmrs.ConceptName; +import org.openmrs.Order; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.module.ipd.api.dao.SlotDAO; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.Slot; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; + +@RunWith(MockitoJUnitRunner.class) +public class SlotServiceImplTest { + + @InjectMocks + private SlotServiceImpl slotService; + + @Mock + private SlotDAO slotDAO; + + @Test + public void shouldInvokeSaveSlotWithGivenSlot() { + Slot slot = new Slot(); + Slot expectedSlot = new Slot(); + expectedSlot.setId(1); + + Mockito.when(slotDAO.saveSlot(slot)).thenReturn(expectedSlot); + + slotService.saveSlot(slot); + + Mockito.verify(slotDAO, Mockito.times(1)).saveSlot(slot); + } + + @Test + public void shouldInvokeGetSlotWithGivenSlotId() { + Slot expectedSlot = new Slot(); + expectedSlot.setId(1); + + Mockito.when(slotDAO.getSlot(1)).thenReturn(expectedSlot); + + slotService.getSlot(1); + + Mockito.verify(slotDAO, Mockito.times(1)).getSlot(1); + } + + @Test + public void shouldInvokeGetSlotsByForReferenceAndForDateAndServiceTypeWithGivenScheduleId() { + Slot expectedSlot = new Slot(); + expectedSlot.setId(1); + List slots = new ArrayList<>(); + + LocalDate today = LocalDate.now(); + Concept medicationRequestConcept = new Concept(); + ConceptName conceptName = new ConceptName(); + conceptName.setName("MedicationRequest"); + conceptName.setLocale(Locale.US); + medicationRequestConcept.setFullySpecifiedName(conceptName); + + Reference patientReference = new Reference(Patient.class.getTypeName(), "patientUuid"); + + Mockito.when(slotDAO.getSlotsBySubjectReferenceIdAndForDateAndServiceType(patientReference, today, medicationRequestConcept)).thenReturn(slots); + + slotService.getSlotsBySubjectReferenceIdAndForDateAndServiceType(patientReference, today, medicationRequestConcept); + + Mockito.verify(slotDAO, Mockito.times(1)).getSlotsBySubjectReferenceIdAndForDateAndServiceType(patientReference, today, medicationRequestConcept); + } + + @Test + public void shouldInvokeGetSlotsByForReferenceAndServiceTypeWithGivenScheduleId() { + List slots = new ArrayList<>(); + + LocalDate today = LocalDate.now(); + Concept medicationRequestConcept = new Concept(); + ConceptName conceptName = new ConceptName(); + conceptName.setName("MedicationRequest"); + conceptName.setLocale(Locale.US); + medicationRequestConcept.setFullySpecifiedName(conceptName); + + Reference patientReference = new Reference(Patient.class.getTypeName(), "patientUuid"); + + Mockito.when(slotDAO.getSlotsBySubjectReferenceIdAndServiceType(patientReference, medicationRequestConcept)).thenReturn(slots); + + slotService.getSlotsBySubjectReferenceIdAndServiceType(patientReference, medicationRequestConcept); + + Mockito.verify(slotDAO, Mockito.times(1)).getSlotsBySubjectReferenceIdAndServiceType(patientReference, medicationRequestConcept); + } + + @Test + public void shouldInvokeGetSlotsByForReferenceAndServiceTypeAndOrderUuidsWithGivenScheduleId() { + Schedule expectedSchedule = new Schedule(); + expectedSchedule.setId(1); + List slots = new ArrayList<>(); + + LocalDate today = LocalDate.now(); + Concept medicationRequestConcept = new Concept(); + ConceptName conceptName = new ConceptName(); + conceptName.setName("MedicationRequest"); + conceptName.setLocale(Locale.US); + medicationRequestConcept.setFullySpecifiedName(conceptName); + + List orderUuids = new ArrayList<>(); + orderUuids.add("orderUuid"); + + Reference patientReference = new Reference(Patient.class.getTypeName(), "patientUuid"); + + Mockito.when(slotDAO.getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(patientReference, medicationRequestConcept, orderUuids)).thenReturn(slots); + + slotService.getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(patientReference, medicationRequestConcept, orderUuids); + + Mockito.verify(slotDAO, Mockito.times(1)).getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(patientReference, medicationRequestConcept, orderUuids); + } + + @Test + public void shouldInvokeGetSlotsBySubjectReferenceAndAdministeredTimeWithGivenTimeFrame() { + + List slots = new ArrayList<>(); + LocalDateTime startTime= LocalDateTime.now(); + LocalDateTime endTime = startTime.plusHours(8); + Reference patientReference = new Reference(Patient.class.getTypeName(), "patientUuid"); + Visit visit = new Visit(123); + + Mockito.when(slotDAO.getSlotsBySubjectIncludingAdministeredTimeFrame(patientReference, startTime, endTime, visit)).thenReturn(slots); + + slotService.getSlotsBySubjectReferenceIncludingAdministeredTimeFrame(patientReference,startTime,endTime,visit); + + Mockito.verify(slotDAO, Mockito.times(1)).getSlotsBySubjectIncludingAdministeredTimeFrame(patientReference, startTime, endTime, visit); + } + + @Test + public void shouldInvokeGetSlotsForPatientListByTime() { + List slots = new ArrayList<>(); + LocalDateTime startTime= LocalDateTime.now(); + LocalDateTime endTime = startTime.plusHours(3); + List patientUuids = new ArrayList<>(); + patientUuids.add("patientUuid1"); + patientUuids.add("patientUuid2"); + + Mockito.when(slotDAO.getSlotsForPatientListByTime(patientUuids, startTime, endTime)).thenReturn(slots); + slotService.getSlotsForPatientListByTime(patientUuids, startTime, endTime); + + Mockito.verify(slotDAO, Mockito.times(1)).getSlotsForPatientListByTime(patientUuids, startTime, endTime); + } + + @Test + public void shouldInvokeGetImmediatePreviousSlotsForPatientListByTime() { + List slots = new ArrayList<>(); + LocalDateTime startTime= LocalDateTime.now(); + List patientUuids = new ArrayList<>(); + patientUuids.add("patientUuid1"); + patientUuids.add("patientUuid2"); + + Mockito.when(slotDAO.getImmediatePreviousSlotsForPatientListByTime(patientUuids, startTime)).thenReturn(slots); + slotService.getImmediatePreviousSlotsForPatientListByTime(patientUuids, startTime); + + Mockito.verify(slotDAO, Mockito.times(1)).getImmediatePreviousSlotsForPatientListByTime(patientUuids, startTime); + } + + @Test + public void shouldInvokeGetSlotDurationForPatientsByOrder() { + List slotDurationObjects = new ArrayList<>(); + List orders = new ArrayList<>(); + Order order = new Order(); + order.setUuid("orderUuid1"); + orders.add(order); + order = new Order(); + order.setUuid("orderUuid2"); + orders.add(order); + + List serviceTypes = new ArrayList<>(); + Concept concept = new Concept(); + concept.setUuid("serviceType1"); + serviceTypes.add(concept); + + Mockito.when(slotDAO.getSlotDurationForPatientsByOrder(orders, serviceTypes)).thenReturn(slotDurationObjects); + slotService.getSlotDurationForPatientsByOrder(orders, serviceTypes); + + Mockito.verify(slotDAO, Mockito.times(1)).getSlotDurationForPatientsByOrder(orders, serviceTypes); + } + @Test + public void shouldInvokeMarkSlotsAsMissed() { + Order order = new Order(); + Slot slot1 = new Slot(); + LocalDateTime localDateTime = LocalDateTime.now(); + slot1.setStatus(Slot.SlotStatus.SCHEDULED); + slot1.setOrder(order); + slot1.setStartDateTime(localDateTime); + + LocalDateTime futureTime = LocalDateTime.now().plusHours(2); + + Slot slot2 = new Slot(); + slot2.setStatus(Slot.SlotStatus.SCHEDULED); + slot2.setOrder(order); + slot2.setStartDateTime(futureTime); + ArrayList slots = new ArrayList<>(); + slots.add(slot1); + slots.add(slot2); + HashMap maxTimeForAnOrder = new HashMap<>(); + + Mockito.when(slotDAO.saveSlot(slot1)).thenReturn(slot1); + + + maxTimeForAnOrder.put(order, futureTime); + slotService.markSlotsAsMissed(slots, maxTimeForAnOrder); + Mockito.verify(slotDAO, Mockito.times(1)).saveSlot(slot1); + + } +} \ No newline at end of file diff --git a/api/src/test/java/org/openmrs/module/ipd/api/util/DateTimeUtilTest.java b/api/src/test/java/org/openmrs/module/ipd/api/util/DateTimeUtilTest.java new file mode 100644 index 0000000..88b2a7e --- /dev/null +++ b/api/src/test/java/org/openmrs/module/ipd/api/util/DateTimeUtilTest.java @@ -0,0 +1,58 @@ +package org.openmrs.module.ipd.api.util; + +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; +import java.util.TimeZone; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DateTimeUtilTest { + + @Test + public void shouldConvertEPOCUTCToLocalTimeZone() { + ZoneId defaultZoneId = TimeZone.getDefault().toZoneId(); + TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("Asia/Kolkata"))); + + LocalDateTime localDateTime = DateTimeUtil.convertEpocUTCToLocalTimeZone(1690906304); + + assertEquals(2023,localDateTime.getYear()); + assertEquals(8, localDateTime.getMonthValue()); + assertEquals(1, localDateTime.getDayOfMonth()); + assertEquals(21, localDateTime.getHour()); + assertEquals(41, localDateTime.getMinute()); + assertEquals(44, localDateTime.getSecond()); + + TimeZone.setDefault(TimeZone.getTimeZone(defaultZoneId)); + } + + @Test + public void shouldConvertLocalTimeZoneToEPOCUTC() { + ZoneId defaultZoneId = TimeZone.getDefault().toZoneId(); + TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("Asia/Kolkata"))); + + LocalDateTime localDateTime = LocalDateTime.of(2023, 8, 1, 21, 41, 44); + long epocUTCTime = DateTimeUtil.convertLocalDateTimeToUTCEpoc(localDateTime); + + assertEquals(1690906304,epocUTCTime); + + TimeZone.setDefault(TimeZone.getTimeZone(defaultZoneId)); + } + + @Test + public void shouldConvertDateToLocalDateTime() { + ZoneId defaultZoneId = TimeZone.getDefault().toZoneId(); + TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("Asia/Kolkata"))); + + Date date = Date.from(Instant.ofEpochSecond(1690906304)); + LocalDateTime localDateTime = DateTimeUtil.convertDateToLocalDateTime(date); + + assertEquals(1690906304, localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond()); + + TimeZone.setDefault(TimeZone.getTimeZone(defaultZoneId)); + } +} \ No newline at end of file diff --git a/api/src/test/resources/CareTeamDAOTestData.xml b/api/src/test/resources/CareTeamDAOTestData.xml new file mode 100644 index 0000000..222818f --- /dev/null +++ b/api/src/test/resources/CareTeamDAOTestData.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/api/src/test/resources/TestingApplicationContext.xml b/api/src/test/resources/TestingApplicationContext.xml new file mode 100644 index 0000000..bf8a8fc --- /dev/null +++ b/api/src/test/resources/TestingApplicationContext.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/api/src/test/resources/WardDAOTestData.xml b/api/src/test/resources/WardDAOTestData.xml new file mode 100644 index 0000000..3688c59 --- /dev/null +++ b/api/src/test/resources/WardDAOTestData.xml @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/api/src/test/resources/scheduleMedicationsTestData.xml b/api/src/test/resources/scheduleMedicationsTestData.xml new file mode 100644 index 0000000..920b1d3 --- /dev/null +++ b/api/src/test/resources/scheduleMedicationsTestData.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..8d937f4 --- /dev/null +++ b/mvnw @@ -0,0 +1,308 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.2.0 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "$(uname)" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then + if $darwin ; then + javaHome="$(dirname "\"$javaExecutable\"")" + javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" + else + javaExecutable="$(readlink -f "\"$javaExecutable\"")" + fi + javaHome="$(dirname "\"$javaExecutable\"")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=$(cd "$wdir/.." || exit 1; pwd) + fi + # end of workaround + done + printf '%s' "$(cd "$basedir" || exit 1; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; + esac + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget > /dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +fi + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# shellcheck disable=SC2086 # safe args +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..c4586b5 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,205 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.2.0 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/omod/pom.xml b/omod/pom.xml new file mode 100644 index 0000000..156e1d2 --- /dev/null +++ b/omod/pom.xml @@ -0,0 +1,191 @@ + + + + 4.0.0 + + bahmni-ipd + org.bahmni.module + 1.0.0-SNAPSHOT + + + bahmni-ipd-omod + jar + Bahmni IPD omod + Bahmni IPD module contains all backend APIs for IPD + + + bahmni-ipd + ${project.name} + ${project.version} + ${project.groupId}.${MODULE_ID} + + + + ${project.parent.artifactId}-${project.parent.version} + + + + maven-resources-plugin + + true + + + + + + + + org.openmrs.maven.plugins + maven-openmrs-plugin + true + + + init + initialize + + initialize-module + + + + pack + package + + package-module + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + Expand moduleApplicationContext and messages + + unpack-dependencies + + generate-resources + + ${project.parent.groupId} + ${project.parent.artifactId}-api + true + **/* + ${project.build.directory}/classes + + + + + + + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.parent.version} + + + org.projectlombok + lombok + + + org.openmrs.web + openmrs-web + provided + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + org.openmrs.module + webservices.rest-omod-common + provided + + + org.openmrs.module + bedmanagement-api + provided + + + + org.openmrs.module + fhir2-api + provided + + + + org.openmrs.module + fhir2-omod + provided + + + + org.bahmni.module + fhir2Extension-api + provided + + + + org.bahmni.module + fhir2Extension-omod + provided + + + + org.openmrs.module + emrapi-api + provided + + + + org.bahmni.module + bahmnicore-api + provided + + + + org.bahmni.module + medication-administration-api + provided + + + + org.openmrs.test + openmrs-test + pom + + + org.openmrs.web + openmrs-web + test-jar + test + + + org.openmrs.api + openmrs-api + test-jar + test + + + javax.servlet + servlet-api + test + + + commons-digester + commons-digester + 2.1 + compile + + + ${project.parent.groupId} + ${project.parent.artifactId}-api + ${project.parent.version} + + + + \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/ipd/ModuleDescriptor.java b/omod/src/main/java/org/openmrs/module/ipd/ModuleDescriptor.java new file mode 100644 index 0000000..7b43171 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/ModuleDescriptor.java @@ -0,0 +1,3 @@ +package org.openmrs.module.ipd; + +public class ModuleDescriptor {} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/AdmittedPatientResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/AdmittedPatientResponse.java new file mode 100644 index 0000000..75f7e8b --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/AdmittedPatientResponse.java @@ -0,0 +1,33 @@ +package org.openmrs.module.ipd.contract; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.openmrs.module.webservices.rest.web.ConversionUtil; +import org.openmrs.module.webservices.rest.web.representation.Representation; + +@Getter +@Setter +@Builder +public class AdmittedPatientResponse { + + private Object patientDetails; + private Object bedDetails; + private Object visitDetails; + private Long newTreatments; + private Object careTeam; + public static AdmittedPatientResponse createFrom(AdmittedPatient admittedPatient) { + AdmittedPatientResponse admittedPatientResponse = AdmittedPatientResponse.builder(). + patientDetails(ConversionUtil.convertToRepresentation(admittedPatient.getBedPatientAssignment().getPatient(), Representation.DEFAULT)). + bedDetails(ConversionUtil.convertToRepresentation(admittedPatient.getBedPatientAssignment().getBed(),Representation.REF)). + visitDetails(ConversionUtil.convertToRepresentation(admittedPatient.getBedPatientAssignment().getEncounter().getVisit(), Representation.REF)). + newTreatments(admittedPatient.getNewTreatments()).build(); + + if ( admittedPatient.getCareTeam() != null ) { + admittedPatientResponse.setCareTeam(CareTeamResponse.createFrom(admittedPatient.getCareTeam())); + } + + return admittedPatientResponse; + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantRequest.java b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantRequest.java new file mode 100644 index 0000000..a98afec --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantRequest.java @@ -0,0 +1,24 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Date; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Builder +public class CareTeamParticipantRequest { + + private String uuid; + private Long startTime; + private Long endTime; + private String providerUuid; + private Boolean voided; + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantResponse.java new file mode 100644 index 0000000..427c6c5 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamParticipantResponse.java @@ -0,0 +1,30 @@ +package org.openmrs.module.ipd.contract; + +import lombok.Builder; +import lombok.Getter; +import org.openmrs.module.ipd.api.model.CareTeamParticipant; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.openmrs.module.webservices.rest.web.ConversionUtil; +import org.openmrs.module.webservices.rest.web.representation.Representation; + +@Getter +@Builder +public class CareTeamParticipantResponse { + + private String uuid; + private Object provider; + private Long startTime; + private Long endTime; + private Boolean voided; + + public static CareTeamParticipantResponse createFrom(CareTeamParticipant careTeamParticipant) { + return CareTeamParticipantResponse.builder(). + uuid(careTeamParticipant.getUuid()). + provider(ConversionUtil.convertToRepresentation(careTeamParticipant.getProvider(), Representation.REF)). + startTime(careTeamParticipant.getStartTime().getTime()). + endTime(careTeamParticipant.getEndTime().getTime()). + voided(careTeamParticipant.getVoided()). + build(); + } + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamRequest.java b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamRequest.java new file mode 100644 index 0000000..4073924 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamRequest.java @@ -0,0 +1,15 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class CareTeamRequest { + private String patientUuid; + private List careTeamParticipantsRequest; +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamResponse.java new file mode 100644 index 0000000..ade81b7 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/CareTeamResponse.java @@ -0,0 +1,28 @@ +package org.openmrs.module.ipd.contract; + +import lombok.Builder; +import lombok.Getter; +import org.openmrs.module.ipd.api.model.CareTeam; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +@Builder +public class CareTeamResponse { + + private String uuid; + private String patientUuid; + private List participants; + + public static CareTeamResponse createFrom(CareTeam careTeam){ + return CareTeamResponse.builder(). + uuid(careTeam.getUuid()). + patientUuid(careTeam.getPatient().getUuid()). + participants(careTeam.getParticipants().stream(). + filter(careTeamParticipant -> !careTeamParticipant.getVoided()). + map(CareTeamParticipantResponse::createFrom).collect(Collectors.toList())). + build(); + } + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/DrugOrderScheduleResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/DrugOrderScheduleResponse.java new file mode 100644 index 0000000..e00077f --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/DrugOrderScheduleResponse.java @@ -0,0 +1,37 @@ +package org.openmrs.module.ipd.contract; + +import lombok.*; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.model.DrugOrderSchedule; + +import java.time.LocalDateTime; +import java.util.List; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DrugOrderScheduleResponse { + + private List firstDaySlotsStartTime; + private List dayWiseSlotsStartTime; + private List remainingDaySlotsStartTime; + private Long slotStartTime; + private Boolean medicationAdministrationStarted; + private Boolean pendingSlotsAvailable; + private Boolean allSlotsAttended; + private String notes; + + public static DrugOrderScheduleResponse createFrom(DrugOrderSchedule drugOrderSchedule){ + return DrugOrderScheduleResponse.builder(). + firstDaySlotsStartTime(drugOrderSchedule.getFirstDaySlotsStartTime()). + dayWiseSlotsStartTime(drugOrderSchedule.getDayWiseSlotsStartTime()). + remainingDaySlotsStartTime(drugOrderSchedule.getRemainingDaySlotsStartTime()). + slotStartTime(drugOrderSchedule.getSlotStartTime()). + medicationAdministrationStarted(drugOrderSchedule.getSlots().stream().anyMatch(slot -> slot.getMedicationAdministration() != null)). + allSlotsAttended(!(drugOrderSchedule.getSlots().stream().anyMatch(slot -> slot.getStatus().equals(Slot.SlotStatus.SCHEDULED)))). + pendingSlotsAvailable(drugOrderSchedule.getSlots().stream().anyMatch(slot -> (LocalDateTime.now().isBefore(slot.getStartDateTime()) && slot.getStatus().equals(Slot.SlotStatus.SCHEDULED)))). + notes(drugOrderSchedule.getSlots().get(0).getNotes()). + build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/IPDDrugOrderResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDDrugOrderResponse.java new file mode 100644 index 0000000..5ccb047 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDDrugOrderResponse.java @@ -0,0 +1,40 @@ +package org.openmrs.module.ipd.contract; + +import lombok.*; +import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; +import org.openmrs.module.ipd.model.IPDDrugOrder; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class IPDDrugOrderResponse { + + private EncounterTransaction.DrugOrder drugOrder; + private EncounterTransaction.Provider provider; + private DrugOrderScheduleResponse drugOrderSchedule; + + public static IPDDrugOrderResponse createFrom(IPDDrugOrder ipdDrugOrder) { + IPDDrugOrderResponse ipdDrugOrderResponse= IPDDrugOrderResponse.builder(). + drugOrder(ipdDrugOrder.getBahmniDrugOrder().getDrugOrder()) + .provider(ipdDrugOrder.getBahmniDrugOrder().getProvider()) + .build(); + if (ipdDrugOrder.getDrugOrderSchedule() != null){ + ipdDrugOrderResponse.setDrugOrderSchedule(DrugOrderScheduleResponse.createFrom(ipdDrugOrder.getDrugOrderSchedule())); + } + return ipdDrugOrderResponse; + } + + public boolean equals(Object otherOrder) { + if (otherOrder == null) { + return false; + } else if (!(otherOrder instanceof IPDDrugOrderResponse)) { + return false; + } else { + return super.equals(otherOrder); + } + } + + +} \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/IPDPatientDetailsResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDPatientDetailsResponse.java new file mode 100644 index 0000000..eebedfd --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDPatientDetailsResponse.java @@ -0,0 +1,23 @@ +package org.openmrs.module.ipd.contract; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import org.openmrs.module.ipd.api.model.IPDPatientDetails; +import java.util.List; +import java.util.stream.Collectors; + +@Builder +@Getter +@Setter +public class IPDPatientDetailsResponse { + private List admittedPatients; + private Integer totalPatients; + + public static IPDPatientDetailsResponse createFrom(IPDPatientDetails ipdPatientDetails) { + return IPDPatientDetailsResponse.builder() + .admittedPatients(ipdPatientDetails.getAdmittedPatients().stream().map(AdmittedPatientResponse::createFrom).collect(Collectors.toList())) + .totalPatients(ipdPatientDetails.getPatientCount()) + .build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/IPDTreatmentsResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDTreatmentsResponse.java new file mode 100644 index 0000000..1b9e195 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDTreatmentsResponse.java @@ -0,0 +1,28 @@ +package org.openmrs.module.ipd.contract; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class IPDTreatmentsResponse { + + private List ipdDrugOrders; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private List emergencyMedications; + + public static IPDTreatmentsResponse createFrom(List ipdDrugOrders, List emergencyMedications) { + return IPDTreatmentsResponse.builder() + .ipdDrugOrders(ipdDrugOrders) + .emergencyMedications(emergencyMedications) + .build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientDetailsResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientDetailsResponse.java new file mode 100644 index 0000000..10e8f33 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientDetailsResponse.java @@ -0,0 +1,24 @@ +package org.openmrs.module.ipd.contract; + +import lombok.Builder; +import lombok.Getter; +import org.openmrs.module.ipd.api.model.IPDWardPatientDetails; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +@Builder +public class IPDWardPatientDetailsResponse { + + private List admittedPatients; + private Long totalPatients; + + + public static IPDWardPatientDetailsResponse createFrom(IPDWardPatientDetails ipdWardPatientDetails) { + return IPDWardPatientDetailsResponse.builder(). + admittedPatients(ipdWardPatientDetails.getActivePatients().stream().map(AdmittedPatientResponse::createFrom).collect(Collectors.toList())). + totalPatients(ipdWardPatientDetails.getIpdWardWardPatientsSummary().getTotalPatients()). + build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientSummaryResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientSummaryResponse.java new file mode 100644 index 0000000..fc3bfa2 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardPatientSummaryResponse.java @@ -0,0 +1,23 @@ +package org.openmrs.module.ipd.contract; + + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import org.openmrs.module.ipd.api.model.WardPatientsSummary; + +@Getter +@Setter +@Builder +public class IPDWardPatientSummaryResponse { + + private Long totalPatients; + private Long totalProviderPatients; + + public static IPDWardPatientSummaryResponse createFrom(WardPatientsSummary wardPatientsSummary){ + return IPDWardPatientSummaryResponse.builder(). + totalPatients(wardPatientsSummary.getTotalPatients()). + totalProviderPatients(wardPatientsSummary.getTotalProviderPatients()). + build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardResponse.java new file mode 100644 index 0000000..e82967e --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/IPDWardResponse.java @@ -0,0 +1,25 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.openmrs.Location; +import org.openmrs.module.bedmanagement.AdmissionLocation; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class IPDWardResponse { + private String uuid; + private String name; + + public static IPDWardResponse createFrom (AdmissionLocation admissionLocation){ + return IPDWardResponse.builder(). + uuid(admissionLocation.getWard().getUuid()). + name(admissionLocation.getWard().getName()). + build(); + } + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteRequest.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteRequest.java new file mode 100644 index 0000000..87fdd58 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteRequest.java @@ -0,0 +1,26 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties +public class MedicationAdministrationNoteRequest { + private String uuid; + private String authorUuid; + private Long recordedTime; + private String text; + + public Date getRecordedTimeAsLocaltime() { + return this.recordedTime != null ? new Date(TimeUnit.SECONDS.toMillis(this.recordedTime)): new Date(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteResponse.java new file mode 100644 index 0000000..b8e2f01 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationNoteResponse.java @@ -0,0 +1,31 @@ +package org.openmrs.module.ipd.contract; + +import lombok.*; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.openmrs.module.ipd.api.model.MedicationAdministrationNote; +import org.openmrs.module.webservices.rest.web.ConversionUtil; +import org.openmrs.module.webservices.rest.web.representation.Representation; + +import java.util.Date; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties +public class MedicationAdministrationNoteResponse { + private String uuid; + private Object author; + private Date recordedTime; + private String text; + + public static MedicationAdministrationNoteResponse createFrom(MedicationAdministrationNote openmrsObject) { + return MedicationAdministrationNoteResponse.builder() + .uuid(openmrsObject.getUuid()) + .author(ConversionUtil.convertToRepresentation(openmrsObject.getAuthor(), Representation.REF)) + .recordedTime(openmrsObject.getRecordedTime()) + .text(openmrsObject.getText()) + .build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerRequest.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerRequest.java new file mode 100644 index 0000000..c1d5a36 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerRequest.java @@ -0,0 +1,21 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties +public class MedicationAdministrationPerformerRequest { + private String uuid; + private String providerUuid; + private String function; +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerResponse.java new file mode 100644 index 0000000..3b1c1cf --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationPerformerResponse.java @@ -0,0 +1,28 @@ +package org.openmrs.module.ipd.contract; + +import lombok.*; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +import org.openmrs.module.ipd.api.model.MedicationAdministrationPerformer; +import org.openmrs.module.webservices.rest.web.ConversionUtil; +import org.openmrs.module.webservices.rest.web.representation.Representation; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties +public class MedicationAdministrationPerformerResponse { + private String uuid; + private Object provider; + private String function; + + public static MedicationAdministrationPerformerResponse createFrom(MedicationAdministrationPerformer openmrsMedicationAdministrationPerformer) { + String function = openmrsMedicationAdministrationPerformer.getFunction() != null ? openmrsMedicationAdministrationPerformer.getFunction().getDisplayString() : null; + return MedicationAdministrationPerformerResponse.builder() + .uuid(openmrsMedicationAdministrationPerformer.getUuid()) + .provider(ConversionUtil.convertToRepresentation(openmrsMedicationAdministrationPerformer.getActor(), Representation.REF)) + .function(function) + .build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationRequest.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationRequest.java new file mode 100644 index 0000000..43402ec --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationRequest.java @@ -0,0 +1,38 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Date; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MedicationAdministrationRequest { + + private String uuid; + private String patientUuid; + private String encounterUuid; + private String orderUuid; + private List providers; + private List notes; + private String status; + private String statusReason; + private String drugUuid; + private String dosingInstructions; + private Double dose; + private String doseUnits; + private String route; + private String site; + private Long administeredDateTime; + private String slotUuid; + + public Date getAdministeredDateTimeAsLocaltime() { + return this.administeredDateTime != null ? new Date(TimeUnit.SECONDS.toMillis(this.administeredDateTime)): new Date(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java new file mode 100644 index 0000000..4857b4e --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java @@ -0,0 +1,78 @@ +package org.openmrs.module.ipd.contract; + +import lombok.*; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.model.MedicationAdministrationNote; +import org.openmrs.module.ipd.api.model.MedicationAdministrationPerformer; +import org.openmrs.module.webservices.rest.web.ConversionUtil; +import org.openmrs.module.webservices.rest.web.representation.Representation; + + +import java.util.Date; +import java.util.List; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MedicationAdministrationResponse { + + private String uuid; + private String patientUuid; + private String encounterUuid; + private String orderUuid; + private List providers; + private List notes; + private String status; + private String statusReason; + private Object drug; + private String dosingInstructions; + private Double dose; + private Object doseUnits; + private Object route; + private Object site; + private Date administeredDateTime; + + public static MedicationAdministrationResponse createFrom(org.openmrs.module.ipd.api.model.MedicationAdministration openmrsMedicationAdministration) { + if (openmrsMedicationAdministration == null) { + return null; + } + String status = openmrsMedicationAdministration.getStatus() != null ? openmrsMedicationAdministration.getStatus().getShortNameInLocale(Context.getLocale()).getName() : null; + String statusReason = openmrsMedicationAdministration.getStatusReason() != null ? openmrsMedicationAdministration.getStatusReason().getDisplayString() : null; + String patientUuid = openmrsMedicationAdministration.getPatient() != null ? openmrsMedicationAdministration.getPatient().getUuid() : null; + String encounterUuid = openmrsMedicationAdministration.getEncounter() != null ? openmrsMedicationAdministration.getEncounter().getUuid() : null; + String orderUuid = openmrsMedicationAdministration.getDrugOrder() != null ? openmrsMedicationAdministration.getDrugOrder().getUuid() : null; + + List providers = new java.util.ArrayList<>(); + if (openmrsMedicationAdministration.getPerformers() != null) { + for (MedicationAdministrationPerformer performer : openmrsMedicationAdministration.getPerformers()) { + providers.add(MedicationAdministrationPerformerResponse.createFrom(performer)); + } + } + List notes = new java.util.ArrayList<>(); + if (openmrsMedicationAdministration.getNotes() != null) { + for (MedicationAdministrationNote note : openmrsMedicationAdministration.getNotes()) { + notes.add(MedicationAdministrationNoteResponse.createFrom(note)); + } + } + return MedicationAdministrationResponse.builder() + .uuid(openmrsMedicationAdministration.getUuid()) + .administeredDateTime(openmrsMedicationAdministration.getAdministeredDateTime()) + .status(status) + .statusReason(statusReason) + .patientUuid(patientUuid) + .encounterUuid(encounterUuid) + .orderUuid(orderUuid) + .providers(providers) + .notes(notes) + .drug(ConversionUtil.convertToRepresentation(openmrsMedicationAdministration.getDrug(), Representation.REF)) + .dosingInstructions(openmrsMedicationAdministration.getDosingInstructions()) + .dose(openmrsMedicationAdministration.getDose()) + .doseUnits(ConversionUtil.convertToRepresentation(openmrsMedicationAdministration.getDoseUnits(), Representation.REF)) + .route(ConversionUtil.convertToRepresentation(openmrsMedicationAdministration.getRoute(), Representation.REF)) + .site(ConversionUtil.convertToRepresentation(openmrsMedicationAdministration.getSite(), Representation.REF)) + .build(); + } +} + diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationScheduleResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationScheduleResponse.java new file mode 100644 index 0000000..80ba08e --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationScheduleResponse.java @@ -0,0 +1,43 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.Slot; + +import java.util.List; +import java.util.stream.Collectors; + +import static org.openmrs.module.ipd.api.util.DateTimeUtil.convertLocalDateTimeToUTCEpoc; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MedicationScheduleResponse { + + private Integer id; + private String uuid; + private String serviceType; + private String comments; + private long startDate; + private Object endDate; + private List slots; + public static MedicationScheduleResponse createFrom(Schedule schedule, List slots) { + + return MedicationScheduleResponse.builder() + .id(schedule.getId()) + .uuid(schedule.getUuid()) + .serviceType(schedule.getServiceType().getName().getName()) + .comments(schedule.getComments()) + .startDate(convertLocalDateTimeToUTCEpoc(schedule.getStartDate())) + .endDate(schedule.getEndDate() != null ? convertLocalDateTimeToUTCEpoc(schedule.getEndDate()) : null) + .slots(slots.stream().map(MedicationSlotResponse::createFrom).collect(Collectors.toList())) + .build(); + + } + +} + diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationSlotResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationSlotResponse.java new file mode 100644 index 0000000..60d103f --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationSlotResponse.java @@ -0,0 +1,60 @@ +package org.openmrs.module.ipd.contract; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hl7.fhir.r4.model.MedicationAdministration; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.factory.MedicationAdministrationFactory; +import org.openmrs.module.webservices.rest.web.ConversionUtil; +import org.openmrs.module.webservices.rest.web.representation.Representation; + +import static org.openmrs.module.ipd.api.util.DateTimeUtil.convertLocalDateTimeToUTCEpoc; + +@Builder +@Getter +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +@AllArgsConstructor +@NoArgsConstructor +public class MedicationSlotResponse { + private Integer id; + private String uuid; + private String serviceType; + private String status; + private long startTime; + private Object order; + private Object medicationAdministration; + private String notes; + + public static MedicationSlotResponse createFrom(Slot slot) { + return MedicationSlotResponse.builder() + .id(slot.getId()) + .uuid(slot.getUuid()) + .serviceType(slot.getServiceType().getName().getName()) + .status(slot.getStatus().name()) + .startTime(convertLocalDateTimeToUTCEpoc(slot.getStartDateTime())) + .order(ConversionUtil.convertToRepresentation(slot.getOrder(), Representation.FULL)) + .medicationAdministration(MedicationAdministrationResponse.createFrom((slot.getMedicationAdministration()))) + .notes(slot.getNotes()) + .build(); + } + + public static MedicationSlotResponse createFrom(Slot slot, Representation rep) { + if (rep.equals(Representation.REF)) + { + return MedicationSlotResponse.builder() + .id(slot.getId()) + .uuid(slot.getUuid()) + .serviceType(slot.getServiceType().getName().getName()) + .status(slot.getStatus().name()) + .startTime(convertLocalDateTimeToUTCEpoc(slot.getStartDateTime())) + .medicationAdministration(MedicationAdministrationResponse.createFrom((slot.getMedicationAdministration()))) + .notes(slot.getNotes()) + .build(); + } + return MedicationSlotResponse.createFrom(slot); + + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/PatientMedicationSummaryResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/PatientMedicationSummaryResponse.java new file mode 100644 index 0000000..d7b3509 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/PatientMedicationSummaryResponse.java @@ -0,0 +1,35 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.openmrs.module.ipd.model.PatientMedicationSummary; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PatientMedicationSummaryResponse { + + private String patientUuid; + private List prescribedOrderSlots; + private List emergencyMedicationSlots; + + public static PatientMedicationSummaryResponse createFrom(PatientMedicationSummary patientMedicationSummary) { + List prescribedOrderSlots = patientMedicationSummary.getPrescribedOrderSlots() != null + ? patientMedicationSummary.getPrescribedOrderSlots().stream().map(PrescribedOrderSlotSummaryResponse::createFrom).collect(Collectors.toList()) + : null; + List emergencyMedicationSlots = patientMedicationSummary.getEmergencyMedicationSlots() != null + ? patientMedicationSummary.getEmergencyMedicationSlots().stream().map(MedicationSlotResponse::createFrom).collect(Collectors.toList()) + : null; + return PatientMedicationSummaryResponse.builder() + .patientUuid(patientMedicationSummary.getPatientUuid()) + .prescribedOrderSlots(prescribedOrderSlots) + .emergencyMedicationSlots(emergencyMedicationSlots) + .build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/PrescribedOrderSlotSummaryResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/PrescribedOrderSlotSummaryResponse.java new file mode 100644 index 0000000..bff5a15 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/PrescribedOrderSlotSummaryResponse.java @@ -0,0 +1,36 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.openmrs.module.ipd.model.PrescribedOrderSlotSummary; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PrescribedOrderSlotSummaryResponse { + + private String orderUuid; + private List currentSlots; + private MedicationSlotResponse previousSlot; + private Long initialSlotStartTime; + private Long finalSlotStartTime; + + public static PrescribedOrderSlotSummaryResponse createFrom(PrescribedOrderSlotSummary prescribedOrderSlotsSummary){ + MedicationSlotResponse previousSlot = prescribedOrderSlotsSummary.getPreviousSlot() != null + ? MedicationSlotResponse.createFrom(prescribedOrderSlotsSummary.getPreviousSlot()) + : null; + return PrescribedOrderSlotSummaryResponse.builder() + .orderUuid(prescribedOrderSlotsSummary.getOrderUuid()) + .currentSlots(prescribedOrderSlotsSummary.getCurrentSlots().stream().map(slot -> MedicationSlotResponse.createFrom(slot)).collect(Collectors.toList())) + .previousSlot(previousSlot) + .initialSlotStartTime(prescribedOrderSlotsSummary.getInitialSlotStartTime()) + .finalSlotStartTime(prescribedOrderSlotsSummary.getFinalSlotStartTime()) + .build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationRequest.java b/omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationRequest.java new file mode 100644 index 0000000..51080fe --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationRequest.java @@ -0,0 +1,55 @@ +package org.openmrs.module.ipd.contract; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.NoArgsConstructor; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.util.DateTimeUtil; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +import static org.openmrs.module.ipd.api.util.DateTimeUtil.convertEpocUTCToLocalTimeZone; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ScheduleMedicationRequest { + + private String patientUuid; + private String orderUuid; + private String providerUuid; + private String comments; + private Long slotStartTime; + private List firstDaySlotsStartTime; + private List dayWiseSlotsStartTime; + private List remainingDaySlotsStartTime; + private MedicationFrequency medicationFrequency; + private ServiceType serviceType; + + public enum MedicationFrequency { + START_TIME_DURATION_FREQUENCY, + FIXED_SCHEDULE_FREQUENCY + } + + public LocalDateTime getSlotStartTimeAsLocaltime() { + return slotStartTime != null ? convertEpocUTCToLocalTimeZone(slotStartTime): null; + } + + public List getFirstDaySlotsStartTimeAsLocalTime() { + return firstDaySlotsStartTime != null ? firstDaySlotsStartTime.stream().map(DateTimeUtil::convertEpocUTCToLocalTimeZone).collect(Collectors.toList()) : null; + } + + public List getDayWiseSlotsStartTimeAsLocalTime() { + return dayWiseSlotsStartTime != null ? dayWiseSlotsStartTime.stream().map(DateTimeUtil::convertEpocUTCToLocalTimeZone).collect(Collectors.toList()) : null; + } + + public List getRemainingDaySlotsStartTimeAsLocalTime() { + return remainingDaySlotsStartTime != null ? remainingDaySlotsStartTime.stream().map(DateTimeUtil::convertEpocUTCToLocalTimeZone).collect(Collectors.toList()) : null; + } +} \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationResponse.java new file mode 100644 index 0000000..5478ead --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/ScheduleMedicationResponse.java @@ -0,0 +1,35 @@ +package org.openmrs.module.ipd.contract; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.openmrs.module.ipd.api.model.Schedule; + +import static org.openmrs.module.ipd.api.util.DateTimeUtil.convertLocalDateTimeToUTCEpoc; + +@Builder +@Getter +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +@AllArgsConstructor +@NoArgsConstructor +public class ScheduleMedicationResponse { + private Integer id; + private String patientUuid; + private String comments; + private long startDate; + private Object endDate; + private Object order; + + public static ScheduleMedicationResponse constructFrom(Schedule schedule) { + return ScheduleMedicationResponse.builder() + .id(schedule.getId()) + .patientUuid(schedule.getSubject().getUuid()) + .comments(schedule.getComments()) +// .order(ConversionUtil.convertToRepresentation(schedule.getOrder(), Representation.REF)) // TODO. Clarify why we need to use REF here with product team + .startDate(convertLocalDateTimeToUTCEpoc(schedule.getStartDate())) + .endDate(schedule.getEndDate() != null ? convertLocalDateTimeToUTCEpoc(schedule.getEndDate()) : null) + .build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDCareTeamController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDCareTeamController.java new file mode 100644 index 0000000..e713dcd --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDCareTeamController.java @@ -0,0 +1,47 @@ +package org.openmrs.module.ipd.controller; + +import lombok.extern.slf4j.Slf4j; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.contract.CareTeamRequest; +import org.openmrs.module.ipd.contract.CareTeamResponse; +import org.openmrs.module.ipd.contract.ScheduleMedicationResponse; +import org.openmrs.module.ipd.service.IPDCareTeamService; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.OK; + + +@Controller +@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/ipd/careteam") +@Slf4j +public class IPDCareTeamController extends BaseRestController { + + private final IPDCareTeamService ipdCareTeamService; + + @Autowired + public IPDCareTeamController(IPDCareTeamService ipdCareTeamService) { + this.ipdCareTeamService = ipdCareTeamService; + } + + @RequestMapping(value = "/participants", method = RequestMethod.POST) + @ResponseBody + public ResponseEntity createMedicationSchedule(@RequestBody CareTeamRequest careTeamRequest) { + try { + CareTeam careTeam = ipdCareTeamService.saveCareTeamParticipants(careTeamRequest); + return new ResponseEntity<>(CareTeamResponse.createFrom(careTeam), OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new schedule", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java new file mode 100644 index 0000000..d22cd8a --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java @@ -0,0 +1,92 @@ +package org.openmrs.module.ipd.controller; + +import lombok.extern.slf4j.Slf4j; +import org.hl7.fhir.r4.model.MedicationAdministration; +import org.openmrs.api.context.Context; +import org.openmrs.module.fhir2.apiext.dao.FhirMedicationAdministrationDao; +import org.openmrs.module.ipd.api.service.SlotService; +import org.openmrs.module.ipd.contract.MedicationAdministrationRequest; +import org.openmrs.module.ipd.contract.MedicationAdministrationResponse; +import org.openmrs.module.ipd.factory.MedicationAdministrationFactory; +import org.openmrs.module.ipd.service.IPDMedicationAdministrationService; +import org.openmrs.module.ipd.util.PrivilegeConstants; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +import static org.springframework.http.HttpStatus.*; + +@Controller +@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/ipd") +@Slf4j +public class IPDMedicationAdministrationController extends BaseRestController { + + private final IPDMedicationAdministrationService ipdMedicationAdministrationService; + private final MedicationAdministrationFactory medicationAdministrationFactory; + + @Autowired + public IPDMedicationAdministrationController(IPDMedicationAdministrationService ipdMedicationAdministrationService, + SlotService slotService, + FhirMedicationAdministrationDao medicationAdministrationDao, + MedicationAdministrationFactory medicationAdministrationFactory) { + this.ipdMedicationAdministrationService = ipdMedicationAdministrationService; + this.medicationAdministrationFactory = medicationAdministrationFactory; + } + + @RequestMapping(value = "/scheduledMedicationAdministrations", method = RequestMethod.POST) + @ResponseBody + public ResponseEntity createScheduledMedicationAdministration(@RequestBody List medicationAdministrationRequestList) { + try { + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege " + PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION), FORBIDDEN); + } + List medicationAdministrationResponseList = new ArrayList<>(); + for (MedicationAdministrationRequest medicationAdministrationRequest : medicationAdministrationRequestList) { + MedicationAdministration medicationAdministration = ipdMedicationAdministrationService.saveScheduledMedicationAdministration(medicationAdministrationRequest); + medicationAdministrationResponseList.add(medicationAdministrationFactory.mapMedicationAdministrationToResponse(medicationAdministration)); + } + return new ResponseEntity<>(medicationAdministrationResponseList, OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new medicationAdministration", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "/adhocMedicationAdministrations", method = RequestMethod.POST) + @ResponseBody + public ResponseEntity createAdhocMedicationAdministration(@RequestBody MedicationAdministrationRequest medicationAdministrationRequest) { + try { + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", "+PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION), FORBIDDEN); + } + MedicationAdministration medicationAdministration = ipdMedicationAdministrationService.saveAdhocMedicationAdministration(medicationAdministrationRequest); + MedicationAdministrationResponse medicationAdministrationResponse = medicationAdministrationFactory.mapMedicationAdministrationToResponse(medicationAdministration); + return new ResponseEntity<>(medicationAdministrationResponse, OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new medicationAdministration", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "/adhocMedicationAdministrations/{medicationAdministrationUuid}", method = RequestMethod.PUT) + @ResponseBody + public ResponseEntity updateAdhocMedicationAdministration( + @PathVariable("medicationAdministrationUuid") String medicationAdministrationUuid, + @RequestBody MedicationAdministrationRequest medicationAdministrationRequest) { + try { + MedicationAdministration medicationAdministration = ipdMedicationAdministrationService.updateAdhocMedicationAdministration(medicationAdministrationUuid,medicationAdministrationRequest); + return new ResponseEntity(medicationAdministrationFactory.mapMedicationAdministrationToResponse(medicationAdministration),OK); + } catch (Exception e) { + log.error("Runtime error while trying to update new medicationAdministration", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java new file mode 100644 index 0000000..09f3604 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java @@ -0,0 +1,180 @@ +package org.openmrs.module.ipd.controller; + +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.bahmni.module.bahmnicore.util.WebUtils; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.api.PatientService; +import org.openmrs.api.VisitService; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.util.IPDConstants; +import org.openmrs.module.ipd.api.service.ScheduleService; +import org.openmrs.module.ipd.contract.MedicationScheduleResponse; +import org.openmrs.module.ipd.contract.MedicationSlotResponse; +import org.openmrs.module.ipd.contract.PatientMedicationSummaryResponse; +import org.openmrs.module.ipd.contract.ScheduleMedicationRequest; +import org.openmrs.module.ipd.contract.ScheduleMedicationResponse; +import org.openmrs.module.ipd.model.PatientMedicationSummary; +import org.openmrs.module.ipd.service.IPDScheduleService; +import org.openmrs.module.ipd.util.PrivilegeConstants; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.openmrs.module.ipd.api.model.ServiceType.MEDICATION_REQUEST; +import static org.openmrs.module.ipd.api.util.DateTimeUtil.convertEpocUTCToLocalTimeZone; +import static org.openmrs.module.ipd.contract.MedicationScheduleResponse.createFrom; +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.OK; +import static org.springframework.http.HttpStatus.FORBIDDEN; + +@Controller +@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/ipd/schedule") +@Slf4j +public class IPDScheduleController extends BaseRestController { + + private final IPDScheduleService ipdScheduleService; + private final VisitService visitService; + private final PatientService patientService; + private final ScheduleService scheduleService; + + @Autowired + public IPDScheduleController(IPDScheduleService ipdScheduleService, VisitService visitService, PatientService patientService, ScheduleService scheduleService) { + this.ipdScheduleService = ipdScheduleService; + this.visitService = visitService; + this.patientService = patientService; + this.scheduleService = scheduleService; + } + + @RequestMapping(value = "type/medication", method = RequestMethod.POST) + @ResponseBody + public ResponseEntity createMedicationSchedule(@RequestBody ScheduleMedicationRequest scheduleMedicationRequest) { + try { + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_MEDICATION_TASKS)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege " + PrivilegeConstants.EDIT_MEDICATION_TASKS), FORBIDDEN); + } + Schedule schedule = ipdScheduleService.saveMedicationSchedule(scheduleMedicationRequest); + return new ResponseEntity<>(ScheduleMedicationResponse.constructFrom(schedule), OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new schedule", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "type/medication/edit", method = RequestMethod.POST) + @ResponseBody + public ResponseEntity updateMedicationSchedule(@RequestBody ScheduleMedicationRequest scheduleMedicationRequest) { + try { + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_MEDICATION_TASKS)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege " + PrivilegeConstants.EDIT_MEDICATION_TASKS), FORBIDDEN); + } + Schedule schedule = ipdScheduleService.updateMedicationSchedule(scheduleMedicationRequest); + return new ResponseEntity<>(ScheduleMedicationResponse.constructFrom(schedule), OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new schedule", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "type/medication", method = RequestMethod.GET, params = {"patientUuid", "startTime", "endTime"}) + @ResponseBody + public ResponseEntity getMedicationSlotsByDate(@RequestParam(value = "patientUuid") String patientUuid, + @RequestParam(value = "startTime") Long startTime, @RequestParam(value = "endTime") Long endTime, + @RequestParam(value = "visitUuid",required = false) String visitUuid, + @RequestParam(value = "view", required = false) String view) { + try { + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+", "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + } +; if (startTime != null && endTime != null) { + LocalDateTime localStartDate = convertEpocUTCToLocalTimeZone(startTime); + LocalDateTime localEndDate = convertEpocUTCToLocalTimeZone(endTime); + Boolean considerAdministeredTime = view!=null & IPDConstants.IPD_VIEW_DRUG_CHART.equals(view); + Patient patient=patientService.getPatientByUuid(patientUuid); + Visit visit = visitUuid !=null ? visitService.getVisitByUuid(visitUuid) : visitService.getActiveVisitsByPatient(patient).get(0); + List slots = ipdScheduleService.getMedicationSlotsForTheGivenTimeFrame(patientUuid, localStartDate, localEndDate,considerAdministeredTime, visit); + return new ResponseEntity<>(constructResponse(slots, visit), OK); + } + throw new Exception(); + } catch (Exception e) { + log.error("Runtime error while trying to create new schedule", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "type/medication", method = RequestMethod.GET, params = {"patientUuid"}) + @ResponseBody + public ResponseEntity getMedicationSlotsByOrderUuids(@RequestParam(value = "patientUuid") String patientUuid, + @RequestParam(value = "serviceType", required = false) ServiceType serviceType, + @RequestParam(value = "orderUuids", required = false) List orderUuids) { + try { + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+" "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + } + List slots; + if (orderUuids == null || orderUuids.isEmpty()) { + slots = + serviceType == null ? ipdScheduleService.getMedicationSlots(patientUuid, MEDICATION_REQUEST) : + ipdScheduleService.getMedicationSlots(patientUuid, serviceType); + } else { + slots = + serviceType == null ? ipdScheduleService.getMedicationSlots(patientUuid, MEDICATION_REQUEST, orderUuids) : + ipdScheduleService.getMedicationSlots(patientUuid, serviceType, orderUuids); + } + List medicationResponses = slots.stream() + .map(MedicationSlotResponse::createFrom) + .collect(Collectors.toList()); + return new ResponseEntity<>(medicationResponses, OK); + } catch (Exception e) { + log.error("Runtime error while trying to retrieve schedules created by patient", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "type/medication/patientsMedicationSummary", method = RequestMethod.GET, params = {"patientUuids", "startTime", "endTime"}) + @ResponseBody + public ResponseEntity getSlotsForPatientsAndTime(@RequestParam(value = "patientUuids") List patientUuidList, + @RequestParam(value = "startTime") Long startTime, + @RequestParam(value = "endTime") Long endTime, + @RequestParam(value = "includePreviousSlot",required = false) Boolean includePreviousSlot, + @RequestParam(value = "includeSlotDuration",required = false) Boolean includeSlotDuration) { + try { + if (startTime != null && endTime != null) { + LocalDateTime localStartDate = convertEpocUTCToLocalTimeZone(startTime); + LocalDateTime localEndDate = convertEpocUTCToLocalTimeZone(endTime); + List patientMedicationSummaries = ipdScheduleService.getSlotsForPatientListByTime(patientUuidList, + localStartDate, localEndDate, includePreviousSlot, includeSlotDuration); + return new ResponseEntity<>(patientMedicationSummaries.stream().map(PatientMedicationSummaryResponse::createFrom).collect(Collectors.toList()), OK); + } + throw new Exception(); + } catch (Exception e) { + log.error("Runtime error while fetching patient medication summaries", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + + private List constructResponse(List slots, Visit visit) { + Schedule schedule = scheduleService.getScheduleByVisit(visit); + if(slots.isEmpty() && schedule != null){ + return Lists.newArrayList(createFrom(schedule, slots)); + } + Map> slotsBySchedule = slots.stream().collect(Collectors.groupingBy(Slot::getSchedule)); + return slotsBySchedule.entrySet().stream().map(entry -> createFrom(entry.getKey(), entry.getValue())).collect(Collectors.toList()); + } + +} \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java new file mode 100644 index 0000000..975d4cf --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java @@ -0,0 +1,57 @@ +package org.openmrs.module.ipd.controller; + +import lombok.extern.slf4j.Slf4j; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.contract.IPDDrugOrderResponse; +import org.openmrs.module.ipd.contract.IPDTreatmentsResponse; +import org.openmrs.module.ipd.contract.MedicationAdministrationResponse; +import org.openmrs.module.ipd.model.IPDDrugOrder; +import org.openmrs.module.ipd.service.IPDVisitService; +import org.openmrs.module.ipd.util.PrivilegeConstants; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.text.ParseException; +import java.util.*; +import java.util.stream.Collectors; + +import static org.springframework.http.HttpStatus.FORBIDDEN; +import static org.springframework.http.HttpStatus.OK; + +@Controller +@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/ipdVisit/{visitUuid}") +@Slf4j +public class IPDVisitController extends BaseRestController { + + private IPDVisitService ipdVisitService; + + @Autowired + public IPDVisitController(IPDVisitService ipdVisitService) { + this.ipdVisitService = ipdVisitService; + } + + @RequestMapping(value = "/medication", method = RequestMethod.GET) + @ResponseBody + public ResponseEntity getVisitWiseMedications ( + @PathVariable("visitUuid") String visitUuid, + @RequestParam(value = "includes", required = false) List includes) throws ParseException { + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", " + PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + } + List prescribedOrders = ipdVisitService.getPrescribedOrders(visitUuid, true, null, null, null, false); + List prescribedOrderResponse = prescribedOrders.stream().map(IPDDrugOrderResponse::createFrom).collect(Collectors.toList()); + List emergencyMedications = null; + if (includes != null && includes.contains("emergencyMedications")) { + List emergencyMedicationSlots = ipdVisitService.getMedicationSlots(visitUuid, ServiceType.EMERGENCY_MEDICATION_REQUEST); + emergencyMedications = emergencyMedicationSlots.stream().map(slot -> MedicationAdministrationResponse.createFrom(slot.getMedicationAdministration())).collect(Collectors.toList()); + } + return new ResponseEntity(IPDTreatmentsResponse.createFrom(prescribedOrderResponse, emergencyMedications), OK); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDWardController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDWardController.java new file mode 100644 index 0000000..61f2e7d --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDWardController.java @@ -0,0 +1,89 @@ +package org.openmrs.module.ipd.controller; + +import lombok.extern.slf4j.Slf4j; +import org.openmrs.module.ipd.api.model.*; +import org.openmrs.module.ipd.contract.*; +import org.openmrs.module.ipd.service.IPDWardService; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.RestUtil; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.text.ParseException; +import java.util.List; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.OK; + +@Controller +@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/ipd/wards") +@Slf4j +public class IPDWardController extends BaseRestController { + + private IPDWardService ipdWardService; + + @Autowired + public IPDWardController(IPDWardService ipdWardService) { + this.ipdWardService = ipdWardService; + } + + @RequestMapping(value = "{wardUuid}/summary",method = RequestMethod.GET) + @ResponseBody + public ResponseEntity getIPDWardPatientStats (@PathVariable("wardUuid") String wardUuid, + @RequestParam(value = "providerUuid") String providerUuid) throws ParseException { + WardPatientsSummary wardPatientsSummary = ipdWardService.getIPDWardPatientSummary(wardUuid, providerUuid); + return new ResponseEntity<>(IPDWardPatientSummaryResponse.createFrom(wardPatientsSummary), OK); + } + + @RequestMapping(value = "{wardUuid}/patients", method = RequestMethod.GET) + @ResponseBody + public ResponseEntity getIPDWardPatient(@PathVariable("wardUuid") String wardUuid, + @RequestParam(value = "offset") Integer offset, + @RequestParam (value = "limit") Integer limit, + @RequestParam(value = "sortBy", required = false) String sortBy) throws ParseException { + try { + IPDPatientDetails ipdPatientDetails = ipdWardService.getIPDPatientByWard(wardUuid,offset,limit,sortBy); + return new ResponseEntity<>(IPDPatientDetailsResponse.createFrom(ipdPatientDetails), OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new schedule", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "{wardUuid}/myPatients", method = RequestMethod.GET) + @ResponseBody + public ResponseEntity getIPDWardPatientsForProvider(@PathVariable("wardUuid") String wardUuid, + @RequestParam(value = "providerUuid") String providerUuid, + @RequestParam(value = "offset") Integer offset, + @RequestParam (value = "limit") Integer limit, + @RequestParam(value = "sortBy", required = false) String sortBy) throws ParseException { + try { + IPDPatientDetails ipdPatientDetails = ipdWardService.getIPDPatientsByWardAndProvider(wardUuid, providerUuid, offset, limit, sortBy); + return new ResponseEntity<>(IPDPatientDetailsResponse.createFrom(ipdPatientDetails), OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new schedule", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + + @RequestMapping(value = "{wardUuid}/patients/search", method = RequestMethod.GET) + @ResponseBody + public ResponseEntity searchIPDWardPatient(@PathVariable("wardUuid") String wardUuid, + @RequestParam(value = "offset") Integer offset, + @RequestParam (value = "limit") Integer limit, + @RequestParam(value = "searchKeys") List searchKeys, + @RequestParam(value = "searchValue") String searchValue, + @RequestParam(value = "sortBy", required = false) String sortBy) throws ParseException { + try { + IPDPatientDetails ipdPatientDetails = ipdWardService.searchIPDPatientsInWard(wardUuid,searchKeys,searchValue,offset,limit,sortBy); + return new ResponseEntity<>(IPDPatientDetailsResponse.createFrom(ipdPatientDetails), OK); + } catch (Exception e) { + log.error("Runtime error while trying to create new schedule", e); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(e, e.getMessage()), BAD_REQUEST); + } + } + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/factory/CareTeamFactory.java b/omod/src/main/java/org/openmrs/module/ipd/factory/CareTeamFactory.java new file mode 100644 index 0000000..7eee78a --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/factory/CareTeamFactory.java @@ -0,0 +1,65 @@ +package org.openmrs.module.ipd.factory; + +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.api.APIException; +import org.openmrs.api.context.Context; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.api.model.CareTeamParticipant; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.openmrs.module.ipd.contract.CareTeamParticipantRequest; +import org.openmrs.module.ipd.contract.CareTeamRequest; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +public class CareTeamFactory { + + + public CareTeam createCareTeamFromRequest(CareTeamRequest request, Patient patient, Visit visit) { + CareTeam careTeam = new CareTeam(); + careTeam.setVisit(visit); + careTeam.setPatient(patient); + careTeam.setStartTime(visit.getStartDatetime()); + + if (request.getCareTeamParticipantsRequest() !=null){ + List careTeamParticipants = new ArrayList<>(); + for (CareTeamParticipantRequest participantRequest: request.getCareTeamParticipantsRequest()) { + CareTeamParticipant participant = new CareTeamParticipant(); + participant.setStartTime(DateTimeUtil.convertEpochTimeToDate(participantRequest.getStartTime())); + participant.setEndTime(DateTimeUtil.convertEpochTimeToDate(participantRequest.getEndTime())); + participant.setProvider(Context.getProviderService().getProviderByUuid(participantRequest.getProviderUuid())); + careTeamParticipants.add(participant); + } + careTeam.setParticipants(new HashSet<>(careTeamParticipants)); + } + return careTeam; + } + + public CareTeam updateCareTeamFromRequest(CareTeamRequest careTeamRequest, CareTeam careTeam) { + if (careTeamRequest.getCareTeamParticipantsRequest() !=null){ + List careTeamParticipants = new ArrayList<>(); + for (CareTeamParticipantRequest participantRequest: careTeamRequest.getCareTeamParticipantsRequest()) { + if (participantRequest.getUuid()!=null){ + CareTeamParticipant careTeamParticipant = careTeam.getParticipants().stream() + .filter(participant -> participant.getUuid().equals(participantRequest.getUuid())) + .findFirst().get(); + if (participantRequest.getVoided() != null) careTeamParticipant.setVoided(participantRequest.getVoided()); + } + else { + Boolean participantAlreadyExists = careTeam.getParticipants().stream(). + anyMatch(participant -> participant.getVoided()!=true + && DateTimeUtil.convertEpochTimeToDate(participantRequest.getStartTime()).equals(participant.getStartTime())); + if (participantAlreadyExists) throw new APIException("Participant Already exists for given time frame"); + CareTeamParticipant participant = new CareTeamParticipant(); + participant.setStartTime(DateTimeUtil.convertEpochTimeToDate(participantRequest.getStartTime())); + participant.setEndTime(DateTimeUtil.convertEpochTimeToDate(participantRequest.getEndTime())); + participant.setProvider(Context.getProviderService().getProviderByUuid(participantRequest.getProviderUuid())); + careTeam.getParticipants().add(participant); + } + } + } + return careTeam; + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java b/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java new file mode 100644 index 0000000..7573ac6 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java @@ -0,0 +1,91 @@ +package org.openmrs.module.ipd.factory; + +import org.openmrs.DrugOrder; +import org.openmrs.api.context.Context; +import org.openmrs.module.fhir2.apiext.translators.MedicationAdministrationStatusTranslator; +import org.openmrs.module.fhir2.apiext.translators.MedicationAdministrationTranslator; +import org.openmrs.module.ipd.api.model.MedicationAdministration; +import org.openmrs.module.ipd.api.model.MedicationAdministrationNote; +import org.openmrs.module.ipd.api.model.MedicationAdministrationPerformer; +import org.openmrs.module.ipd.contract.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; + + +@Component +public class MedicationAdministrationFactory { + + private MedicationAdministrationTranslator medicationAdministrationTranslator; + private MedicationAdministrationStatusTranslator medicationAdministrationStatusTranslator; + + @Autowired + public MedicationAdministrationFactory(MedicationAdministrationTranslator medicationAdministrationTranslator, + MedicationAdministrationStatusTranslator medicationAdministrationStatusTranslator) { + this.medicationAdministrationTranslator = medicationAdministrationTranslator; + this.medicationAdministrationStatusTranslator = medicationAdministrationStatusTranslator; + } + + public MedicationAdministration mapRequestToMedicationAdministration(MedicationAdministrationRequest request, MedicationAdministration existingMedicationAdministration) { + + MedicationAdministration medicationAdministration = new MedicationAdministration(); + if (existingMedicationAdministration ==null || existingMedicationAdministration.getId() == null) { + medicationAdministration.setAdministeredDateTime(request.getAdministeredDateTimeAsLocaltime()); + medicationAdministration.setStatus(medicationAdministrationStatusTranslator.toOpenmrsType(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.fromCode(request.getStatus()))); + medicationAdministration.setPatient(Context.getPatientService().getPatientByUuid(request.getPatientUuid())); + medicationAdministration.setEncounter(Context.getEncounterService().getEncounterByUuid(request.getEncounterUuid())); + medicationAdministration.setDrugOrder((DrugOrder) Context.getOrderService().getOrderByUuid(request.getOrderUuid())); + medicationAdministration.setDrug(Context.getConceptService().getDrugByUuid(request.getDrugUuid())); + medicationAdministration.setDosingInstructions(request.getDosingInstructions()); + medicationAdministration.setDose(request.getDose()); + medicationAdministration.setDoseUnits(Context.getConceptService().getConceptByName(request.getDoseUnits())); + medicationAdministration.setRoute(Context.getConceptService().getConceptByName(request.getRoute())); + medicationAdministration.setSite(Context.getConceptService().getConceptByName(request.getSite())); + } + else { + medicationAdministration.setUuid(existingMedicationAdministration.getUuid()); + } + List providers = new ArrayList<>(); + if (request.getProviders() != null) { + for (MedicationAdministrationPerformerRequest performer : request.getProviders()) { + MedicationAdministrationPerformer newProvider = new MedicationAdministrationPerformer(); + newProvider.setUuid(performer.getUuid()); + newProvider.setActor(Context.getProviderService().getProviderByUuid(performer.getProviderUuid())); + newProvider.setFunction(Context.getConceptService().getConceptByName(performer.getFunction())); + providers.add(newProvider); + } + if (existingMedicationAdministration !=null && existingMedicationAdministration.getPerformers() !=null){ + providers.addAll(existingMedicationAdministration.getPerformers()); + } + } + medicationAdministration.setPerformers(new HashSet<>(providers)); + List notes = new ArrayList<>(); + if (request.getNotes() != null) { + for (MedicationAdministrationNoteRequest note : request.getNotes()) { + MedicationAdministrationNote newNote = new MedicationAdministrationNote(); + newNote.setUuid(note.getUuid()); + newNote.setAuthor(Context.getProviderService().getProviderByUuid(note.getAuthorUuid())); + newNote.setText(note.getText()); + newNote.setRecordedTime(note.getRecordedTimeAsLocaltime()); + notes.add(newNote); + } + if (existingMedicationAdministration !=null && existingMedicationAdministration.getNotes() !=null){ + notes.addAll(existingMedicationAdministration.getNotes()); + } + } + medicationAdministration.setNotes(new HashSet<>(notes)); + return medicationAdministration; + } + + public MedicationAdministrationResponse mapMedicationAdministrationToResponse(org.hl7.fhir.r4.model.MedicationAdministration fhirMedicationAdministration) { + MedicationAdministration openmrsMedicationAdministration = (MedicationAdministration) medicationAdministrationTranslator.toOpenmrsType(fhirMedicationAdministration); + MedicationAdministrationResponse response = MedicationAdministrationResponse.createFrom(openmrsMedicationAdministration); + return response; + } + + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/factory/ScheduleFactory.java b/omod/src/main/java/org/openmrs/module/ipd/factory/ScheduleFactory.java new file mode 100644 index 0000000..8daeb75 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/factory/ScheduleFactory.java @@ -0,0 +1,55 @@ +package org.openmrs.module.ipd.factory; + +import org.openmrs.Concept; +import org.openmrs.Patient; +import org.openmrs.Provider; +import org.openmrs.Visit; +import org.openmrs.api.ConceptService; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.service.ReferenceService; +import org.openmrs.module.ipd.contract.ScheduleMedicationRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +import static org.openmrs.module.ipd.api.model.ServiceType.MEDICATION_REQUEST; +import static org.openmrs.module.ipd.api.util.DateTimeUtil.convertDateToLocalDateTime; + +@Component +public class ScheduleFactory { + + private final ConceptService conceptService; + private final ReferenceService referenceService; + + @Autowired + public ScheduleFactory(ConceptService conceptService, ReferenceService referenceService) { + this.conceptService = conceptService; + this.referenceService = referenceService; + } + + public Schedule createScheduleForMedicationFrom(ScheduleMedicationRequest request, Visit visit) { + Schedule schedule = new Schedule(); + Concept medicationRequestServiceType = conceptService.getConceptByName(MEDICATION_REQUEST.conceptName()); + + Reference subject = getReference(Patient.class.getTypeName(), request.getPatientUuid()); + Reference actor = getReference(Provider.class.getTypeName(), request.getProviderUuid()); + + schedule.setSubject(subject); + schedule.setActor(actor); + schedule.setStartDate(convertDateToLocalDateTime(visit.getStartDatetime())); +// schedule.setEndDate(convertDateToLocalDateTime(null); + + schedule.setServiceType(medicationRequestServiceType); + schedule.setVisit(visit); + schedule.setActive(true); + + return schedule; + } + + private Reference getReference(String type, String targetUuid) { + Optional reference = referenceService.getReferenceByTypeAndTargetUUID(type, targetUuid); + return reference.orElseGet(() -> new Reference(type, targetUuid)); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/factory/SlotFactory.java b/omod/src/main/java/org/openmrs/module/ipd/factory/SlotFactory.java new file mode 100644 index 0000000..4f63c5b --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/factory/SlotFactory.java @@ -0,0 +1,91 @@ +package org.openmrs.module.ipd.factory; + +import org.openmrs.Concept; +import org.openmrs.Order; +import org.openmrs.Patient; +import org.openmrs.api.ConceptService; +import org.openmrs.api.PatientService; +import org.openmrs.module.bedmanagement.BedDetails; +import org.openmrs.module.bedmanagement.service.BedManagementService; +import org.openmrs.module.ipd.api.model.MedicationAdministration; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.service.SlotService; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + +@Component +public class SlotFactory { + + private final BedManagementService bedManagementService; + private final ConceptService conceptService; + private final PatientService patientService; + private final SlotService slotService; + + @Autowired + public SlotFactory(BedManagementService bedManagementService, ConceptService conceptService, PatientService patientService,SlotService slotService) { + this.bedManagementService = bedManagementService; + this.conceptService = conceptService; + this.patientService = patientService; + this.slotService = slotService; + } + + public List createSlotsForMedicationFrom(Schedule savedSchedule, List slotsStartTime, + Order drugOrder, MedicationAdministration medicationAdministration, + Slot.SlotStatus status, ServiceType serviceType, String comments) { + + return slotsStartTime.stream().map(slotStartTime -> { + Slot slot = new Slot(); + + String patientUuid = savedSchedule.getSubject().getTargetUuid(); + Patient patient = patientService.getPatientByUuid(patientUuid); + BedDetails bedAssignmentDetailsByPatient = bedManagementService.getBedAssignmentDetailsByPatient(patient); + if(bedAssignmentDetailsByPatient != null){ + slot.setLocation(bedAssignmentDetailsByPatient.getPhysicalLocation()); + } + + Concept medicationRequestServiceType = conceptService.getConceptByName(serviceType.conceptName()); + slot.setServiceType(medicationRequestServiceType); + + slot.setOrder(drugOrder); + slot.setSchedule(savedSchedule); + slot.setStartDateTime(slotStartTime); + slot.setStatus(status); + slot.setMedicationAdministration(medicationAdministration); + slot.setNotes(comments); + return slot; + }).collect(Collectors.toList()); + } + + public Slot getSlotFromUUID(String uuid){ + return slotService.getSlotByUUID(uuid); + } + + public Slot createAsNeededPlaceholderSlot(Schedule savedSchedule, Order drugOrder, String comments) { + Slot slot = new Slot(); + + String patientUuid = savedSchedule.getSubject().getTargetUuid(); + Patient patient = patientService.getPatientByUuid(patientUuid); + BedDetails bedAssignmentDetailsByPatient = bedManagementService.getBedAssignmentDetailsByPatient(patient); + if(bedAssignmentDetailsByPatient != null){ + slot.setLocation(bedAssignmentDetailsByPatient.getPhysicalLocation()); + } + + Concept medicationRequestServiceType = conceptService.getConceptByName(ServiceType.AS_NEEDED_PLACEHOLDER.conceptName()); + slot.setServiceType(medicationRequestServiceType); + + slot.setOrder(drugOrder); + slot.setSchedule(savedSchedule); + slot.setStartDateTime(DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStartDate())); + slot.setEndDateTime(DateTimeUtil.convertDateToLocalDateTime(drugOrder.getEffectiveStopDate())); + slot.setStatus(Slot.SlotStatus.SCHEDULED); + slot.setNotes(comments); + return slot; + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/model/DrugOrderSchedule.java b/omod/src/main/java/org/openmrs/module/ipd/model/DrugOrderSchedule.java new file mode 100644 index 0000000..4dec972 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/model/DrugOrderSchedule.java @@ -0,0 +1,21 @@ +package org.openmrs.module.ipd.model; + +import lombok.*; +import org.openmrs.module.ipd.api.model.Slot; + +import java.util.List; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DrugOrderSchedule { + + private List firstDaySlotsStartTime; + private List dayWiseSlotsStartTime; + private List remainingDaySlotsStartTime; + private Long slotStartTime; + private List slots; + private String notes; +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/model/IPDDrugOrder.java b/omod/src/main/java/org/openmrs/module/ipd/model/IPDDrugOrder.java new file mode 100644 index 0000000..d4c809d --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/model/IPDDrugOrder.java @@ -0,0 +1,23 @@ +package org.openmrs.module.ipd.model; + +import lombok.*; +import org.openmrs.Provider; +import org.openmrs.module.bahmniemrapi.drugorder.contract.BahmniDrugOrder; +import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction.DrugOrder; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class IPDDrugOrder { + + private BahmniDrugOrder bahmniDrugOrder; + private DrugOrderSchedule drugOrderSchedule; + + public static IPDDrugOrder createFrom(BahmniDrugOrder bahmniDrugOrder,DrugOrderSchedule drugOrderSchedule){ + return IPDDrugOrder.builder(). + bahmniDrugOrder(bahmniDrugOrder). + drugOrderSchedule(drugOrderSchedule). + build(); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/model/PatientMedicationSummary.java b/omod/src/main/java/org/openmrs/module/ipd/model/PatientMedicationSummary.java new file mode 100644 index 0000000..e9323fd --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/model/PatientMedicationSummary.java @@ -0,0 +1,19 @@ +package org.openmrs.module.ipd.model; + +import lombok.*; +import org.openmrs.module.ipd.api.model.Slot; + +import java.util.List; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PatientMedicationSummary { + + private String patientUuid; + private List prescribedOrderSlots; + private List emergencyMedicationSlots; + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/model/PrescribedOrderSlotSummary.java b/omod/src/main/java/org/openmrs/module/ipd/model/PrescribedOrderSlotSummary.java new file mode 100644 index 0000000..4592f07 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/model/PrescribedOrderSlotSummary.java @@ -0,0 +1,20 @@ +package org.openmrs.module.ipd.model; + +import lombok.*; +import org.openmrs.module.ipd.api.model.Slot; + +import java.util.List; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PrescribedOrderSlotSummary { + + private String orderUuid; + private List currentSlots; + private Slot previousSlot; + private Long initialSlotStartTime; + private Long finalSlotStartTime; +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java b/omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java new file mode 100644 index 0000000..d12737e --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/postprocessor/IPDTransactionHandler.java @@ -0,0 +1,36 @@ +package org.openmrs.module.ipd.postprocessor; + +import org.openmrs.Encounter; +import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; +import org.openmrs.module.emrapi.encounter.postprocessor.EncounterTransactionHandler; +import org.openmrs.module.ipd.api.events.model.IPDEvent; +import org.openmrs.module.ipd.service.IPDScheduleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.openmrs.module.ipd.api.events.model.IPDEventType; +import org.openmrs.module.ipd.api.events.IPDEventManager; + +@Component +public class IPDTransactionHandler implements EncounterTransactionHandler { + + @Autowired + IPDScheduleService ipdScheduleService; + + @Autowired + IPDEventManager eventManager; + + @Override + public void forRead(Encounter encounter, EncounterTransaction encounterTransaction) { + // No Implementation needed as of now + } + + @Override + public void forSave(Encounter encounter, EncounterTransaction encounterTransaction) { + IPDEventType eventType = eventManager.getEventTypeForEncounter(encounter.getEncounterType().getName()); + if (eventType != null) { + IPDEvent ipdEvent = new IPDEvent(encounter.getUuid(), encounter.getPatient().getUuid(), eventType); + eventManager.processEvent(ipdEvent); + } + ipdScheduleService.handlePostProcessEncounterTransaction(encounter,encounterTransaction); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/IPDCareTeamService.java b/omod/src/main/java/org/openmrs/module/ipd/service/IPDCareTeamService.java new file mode 100644 index 0000000..42243a8 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/IPDCareTeamService.java @@ -0,0 +1,12 @@ +package org.openmrs.module.ipd.service; + +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.contract.CareTeamParticipantRequest; +import org.openmrs.module.ipd.contract.CareTeamRequest; + +import java.util.List; + +public interface IPDCareTeamService { + + CareTeam saveCareTeamParticipants(CareTeamRequest careTeamRequest); +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/IPDMedicationAdministrationService.java b/omod/src/main/java/org/openmrs/module/ipd/service/IPDMedicationAdministrationService.java new file mode 100644 index 0000000..6de9108 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/IPDMedicationAdministrationService.java @@ -0,0 +1,14 @@ +package org.openmrs.module.ipd.service; + +import org.hl7.fhir.r4.model.MedicationAdministration; +import org.openmrs.module.ipd.contract.MedicationAdministrationRequest; + +public interface IPDMedicationAdministrationService { + + MedicationAdministration saveScheduledMedicationAdministration(MedicationAdministrationRequest medicationAdministrationRequest); + + MedicationAdministration updateAdhocMedicationAdministration(String uuid,MedicationAdministrationRequest medicationAdministrationRequest); + + MedicationAdministration saveAdhocMedicationAdministration(MedicationAdministrationRequest medicationAdministrationRequest); + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/IPDScheduleService.java b/omod/src/main/java/org/openmrs/module/ipd/service/IPDScheduleService.java new file mode 100644 index 0000000..c220b51 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/IPDScheduleService.java @@ -0,0 +1,26 @@ +package org.openmrs.module.ipd.service; + +import org.openmrs.Visit; +import org.openmrs.Encounter; +import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.contract.ScheduleMedicationRequest; +import org.openmrs.module.ipd.model.PatientMedicationSummary; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +public interface IPDScheduleService { + Schedule saveMedicationSchedule(ScheduleMedicationRequest scheduleMedicationRequest); + List getMedicationSlots(String patientUuid, ServiceType serviceType, LocalDate forDate); + List getMedicationSlots(String patientUuid, ServiceType serviceType); + List getMedicationSlots(String patientUuid, ServiceType serviceType, List orderUuids); + Schedule updateMedicationSchedule(ScheduleMedicationRequest scheduleMedicationRequest); + List getMedicationSlotsForTheGivenTimeFrame(String patientUuid, LocalDateTime localStartDate, LocalDateTime localEndDate,Boolean considerAdministeredTime, Visit visit); + void handlePostProcessEncounterTransaction(Encounter encounter, EncounterTransaction encounterTransaction); + List getSlotsForPatientListByTime(List patientUuidList, LocalDateTime localStartDate, + LocalDateTime localEndDate, Boolean includePreviousSlot, Boolean includeSlotDuration); +} \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/IPDVisitService.java b/omod/src/main/java/org/openmrs/module/ipd/service/IPDVisitService.java new file mode 100644 index 0000000..c000f32 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/IPDVisitService.java @@ -0,0 +1,14 @@ +package org.openmrs.module.ipd.service; + +import org.openmrs.module.ipd.model.IPDDrugOrder; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; + +import java.util.Date; +import java.util.List; + +public interface IPDVisitService { + + List getPrescribedOrders(String visitUuid, Boolean includeActiveVisit, Integer numberOfVisits, Date startDate, Date endDate, Boolean getEffectiveOrdersOnly); + List getMedicationSlots(String visitUuid, ServiceType serviceType); +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/IPDWardService.java b/omod/src/main/java/org/openmrs/module/ipd/service/IPDWardService.java new file mode 100644 index 0000000..97d2b88 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/IPDWardService.java @@ -0,0 +1,18 @@ +package org.openmrs.module.ipd.service; + + +import org.openmrs.module.ipd.api.model.IPDPatientDetails; +import org.openmrs.module.ipd.api.model.WardPatientsSummary; + +import java.util.List; + +public interface IPDWardService { + + WardPatientsSummary getIPDWardPatientSummary(String wardUuid, String providerUuid); + + IPDPatientDetails getIPDPatientByWard(String wardUuid, Integer offset, Integer limit, String sortBy); + + IPDPatientDetails searchIPDPatientsInWard(String wardUuid, List searchKeys, String searchValue, Integer offset, Integer limit, String sortBy); + + IPDPatientDetails getIPDPatientsByWardAndProvider(String wardUuid, String providerUuid, Integer offset, Integer limit, String sortBy); +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDCareTeamServiceImpl.java b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDCareTeamServiceImpl.java new file mode 100644 index 0000000..48e53db --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDCareTeamServiceImpl.java @@ -0,0 +1,49 @@ +package org.openmrs.module.ipd.service.impl; + +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.api.ConceptService; +import org.openmrs.api.PatientService; +import org.openmrs.api.VisitService; +import org.openmrs.module.ipd.api.model.CareTeam; +import org.openmrs.module.ipd.api.service.CareTeamService; +import org.openmrs.module.ipd.contract.CareTeamRequest; +import org.openmrs.module.ipd.factory.CareTeamFactory; +import org.openmrs.module.ipd.service.IPDCareTeamService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class IPDCareTeamServiceImpl implements IPDCareTeamService { + + private final CareTeamService careTeamService; + private final CareTeamFactory careTeamFactory; + private final ConceptService conceptService; + private final VisitService visitService; + private final PatientService patientService; + + @Autowired + public IPDCareTeamServiceImpl(CareTeamService careTeamService, CareTeamFactory careTeamFactory, ConceptService conceptService, VisitService visitService, PatientService patientService) { + this.careTeamService = careTeamService; + this.careTeamFactory = careTeamFactory; + this.conceptService = conceptService; + this.visitService = visitService; + this.patientService = patientService; + } + + @Override + public CareTeam saveCareTeamParticipants(CareTeamRequest careTeamRequest) { + Patient patient = patientService.getPatientByUuid(careTeamRequest.getPatientUuid()); + Visit visit = visitService.getActiveVisitsByPatient(patient).get(0); + CareTeam careTeam = careTeamService.getCareTeamByVisit(visit); + if (careTeam==null || careTeam.getCareTeamId()==null){ + careTeam = careTeamFactory.createCareTeamFromRequest(careTeamRequest,patient,visit); + } + else { + careTeam = careTeamFactory.updateCareTeamFromRequest(careTeamRequest, careTeam); + } + return careTeamService.saveCareTeam(careTeam); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDMedicationAdministrationServiceImpl.java b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDMedicationAdministrationServiceImpl.java new file mode 100644 index 0000000..42f8d22 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDMedicationAdministrationServiceImpl.java @@ -0,0 +1,121 @@ +package org.openmrs.module.ipd.service.impl; + +import org.apache.commons.lang.StringUtils; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.api.context.Context; +import org.openmrs.module.fhir2.apiext.FhirMedicationAdministrationService; +import org.openmrs.module.fhir2.apiext.dao.FhirMedicationAdministrationDao; +import org.openmrs.module.fhir2.apiext.translators.MedicationAdministrationTranslator; +import org.openmrs.module.ipd.api.model.MedicationAdministration; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.service.ScheduleService; +import org.openmrs.module.ipd.api.service.SlotService; +import org.openmrs.module.ipd.api.translators.MedicationAdministrationToSlotStatusTranslator; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.openmrs.module.ipd.contract.MedicationAdministrationRequest; +import org.openmrs.module.ipd.contract.ScheduleMedicationRequest; +import org.openmrs.module.ipd.factory.MedicationAdministrationFactory; +import org.openmrs.module.ipd.factory.ScheduleFactory; +import org.openmrs.module.ipd.factory.SlotFactory; +import org.openmrs.module.ipd.service.IPDMedicationAdministrationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + + +@Transactional +@Service +public class IPDMedicationAdministrationServiceImpl implements IPDMedicationAdministrationService { + + + private FhirMedicationAdministrationService fhirMedicationAdministrationService; + private MedicationAdministrationTranslator medicationAdministrationTranslator; + private MedicationAdministrationFactory medicationAdministrationFactory; + private SlotFactory slotFactory; + private SlotService slotService; + private ScheduleService scheduleService; + private FhirMedicationAdministrationDao fhirMedicationAdministrationDao; + private MedicationAdministrationToSlotStatusTranslator medicationAdministrationToSlotStatusTranslator; + private ScheduleFactory scheduleFactory; + + @Autowired + public IPDMedicationAdministrationServiceImpl(FhirMedicationAdministrationService fhirMedicationAdministrationService, + MedicationAdministrationTranslator medicationAdministrationTranslator, + MedicationAdministrationFactory medicationAdministrationFactory, + SlotFactory slotFactory, SlotService slotService, ScheduleService scheduleService, + FhirMedicationAdministrationDao fhirMedicationAdministrationDao, + MedicationAdministrationToSlotStatusTranslator medicationAdministrationToSlotStatusTranslator, + ScheduleFactory scheduleFactory) { + this.fhirMedicationAdministrationService = fhirMedicationAdministrationService; + this.medicationAdministrationTranslator = medicationAdministrationTranslator; + this.medicationAdministrationFactory = medicationAdministrationFactory; + this.slotFactory = slotFactory; + this.slotService = slotService; + this.scheduleService = scheduleService; + this.fhirMedicationAdministrationDao = fhirMedicationAdministrationDao; + this.medicationAdministrationToSlotStatusTranslator=medicationAdministrationToSlotStatusTranslator; + this.scheduleFactory = scheduleFactory; + } + + private org.hl7.fhir.r4.model.MedicationAdministration createMedicationAdministration(MedicationAdministrationRequest medicationAdministrationRequest) { + MedicationAdministration medicationAdministration = medicationAdministrationFactory.mapRequestToMedicationAdministration(medicationAdministrationRequest, new MedicationAdministration()); + return fhirMedicationAdministrationService.create(medicationAdministrationTranslator.toFhirResource(medicationAdministration)); + } + + @Override + public org.hl7.fhir.r4.model.MedicationAdministration saveScheduledMedicationAdministration(MedicationAdministrationRequest medicationAdministrationRequest) { + Slot slot = slotService.getSlotByUUID(medicationAdministrationRequest.getSlotUuid()); + if (slot == null) { + throw new RuntimeException("Slot not found"); + } else { + if (slot.getMedicationAdministration() != null) { + return fhirMedicationAdministrationService.get(slot.getMedicationAdministration().getUuid()); + } + if (!StringUtils.isBlank(medicationAdministrationRequest.getUuid())) { + return fhirMedicationAdministrationService.get(medicationAdministrationRequest.getUuid()); + } + org.hl7.fhir.r4.model.MedicationAdministration medicationAdministration = createMedicationAdministration(medicationAdministrationRequest); + slot.setStatus(medicationAdministrationToSlotStatusTranslator.toSlotStatus(medicationAdministration.getStatus())); + slot.setMedicationAdministration((MedicationAdministration) fhirMedicationAdministrationDao.get(medicationAdministration.getId())); + slotService.saveSlot(slot); + return medicationAdministration; + } + } + + @Override + public org.hl7.fhir.r4.model.MedicationAdministration updateAdhocMedicationAdministration(String uuid, MedicationAdministrationRequest medicationAdministrationRequest) { + MedicationAdministration medicationAdministration = medicationAdministrationFactory.mapRequestToMedicationAdministration(medicationAdministrationRequest, + (MedicationAdministration) fhirMedicationAdministrationDao.get(uuid)); + return fhirMedicationAdministrationService.update(uuid,medicationAdministrationTranslator.toFhirResource(medicationAdministration)); + } + + @Override + public org.hl7.fhir.r4.model.MedicationAdministration saveAdhocMedicationAdministration(MedicationAdministrationRequest medicationAdministrationRequest) { + Patient patient = Context.getPatientService().getPatientByUuid(medicationAdministrationRequest.getPatientUuid()); + Visit visit = Context.getVisitService().getActiveVisitsByPatient(patient).get(0); + Schedule schedule = scheduleService.getScheduleByVisit(visit); + if (schedule == null) { + ScheduleMedicationRequest scheduleMedicationRequest = new ScheduleMedicationRequest(); + scheduleMedicationRequest.setPatientUuid(medicationAdministrationRequest.getPatientUuid()); + scheduleMedicationRequest.setProviderUuid(medicationAdministrationRequest.getProviders().get(0).getProviderUuid()); + schedule = scheduleService.saveSchedule(scheduleFactory.createScheduleForMedicationFrom(scheduleMedicationRequest, visit)); + } + org.hl7.fhir.r4.model.MedicationAdministration medicationAdministration = createMedicationAdministration(medicationAdministrationRequest); + MedicationAdministration openmrsMedicationAdministration = (MedicationAdministration) fhirMedicationAdministrationDao.get(medicationAdministration.getId()); + List slotsStartTime = new ArrayList<>(); + slotsStartTime.add(DateTimeUtil.convertEpocUTCToLocalTimeZone(medicationAdministrationRequest.getAdministeredDateTime())); + ServiceType serviceType = openmrsMedicationAdministration.getDrugOrder() == null ? ServiceType.EMERGENCY_MEDICATION_REQUEST : ServiceType.AS_NEEDED_MEDICATION_REQUEST; + slotFactory.createSlotsForMedicationFrom(schedule, slotsStartTime, openmrsMedicationAdministration.getDrugOrder(), + openmrsMedicationAdministration, Slot.SlotStatus.COMPLETED, serviceType,"") + .forEach(slotService::saveSlot); + return medicationAdministration; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDScheduleServiceImpl.java b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDScheduleServiceImpl.java new file mode 100644 index 0000000..89fefc9 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDScheduleServiceImpl.java @@ -0,0 +1,247 @@ +package org.openmrs.module.ipd.service.impl; + +import org.openmrs.*; +import org.openmrs.api.ConceptService; +import org.openmrs.api.OrderService; +import org.openmrs.api.PatientService; +import org.openmrs.api.VisitService; +import org.openmrs.api.context.Context; +import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction; +import org.openmrs.module.ipd.api.model.Reference; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.service.ReferenceService; +import org.openmrs.module.ipd.api.service.ScheduleService; +import org.openmrs.module.ipd.api.service.SlotService; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.openmrs.module.ipd.contract.ScheduleMedicationRequest; +import org.openmrs.module.ipd.factory.ScheduleFactory; +import org.openmrs.module.ipd.factory.SlotFactory; +import org.openmrs.module.ipd.model.PrescribedOrderSlotSummary; +import org.openmrs.module.ipd.model.PatientMedicationSummary; +import org.openmrs.module.ipd.service.IPDScheduleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + +import static org.openmrs.module.ipd.api.model.Slot.SlotStatus.SCHEDULED; + +@Service +@Transactional +public class IPDScheduleServiceImpl implements IPDScheduleService { + + private final ScheduleService scheduleService; + private final ScheduleFactory scheduleFactory; + private final SlotFactory slotFactory; + private final SlotService slotService; + private final SlotTimeCreationService slotTimeCreationService; + private final ConceptService conceptService; + private final ReferenceService referenceService; + private final VisitService visitService; + private final PatientService patientService; + private final OrderService orderService; + + @Autowired + public IPDScheduleServiceImpl(ScheduleService scheduleService, ScheduleFactory scheduleFactory, SlotFactory slotFactory, SlotService slotService, SlotTimeCreationService slotTimeCreationService, ConceptService conceptService, ReferenceService referenceService, VisitService visitService, PatientService patientService, OrderService orderService) { + this.scheduleService = scheduleService; + this.scheduleFactory = scheduleFactory; + this.slotFactory = slotFactory; + this.slotService = slotService; + this.slotTimeCreationService = slotTimeCreationService; + this.conceptService = conceptService; + this.referenceService = referenceService; + this.visitService = visitService; + this.patientService = patientService; + this.orderService = orderService; + } + + @Override + public Schedule saveMedicationSchedule(ScheduleMedicationRequest scheduleMedicationRequest) { + Patient patient = patientService.getPatientByUuid(scheduleMedicationRequest.getPatientUuid()); + Visit visit = visitService.getActiveVisitsByPatient(patient).get(0); + Schedule savedSchedule = scheduleService.getScheduleByVisit(visit); + if(savedSchedule == null || savedSchedule.getId() == null) { + Schedule schedule = scheduleFactory.createScheduleForMedicationFrom(scheduleMedicationRequest, visit); + savedSchedule = scheduleService.saveSchedule(schedule); + } + DrugOrder order = (DrugOrder) orderService.getOrderByUuid(scheduleMedicationRequest.getOrderUuid()); + ServiceType serviceType = scheduleMedicationRequest.getServiceType() !=null ? scheduleMedicationRequest.getServiceType() : ServiceType.MEDICATION_REQUEST; + if(serviceType.equals(ServiceType.MEDICATION_REQUEST)){ + List existingSlots = getMedicationSlots(patient.getUuid(),ServiceType.MEDICATION_REQUEST,new ArrayList<>(Arrays.asList(new String[]{order.getUuid()}))); + if (existingSlots !=null && !existingSlots.isEmpty()) { + throw new RuntimeException("Slots already created for this drug order"); + } + List slotsStartTime = slotTimeCreationService.createSlotsStartTimeFrom(scheduleMedicationRequest, order); + slotFactory.createSlotsForMedicationFrom(savedSchedule, slotsStartTime, order, null, SCHEDULED, ServiceType.MEDICATION_REQUEST, scheduleMedicationRequest.getComments()) + .forEach(slotService::saveSlot); + } + else if (serviceType.equals(ServiceType.AS_NEEDED_PLACEHOLDER)){ + Slot slot = slotFactory.createAsNeededPlaceholderSlot(savedSchedule, order, scheduleMedicationRequest.getComments()); + slotService.saveSlot(slot); + } + + return savedSchedule; + } + + @Override + public List getMedicationSlots(String patientUuid, ServiceType serviceType, LocalDate forDate) { + Concept concept = conceptService.getConceptByName(serviceType.conceptName()); + Optional subjectReference = referenceService.getReferenceByTypeAndTargetUUID(Patient.class.getTypeName(), patientUuid); + if(!subjectReference.isPresent()) + return Collections.emptyList(); + return slotService.getSlotsBySubjectReferenceIdAndForDateAndServiceType(subjectReference.get(), forDate, concept); + } + + @Override + public List getMedicationSlots(String patientUuid, ServiceType serviceType) { + Concept concept = conceptService.getConceptByName(serviceType.conceptName()); + Optional subjectReference = referenceService.getReferenceByTypeAndTargetUUID(Patient.class.getTypeName(), patientUuid); + if(!subjectReference.isPresent()) + return Collections.emptyList(); + return slotService.getSlotsBySubjectReferenceIdAndServiceType(subjectReference.get(), concept); + } + + @Override + public List getMedicationSlots(String patientUuid, ServiceType serviceType, List orderUuids) { + Concept concept = conceptService.getConceptByName(serviceType.conceptName()); + Optional subjectReference = referenceService.getReferenceByTypeAndTargetUUID(Patient.class.getTypeName(), patientUuid); + if(!subjectReference.isPresent()) + return Collections.emptyList(); + return slotService.getSlotsBySubjectReferenceIdAndServiceTypeAndOrderUuids(subjectReference.get(), concept, orderUuids); + } + + @Override + public Schedule updateMedicationSchedule(ScheduleMedicationRequest scheduleMedicationRequest) { + voidExistingMedicationSlotsForOrder(scheduleMedicationRequest.getPatientUuid(),scheduleMedicationRequest.getOrderUuid(),""); + return saveMedicationSchedule(scheduleMedicationRequest); + } + + private void voidExistingMedicationSlotsForOrder(String patientUuid,String orderUuid,String voidReason){ + List existingSlots = getMedicationSlots(patientUuid,ServiceType.MEDICATION_REQUEST,new ArrayList<>(Arrays.asList(new String[]{orderUuid}))); + existingSlots.stream().forEach(slot -> slotService.voidSlot(slot,voidReason)); + } + + + @Override + public List getMedicationSlotsForTheGivenTimeFrame(String patientUuid, LocalDateTime localStartDate, LocalDateTime localEndDate, Boolean considerAdministeredTime, Visit visit) { + Optional subjectReference = referenceService.getReferenceByTypeAndTargetUUID(Patient.class.getTypeName(), patientUuid); + if(!subjectReference.isPresent()) + return Collections.emptyList(); + if (considerAdministeredTime) { + return slotService.getSlotsBySubjectReferenceIncludingAdministeredTimeFrame(subjectReference.get(), localStartDate, localEndDate, visit); + } + return slotService.getSlotsBySubjectReferenceIdAndForTheGivenTimeFrame(subjectReference.get(), localStartDate,localEndDate, visit); + } + + @Override + public void handlePostProcessEncounterTransaction(Encounter encounter, EncounterTransaction encounterTransaction) { + if (Boolean.valueOf(Context.getAdministrationService().getGlobalProperty("bahmni-ipd.allowSlotStopOnDrugOrderStop","false"))) { + handleDrugOrderStop(encounterTransaction); + } + } + + @Override + public List getSlotsForPatientListByTime(List patientUuidList, + LocalDateTime localStartDate, + LocalDateTime localEndDate, + Boolean includePreviousSlot, + Boolean includeSlotDuration) { + List slots = slotService.getSlotsForPatientListByTime(patientUuidList, localStartDate, localEndDate); + + List previousSlots = null; + if (Boolean.TRUE.equals(includePreviousSlot)) { + previousSlots = slotService.getImmediatePreviousSlotsForPatientListByTime(patientUuidList, localStartDate); + } + + List slotsDuration = null; + if (Boolean.TRUE.equals(includeSlotDuration)) { + List orders = slots.stream() + .map(Slot::getOrder) + .filter(order -> order != null) + .distinct() + .collect(Collectors.toList()); + List serviceTypes = new ArrayList<>(); + serviceTypes.add(Context.getConceptService().getConceptByName(ServiceType.MEDICATION_REQUEST.conceptName())); + serviceTypes.add(Context.getConceptService().getConceptByName(ServiceType.AS_NEEDED_MEDICATION_REQUEST.conceptName())); + + slotsDuration = slotService.getSlotDurationForPatientsByOrder(orders, serviceTypes); + } + + return groupSlotsByMedicationsAndPatients(slots, previousSlots, slotsDuration); + } + + private List groupSlotsByMedicationsAndPatients(List currentSlots, + List previousSlots, + List slotsDuration) { + + Map>> groupedSlots = currentSlots.stream() + .collect(Collectors.groupingBy( + slot -> slot.getSchedule().getSubject().getTargetUuid(), + Collectors.groupingBy( + slot -> slot.getOrder() != null ? slot.getOrder().getUuid() : "emergencyMedications" + ) + )); + + List patientMedicationsList = groupedSlots.entrySet().stream() + .map(entry -> { + PatientMedicationSummary patientMedicationSummary = new PatientMedicationSummary(); + patientMedicationSummary.setPatientUuid(entry.getKey()); + List prescribedOrderSlotsSummaryList = entry.getValue().entrySet().stream() + .filter(subEntry -> subEntry.getKey() != null) + .map(subEntry -> { + PrescribedOrderSlotSummary prescribedOrderSlotSummary = new PrescribedOrderSlotSummary(); + prescribedOrderSlotSummary.setOrderUuid(subEntry.getKey()); + prescribedOrderSlotSummary.setCurrentSlots(subEntry.getValue()); + if (previousSlots != null) { + prescribedOrderSlotSummary.setPreviousSlot(previousSlots.stream() + .filter(slot -> slot.getOrder().getUuid().equals(subEntry.getKey())) + .findFirst() + .orElse(null)); + } + if (slotsDuration != null) { + Object[] durationObj = slotsDuration.stream() + .filter(item -> ((Order) item[0]).getUuid().equals(subEntry.getKey())) + .findFirst() + .orElse(null); + prescribedOrderSlotSummary.setInitialSlotStartTime(DateTimeUtil.convertLocalDateTimeToUTCEpoc((LocalDateTime) durationObj[1])); + prescribedOrderSlotSummary.setFinalSlotStartTime(DateTimeUtil.convertLocalDateTimeToUTCEpoc((LocalDateTime) durationObj[2])); + } + return prescribedOrderSlotSummary; + }) + .collect(Collectors.toList()); + patientMedicationSummary.setPrescribedOrderSlots(prescribedOrderSlotsSummaryList); + patientMedicationSummary.setEmergencyMedicationSlots(entry.getValue().get("emergencyMedications")); + + return patientMedicationSummary; + }) + .collect(Collectors.toList()); + + return patientMedicationsList; + } + + private void handleDrugOrderStop(EncounterTransaction encounterTransaction){ + List stoppedDrugOrders = encounterTransaction.getDrugOrders().stream().filter(drugOrder -> drugOrder.getDateStopped() !=null).collect(Collectors.toList()); + String patientUuid = encounterTransaction.getPatientUuid(); + for (EncounterTransaction.DrugOrder drugOrder : stoppedDrugOrders) { + List existingSlots = getMedicationSlots(patientUuid,ServiceType.MEDICATION_REQUEST,new ArrayList<>(Arrays.asList(new String[]{drugOrder.getPreviousOrderUuid()}))); + if (existingSlots == null || existingSlots.isEmpty()) { + continue; + } + boolean atleastOneMedicationAdministered = existingSlots.stream().anyMatch(slot -> slot.getMedicationAdministration() != null); + if (atleastOneMedicationAdministered){ // Mark status of non administered slots to stopped + existingSlots.stream().forEach(slot -> { + if ((slot.getMedicationAdministration() == null) && !slot.isStopped() && (DateTimeUtil.convertDateToLocalDateTime(drugOrder.getDateStopped()) + .compareTo(slot.getStartDateTime())) < 0) {slot.setStatus(Slot.SlotStatus.STOPPED); slotService.saveSlot(slot);}}); + } else { // Void all slots + existingSlots.stream().forEach(slot -> slotService.voidSlot(slot, "")); + } + } + + } +} \ No newline at end of file diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDVisitServiceImpl.java b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDVisitServiceImpl.java new file mode 100644 index 0000000..1b3cfc6 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDVisitServiceImpl.java @@ -0,0 +1,194 @@ +package org.openmrs.module.ipd.service.impl; + +import org.bahmni.module.bahmnicore.service.BahmniDrugOrderService; +import org.bahmni.module.bahmnicore.service.BahmniObsService; +import org.openmrs.Concept; +import org.openmrs.DrugOrder; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.api.ConceptService; +import org.openmrs.api.VisitService; +import org.openmrs.module.bahmniemrapi.drugorder.contract.BahmniDrugOrder; +import org.openmrs.module.bahmniemrapi.drugorder.contract.BahmniOrderAttribute; +import org.openmrs.module.bahmniemrapi.drugorder.mapper.BahmniDrugOrderMapper; +import org.openmrs.module.bahmniemrapi.encountertransaction.contract.BahmniObservation; +import org.openmrs.module.ipd.model.DrugOrderSchedule; +import org.openmrs.module.ipd.model.IPDDrugOrder; +import org.openmrs.module.ipd.api.model.ServiceType; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.api.model.*; +import org.openmrs.module.ipd.api.service.ReferenceService; +import org.openmrs.module.ipd.api.service.SlotService; +import org.openmrs.module.ipd.service.IPDVisitService; +import org.openmrs.module.ipd.service.IPDScheduleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +@Service +@Transactional +public class IPDVisitServiceImpl implements IPDVisitService { + + private BahmniDrugOrderService drugOrderService; + private IPDScheduleService ipdScheduleService; + private SlotTimeCreationService slotTimeCreationService; + private BahmniObsService bahmniObsService; + private ConceptService conceptService; + private BahmniDrugOrderMapper bahmniDrugOrderMapper; + private ReferenceService referenceService; + private VisitService visitService; + private SlotService slotService; + + @Autowired + public IPDVisitServiceImpl(BahmniDrugOrderService drugOrderService, + IPDScheduleService ipdScheduleService, + SlotTimeCreationService slotTimeCreationService, + BahmniObsService bahmniObsService, + ConceptService conceptService, + ReferenceService referenceService, + VisitService visitService, + SlotService slotService) { + this.drugOrderService = drugOrderService; + this.ipdScheduleService = ipdScheduleService; + this.slotTimeCreationService = slotTimeCreationService; + this.bahmniObsService = bahmniObsService; + this.conceptService = conceptService; + this.bahmniDrugOrderMapper = new BahmniDrugOrderMapper(); + this.referenceService = referenceService; + this.visitService = visitService; + this.slotService = slotService; + } + + + + @Override + public List getPrescribedOrders(String visitUuid, Boolean includeActiveVisit, Integer numberOfVisits, Date startDate, Date endDate, Boolean getEffectiveOrdersOnly) { + List visitUuidsList = new ArrayList<>(); + visitUuidsList.add(visitUuid); + Visit visit = visitService.getVisitByUuid(visitUuid); + // Logic to fetch immediate preceded OPD Visit's drug orders as well as doctors tend to convert OPD to IPD immediately on emergency situations. + String precededVisitUuid= getImmediatePrecededOPDVisit(visit.getPatient(),visitUuid); + if (precededVisitUuid!=null){ + visitUuidsList.add(precededVisitUuid); + } + List prescribedDrugOrders = drugOrderService.getPrescribedDrugOrders(visitUuidsList, visit.getPatient().getUuid(), includeActiveVisit, numberOfVisits, startDate, endDate, getEffectiveOrdersOnly); + return getIPDDrugOrders(visit.getPatient().getUuid(), prescribedDrugOrders,visit); + } + + private List getIPDDrugOrders(String patientUuid, List drugOrders,Visit currentVisit) { + Map drugOrderMap = drugOrderService.getDiscontinuedDrugOrders(drugOrders); + // filter drug orders where its stop date is after current visit start Date + List drugOrdersFiltered = drugOrders.stream() + .filter(drugOrder -> drugOrder.getEffectiveStopDate() == null || drugOrder.getEffectiveStopDate().after(currentVisit.getStartDatetime())) + .collect(Collectors.toList()); + + try { + Collection orderAttributeObs = bahmniObsService.observationsFor(patientUuid, getOrdAttributeConcepts(), null, null, false, null, null, null); + List bahmniDrugOrders = bahmniDrugOrderMapper.mapToResponse(drugOrdersFiltered, orderAttributeObs, drugOrderMap , null); + bahmniDrugOrders=sortDrugOrdersAccordingToTheirSortWeight(bahmniDrugOrders); + Map drugOrderScheduleByOrders = getDrugOrderScheduleForOrders(patientUuid, bahmniDrugOrders); + + return bahmniDrugOrders.stream().map(bahmniDrugOrder -> IPDDrugOrder.createFrom(bahmniDrugOrder,drugOrderScheduleByOrders.get(bahmniDrugOrder.getUuid()))).collect(Collectors.toList()); + + } catch (IOException e) { + throw new RuntimeException("Could not parse drug order", e); + } + } + + private Map getDrugOrderScheduleForOrders(String patientUuid, List bahmniDrugOrders) { + List orderUuids = bahmniDrugOrders.stream() + .map(BahmniDrugOrder::getUuid) + .collect(Collectors.toList()); + List slots = ipdScheduleService.getMedicationSlots(patientUuid, ServiceType.MEDICATION_REQUEST,orderUuids); + List prnSlots = ipdScheduleService.getMedicationSlots(patientUuid, ServiceType.AS_NEEDED_MEDICATION_REQUEST,orderUuids); + slots.addAll(prnSlots); + Map> groupedByOrders = slots.stream() + .collect(Collectors.groupingBy(slot -> (DrugOrder) slot.getOrder())); + + Map drugOrderScheduleByOrders = slotTimeCreationService.getDrugOrderScheduledTime(groupedByOrders); + + + return drugOrderScheduleByOrders; + } + + private List sortDrugOrdersAccordingToTheirSortWeight(List bahmniDrugOrders) { + Map> bahmniDrugOrderMap = groupDrugOrdersAccordingToOrderSet(bahmniDrugOrders); + List sortDrugOrders = new ArrayList<>(); + for (String key : bahmniDrugOrderMap.keySet()) { + if(key == null) { + continue; + } + List bahmniDrugOrder = bahmniDrugOrderMap.get(key); + Collections.sort(bahmniDrugOrder, new Comparator() { + @Override + public int compare(BahmniDrugOrder o1, BahmniDrugOrder o2) { + return o1.getSortWeight().compareTo(o2.getSortWeight()); + } + }); + } + + for (String s : bahmniDrugOrderMap.keySet()) { + sortDrugOrders.addAll(bahmniDrugOrderMap.get(s)); + } + return sortDrugOrders; + } + + private Map> groupDrugOrdersAccordingToOrderSet(List bahmniDrugOrders) { + Map> groupedDrugOrders = new LinkedHashMap<>(); + + for (BahmniDrugOrder bahmniDrugOrder: bahmniDrugOrders) { + String orderSetUuid = null == bahmniDrugOrder.getOrderGroup() ? null : bahmniDrugOrder.getOrderGroup().getOrderSet().getUuid(); + + if(!groupedDrugOrders.containsKey(orderSetUuid)){ + groupedDrugOrders.put(orderSetUuid, new ArrayList()); + } + + groupedDrugOrders.get(orderSetUuid).add(bahmniDrugOrder); + } + + return groupedDrugOrders; + } + + private Collection getOrdAttributeConcepts() { + Concept orderAttribute = conceptService.getConceptByName(BahmniOrderAttribute.ORDER_ATTRIBUTES_CONCEPT_SET_NAME); + return orderAttribute == null ? Collections.EMPTY_LIST : orderAttribute.getSetMembers(); + } + + @Override + public List getMedicationSlots(String visitUuid, ServiceType serviceType) { + Visit visit = visitService.getVisitByUuid(visitUuid); + Concept concept = conceptService.getConceptByName(serviceType.conceptName()); + Optional subjectReference = referenceService.getReferenceByTypeAndTargetUUID(Patient.class.getTypeName(), visit.getPatient().getUuid()); + + if(!subjectReference.isPresent()) + return Collections.emptyList(); + + return slotService.getSlotsByPatientAndVisitAndServiceType(subjectReference.get(), visit, concept); + } + + private String getImmediatePrecededOPDVisit(Patient patient,String currentVisitUuid){ + String previousOPDVisitUuid=null; + List visits= visitService.getVisitsByPatient(patient); + List sortedVisits = visits.stream() + .sorted(Comparator.comparing(Visit::getStartDatetime).reversed()) + .collect(Collectors.toList()); + + int currentVisitIndex = IntStream.range(0, sortedVisits.size()) + .filter(i -> sortedVisits.get(i).getUuid().equals(currentVisitUuid)) + .findFirst() + .orElse(-1); + + if (currentVisitIndex != -1 && currentVisitIndex + 1 < sortedVisits.size()) { + Visit previousVisit = sortedVisits.get(currentVisitIndex + 1); + if ("OPD".equals(previousVisit.getVisitType().getName())){ + previousOPDVisitUuid=previousVisit.getUuid(); + } + } + return previousOPDVisitUuid; + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java new file mode 100644 index 0000000..2f487dd --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java @@ -0,0 +1,77 @@ +package org.openmrs.module.ipd.service.impl; + + +import org.openmrs.module.ipd.api.model.AdmittedPatient; +import org.openmrs.module.ipd.api.model.IPDPatientDetails; +import org.openmrs.module.ipd.api.model.WardPatientsSummary; +import org.openmrs.module.ipd.api.service.WardService; +import org.openmrs.module.ipd.service.IPDWardService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +@Transactional +public class IPDWardServiceImpl implements IPDWardService { + + private final WardService wardService; + + @Autowired + public IPDWardServiceImpl(WardService wardService) { + this.wardService = wardService; + } + + + @Override + public WardPatientsSummary getIPDWardPatientSummary(String wardUuid, String providerUuid) { + return wardService.getIPDWardPatientSummary(wardUuid, providerUuid); + } + + @Override + public IPDPatientDetails getIPDPatientByWard(String wardUuid, Integer offset, Integer limit, String sortBy) { + + List admittedPatients = wardService.getWardPatientsByUuid(wardUuid,sortBy); + + if (admittedPatients ==null ){ + return new IPDPatientDetails(new ArrayList<>(),0); + } + + offset = Math.min(offset, admittedPatients.size()); + limit = Math.min(limit, admittedPatients.size() - offset); + + return new IPDPatientDetails(admittedPatients.subList(offset, offset + limit), admittedPatients.size()); + } + + @Override + public IPDPatientDetails getIPDPatientsByWardAndProvider(String wardUuid, String providerUuid, Integer offset, Integer limit, String sortBy) { + + List admittedPatients = wardService.getPatientsByWardAndProvider(wardUuid, providerUuid, sortBy); + + if (admittedPatients ==null ){ + return new IPDPatientDetails(new ArrayList<>(),0); + } + + offset = Math.min(offset, admittedPatients.size()); + limit = Math.min(limit, admittedPatients.size() - offset); + + return new IPDPatientDetails(admittedPatients.subList(offset, offset + limit), admittedPatients.size()); + } + + @Override + public IPDPatientDetails searchIPDPatientsInWard(String wardUuid, List searchKeys, String searchValue, + Integer offset, Integer limit, String sortBy) { + + List admittedPatients = wardService.searchWardPatients(wardUuid,searchKeys,searchValue,sortBy); + if (admittedPatients ==null ){ + return new IPDPatientDetails(new ArrayList<>(),0); + } + + offset = Math.min(offset, admittedPatients.size()); + limit = Math.min(limit, admittedPatients.size() - offset); + + return new IPDPatientDetails(admittedPatients.subList(offset, offset + limit), admittedPatients.size()); + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/impl/SlotTimeCreationService.java b/omod/src/main/java/org/openmrs/module/ipd/service/impl/SlotTimeCreationService.java new file mode 100644 index 0000000..01263cc --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/service/impl/SlotTimeCreationService.java @@ -0,0 +1,145 @@ +package org.openmrs.module.ipd.service.impl; + +import org.openmrs.DrugOrder; +import org.openmrs.api.impl.BaseOpenmrsService; +import org.openmrs.module.ipd.api.util.DateTimeUtil; +import org.openmrs.module.ipd.model.DrugOrderSchedule; +import org.openmrs.module.ipd.api.model.Slot; +import org.openmrs.module.ipd.contract.ScheduleMedicationRequest; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.*; +import java.util.stream.Collectors; + +import static org.openmrs.module.ipd.contract.ScheduleMedicationRequest.MedicationFrequency.FIXED_SCHEDULE_FREQUENCY; +import static org.openmrs.module.ipd.contract.ScheduleMedicationRequest.MedicationFrequency.START_TIME_DURATION_FREQUENCY; + +@Service +@Component +public class SlotTimeCreationService extends BaseOpenmrsService { + + public static final List START_TIME_FREQUENCIES= Arrays.asList(new String[]{"Every Hour", "Every 2 hours", "Every 3 hours", "Every 4 hours", "Every 6 hours", "Every 8 hours", "Every 12 hours", "Once a day", "Nocte (At Night)", "Every 30 minutes", "STAT (Immediately)", "In Afternoon", "In Morning"}); + + public List createSlotsStartTimeFrom(ScheduleMedicationRequest request, DrugOrder order) { + if (request.getSlotStartTimeAsLocaltime() != null && request.getMedicationFrequency() == START_TIME_DURATION_FREQUENCY) { + return getSlotsStartTimeWithStartTimeDurationFrequency(request, order); + } else if ((!CollectionUtils.isEmpty(request.getFirstDaySlotsStartTimeAsLocalTime()) || + !CollectionUtils.isEmpty(request.getDayWiseSlotsStartTimeAsLocalTime()) || + !CollectionUtils.isEmpty(request.getRemainingDaySlotsStartTimeAsLocalTime())) + && request.getMedicationFrequency() == FIXED_SCHEDULE_FREQUENCY) { + return getSlotsStartTimeWithFixedScheduleFrequency(request, order); + } + + return Collections.emptyList(); + } + + private List getSlotsStartTimeWithFixedScheduleFrequency(ScheduleMedicationRequest request, DrugOrder order) { + int numberOfSlotsStartTimeToBeCreated = (int) (Math.ceil(order.getQuantity() / order.getDose())); + + List slotsStartTime = new ArrayList<>(); + if (!CollectionUtils.isEmpty(request.getFirstDaySlotsStartTimeAsLocalTime())) { + List slotsToBeAddedForFirstDay = numberOfSlotsStartTimeToBeCreated < request.getFirstDaySlotsStartTimeAsLocalTime().size() + ? request.getFirstDaySlotsStartTimeAsLocalTime().subList(0, numberOfSlotsStartTimeToBeCreated) + : request.getFirstDaySlotsStartTimeAsLocalTime(); + + slotsStartTime.addAll(slotsToBeAddedForFirstDay); + numberOfSlotsStartTimeToBeCreated -= slotsToBeAddedForFirstDay.size(); + } + + + List remainingDaySlotsStartTime = request.getRemainingDaySlotsStartTimeAsLocalTime(); + if (!CollectionUtils.isEmpty(remainingDaySlotsStartTime) && numberOfSlotsStartTimeToBeCreated > 0) { + List slotsToBeAddedForRemainingDay = numberOfSlotsStartTimeToBeCreated < remainingDaySlotsStartTime.size() + ? remainingDaySlotsStartTime.subList(0, numberOfSlotsStartTimeToBeCreated) + : remainingDaySlotsStartTime; + numberOfSlotsStartTimeToBeCreated -= slotsToBeAddedForRemainingDay.size(); + slotsStartTime.addAll(slotsToBeAddedForRemainingDay); + } + + List nextSlotsStartTime = request.getDayWiseSlotsStartTimeAsLocalTime(); + if (!CollectionUtils.isEmpty(nextSlotsStartTime) && numberOfSlotsStartTimeToBeCreated > 0) { + List initialSlotsToBeAddedForSecondDay = numberOfSlotsStartTimeToBeCreated < nextSlotsStartTime.size() + ? nextSlotsStartTime.subList(0, numberOfSlotsStartTimeToBeCreated) + : nextSlotsStartTime; + slotsStartTime.addAll(initialSlotsToBeAddedForSecondDay); + numberOfSlotsStartTimeToBeCreated -= initialSlotsToBeAddedForSecondDay.size(); + while (numberOfSlotsStartTimeToBeCreated > 0) { + nextSlotsStartTime = nextSlotsStartTime.stream().map(slotStartTime -> slotStartTime.plusHours(24)).collect(Collectors.toList()); + if (numberOfSlotsStartTimeToBeCreated >= nextSlotsStartTime.size()) { + slotsStartTime.addAll(nextSlotsStartTime); + numberOfSlotsStartTimeToBeCreated -= nextSlotsStartTime.size(); + } else { + slotsStartTime.addAll(nextSlotsStartTime.subList(0, numberOfSlotsStartTimeToBeCreated)); + numberOfSlotsStartTimeToBeCreated -= nextSlotsStartTime.subList(0, numberOfSlotsStartTimeToBeCreated).size(); + } + } + } + + return slotsStartTime; + } + + private List getSlotsStartTimeWithStartTimeDurationFrequency(ScheduleMedicationRequest request, DrugOrder order) { + int numberOfSlotsStartTimeToBeCreated = (order.getQuantity() == 0.0 || order.getFrequency() == null || order.getDuration() == null) ? 1 : (int) (Math.ceil(order.getQuantity() / order.getDose())); + List slotsStartTime = new ArrayList<>(); + Double slotDurationInHours = order.getFrequency() != null ? 24 / order.getFrequency().getFrequencyPerDay() : 0; + LocalDateTime slotStartTime = request.getSlotStartTimeAsLocaltime(); + while (numberOfSlotsStartTimeToBeCreated-- > 0) { + slotsStartTime.add(slotStartTime); + if(slotDurationInHours.compareTo(1.0) >= 0) + { + slotStartTime = slotStartTime.plusHours(slotDurationInHours.longValue()); + } + else { + Double minutesToBeAdded = 60 * slotDurationInHours; + slotStartTime = slotStartTime.plusMinutes(minutesToBeAdded.longValue()); + } + } + return slotsStartTime; + } + + public HashMap getDrugOrderScheduledTime(Map> slotsByOrder){ + HashMap drugOrderScheduleHash= new HashMap<>(); + for (DrugOrder drugOrder : slotsByOrder.keySet()) { + DrugOrderSchedule drugOrderSchedule = new DrugOrderSchedule(); + if (drugOrder.getAsNeeded() || drugOrder.getFrequency() == null || drugOrder.getDuration() == null || drugOrder.getQuantity() == 0.0) { + drugOrderSchedule.setSlotStartTime(DateTimeUtil.convertLocalDateTimeToUTCEpoc(slotsByOrder.get(drugOrder).get(0).getStartDateTime())); + } + else { + Double frequencyPerDay = drugOrder.getFrequency().getFrequencyPerDay(); + String frequency = drugOrder.getFrequency().getName(); + Map> groupedByDateAndEpoch = slotsByOrder.get(drugOrder).stream() + .collect(Collectors.groupingBy( + obj -> obj.getStartDateTime().toLocalDate(), + Collectors.mapping( + obj -> obj.getStartDateTime(), + Collectors.toList() + ) + )); + + List> sortedList = groupedByDateAndEpoch.entrySet().stream() + .sorted(Map.Entry.comparingByKey()) // Sort by LocalDate in ascending order + .map(Map.Entry::getValue) // Get the list of Longs for each entry + .collect(Collectors.toList()); // Collect the list of lists into a single ArrayList + + if (START_TIME_FREQUENCIES.contains(frequency)) { + drugOrderSchedule.setSlotStartTime(DateTimeUtil.convertLocalDateTimeToUTCEpoc(sortedList.get(0).get(0))); + } else if (sortedList.get(0).size() == frequencyPerDay || (sortedList.size() == 1)) { + drugOrderSchedule.setDayWiseSlotsStartTime(sortedList.get(0).stream().map(DateTimeUtil::convertLocalDateTimeToUTCEpoc).collect(Collectors.toList())); + } else { + drugOrderSchedule.setFirstDaySlotsStartTime(sortedList.get(0).stream().map(DateTimeUtil::convertLocalDateTimeToUTCEpoc).collect(Collectors.toList())); + drugOrderSchedule.setRemainingDaySlotsStartTime(sortedList.get(sortedList.size() - 1).stream().map(DateTimeUtil::convertLocalDateTimeToUTCEpoc).collect(Collectors.toList())); + if (sortedList.size() > 2) { + drugOrderSchedule.setDayWiseSlotsStartTime(sortedList.get(1).stream().map(DateTimeUtil::convertLocalDateTimeToUTCEpoc).collect(Collectors.toList())); + } + } + } + drugOrderSchedule.setSlots(slotsByOrder.get(drugOrder)); + drugOrderScheduleHash.put(drugOrder.getUuid(),drugOrderSchedule); + } + return drugOrderScheduleHash; + } +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/util/PrivilegeConstants.java b/omod/src/main/java/org/openmrs/module/ipd/util/PrivilegeConstants.java new file mode 100644 index 0000000..2fdb09a --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/ipd/util/PrivilegeConstants.java @@ -0,0 +1,19 @@ +package org.openmrs.module.ipd.util; + +import org.openmrs.annotation.AddOnStartup; + +public class PrivilegeConstants { + + @AddOnStartup(description = "Edit Medication Tasks description") + public static final String EDIT_MEDICATION_TASKS = "Edit Medication Tasks"; + @AddOnStartup(description = "Delete Medication Tasks description") + public static final String DELETE_MEDICATION_TASKS = "Delete Medication Tasks"; + @AddOnStartup(description = "Edit adhoc medication tasks description") + public static final String EDIT_ADHOC_MEDICATION_TASKS = "Edit adhoc medication tasks"; + @AddOnStartup(description = "Edit Medication Administration description") + public static final String EDIT_MEDICATION_ADMINISTRATION = "Edit Medication Administration"; + @AddOnStartup(description = "Get Medication Administration description") + public static final String GET_MEDICATION_ADMINISTRATION = "Get Medication Administration"; + @AddOnStartup(description = "Get Medication Tasks description") + public static final String GET_MEDICATION_TASKS = "Get Medication Tasks"; +} diff --git a/omod/src/main/resources/application.properties b/omod/src/main/resources/application.properties new file mode 100644 index 0000000..ed16b69 --- /dev/null +++ b/omod/src/main/resources/application.properties @@ -0,0 +1,3 @@ + +# Route definitions +config-file.path=/etc/bahmni_config/openmrs/apps/ipdDashboard/eventsConfig.json \ No newline at end of file diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml new file mode 100644 index 0000000..6a691b1 --- /dev/null +++ b/omod/src/main/resources/config.xml @@ -0,0 +1,21 @@ + + + + + bahmni-ipd + Bahmni IPD + 1.0.0-SNAPSHOT + ${MODULE_PACKAGE} + Bahmni + ${project.parent.description} + + + org.openmrs.module.webservices.rest + org.bahmni.module.bahmnicore + org.openmrs.module.bedmanagement + org.bahmni.module.medication-administration + org.bahmni.module.fhir2Extension + + org.openmrs.module.ipd.api.IPDActivator + + diff --git a/omod/src/main/resources/webModuleApplicationContext.xml b/omod/src/main/resources/webModuleApplicationContext.xml new file mode 100644 index 0000000..a12d5d4 --- /dev/null +++ b/omod/src/main/resources/webModuleApplicationContext.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/omod/src/test/java/org/openmrs/module/ipd/BaseIntegrationTest.java b/omod/src/test/java/org/openmrs/module/ipd/BaseIntegrationTest.java new file mode 100644 index 0000000..642bc1f --- /dev/null +++ b/omod/src/test/java/org/openmrs/module/ipd/BaseIntegrationTest.java @@ -0,0 +1,7 @@ +package org.openmrs.module.ipd; + +import org.springframework.test.context.ContextConfiguration; + +@ContextConfiguration(locations = {"classpath:TestingApplicationContext.xml"}) +public abstract class BaseIntegrationTest extends BaseWebControllerTest { +} diff --git a/omod/src/test/java/org/openmrs/module/ipd/BaseWebControllerTest.java b/omod/src/test/java/org/openmrs/module/ipd/BaseWebControllerTest.java new file mode 100644 index 0000000..169b6e5 --- /dev/null +++ b/omod/src/test/java/org/openmrs/module/ipd/BaseWebControllerTest.java @@ -0,0 +1,176 @@ +package org.openmrs.module.ipd; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import junit.framework.Assert; +import org.junit.Ignore; +import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.HandlerExecutionChain; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; +import java.util.Map; + +@Ignore +@ContextConfiguration(locations = {"classpath:TestingApplicationContext.xml"}) +public class BaseWebControllerTest extends BaseModuleWebContextSensitiveTest { + + @Autowired + private RequestMappingHandlerAdapter handlerAdapter; + + @Autowired + private List handlerMappings; + + private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); + + /** + * Creates a request from the given parameters. + *

+ * The requestURI is automatically preceded with "/rest/" + RestConstants.VERSION_1. + * + * @param method + * @param requestURI + * @return + */ + public MockHttpServletRequest request(RequestMethod method, String requestURI) { + MockHttpServletRequest request = new MockHttpServletRequest(method.toString(), requestURI); + request.addHeader("content-type", "application/json"); + request.addHeader("accept", "application/json"); + return request; + } + + public static class Parameter { + + public String name; + + public String value; + + public Parameter(String name, String value) { + this.name = name; + this.value = value; + } + } + + public MockHttpServletRequest newRequest(RequestMethod method, String requestURI, Parameter... parameters) { + MockHttpServletRequest request = request(method, requestURI); + for (Parameter parameter : parameters) { + request.addParameter(parameter.name, parameter.value); + } + return request; + } + + public MockHttpServletRequest newRequest(RequestMethod method, String requestURI, Map headers, Parameter... parameters) { + MockHttpServletRequest request = newRequest(method, requestURI, parameters); + for (String key : headers.keySet()) { + request.addHeader(key, headers.get(key)); + } + return request; + } + + public MockHttpServletRequest newDeleteRequest(String requestURI, Parameter... parameters) { + return newRequest(RequestMethod.DELETE, requestURI, parameters); + } + + public MockHttpServletRequest newGetRequest(String requestURI, Parameter... parameters) { + return newRequest(RequestMethod.GET, requestURI, parameters); + } + + public MockHttpServletRequest newGetRequest(String requestURI, Map headers, Parameter... parameters) { + return newRequest(RequestMethod.GET, requestURI, headers, parameters); + } + + public MockHttpServletRequest newPostRequest(String requestURI, Object content) { + return newWriteRequest(requestURI, content, RequestMethod.POST); + } + + public MockHttpServletRequest newPutRequest(String requestURI, Object content) { + return newWriteRequest(requestURI, content, RequestMethod.PUT); + } + + private MockHttpServletRequest newWriteRequest(String requestURI, Object content, RequestMethod requestMethod) { + MockHttpServletRequest request = request(requestMethod, requestURI); + try { + String json = new ObjectMapper().writeValueAsString(content); + request.setContent(json.getBytes("UTF-8")); + } catch (Exception e) { + throw new RuntimeException(e); + } + return request; + } + + public MockHttpServletRequest newPostRequest(String requestURI, String content) { + MockHttpServletRequest request = request(RequestMethod.POST, requestURI); + try { + request.setContent(content.getBytes("UTF-8")); + } catch (Exception e) { + throw new RuntimeException(e); + } + return request; + } + + public MockHttpServletRequest newPutRequest(String requestURI, String content) { + MockHttpServletRequest request = request(RequestMethod.PUT, requestURI); + try { + request.setContent(content.getBytes("UTF-8")); + } catch (Exception e) { + throw new RuntimeException(e); + } + return request; + } + + /** + * Passes the given request to a proper controller. + * + * @param request + * @return + * @throws Exception + */ + public MockHttpServletResponse handle(HttpServletRequest request) throws Exception { + MockHttpServletResponse response = new MockHttpServletResponse(); + + HandlerExecutionChain handlerExecutionChain = null; + for (RequestMappingHandlerMapping handlerMapping : handlerMappings) { + handlerExecutionChain = handlerMapping.getHandler(request); + if (handlerExecutionChain != null) { + break; + } + } + Assert.assertNotNull("The request URI does not exist", handlerExecutionChain); + + handlerAdapter.handle(request, response, handlerExecutionChain.getHandler()); + + return response; + } + + /** + * Deserializes the JSON response. + * + * @param response + * @param type + * @return + * @throws Exception + */ + public T deserialize(MockHttpServletResponse response, Class type) throws Exception { + return objectMapper.readValue(response.getContentAsString(), type); + } + + /** + * Deserializes the JSON response. + * + * @param response + * @param typeReference + * @return + * @throws Exception + */ + public T deserialize(MockHttpServletResponse response, final TypeReference typeReference) throws Exception { + return objectMapper.readValue(response.getContentAsString(), typeReference); + } +} \ No newline at end of file diff --git a/omod/src/test/java/org/openmrs/module/ipd/controller/IPDScheduleControllerIntegrationTest.java b/omod/src/test/java/org/openmrs/module/ipd/controller/IPDScheduleControllerIntegrationTest.java new file mode 100644 index 0000000..e135b58 --- /dev/null +++ b/omod/src/test/java/org/openmrs/module/ipd/controller/IPDScheduleControllerIntegrationTest.java @@ -0,0 +1,57 @@ +package org.openmrs.module.ipd.controller; + +import com.fasterxml.jackson.core.type.TypeReference; +import org.hibernate.SessionFactory; +import org.hibernate.query.Query; +import org.junit.Test; +import org.openmrs.DrugOrder; +import org.openmrs.module.bedmanagement.entity.BedPatientAssignment; +import org.openmrs.module.ipd.BaseIntegrationTest; +import org.openmrs.module.ipd.api.model.Schedule; +import org.openmrs.module.ipd.api.service.ScheduleService; +import org.openmrs.module.ipd.contract.ScheduleMedicationResponse; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpServletResponse; + +import java.util.List; + +/*public class IPDScheduleControllerIntegrationTest extends BaseIntegrationTest { + + @Autowired + private ScheduleService scheduleService; + + @Autowired + private SessionFactory sessionFactory; + + @Test + public void shouldSaveMedicationSchedule() throws Exception { + + List allDrugOrders = getAllDrudOrders(); + + String content = "{ \"providerUuid\": \"823fdcd7-3f10-11e4-adec-0800271c1b75\", " + + "\"patientUuid\": \"2c33920f-7aa6-48d6-998a-60412d8ff7d5\", " + + "\"orderUuid\": \""+allDrugOrders.get(0).getUuid()+"\", " + + "\"slotStartTime\": \"2107-07-15T17:30:00.0\"," + + "\"firstDaySlotsStartTime\": [\"2107-07-15T17:30:00.0\"]," + + "\"dayWiseSlotsStartTime\": [\"2107-07-15T17:30:00.0\"]," + + "\"comments\":\"changes the schedule\"," + + "\"medicationFrequency\":\"START_TIME_DURATION_FREQUENCY\"" + + "}"; + + MockHttpServletResponse response = handle(newPostRequest("/rest/" + RestConstants.VERSION_1 + "/ipd/schedule/type/medication", content)); + ScheduleMedicationResponse scheduleMedicationResponse = deserialize(response, new TypeReference() {}); + Schedule savedSchedule = scheduleService.getSchedule(scheduleMedicationResponse.getId()); + scheduleService.purgeSchedule(savedSchedule); + } + + private List getAllDrudOrders() { + Query query = sessionFactory.getCurrentSession().createQuery("FROM org.openmrs.DrugOrder"); + return (List) query.getResultList(); + } + + private List getAllBedsAssignedToPatient() { + Query query = sessionFactory.getCurrentSession().createQuery("FROM org.openmrs.module.bedmanagement.entity.BedPatientAssignment"); + return (List) query.getResultList(); + } +}*/ diff --git a/omod/src/test/resources/config.xml b/omod/src/test/resources/config.xml new file mode 100644 index 0000000..040350d --- /dev/null +++ b/omod/src/test/resources/config.xml @@ -0,0 +1,21 @@ + + + + + + bahmni-ipd + Bahmni IPD + 1.0.0-SNAPSHOT + Provides bahmni ipd services + ${MODULE_PACKAGE} + Bahmni + + + org.openmrs.module.webservices.rest + org.bahmni.module.bahmnicore + + + org.openmrs.module.ipd.api.IPDActivator + + 1.11.6 + \ No newline at end of file diff --git a/omod/src/test/resources/webModuleApplicationContext.xml b/omod/src/test/resources/webModuleApplicationContext.xml new file mode 100644 index 0000000..1a906f3 --- /dev/null +++ b/omod/src/test/resources/webModuleApplicationContext.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..da3f0db --- /dev/null +++ b/pom.xml @@ -0,0 +1,435 @@ + + + 4.0.0 + + org.bahmni.module + bahmni-ipd + 1.0.0-SNAPSHOT + pom + Bahmni IPD + Bahmni IPD module contains all backend APIs for IPD + https://demo.mybahmni.org/bahmni/home/index.html + + + + GNU AFFERO GENERAL PUBLIC LICENSE + https://www.gnu.org/licenses/agpl-3.0.txt + + + + + Bahmnitw + bahmnicommunity@gmail.com + Bahmni + https://github.com/Bahmni + + + + scm:git:git@github.com:Bahmni/openmrs-module-ipd.git + scm:git:https://github.com/Bahmni/openmrs-module-ipd.git + https://github.com/Bahmni/openmrs-module-ipd + + + + api + omod + + + + 2.5.10 + 2.39.0 + 5.13.0 + 5.2.14.RELEASE + 4.13 + 2.0.7 + 1.3 + 3.5.11 + -Xmx1024m + 0.7.9 + 1.18.26 + 2.1.0-SNAPSHOT + 1.3.0-SNAPSHOT + 0.94-SNAPSHOT + 1.32.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.openmrs.maven.plugins + maven-openmrs-plugin + 1.0.1 + + + org.apache.maven.plugins + maven-dependency-plugin + 2.4 + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + test-jar + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.10 + + + **/*Test.java + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.5.1 + true + + + default-deploy + deploy + + deploy + + + + + nexus-sonatype + https://oss.sonatype.org + + + + + + + + + + org.projectlombok + lombok + ${lombokVersion} + provided + + + + org.openmrs.api + openmrs-api + ${openmrsPlatformVersion} + jar + provided + + + javax.servlet + servlet-api + + + + + org.openmrs.module + webservices.rest-omod-common + ${openMRSWebServicesVersion} + jar + provided + + + org.openmrs.module + webservices.rest-omod-2.0 + ${openMRSWebServicesVersion} + provided + + + org.openmrs.web + openmrs-web + ${openmrsPlatformVersion} + provided + + + + org.openmrs.module + emrapi-api + ${emrapi-omod.version} + provided + + + + org.bahmni.module + bahmnicore-api + ${bahmniVersion} + provided + jar + + + + org.openmrs.module + bedmanagement-api + ${bedManagementVersion} + provided + + + + + org.openmrs.module + fhir2-api + ${openmrsFhir2Version} + provided + + + + org.openmrs.module + fhir2-omod + ${openmrsFhir2Version} + provided + + + + org.bahmni.module + fhir2Extension-api + ${fhir2ExtensionVersion} + provided + + + + + org.bahmni.module + fhir2Extension-omod + ${fhir2ExtensionVersion} + provided + + + + org.bahmni.module + medication-administration-api + 1.0.0-SNAPSHOT + provided + + + + + + org.openmrs.module + webservices.rest-omod-common + ${openMRSWebServicesVersion} + test-jar + test + + + org.openmrs.web + openmrs-web + ${openmrsPlatformVersion} + test-jar + test + + + org.openmrs.api + openmrs-api + ${openmrsPlatformVersion} + test-jar + test + + + javax.servlet + servlet-api + + + + + org.openmrs.test + openmrs-test + ${openmrsPlatformVersion} + pom + test + + + javax.servlet + servlet-api + 2.5 + test + + + + + junit + junit + ${junitVersion} + + + org.hamcrest + hamcrest-core + + + test + + + + + org.powermock + powermock-api-mockito2 + ${powerMockVersion} + test + + + mockito-all + org.mockito + + + + + org.powermock + powermock-module-junit4 + ${powerMockVersion} + test + + + + + org.mockito + mockito-core + ${mockitoVersion} + + + org.hamcrest + hamcrest-core + + + test + + + + + + + openmrs-repo + OpenMRS Nexus Repository + https://mavenrepo.openmrs.org/public + + + central + Maven Repository Switchboard + default + https://repo1.maven.org/maven2 + + + sonatype-nexus-releases + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/releases + + false + + + true + + + + + + + openmrs-repo + OpenMRS Nexus Repository + https://mavenrepo.openmrs.org/public + + false + + + + + + + nexus-sonatype + https://oss.sonatype.org/content/repositories/snapshots + + + nexus-sonatype + https://oss.sonatype.org/service/local/staging/deploy/maven2 + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.17 + + + + integration-test + verify + + + -Xmx512m + + **/*IT.java + + + + + + + + + + From 0db5c183cea03a0b5f8016fac8aa178964175036 Mon Sep 17 00:00:00 2001 From: Arjun G <91885483+Arjun-Go@users.noreply.github.com> Date: Thu, 6 Jun 2024 19:02:24 +0530 Subject: [PATCH 02/15] BAH-3842 | Add. Application Properties In API Resources (#60) --- api/src/main/resources/application.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 api/src/main/resources/application.properties diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties new file mode 100644 index 0000000..ed16b69 --- /dev/null +++ b/api/src/main/resources/application.properties @@ -0,0 +1,3 @@ + +# Route definitions +config-file.path=/etc/bahmni_config/openmrs/apps/ipdDashboard/eventsConfig.json \ No newline at end of file From 1dda6746b54d2371c95bb9e22c7461b98905d1af Mon Sep 17 00:00:00 2001 From: Arjun G <91885483+Arjun-Go@users.noreply.github.com> Date: Thu, 6 Jun 2024 19:52:03 +0530 Subject: [PATCH 03/15] BAH-3842 | Add. Application Properties In API Resources (#61) --- api/src/main/resources/moduleApplicationContext.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index 0dde695..c9dd5ed 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -10,6 +10,7 @@ + @@ -35,4 +36,4 @@ - \ No newline at end of file + From 65b6bf2d52d2650c5fd4e8447c16ae6bddfab3f6 Mon Sep 17 00:00:00 2001 From: Rahul Ramesh <121226043+rahu1ramesh@users.noreply.github.com> Date: Fri, 5 Jul 2024 09:34:18 +0530 Subject: [PATCH 04/15] Merge IPD Branch Latest Changes To Master * Kavitha| refactored search to support multiple words (#64) (cherry picked from commit c3459744a5574301c4bc940368a2ecce2940e9ec) * A-1207053820490648 | [CURE IPD Bug] - Patients are not arranged in ascending order of bed number (#62) * add. sort logic to handle sorting of bed numbers that are purely integers * update. sort logic for numeric bed numbers (cherry picked from commit abcdb78c1c16101ea68cc80bd8b38cfb224f7e0a) * Remove IPD branch publish (#65) (cherry picked from commit f9693ee1f732882f8ca1b7047e4bafaef9b2f49f) * add. check to filter out orders that are inactive and not scheduled (#66) (cherry picked from commit 9ce0056f02e2c01ed7d26cadc265bf9d7479df14) --------- Co-authored-by: kavitha-sundararajan <90255023+kavitha-sundararajan@users.noreply.github.com> Co-authored-by: Arjun G <91885483+Arjun-Go@users.noreply.github.com> --- .../ipd/api/dao/impl/HibernateWardDAO.java | 36 ++++++++++----- .../ipd/service/impl/IPDWardServiceImpl.java | 44 ++++++++++++++----- omod/src/main/resources/config.xml | 2 +- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java index 599ffa3..af76bbf 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/dao/impl/HibernateWardDAO.java @@ -151,23 +151,24 @@ public List searchAdmittedPatients(Location location, List searchAdmittedPatients(Location location, List searchKeys,StringBuilder additionalJoins,StringBuilder whereClause) { + + private void generateSQLSearchConditions(List searchKeys, StringBuilder additionalJoins, StringBuilder whereClause, String searchValue) { whereClause.append("where (assignment.endDatetime is null and v.stopDatetime is null and l.parentLocation = :location)"); if (searchKeys != null && !searchKeys.isEmpty()) { whereClause.append(" and ("); @@ -203,7 +205,16 @@ private void generateSQLSearchConditions(List searchKeys,StringBuilder a break; case "patientName": additionalJoins.append(" JOIN pr.names prn "); - whereClause.append(" (prn.givenName LIKE :patientName or prn.middleName LIKE :patientName or prn.familyName LIKE :patientName) "); + whereClause.append(" ("); + + String[] nameParts = searchValue.split("\\s+"); + for (int j = 0; j < nameParts.length; j++) { + if (j > 0) whereClause.append(" and "); + whereClause.append(" (prn.givenName LIKE :namePart" + j + + " or prn.middleName LIKE :namePart" + j + + " or prn.familyName LIKE :namePart" + j + ") "); + } + whereClause.append(" )"); break; } if (i < searchKeys.size() - 1) { @@ -223,7 +234,10 @@ private void setQueryParameters(Query query, List searchKeys, String sea query.setParameter("patientIdentifier", "%" + searchValue + "%"); } if (searchKeys.contains("patientName")) { - query.setParameter("patientName", "%" + searchValue + "%"); + String[] nameParts = searchValue.split("\\s+"); + for (int i = 0; i < nameParts.length; i++) { + query.setParameter("namePart" + i, "%" + nameParts[i] + "%"); + } } } } diff --git a/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java index 2f487dd..e09998e 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java +++ b/omod/src/main/java/org/openmrs/module/ipd/service/impl/IPDWardServiceImpl.java @@ -1,6 +1,5 @@ package org.openmrs.module.ipd.service.impl; - import org.openmrs.module.ipd.api.model.AdmittedPatient; import org.openmrs.module.ipd.api.model.IPDPatientDetails; import org.openmrs.module.ipd.api.model.WardPatientsSummary; @@ -12,6 +11,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.regex.Pattern; @Service @Transactional @@ -24,6 +25,7 @@ public IPDWardServiceImpl(WardService wardService) { this.wardService = wardService; } + private static final Pattern numericPattern = Pattern.compile("^\\d+$"); @Override public WardPatientsSummary getIPDWardPatientSummary(String wardUuid, String providerUuid) { @@ -38,11 +40,12 @@ public IPDPatientDetails getIPDPatientByWard(String wardUuid, Integer offset, In if (admittedPatients ==null ){ return new IPDPatientDetails(new ArrayList<>(),0); } + List admittedPatientsSortedList = Objects.equals(sortBy, "bedNumber") ? sortNumericBedNumbers(admittedPatients) : admittedPatients; - offset = Math.min(offset, admittedPatients.size()); - limit = Math.min(limit, admittedPatients.size() - offset); + offset = Math.min(offset, admittedPatientsSortedList.size()); + limit = Math.min(limit, admittedPatientsSortedList.size() - offset); - return new IPDPatientDetails(admittedPatients.subList(offset, offset + limit), admittedPatients.size()); + return new IPDPatientDetails(admittedPatientsSortedList.subList(offset, offset + limit), admittedPatientsSortedList.size()); } @Override @@ -53,11 +56,12 @@ public IPDPatientDetails getIPDPatientsByWardAndProvider(String wardUuid, String if (admittedPatients ==null ){ return new IPDPatientDetails(new ArrayList<>(),0); } + List admittedPatientsSortedList = Objects.equals(sortBy, "bedNumber") ? sortNumericBedNumbers(admittedPatients) : admittedPatients; - offset = Math.min(offset, admittedPatients.size()); - limit = Math.min(limit, admittedPatients.size() - offset); + offset = Math.min(offset, admittedPatientsSortedList.size()); + limit = Math.min(limit, admittedPatientsSortedList.size() - offset); - return new IPDPatientDetails(admittedPatients.subList(offset, offset + limit), admittedPatients.size()); + return new IPDPatientDetails(admittedPatientsSortedList.subList(offset, offset + limit), admittedPatientsSortedList.size()); } @Override @@ -65,13 +69,33 @@ public IPDPatientDetails searchIPDPatientsInWard(String wardUuid, List s Integer offset, Integer limit, String sortBy) { List admittedPatients = wardService.searchWardPatients(wardUuid,searchKeys,searchValue,sortBy); + if (admittedPatients ==null ){ return new IPDPatientDetails(new ArrayList<>(),0); } - offset = Math.min(offset, admittedPatients.size()); - limit = Math.min(limit, admittedPatients.size() - offset); + List admittedPatientsSortedList = Objects.equals(sortBy, "bedNumber") ? sortNumericBedNumbers(admittedPatients) : admittedPatients; + + offset = Math.min(offset, admittedPatientsSortedList.size()); + limit = Math.min(limit, admittedPatientsSortedList.size() - offset); + + return new IPDPatientDetails(admittedPatientsSortedList.subList(offset, offset + limit), admittedPatientsSortedList.size()); + } - return new IPDPatientDetails(admittedPatients.subList(offset, offset + limit), admittedPatients.size()); + private List sortNumericBedNumbers(List admittedPatients) { + + boolean allNumeric = admittedPatients.stream() + .map(patient -> patient.getBedPatientAssignment().getBed().getBedNumber()) + .allMatch(bedNumber -> numericPattern.matcher(bedNumber).matches()); + + if(allNumeric) { + admittedPatients.sort((patientA, patientB) -> { + String bedNumberA = patientA.getBedPatientAssignment().getBed().getBedNumber(); + String bedNumberB = patientB.getBedPatientAssignment().getBed().getBedNumber(); + + return Integer.compare(Integer.parseInt(bedNumberA), Integer.parseInt(bedNumberB)); + }); + } + return admittedPatients; } } diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 6a691b1..f33032b 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -7,7 +7,7 @@ 1.0.0-SNAPSHOT ${MODULE_PACKAGE} Bahmni - ${project.parent.description} + Provides APIs for IPD features org.openmrs.module.webservices.rest From 6c4f1d60fedac4a2cf98474b048cb9f4374adae0 Mon Sep 17 00:00:00 2001 From: Parvathy Babu <102500787+parvathy00@users.noreply.github.com> Date: Mon, 15 Jul 2024 12:55:26 +0530 Subject: [PATCH 05/15] Parvathy | BAH-4017 | Add. Global Property bahmni-ipd.allowSlotStopOnDrugOrderStop (#69) --- omod/src/main/resources/config.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index f33032b..2aeeda8 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -16,6 +16,13 @@ org.bahmni.module.medication-administration org.bahmni.module.fhir2Extension + + + bahmni-ipd.allowSlotStopOnDrugOrderStop + true + Feature toggle to decide whether to stop slots associated when drug order is stopped + + org.openmrs.module.ipd.api.IPDActivator From f7892e54fd13b8e2b720e4e045d9b9b023edef3f Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T <31698165+mohan-13@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:42:00 +0530 Subject: [PATCH 06/15] BAH-4001 | Add. Set flag to mark system generated tasks (#70) --- .../java/org/openmrs/module/ipd/api/events/IPDEventUtils.java | 3 ++- .../ipd/api/events/handler/impl/PatientAdmitEventHandler.java | 4 ++-- .../api/events/handler/impl/ShiftStartTaskEventHandler.java | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java index b9da7ab..82426c9 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java @@ -8,7 +8,7 @@ public class IPDEventUtils { - public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, String name, String taskType) { + public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, String name, String taskType, Boolean isSystemGenerated) { TaskRequest taskRequest = new TaskRequest(); taskRequest.setName(name); taskRequest.setTaskType(taskType); @@ -17,6 +17,7 @@ public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, Stri taskRequest.setRequestedStartTime(new Date()); taskRequest.setIntent(FhirTask.TaskIntent.ORDER); taskRequest.setStatus(FhirTask.TaskStatus.REQUESTED); + taskRequest.setIsSystemGeneratedTask(isSystemGenerated); return taskRequest; } } diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java index 9828da5..362e0cb 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java @@ -40,7 +40,7 @@ public void handleEvent(IPDEvent event) { .orElse(null); if (eventConfig != null) { for(TaskDetail taskDetail : eventConfig.getTasks()) { - TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), "nursing_activity_system"); + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), "nursing_activity_system",true); Task task = taskMapper.fromRequest(taskRequest); taskService.saveTask(task); log.info("Task created " + taskDetail.getName()); @@ -49,4 +49,4 @@ public void handleEvent(IPDEvent event) { } -} \ No newline at end of file +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java index e97d620..0ab7c73 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java @@ -39,7 +39,7 @@ public void handleEvent(IPDEvent event) { String patientUuid = admittedPatient.getBedPatientAssignment().getPatient().getUuid(); IPDEvent ipdEvent = new IPDEvent(null, patientUuid, event.getIpdEventType()); for(TaskDetail taskDetail : eventConfig.getTasks()) { - TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), "nursing_activity_system"); + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), "nursing_activity_system",true); Task task = taskMapper.fromRequest(taskRequest); tasks.add(task); } @@ -57,4 +57,4 @@ private ConfigDetail getEventConfig(IPDEvent event){ .orElse(null); return eventConfig; } -} \ No newline at end of file +} From ebd616ef248f8c7faa229406346bc4e577146e4f Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T <31698165+mohan-13@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:29:44 +0530 Subject: [PATCH 07/15] BAH-4033 | Refactor. Get task type for system generated tasks from configuration (#71) --- .../ipd/api/events/handler/impl/PatientAdmitEventHandler.java | 4 ++-- .../ipd/api/events/handler/impl/RolloverTaskEventHandler.java | 4 ++-- .../api/events/handler/impl/ShiftStartTaskEventHandler.java | 4 ++-- .../org/openmrs/module/ipd/api/events/model/ConfigDetail.java | 2 +- .../org/openmrs/module/ipd/api/events/model/TaskDetail.java | 1 + 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java index 362e0cb..bc46e16 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java @@ -35,12 +35,12 @@ public class PatientAdmitEventHandler implements IPDEventHandler { public void handleEvent(IPDEvent event) { List configList = configLoader.getConfigs(); ConfigDetail eventConfig = configList.stream() - .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .filter(config -> config.getEvent().equals(event.getIpdEventType().name())) .findFirst() .orElse(null); if (eventConfig != null) { for(TaskDetail taskDetail : eventConfig.getTasks()) { - TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), "nursing_activity_system",true); + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), taskDetail.getType(), true); Task task = taskMapper.fromRequest(taskRequest); taskService.saveTask(task); log.info("Task created " + taskDetail.getName()); diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java index 16ce44d..016895b 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java @@ -35,7 +35,7 @@ public class RolloverTaskEventHandler implements IPDEventHandler { public void handleEvent(IPDEvent event) { List configList = configLoader.getConfigs(); ConfigDetail eventConfig = configList.stream() - .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .filter(config -> config.getEvent().equals(event.getIpdEventType().name())) .findFirst() .orElse(null); @@ -54,4 +54,4 @@ public void handleEvent(IPDEvent event) { } taskRequestedPeriodDao.update(fhirTaskRequestedPeriods); } -} \ No newline at end of file +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java index 0ab7c73..56a02a1 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java @@ -39,7 +39,7 @@ public void handleEvent(IPDEvent event) { String patientUuid = admittedPatient.getBedPatientAssignment().getPatient().getUuid(); IPDEvent ipdEvent = new IPDEvent(null, patientUuid, event.getIpdEventType()); for(TaskDetail taskDetail : eventConfig.getTasks()) { - TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), "nursing_activity_system",true); + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), taskDetail.getType(), true); Task task = taskMapper.fromRequest(taskRequest); tasks.add(task); } @@ -52,7 +52,7 @@ public void handleEvent(IPDEvent event) { private ConfigDetail getEventConfig(IPDEvent event){ List configList = configLoader.getConfigs(); ConfigDetail eventConfig = configList.stream() - .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .filter(config -> config.getEvent().equals(event.getIpdEventType().name())) .findFirst() .orElse(null); return eventConfig; diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java index 284f2a5..8296049 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java @@ -14,6 +14,6 @@ @NoArgsConstructor @AllArgsConstructor public class ConfigDetail { - private String type; + private String event; private List tasks; } diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java index 7b1426f..3636b4b 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java @@ -13,4 +13,5 @@ @AllArgsConstructor public class TaskDetail { private String name; + private String type; } From 8639e4032e128a1ef2c718f4413060d87c54fcfa Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T <31698165+mohan-13@users.noreply.github.com> Date: Wed, 21 Aug 2024 07:01:49 +0530 Subject: [PATCH 08/15] BAH-4062 | Refactor. Move privilege creation to config.xml (#72) * BAH-4062 | Refactor. Extract privilege creation to config.xml * BAH-4062 | Fix. Error messages for privilege check failures --- api/src/main/resources/liquibase.xml | 61 +------------------ ...IPDMedicationAdministrationController.java | 4 +- .../ipd/controller/IPDScheduleController.java | 6 +- .../ipd/controller/IPDVisitController.java | 2 +- omod/src/main/resources/config.xml | 26 +++++++- 5 files changed, 32 insertions(+), 67 deletions(-) diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index df5fc2f..648ac33 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -467,64 +467,5 @@ '2024-04-11 19:00:00', 'MM/dd/yyyy HH:mm:ss', 86400, true, 1, NOW(), UUID()); - - - select count(*) from privilege where privilege = 'Edit Medication Tasks' - - - - - - - - - - select count(*) from privilege where privilege = 'Delete Medication Tasks' - - - - - - - - - - select count(*) from privilege where privilege = 'Edit adhoc medication tasks' - - - - - - - - - - select count(*) from privilege where privilege = 'Edit Medication Administration' - - - - - - - - - - select count(*) from privilege where privilege = 'Get Medication Administration' - - - - - - - - - - select count(*) from privilege where privilege = 'Get Medication Tasks' - - - - - - - + diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java index d22cd8a..ef626fc 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java @@ -63,8 +63,8 @@ public ResponseEntity createScheduledMedicationAdministration(@RequestBo @ResponseBody public ResponseEntity createAdhocMedicationAdministration(@RequestBody MedicationAdministrationRequest medicationAdministrationRequest) { try { - if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", "+PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION), FORBIDDEN); + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS), FORBIDDEN); } MedicationAdministration medicationAdministration = ipdMedicationAdministrationService.saveAdhocMedicationAdministration(medicationAdministrationRequest); MedicationAdministrationResponse medicationAdministrationResponse = medicationAdministrationFactory.mapMedicationAdministrationToResponse(medicationAdministration); diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java index 09f3604..01c10cc 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java @@ -98,7 +98,7 @@ public ResponseEntity getMedicationSlotsByDate(@RequestParam(value = "pa @RequestParam(value = "view", required = false) String view) { try { if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+", "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION+", "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); } ; if (startTime != null && endTime != null) { LocalDateTime localStartDate = convertEpocUTCToLocalTimeZone(startTime); @@ -123,7 +123,7 @@ public ResponseEntity getMedicationSlotsByOrderUuids(@RequestParam(value @RequestParam(value = "orderUuids", required = false) List orderUuids) { try { if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+" "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION+" "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); } List slots; if (orderUuids == null || orderUuids.isEmpty()) { @@ -177,4 +177,4 @@ private List constructResponse(List slots, Vis return slotsBySchedule.entrySet().stream().map(entry -> createFrom(entry.getKey(), entry.getValue())).collect(Collectors.toList()); } -} \ No newline at end of file +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java index 975d4cf..79f3757 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java @@ -43,7 +43,7 @@ public ResponseEntity getVisitWiseMedications ( @PathVariable("visitUuid") String visitUuid, @RequestParam(value = "includes", required = false) List includes) throws ParseException { if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", " + PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION + ", " + PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); } List prescribedOrders = ipdVisitService.getPrescribedOrders(visitUuid, true, null, null, null, false); List prescribedOrderResponse = prescribedOrders.stream().map(IPDDrugOrderResponse::createFrom).collect(Collectors.toList()); diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 2aeeda8..2a37095 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -22,7 +22,31 @@ true Feature toggle to decide whether to stop slots associated when drug order is stopped - + + + Edit Medication Tasks + Allows to Edit Medication Schedules and Slots + + + Delete Medication Tasks + Allows to Delete Medication Schedules and Slots + + + Edit adhoc medication tasks + Allows to Edit Emergency Medication Tasks + + + Edit Medication Administration + Allows to Edit Medication Administrations + + + Get Medication Administration + Allows to Get Medication Administrations + + + Get Medication Tasks + Allows to Get Medication Tasks + org.openmrs.module.ipd.api.IPDActivator From bd02ff4dd867dce6f3b80a08b42ba58ef2eec26c Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T <31698165+mohan-13@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:18:29 +0530 Subject: [PATCH 09/15] BAH-4073 | Refactor. Change LICENSE to OMRS MPLv2 (#74) * BAH-4073 | Refactor. Change LICENSE to OMRS MPLv2 * BAH-4073 | Fix. License information in pom.xml --- LICENSE | 1062 +++++++++++++++++++++---------------------------------- pom.xml | 4 +- 2 files changed, 403 insertions(+), 663 deletions(-) diff --git a/LICENSE b/LICENSE index 0ad25db..53465c6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,661 +1,401 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. +Mozilla Public License, version 2.0 + +1. Definitions + +1.1. "Contributor" + + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. + +1.2. "Contributor Version" + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or + + b. that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the terms of + a Secondary License. + +1.6. "Executable Form" + + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + + means a work that combines Covered Software with other material, in a + separate file or files, that is not Covered Software. + +1.8. "License" + + means this document. + +1.9. "Licensable" + + means having the right to grant, to the maximum extent possible, whether + at the time of the initial grant or subsequently, any and all of the + rights conveyed by this License. + +1.10. "Modifications" + + means any of the following: + + a. any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered Software; or + + b. any new file in Source Code Form that contains any Covered Software. + +1.11. "Patent Claims" of a Contributor + + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the License, + by the making, using, selling, offering for sale, having made, import, + or transfer of either its Contributions or its Contributor Version. + +1.12. "Secondary License" + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. + +1.13. "Source Code Form" + + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, "control" means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. + + +2. License Grants and Conditions + +2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution + become effective for each Contribution on the date the Contributor first + distributes such Contribution. + +2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under + this License. No additional rights or licenses will be implied from the + distribution or licensing of Covered Software under this License. + Notwithstanding Section 2.1(b) above, no patent license is granted by a + Contributor: + + a. for any code that a Contributor has removed from Covered Software; or + + b. for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. under Patent Claims infringed by Covered Software in the absence of + its Contributions. + + This License does not grant any rights in the trademarks, service marks, + or logos of any Contributor (except as may be necessary to comply with + the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this + License (see Section 10.2) or under the terms of a Secondary License (if + permitted under the terms of Section 3.3). + +2.5. Representation + + Each Contributor represents that the Contributor believes its + Contributions are its original creation(s) or it has sufficient rights to + grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + + This License is not intended to limit any rights You have under + applicable copyright doctrines of fair use, fair dealing, or other + equivalents. + +2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities + +3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under + the terms of this License. You must inform recipients that the Source + Code Form of the Covered Software is governed by the terms of this + License, and how they can obtain a copy of this License. You may not + attempt to alter or restrict the recipients' rights in the Source Code + Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter the + recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for + the Covered Software. If the Larger Work is a combination of Covered + Software with a work governed by one or more Secondary Licenses, and the + Covered Software is not Incompatible With Secondary Licenses, this + License permits You to additionally distribute such Covered Software + under the terms of such Secondary License(s), so that the recipient of + the Larger Work may, at their option, further distribute the Covered + Software under the terms of either this License or such Secondary + License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices + (including copyright notices, patent notices, disclaimers of warranty, or + limitations of liability) contained within the Source Code Form of the + Covered Software, except that You may alter any license notices to the + extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on + behalf of any Contributor. You must make it absolutely clear that any + such warranty, support, indemnity, or liability obligation is offered by + You alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, + judicial order, or regulation then You must: (a) comply with the terms of + this License to the maximum extent possible; and (b) describe the + limitations and the code they affect. Such description must be placed in a + text file included with all distributions of the Covered Software under + this License. Except to the extent prohibited by statute or regulation, + such description must be sufficiently detailed for a recipient of ordinary + skill to be able to understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing + basis, if such Contributor fails to notify You of the non-compliance by + some reasonable means prior to 60 days after You have come back into + compliance. Moreover, Your grants from a particular Contributor are + reinstated on an ongoing basis if such Contributor notifies You of the + non-compliance by some reasonable means, this is the first time You have + received notice of non-compliance with this License from such + Contributor, and You become compliant prior to 30 days after Your receipt + of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, + counter-claims, and cross-claims) alleging that a Contributor Version + directly or indirectly infringes any patent, then the rights granted to + You by any and all Contributors for the Covered Software under Section + 2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, + without warranty of any kind, either expressed, implied, or statutory, + including, without limitation, warranties that the Covered Software is free + of defects, merchantable, fit for a particular purpose or non-infringing. + The entire risk as to the quality and performance of the Covered Software + is with You. Should any Covered Software prove defective in any respect, + You (not any Contributor) assume the cost of any necessary servicing, + repair, or correction. This disclaimer of warranty constitutes an essential + part of this License. No use of any Covered Software is authorized under + this License except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from + such party's negligence to the extent applicable law prohibits such + limitation. Some jurisdictions do not allow the exclusion or limitation of + incidental or consequential damages, so this exclusion and limitation may + not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts + of a jurisdiction where the defendant maintains its principal place of + business and such litigation shall be governed by laws of that + jurisdiction, without reference to its conflict-of-law provisions. Nothing + in this Section shall prevent a party's ability to bring cross-claims or + counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. Any law or regulation which provides that + the language of a contract shall be construed against the drafter shall not + be used to construe this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version + of the License under which You originally received the Covered Software, + or under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a + modified version of this License if you rename the license and remove + any references to the name of the license steward (except to note that + such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses If You choose to distribute Source Code Form that is + Incompatible With Secondary Licenses under the terms of this version of + the License, the notice described in Exhibit B of this License must be + attached. + +Exhibit A - Source Code Form License Notice + + 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/. + +If it is not possible or desirable to put the notice in a particular file, +then You may include the notice in a location (such as a LICENSE file in a +relevant directory) where a recipient would be likely to look for such a +notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice + + This Source Code Form is "Incompatible + With Secondary Licenses", as defined by + the Mozilla Public License, v. 2.0. + +--------------------- + +Healthcare Disclaimer + +In the United States, or any other jurisdictions where they may apply, the +following additional disclaimer of warranty and limitation of liability are +hereby incorporated into the terms and conditions of MPL 2.0: + +1. No warranties of any kind whatsoever are made as to the results that + You will obtain from relying upon the covered code (or any information + or content obtained by way of the covered code), including but not + limited to compliance with privacy laws or regulations or clinical + care industry standards and protocols. Use of the covered code is not + a substitute for a health care provider’s standard practice or + professional judgment. Any decision with regard to the appropriateness + of treatment, or the validity or reliability of information or content + made available by the covered code, is the sole responsibility of the + health care provider. Consequently, it is incumbent upon each health + care provider to verify all medical history and treatment plans with + each patient. + +2. Under no circumstances and under no legal theory, whether tort + (including negligence), contract, or otherwise, shall any Contributor, + or anyone who distributes Covered Software as permitted by the + license, be liable to You for any indirect, special, incidental, + consequential damages of any character including, without limitation, + damages for loss of goodwill, work stoppage, computer failure or + malfunction, or any and all other damages or losses, of any nature + whatsoever (direct or otherwise) on account of or associated with the + use or inability to use the covered content (including, without + limitation, the use of information or content made available by the + covered code, all documentation associated therewith, and the failure + of the covered code to comply with privacy laws and regulations or + clinical care industry standards and protocols), even if such party + shall have been informed of the possibility of such damages. + +Copyright (c) OpenMRS Inc. +OpenMRS is a registered trademark and the OpenMRS graphic logo is a trademark of OpenMRS Inc. diff --git a/pom.xml b/pom.xml index da3f0db..88f95ea 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - https://www.gnu.org/licenses/agpl-3.0.txt + Mozilla Public License 2.0 with Healthcare Disclaimer + https://openmrs.org/license From 7380c98e93990aef489cac8b2fe24843a65b765b Mon Sep 17 00:00:00 2001 From: Rahul Ramesh <121226043+rahu1ramesh@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:54:46 +0530 Subject: [PATCH 10/15] BAH-4061 | Refactor. Change Medication Administration Status Type As VarChar (#73) * [Rahul] | BAH-4061 | Refactor. Change Medication Administration Status Type As VarChar * [Rahul] | BAH-4061 | Refactor. Remove Unused Dependencies * [Rahul] | BAH-4061 | Refactor. Change Status Value In Test * [Rahul] | BAH-4061 | Refactor. Remove MedicationAdministration Status Null Check * [Rahul] | BAH-4061 | Fix. MedicationAdministrationStatus Test Data --- .../api/dao/impl/HibernateSlotDAOIntegrationTest.java | 8 ++++---- api/src/test/resources/scheduleMedicationsTestData.xml | 4 ++-- .../ipd/contract/MedicationAdministrationResponse.java | 2 +- .../IPDMedicationAdministrationController.java | 3 +++ .../ipd/factory/MedicationAdministrationFactory.java | 9 ++------- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java index 231d5b2..e815391 100644 --- a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java +++ b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java @@ -285,12 +285,12 @@ public void shouldGetTheSavedSlotsForPatientByAdministeredTime() { MedicationAdministration medicationAdministration=new MedicationAdministration(); - medicationAdministration.setStatus(testConcept); + medicationAdministration.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime)); MedicationAdministration savedMedicationAdministration= medicationAdministrationDao.createOrUpdate(medicationAdministration); MedicationAdministration medicationAdministration2=new MedicationAdministration(); - medicationAdministration2.setStatus(testConcept); + medicationAdministration2.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration2.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime2)); MedicationAdministration savedMedicationAdministration2= medicationAdministrationDao.createOrUpdate(medicationAdministration2); @@ -376,12 +376,12 @@ public void shouldGetTheSavedSlotsForPatientBySubjectReferenceAndAGivenTimeFrame MedicationAdministration medicationAdministration=new MedicationAdministration(); - medicationAdministration.setStatus(testConcept); + medicationAdministration.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime)); MedicationAdministration savedMedicationAdministration= medicationAdministrationDao.createOrUpdate(medicationAdministration); MedicationAdministration medicationAdministration2=new MedicationAdministration(); - medicationAdministration2.setStatus(testConcept); + medicationAdministration2.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration2.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime2)); MedicationAdministration savedMedicationAdministration2= medicationAdministrationDao.createOrUpdate(medicationAdministration2); diff --git a/api/src/test/resources/scheduleMedicationsTestData.xml b/api/src/test/resources/scheduleMedicationsTestData.xml index 920b1d3..f43448c 100644 --- a/api/src/test/resources/scheduleMedicationsTestData.xml +++ b/api/src/test/resources/scheduleMedicationsTestData.xml @@ -29,8 +29,8 @@ - - + + diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java index 4857b4e..856a047 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java @@ -38,7 +38,7 @@ public static MedicationAdministrationResponse createFrom(org.openmrs.module.ipd if (openmrsMedicationAdministration == null) { return null; } - String status = openmrsMedicationAdministration.getStatus() != null ? openmrsMedicationAdministration.getStatus().getShortNameInLocale(Context.getLocale()).getName() : null; + String status = openmrsMedicationAdministration.getStatus().toCode() != null ? openmrsMedicationAdministration.getStatus().toCode() : null; String statusReason = openmrsMedicationAdministration.getStatusReason() != null ? openmrsMedicationAdministration.getStatusReason().getDisplayString() : null; String patientUuid = openmrsMedicationAdministration.getPatient() != null ? openmrsMedicationAdministration.getPatient().getUuid() : null; String encounterUuid = openmrsMedicationAdministration.getEncounter() != null ? openmrsMedicationAdministration.getEncounter().getUuid() : null; diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java index ef626fc..8caa639 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java @@ -13,6 +13,8 @@ import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.RestUtil; import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -30,6 +32,7 @@ public class IPDMedicationAdministrationController extends BaseRestController { private final IPDMedicationAdministrationService ipdMedicationAdministrationService; private final MedicationAdministrationFactory medicationAdministrationFactory; + private static final Logger log = LoggerFactory.getLogger(IPDMedicationAdministrationController.class); @Autowired public IPDMedicationAdministrationController(IPDMedicationAdministrationService ipdMedicationAdministrationService, diff --git a/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java b/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java index 7573ac6..06bb312 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java +++ b/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java @@ -2,7 +2,6 @@ import org.openmrs.DrugOrder; import org.openmrs.api.context.Context; -import org.openmrs.module.fhir2.apiext.translators.MedicationAdministrationStatusTranslator; import org.openmrs.module.fhir2.apiext.translators.MedicationAdministrationTranslator; import org.openmrs.module.ipd.api.model.MedicationAdministration; import org.openmrs.module.ipd.api.model.MedicationAdministrationNote; @@ -12,7 +11,6 @@ import org.springframework.stereotype.Component; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -21,13 +19,10 @@ public class MedicationAdministrationFactory { private MedicationAdministrationTranslator medicationAdministrationTranslator; - private MedicationAdministrationStatusTranslator medicationAdministrationStatusTranslator; @Autowired - public MedicationAdministrationFactory(MedicationAdministrationTranslator medicationAdministrationTranslator, - MedicationAdministrationStatusTranslator medicationAdministrationStatusTranslator) { + public MedicationAdministrationFactory(MedicationAdministrationTranslator medicationAdministrationTranslator) { this.medicationAdministrationTranslator = medicationAdministrationTranslator; - this.medicationAdministrationStatusTranslator = medicationAdministrationStatusTranslator; } public MedicationAdministration mapRequestToMedicationAdministration(MedicationAdministrationRequest request, MedicationAdministration existingMedicationAdministration) { @@ -35,7 +30,7 @@ public MedicationAdministration mapRequestToMedicationAdministration(MedicationA MedicationAdministration medicationAdministration = new MedicationAdministration(); if (existingMedicationAdministration ==null || existingMedicationAdministration.getId() == null) { medicationAdministration.setAdministeredDateTime(request.getAdministeredDateTimeAsLocaltime()); - medicationAdministration.setStatus(medicationAdministrationStatusTranslator.toOpenmrsType(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.fromCode(request.getStatus()))); + medicationAdministration.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.fromCode(request.getStatus())); medicationAdministration.setPatient(Context.getPatientService().getPatientByUuid(request.getPatientUuid())); medicationAdministration.setEncounter(Context.getEncounterService().getEncounterByUuid(request.getEncounterUuid())); medicationAdministration.setDrugOrder((DrugOrder) Context.getOrderService().getOrderByUuid(request.getOrderUuid())); From 889d745a519a72cddea5bd52d5a2bc64a354508a Mon Sep 17 00:00:00 2001 From: Kavitha S Date: Tue, 27 Aug 2024 20:50:34 +0530 Subject: [PATCH 11/15] Merge main branch changes --- LICENSE | 1062 +++++++---------- .../module/ipd/api/events/IPDEventUtils.java | 3 +- .../impl/PatientAdmitEventHandler.java | 6 +- .../impl/RolloverTaskEventHandler.java | 4 +- .../impl/ShiftStartTaskEventHandler.java | 6 +- .../ipd/api/events/model/ConfigDetail.java | 2 +- .../ipd/api/events/model/TaskDetail.java | 1 + api/src/main/resources/application.properties | 3 + api/src/main/resources/liquibase.xml | 61 +- .../resources/moduleApplicationContext.xml | 3 +- .../impl/HibernateSlotDAOIntegrationTest.java | 8 +- .../resources/scheduleMedicationsTestData.xml | 4 +- .../MedicationAdministrationResponse.java | 2 +- ...IPDMedicationAdministrationController.java | 7 +- .../ipd/controller/IPDScheduleController.java | 6 +- .../ipd/controller/IPDVisitController.java | 2 +- .../MedicationAdministrationFactory.java | 9 +- omod/src/main/resources/config.xml | 31 + pom.xml | 4 +- 19 files changed, 470 insertions(+), 754 deletions(-) create mode 100644 api/src/main/resources/application.properties diff --git a/LICENSE b/LICENSE index 0ad25db..53465c6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,661 +1,401 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU Affero General Public License is a free, copyleft license for -software and other kinds of works, specifically designed to ensure -cooperation with the community in the case of network server software. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -our General Public Licenses are intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - Developers that use our General Public Licenses protect your rights -with two steps: (1) assert copyright on the software, and (2) offer -you this License which gives you legal permission to copy, distribute -and/or modify the software. - - A secondary benefit of defending all users' freedom is that -improvements made in alternate versions of the program, if they -receive widespread use, become available for other developers to -incorporate. Many developers of free software are heartened and -encouraged by the resulting cooperation. However, in the case of -software used on network servers, this result may fail to come about. -The GNU General Public License permits making a modified version and -letting the public access it on a server without ever releasing its -source code to the public. - - The GNU Affero General Public License is designed specifically to -ensure that, in such cases, the modified source code becomes available -to the community. It requires the operator of a network server to -provide the source code of the modified version running there to the -users of that server. Therefore, public use of a modified version, on -a publicly accessible server, gives the public access to the source -code of the modified version. - - An older license, called the Affero General Public License and -published by Affero, was designed to accomplish similar goals. This is -a different license, not a version of the Affero GPL, but Affero has -released a new version of the Affero GPL which permits relicensing under -this license. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - Notwithstanding any other provision of this License, if you modify the -Program, your modified version must prominently offer all users -interacting with it remotely through a computer network (if your version -supports such interaction) an opportunity to receive the Corresponding -Source of your version by providing access to the Corresponding Source -from a network server at no charge, through some standard or customary -means of facilitating copying of software. This Corresponding Source -shall include the Corresponding Source for any work covered by version 3 -of the GNU General Public License that is incorporated pursuant to the -following paragraph. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the work with which it is combined will remain governed by version -3 of the GNU General Public License. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU Affero General Public License from time to time. Such new versions -will be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU Affero General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU Affero General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU Affero General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If your software can interact with users remotely through a computer -network, you should also make sure that it provides a way for users to -get its source. For example, if your program is a web application, its -interface could display a "Source" link that leads users to an archive -of the code. There are many ways you could offer source, and different -solutions will be better for different programs; see section 13 for the -specific requirements. - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU AGPL, see -. +Mozilla Public License, version 2.0 + +1. Definitions + +1.1. "Contributor" + + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. + +1.2. "Contributor Version" + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or + + b. that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the terms of + a Secondary License. + +1.6. "Executable Form" + + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + + means a work that combines Covered Software with other material, in a + separate file or files, that is not Covered Software. + +1.8. "License" + + means this document. + +1.9. "Licensable" + + means having the right to grant, to the maximum extent possible, whether + at the time of the initial grant or subsequently, any and all of the + rights conveyed by this License. + +1.10. "Modifications" + + means any of the following: + + a. any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered Software; or + + b. any new file in Source Code Form that contains any Covered Software. + +1.11. "Patent Claims" of a Contributor + + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the License, + by the making, using, selling, offering for sale, having made, import, + or transfer of either its Contributions or its Contributor Version. + +1.12. "Secondary License" + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. + +1.13. "Source Code Form" + + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, "control" means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. + + +2. License Grants and Conditions + +2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution + become effective for each Contribution on the date the Contributor first + distributes such Contribution. + +2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under + this License. No additional rights or licenses will be implied from the + distribution or licensing of Covered Software under this License. + Notwithstanding Section 2.1(b) above, no patent license is granted by a + Contributor: + + a. for any code that a Contributor has removed from Covered Software; or + + b. for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. under Patent Claims infringed by Covered Software in the absence of + its Contributions. + + This License does not grant any rights in the trademarks, service marks, + or logos of any Contributor (except as may be necessary to comply with + the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this + License (see Section 10.2) or under the terms of a Secondary License (if + permitted under the terms of Section 3.3). + +2.5. Representation + + Each Contributor represents that the Contributor believes its + Contributions are its original creation(s) or it has sufficient rights to + grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + + This License is not intended to limit any rights You have under + applicable copyright doctrines of fair use, fair dealing, or other + equivalents. + +2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities + +3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under + the terms of this License. You must inform recipients that the Source + Code Form of the Covered Software is governed by the terms of this + License, and how they can obtain a copy of this License. You may not + attempt to alter or restrict the recipients' rights in the Source Code + Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter the + recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for + the Covered Software. If the Larger Work is a combination of Covered + Software with a work governed by one or more Secondary Licenses, and the + Covered Software is not Incompatible With Secondary Licenses, this + License permits You to additionally distribute such Covered Software + under the terms of such Secondary License(s), so that the recipient of + the Larger Work may, at their option, further distribute the Covered + Software under the terms of either this License or such Secondary + License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices + (including copyright notices, patent notices, disclaimers of warranty, or + limitations of liability) contained within the Source Code Form of the + Covered Software, except that You may alter any license notices to the + extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on + behalf of any Contributor. You must make it absolutely clear that any + such warranty, support, indemnity, or liability obligation is offered by + You alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, + judicial order, or regulation then You must: (a) comply with the terms of + this License to the maximum extent possible; and (b) describe the + limitations and the code they affect. Such description must be placed in a + text file included with all distributions of the Covered Software under + this License. Except to the extent prohibited by statute or regulation, + such description must be sufficiently detailed for a recipient of ordinary + skill to be able to understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing + basis, if such Contributor fails to notify You of the non-compliance by + some reasonable means prior to 60 days after You have come back into + compliance. Moreover, Your grants from a particular Contributor are + reinstated on an ongoing basis if such Contributor notifies You of the + non-compliance by some reasonable means, this is the first time You have + received notice of non-compliance with this License from such + Contributor, and You become compliant prior to 30 days after Your receipt + of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, + counter-claims, and cross-claims) alleging that a Contributor Version + directly or indirectly infringes any patent, then the rights granted to + You by any and all Contributors for the Covered Software under Section + 2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an "as is" basis, + without warranty of any kind, either expressed, implied, or statutory, + including, without limitation, warranties that the Covered Software is free + of defects, merchantable, fit for a particular purpose or non-infringing. + The entire risk as to the quality and performance of the Covered Software + is with You. Should any Covered Software prove defective in any respect, + You (not any Contributor) assume the cost of any necessary servicing, + repair, or correction. This disclaimer of warranty constitutes an essential + part of this License. No use of any Covered Software is authorized under + this License except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from + such party's negligence to the extent applicable law prohibits such + limitation. Some jurisdictions do not allow the exclusion or limitation of + incidental or consequential damages, so this exclusion and limitation may + not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts + of a jurisdiction where the defendant maintains its principal place of + business and such litigation shall be governed by laws of that + jurisdiction, without reference to its conflict-of-law provisions. Nothing + in this Section shall prevent a party's ability to bring cross-claims or + counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. Any law or regulation which provides that + the language of a contract shall be construed against the drafter shall not + be used to construe this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version + of the License under which You originally received the Covered Software, + or under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a + modified version of this License if you rename the license and remove + any references to the name of the license steward (except to note that + such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary + Licenses If You choose to distribute Source Code Form that is + Incompatible With Secondary Licenses under the terms of this version of + the License, the notice described in Exhibit B of this License must be + attached. + +Exhibit A - Source Code Form License Notice + + 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/. + +If it is not possible or desirable to put the notice in a particular file, +then You may include the notice in a location (such as a LICENSE file in a +relevant directory) where a recipient would be likely to look for such a +notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice + + This Source Code Form is "Incompatible + With Secondary Licenses", as defined by + the Mozilla Public License, v. 2.0. + +--------------------- + +Healthcare Disclaimer + +In the United States, or any other jurisdictions where they may apply, the +following additional disclaimer of warranty and limitation of liability are +hereby incorporated into the terms and conditions of MPL 2.0: + +1. No warranties of any kind whatsoever are made as to the results that + You will obtain from relying upon the covered code (or any information + or content obtained by way of the covered code), including but not + limited to compliance with privacy laws or regulations or clinical + care industry standards and protocols. Use of the covered code is not + a substitute for a health care provider’s standard practice or + professional judgment. Any decision with regard to the appropriateness + of treatment, or the validity or reliability of information or content + made available by the covered code, is the sole responsibility of the + health care provider. Consequently, it is incumbent upon each health + care provider to verify all medical history and treatment plans with + each patient. + +2. Under no circumstances and under no legal theory, whether tort + (including negligence), contract, or otherwise, shall any Contributor, + or anyone who distributes Covered Software as permitted by the + license, be liable to You for any indirect, special, incidental, + consequential damages of any character including, without limitation, + damages for loss of goodwill, work stoppage, computer failure or + malfunction, or any and all other damages or losses, of any nature + whatsoever (direct or otherwise) on account of or associated with the + use or inability to use the covered content (including, without + limitation, the use of information or content made available by the + covered code, all documentation associated therewith, and the failure + of the covered code to comply with privacy laws and regulations or + clinical care industry standards and protocols), even if such party + shall have been informed of the possibility of such damages. + +Copyright (c) OpenMRS Inc. +OpenMRS is a registered trademark and the OpenMRS graphic logo is a trademark of OpenMRS Inc. diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java index b9da7ab..82426c9 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/IPDEventUtils.java @@ -8,7 +8,7 @@ public class IPDEventUtils { - public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, String name, String taskType) { + public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, String name, String taskType, Boolean isSystemGenerated) { TaskRequest taskRequest = new TaskRequest(); taskRequest.setName(name); taskRequest.setTaskType(taskType); @@ -17,6 +17,7 @@ public static TaskRequest createNonMedicationTaskRequest(IPDEvent ipdEvent, Stri taskRequest.setRequestedStartTime(new Date()); taskRequest.setIntent(FhirTask.TaskIntent.ORDER); taskRequest.setStatus(FhirTask.TaskStatus.REQUESTED); + taskRequest.setIsSystemGeneratedTask(isSystemGenerated); return taskRequest; } } diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java index 9828da5..bc46e16 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/PatientAdmitEventHandler.java @@ -35,12 +35,12 @@ public class PatientAdmitEventHandler implements IPDEventHandler { public void handleEvent(IPDEvent event) { List configList = configLoader.getConfigs(); ConfigDetail eventConfig = configList.stream() - .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .filter(config -> config.getEvent().equals(event.getIpdEventType().name())) .findFirst() .orElse(null); if (eventConfig != null) { for(TaskDetail taskDetail : eventConfig.getTasks()) { - TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), "nursing_activity_system"); + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(event, taskDetail.getName(), taskDetail.getType(), true); Task task = taskMapper.fromRequest(taskRequest); taskService.saveTask(task); log.info("Task created " + taskDetail.getName()); @@ -49,4 +49,4 @@ public void handleEvent(IPDEvent event) { } -} \ No newline at end of file +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java index 16ce44d..016895b 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/RolloverTaskEventHandler.java @@ -35,7 +35,7 @@ public class RolloverTaskEventHandler implements IPDEventHandler { public void handleEvent(IPDEvent event) { List configList = configLoader.getConfigs(); ConfigDetail eventConfig = configList.stream() - .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .filter(config -> config.getEvent().equals(event.getIpdEventType().name())) .findFirst() .orElse(null); @@ -54,4 +54,4 @@ public void handleEvent(IPDEvent event) { } taskRequestedPeriodDao.update(fhirTaskRequestedPeriods); } -} \ No newline at end of file +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java index e97d620..56a02a1 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/handler/impl/ShiftStartTaskEventHandler.java @@ -39,7 +39,7 @@ public void handleEvent(IPDEvent event) { String patientUuid = admittedPatient.getBedPatientAssignment().getPatient().getUuid(); IPDEvent ipdEvent = new IPDEvent(null, patientUuid, event.getIpdEventType()); for(TaskDetail taskDetail : eventConfig.getTasks()) { - TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), "nursing_activity_system"); + TaskRequest taskRequest = IPDEventUtils.createNonMedicationTaskRequest(ipdEvent, taskDetail.getName(), taskDetail.getType(), true); Task task = taskMapper.fromRequest(taskRequest); tasks.add(task); } @@ -52,9 +52,9 @@ public void handleEvent(IPDEvent event) { private ConfigDetail getEventConfig(IPDEvent event){ List configList = configLoader.getConfigs(); ConfigDetail eventConfig = configList.stream() - .filter(config -> config.getType().equals(event.getIpdEventType().name())) + .filter(config -> config.getEvent().equals(event.getIpdEventType().name())) .findFirst() .orElse(null); return eventConfig; } -} \ No newline at end of file +} diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java index 284f2a5..8296049 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/ConfigDetail.java @@ -14,6 +14,6 @@ @NoArgsConstructor @AllArgsConstructor public class ConfigDetail { - private String type; + private String event; private List tasks; } diff --git a/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java b/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java index 7b1426f..3636b4b 100644 --- a/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java +++ b/api/src/main/java/org/openmrs/module/ipd/api/events/model/TaskDetail.java @@ -13,4 +13,5 @@ @AllArgsConstructor public class TaskDetail { private String name; + private String type; } diff --git a/api/src/main/resources/application.properties b/api/src/main/resources/application.properties new file mode 100644 index 0000000..ed16b69 --- /dev/null +++ b/api/src/main/resources/application.properties @@ -0,0 +1,3 @@ + +# Route definitions +config-file.path=/etc/bahmni_config/openmrs/apps/ipdDashboard/eventsConfig.json \ No newline at end of file diff --git a/api/src/main/resources/liquibase.xml b/api/src/main/resources/liquibase.xml index df5fc2f..648ac33 100644 --- a/api/src/main/resources/liquibase.xml +++ b/api/src/main/resources/liquibase.xml @@ -467,64 +467,5 @@ '2024-04-11 19:00:00', 'MM/dd/yyyy HH:mm:ss', 86400, true, 1, NOW(), UUID()); - - - select count(*) from privilege where privilege = 'Edit Medication Tasks' - - - - - - - - - - select count(*) from privilege where privilege = 'Delete Medication Tasks' - - - - - - - - - - select count(*) from privilege where privilege = 'Edit adhoc medication tasks' - - - - - - - - - - select count(*) from privilege where privilege = 'Edit Medication Administration' - - - - - - - - - - select count(*) from privilege where privilege = 'Get Medication Administration' - - - - - - - - - - select count(*) from privilege where privilege = 'Get Medication Tasks' - - - - - - - + diff --git a/api/src/main/resources/moduleApplicationContext.xml b/api/src/main/resources/moduleApplicationContext.xml index 0dde695..c9dd5ed 100644 --- a/api/src/main/resources/moduleApplicationContext.xml +++ b/api/src/main/resources/moduleApplicationContext.xml @@ -10,6 +10,7 @@ + @@ -35,4 +36,4 @@ - \ No newline at end of file + diff --git a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java index 231d5b2..e815391 100644 --- a/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java +++ b/api/src/test/java/org/openmrs/module/ipd/api/dao/impl/HibernateSlotDAOIntegrationTest.java @@ -285,12 +285,12 @@ public void shouldGetTheSavedSlotsForPatientByAdministeredTime() { MedicationAdministration medicationAdministration=new MedicationAdministration(); - medicationAdministration.setStatus(testConcept); + medicationAdministration.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime)); MedicationAdministration savedMedicationAdministration= medicationAdministrationDao.createOrUpdate(medicationAdministration); MedicationAdministration medicationAdministration2=new MedicationAdministration(); - medicationAdministration2.setStatus(testConcept); + medicationAdministration2.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration2.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime2)); MedicationAdministration savedMedicationAdministration2= medicationAdministrationDao.createOrUpdate(medicationAdministration2); @@ -376,12 +376,12 @@ public void shouldGetTheSavedSlotsForPatientBySubjectReferenceAndAGivenTimeFrame MedicationAdministration medicationAdministration=new MedicationAdministration(); - medicationAdministration.setStatus(testConcept); + medicationAdministration.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime)); MedicationAdministration savedMedicationAdministration= medicationAdministrationDao.createOrUpdate(medicationAdministration); MedicationAdministration medicationAdministration2=new MedicationAdministration(); - medicationAdministration2.setStatus(testConcept); + medicationAdministration2.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.COMPLETED); medicationAdministration2.setAdministeredDateTime(DateTimeUtil.convertLocalDateTimeDate(medicationAdministeredTime2)); MedicationAdministration savedMedicationAdministration2= medicationAdministrationDao.createOrUpdate(medicationAdministration2); diff --git a/api/src/test/resources/scheduleMedicationsTestData.xml b/api/src/test/resources/scheduleMedicationsTestData.xml index 920b1d3..f43448c 100644 --- a/api/src/test/resources/scheduleMedicationsTestData.xml +++ b/api/src/test/resources/scheduleMedicationsTestData.xml @@ -29,8 +29,8 @@ - - + + diff --git a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java index 4857b4e..856a047 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java +++ b/omod/src/main/java/org/openmrs/module/ipd/contract/MedicationAdministrationResponse.java @@ -38,7 +38,7 @@ public static MedicationAdministrationResponse createFrom(org.openmrs.module.ipd if (openmrsMedicationAdministration == null) { return null; } - String status = openmrsMedicationAdministration.getStatus() != null ? openmrsMedicationAdministration.getStatus().getShortNameInLocale(Context.getLocale()).getName() : null; + String status = openmrsMedicationAdministration.getStatus().toCode() != null ? openmrsMedicationAdministration.getStatus().toCode() : null; String statusReason = openmrsMedicationAdministration.getStatusReason() != null ? openmrsMedicationAdministration.getStatusReason().getDisplayString() : null; String patientUuid = openmrsMedicationAdministration.getPatient() != null ? openmrsMedicationAdministration.getPatient().getUuid() : null; String encounterUuid = openmrsMedicationAdministration.getEncounter() != null ? openmrsMedicationAdministration.getEncounter().getUuid() : null; diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java index d22cd8a..8caa639 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDMedicationAdministrationController.java @@ -13,6 +13,8 @@ import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.RestUtil; import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -30,6 +32,7 @@ public class IPDMedicationAdministrationController extends BaseRestController { private final IPDMedicationAdministrationService ipdMedicationAdministrationService; private final MedicationAdministrationFactory medicationAdministrationFactory; + private static final Logger log = LoggerFactory.getLogger(IPDMedicationAdministrationController.class); @Autowired public IPDMedicationAdministrationController(IPDMedicationAdministrationService ipdMedicationAdministrationService, @@ -63,8 +66,8 @@ public ResponseEntity createScheduledMedicationAdministration(@RequestBo @ResponseBody public ResponseEntity createAdhocMedicationAdministration(@RequestBody MedicationAdministrationRequest medicationAdministrationRequest) { try { - if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", "+PrivilegeConstants.EDIT_MEDICATION_ADMINISTRATION), FORBIDDEN); + if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS)) { + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_ADHOC_MEDICATION_TASKS), FORBIDDEN); } MedicationAdministration medicationAdministration = ipdMedicationAdministrationService.saveAdhocMedicationAdministration(medicationAdministrationRequest); MedicationAdministrationResponse medicationAdministrationResponse = medicationAdministrationFactory.mapMedicationAdministrationToResponse(medicationAdministration); diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java index 09f3604..01c10cc 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDScheduleController.java @@ -98,7 +98,7 @@ public ResponseEntity getMedicationSlotsByDate(@RequestParam(value = "pa @RequestParam(value = "view", required = false) String view) { try { if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+", "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION+", "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); } ; if (startTime != null && endTime != null) { LocalDateTime localStartDate = convertEpocUTCToLocalTimeZone(startTime); @@ -123,7 +123,7 @@ public ResponseEntity getMedicationSlotsByOrderUuids(@RequestParam(value @RequestParam(value = "orderUuids", required = false) List orderUuids) { try { if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS+" "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION+" "+PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); } List slots; if (orderUuids == null || orderUuids.isEmpty()) { @@ -177,4 +177,4 @@ private List constructResponse(List slots, Vis return slotsBySchedule.entrySet().stream().map(entry -> createFrom(entry.getKey(), entry.getValue())).collect(Collectors.toList()); } -} \ No newline at end of file +} diff --git a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java index 975d4cf..79f3757 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java +++ b/omod/src/main/java/org/openmrs/module/ipd/controller/IPDVisitController.java @@ -43,7 +43,7 @@ public ResponseEntity getVisitWiseMedications ( @PathVariable("visitUuid") String visitUuid, @RequestParam(value = "includes", required = false) List includes) throws ParseException { if (!Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_ADMINISTRATION) || !Context.getUserContext().hasPrivilege(PrivilegeConstants.GET_MEDICATION_TASKS)) { - return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.EDIT_MEDICATION_TASKS + ", " + PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); + return new ResponseEntity<>(RestUtil.wrapErrorResponse(new Exception(), "User doesn't have the following privilege(s) " + PrivilegeConstants.GET_MEDICATION_ADMINISTRATION + ", " + PrivilegeConstants.GET_MEDICATION_TASKS), FORBIDDEN); } List prescribedOrders = ipdVisitService.getPrescribedOrders(visitUuid, true, null, null, null, false); List prescribedOrderResponse = prescribedOrders.stream().map(IPDDrugOrderResponse::createFrom).collect(Collectors.toList()); diff --git a/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java b/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java index 7573ac6..06bb312 100644 --- a/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java +++ b/omod/src/main/java/org/openmrs/module/ipd/factory/MedicationAdministrationFactory.java @@ -2,7 +2,6 @@ import org.openmrs.DrugOrder; import org.openmrs.api.context.Context; -import org.openmrs.module.fhir2.apiext.translators.MedicationAdministrationStatusTranslator; import org.openmrs.module.fhir2.apiext.translators.MedicationAdministrationTranslator; import org.openmrs.module.ipd.api.model.MedicationAdministration; import org.openmrs.module.ipd.api.model.MedicationAdministrationNote; @@ -12,7 +11,6 @@ import org.springframework.stereotype.Component; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -21,13 +19,10 @@ public class MedicationAdministrationFactory { private MedicationAdministrationTranslator medicationAdministrationTranslator; - private MedicationAdministrationStatusTranslator medicationAdministrationStatusTranslator; @Autowired - public MedicationAdministrationFactory(MedicationAdministrationTranslator medicationAdministrationTranslator, - MedicationAdministrationStatusTranslator medicationAdministrationStatusTranslator) { + public MedicationAdministrationFactory(MedicationAdministrationTranslator medicationAdministrationTranslator) { this.medicationAdministrationTranslator = medicationAdministrationTranslator; - this.medicationAdministrationStatusTranslator = medicationAdministrationStatusTranslator; } public MedicationAdministration mapRequestToMedicationAdministration(MedicationAdministrationRequest request, MedicationAdministration existingMedicationAdministration) { @@ -35,7 +30,7 @@ public MedicationAdministration mapRequestToMedicationAdministration(MedicationA MedicationAdministration medicationAdministration = new MedicationAdministration(); if (existingMedicationAdministration ==null || existingMedicationAdministration.getId() == null) { medicationAdministration.setAdministeredDateTime(request.getAdministeredDateTimeAsLocaltime()); - medicationAdministration.setStatus(medicationAdministrationStatusTranslator.toOpenmrsType(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.fromCode(request.getStatus()))); + medicationAdministration.setStatus(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationStatus.fromCode(request.getStatus())); medicationAdministration.setPatient(Context.getPatientService().getPatientByUuid(request.getPatientUuid())); medicationAdministration.setEncounter(Context.getEncounterService().getEncounterByUuid(request.getEncounterUuid())); medicationAdministration.setDrugOrder((DrugOrder) Context.getOrderService().getOrderByUuid(request.getOrderUuid())); diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index f33032b..2a37095 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -16,6 +16,37 @@ org.bahmni.module.medication-administration org.bahmni.module.fhir2Extension + + + bahmni-ipd.allowSlotStopOnDrugOrderStop + true + Feature toggle to decide whether to stop slots associated when drug order is stopped + + + + Edit Medication Tasks + Allows to Edit Medication Schedules and Slots + + + Delete Medication Tasks + Allows to Delete Medication Schedules and Slots + + + Edit adhoc medication tasks + Allows to Edit Emergency Medication Tasks + + + Edit Medication Administration + Allows to Edit Medication Administrations + + + Get Medication Administration + Allows to Get Medication Administrations + + + Get Medication Tasks + Allows to Get Medication Tasks + org.openmrs.module.ipd.api.IPDActivator diff --git a/pom.xml b/pom.xml index da3f0db..88f95ea 100644 --- a/pom.xml +++ b/pom.xml @@ -12,8 +12,8 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - https://www.gnu.org/licenses/agpl-3.0.txt + Mozilla Public License 2.0 with Healthcare Disclaimer + https://openmrs.org/license From ebd09ba8539337726357f10bf402aaaaca621b1f Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T <31698165+mohan-13@users.noreply.github.com> Date: Tue, 27 Aug 2024 21:03:17 +0530 Subject: [PATCH 12/15] BAH-4093 | Add. Workflow to release artifacts on push of a tag (#77) --- .github/workflows/build_publish.yaml | 8 ++++- .github/workflows/release_deploy.yml | 37 ++++++++++++++++++++++ .github/workflows/validate_pr.yml | 2 +- omod/src/main/resources/config.xml | 9 +++--- omod/src/test/resources/config.xml | 11 ++++--- pom.xml | 47 ++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/release_deploy.yml diff --git a/.github/workflows/build_publish.yaml b/.github/workflows/build_publish.yaml index 8a164f2..01c4730 100644 --- a/.github/workflows/build_publish.yaml +++ b/.github/workflows/build_publish.yaml @@ -19,7 +19,13 @@ jobs: server-username: NEXUS_USERNAME server-password: NEXUS_PASSWORD - name: Build and deploy with Maven - run: ./mvnw --no-transfer-progress clean -U deploy + run: | + PROJECT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) + if [[ "$PROJECT_VERSION" == *"-SNAPSHOT" ]]; then + ./mvnw --no-transfer-progress clean -U deploy + else + echo "❌ The current push is for release. So skipping build." + fi env: NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} diff --git a/.github/workflows/release_deploy.yml b/.github/workflows/release_deploy.yml new file mode 100644 index 0000000..ccb4573 --- /dev/null +++ b/.github/workflows/release_deploy.yml @@ -0,0 +1,37 @@ +name: Build and Release package +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + build-release-package: + name: Build and Release package + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + server-id: nexus-sonatype + server-username: NEXUS_USERNAME + server-password: NEXUS_PASSWORD + gpg-private-key: ${{ secrets.BAHMNI_INFRA_GPG_KEY }} + - name: Compare Git tag with Maven version + run: | + export GIT_TAG=${GITHUB_REF#refs/tags/} + PROJECT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) + if [ "$PROJECT_VERSION" != "$GIT_TAG" ]; then + echo "❌ The Git tag ($GIT_TAG) does not match the Maven version ($PROJECT_VERSION)." + exit 1 + else + echo "✅ The Git tag matches the Maven version." + fi + + - name: Build and deploy with Maven + run: ./mvnw --no-transfer-progress clean -U deploy -DperformRelease=true + env: + NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} + NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} + GPG_PASSPHRASE: ${{ secrets.BAHMNI_INFRA_GPG_PASSPHRASE }} diff --git a/.github/workflows/validate_pr.yml b/.github/workflows/validate_pr.yml index 5a0c37b..035217d 100644 --- a/.github/workflows/validate_pr.yml +++ b/.github/workflows/validate_pr.yml @@ -19,4 +19,4 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn clean package + run: ./mvnw clean package diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 2a37095..83feca0 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -2,12 +2,13 @@ - bahmni-ipd - Bahmni IPD - 1.0.0-SNAPSHOT + + ${project.parent.artifactId} + ${project.parent.name} + ${project.parent.version} ${MODULE_PACKAGE} Bahmni - Provides APIs for IPD features + ${project.parent.description} org.openmrs.module.webservices.rest diff --git a/omod/src/test/resources/config.xml b/omod/src/test/resources/config.xml index 040350d..bb0b333 100644 --- a/omod/src/test/resources/config.xml +++ b/omod/src/test/resources/config.xml @@ -3,11 +3,12 @@ - bahmni-ipd - Bahmni IPD - 1.0.0-SNAPSHOT - Provides bahmni ipd services - ${MODULE_PACKAGE} + + ${project.parent.artifactId} + ${project.parent.name} + ${project.parent.version} + ${MODULE_PACKAGE} + ${project.parent.description} Bahmni diff --git a/pom.xml b/pom.xml index 88f95ea..1643e37 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,46 @@ + + + src/main/resources + true + + **/*.xml + **/*.txt + **/*.properties + + + + src/main/resources + false + + **/*.xml + **/*.txt + **/*.properties + + + + + + src/test/resources + true + + **/*.xml + **/*.txt + **/*.properties + + + + src/test/resources + false + + **/*.xml + **/*.txt + **/*.properties + + + @@ -399,6 +439,13 @@ org.apache.maven.plugins maven-gpg-plugin 1.6 + + + + --pinentry-mode + loopback + + sign-artifacts From 51709333bf7a14a8e0a01a393787caf381052f1a Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 27 Aug 2024 21:10:48 +0530 Subject: [PATCH 13/15] BAH-4093 | Upgrade depencies for release --- pom.xml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1643e37..41ad75d 100644 --- a/pom.xml +++ b/pom.xml @@ -36,9 +36,9 @@ - 2.5.10 - 2.39.0 - 5.13.0 + 2.5.12 + 2.44.0 + 6.0.0 5.2.14.RELEASE 4.13 2.0.7 @@ -47,10 +47,11 @@ -Xmx1024m 0.7.9 1.18.26 - 2.1.0-SNAPSHOT - 1.3.0-SNAPSHOT - 0.94-SNAPSHOT - 1.32.0 + 2.1.0 + 1.3.0 + 1.2.0 + 1.36.0 + 1.0.0 @@ -256,7 +257,7 @@ org.bahmni.module medication-administration-api - 1.0.0-SNAPSHOT + ${medicationAdminstrationVersion} provided From 1167223677ffe92a4e9a3216ccbe197f8fb9fe92 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 27 Aug 2024 21:34:14 +0530 Subject: [PATCH 14/15] BAH-4093 | Release of version 1.0.0 --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index ecc0868..badddb6 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,7 +5,7 @@ org.bahmni.module bahmni-ipd - 1.0.0-SNAPSHOT + 1.0.0 bahmni-ipd-api diff --git a/omod/pom.xml b/omod/pom.xml index 156e1d2..662343d 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -7,7 +7,7 @@ bahmni-ipd org.bahmni.module - 1.0.0-SNAPSHOT + 1.0.0 bahmni-ipd-omod diff --git a/pom.xml b/pom.xml index 41ad75d..b922829 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.bahmni.module bahmni-ipd - 1.0.0-SNAPSHOT + 1.0.0 pom Bahmni IPD Bahmni IPD module contains all backend APIs for IPD From 90b21fbd3adb48eb28aa13ac9b2a98dbdea20eb4 Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T Date: Tue, 27 Aug 2024 22:03:43 +0530 Subject: [PATCH 15/15] BAH-4093 | Incrementing dev version to 1.1.0-SNAPSHOT --- api/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index badddb6..598b0ac 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -5,7 +5,7 @@ org.bahmni.module bahmni-ipd - 1.0.0 + 1.1.0-SNAPSHOT bahmni-ipd-api diff --git a/omod/pom.xml b/omod/pom.xml index 662343d..ad45ce1 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -7,7 +7,7 @@ bahmni-ipd org.bahmni.module - 1.0.0 + 1.1.0-SNAPSHOT bahmni-ipd-omod diff --git a/pom.xml b/pom.xml index b922829..32ee832 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.bahmni.module bahmni-ipd - 1.0.0 + 1.1.0-SNAPSHOT pom Bahmni IPD Bahmni IPD module contains all backend APIs for IPD