From 238443691a840704cd0d0ad8bf3d5bd78b1c1738 Mon Sep 17 00:00:00 2001 From: Tendo Martin Date: Fri, 22 Mar 2024 04:25:32 +0300 Subject: [PATCH 1/5] Remove unused imports and wildcard imports --- .../clientregistry/ClientRegistryConfig.java | 20 +++++++++---------- .../api/impl/FhirCRPatientServiceImpl.java | 8 +++----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java index 574e7f7..e9325cb 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/ClientRegistryConfig.java @@ -21,29 +21,29 @@ */ @Component public class ClientRegistryConfig { - + public final static String MODULE_PRIVILEGE = "Client Registry Privilege"; - + @Autowired @Qualifier("adminService") AdministrationService administrationService; - + @Value("${clientregistry.serverUrl}") private String serverUrl; - + @Value("${clientregistry.username}") private String username; - + @Value("${clientregistry.password}") private String password; - + @Value("${clientregistry.identifierRoot}") private String identifierRoot; - + public boolean clientRegistryConnectionEnabled() { return StringUtils.isNotBlank(getClientRegistryServerUrl()); } - + public String getClientRegistryServerUrl() { return serverUrl; } @@ -65,11 +65,11 @@ public String getClientRegistryDefaultPatientIdentifierSystem() { public String getClientRegistryUserName() { return username; } - + public String getClientRegistryPassword() { return password; } - + public String getClientRegistryIdentifierRoot() { return identifierRoot; } diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java index 6f91773..84270f7 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java @@ -2,14 +2,12 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInputAndPartialOutput; -import ca.uhn.fhir.rest.gclient.IQuery; import ca.uhn.fhir.rest.gclient.StringClientParam; -import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.TokenParam; -import ca.uhn.fhir.rest.param.UriOrListParam; -import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.Patient; import org.openmrs.module.clientregistry.ClientRegistryConfig; import org.openmrs.module.clientregistry.api.CRPatientService; import org.openmrs.module.clientregistry.providers.FhirCRConstants; From 7e15c0cb193baaeea099c0939b7529739508e534 Mon Sep 17 00:00:00 2001 From: Tendo Martin Date: Mon, 1 Apr 2024 11:20:37 +0300 Subject: [PATCH 2/5] Add and implement getPatientByPIX, searchPatients, createOrUpdatePatient purgePatient methods --- .../clientregistry/api/CRPatientService.java | 13 +++++++++++ .../api/impl/FhirCRPatientServiceImpl.java | 22 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java b/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java index f1cc9da..e58a66e 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java @@ -10,4 +10,17 @@ public interface CRPatientService { List getCRPatients(String sourceIdentifier, String sourceIdentifierSystem, List extraTargetSystems); List searchCRForPatients(PatientSearchParams patientSearchParams); + + // Query a patient through a PIXm manager using native IDs + // Question: Should this return a patient bundle? + Patient getPatientByPIX(String sourceIdentifier, String sourceIdentifierSystem, List extraTargetSystems); + + // Method for patient search, including fuzzy search + List searchPatients(PatientSearchParams patientSearchParams); + + // Creates or updated a patient record + Patient createOrUpdatePatient(Patient patient); + + // Purges patient record from the registry + Patient purgePatient(Patient patient); } diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java index 84270f7..48190f2 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java @@ -72,7 +72,27 @@ public List getCRPatients(String sourceIdentifier, String sourceIdentif public List searchCRForPatients(PatientSearchParams patientSearchParams) { return null; } - + + @Override + public Patient getPatientByPIX(String sourceIdentifier, String sourceIdentifierSystem, List extraTargetSystems) { + return null; + } + + @Override + public List searchPatients(PatientSearchParams patientSearchParams) { + return null; + } + + @Override + public Patient createOrUpdatePatient(Patient patient) { + return null; + } + + @Override + public Patient purgePatient(Patient patient) { + return null; + } + /** * Filter and parse out fhir patients from Client Registry Patient Search results */ From 6c80dae2aebbd729b3739fa99ef3a3d0c4f86b83 Mon Sep 17 00:00:00 2001 From: Tendo Martin Date: Mon, 1 Apr 2024 14:47:21 +0300 Subject: [PATCH 3/5] Add Test class for FhirCRPatientServiceImpl --- .../clientregistry/api/CRPatientService.java | 10 +-- .../api/impl/FhirCRPatientServiceImpl.java | 24 ++++-- .../impl/FhirCRPatientServiceImplTest.java | 79 +++++++++++++++++++ 3 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java b/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java index e58a66e..be51b64 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java @@ -10,17 +10,17 @@ public interface CRPatientService { List getCRPatients(String sourceIdentifier, String sourceIdentifierSystem, List extraTargetSystems); List searchCRForPatients(PatientSearchParams patientSearchParams); - + // Query a patient through a PIXm manager using native IDs // Question: Should this return a patient bundle? Patient getPatientByPIX(String sourceIdentifier, String sourceIdentifierSystem, List extraTargetSystems); - + // Method for patient search, including fuzzy search List searchPatients(PatientSearchParams patientSearchParams); - - // Creates or updated a patient record + + // Creates or updates a patient record Patient createOrUpdatePatient(Patient patient); - + // Purges patient record from the registry Patient purgePatient(Patient patient); } diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java index 48190f2..42134b8 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImpl.java @@ -72,27 +72,41 @@ public List getCRPatients(String sourceIdentifier, String sourceIdentif public List searchCRForPatients(PatientSearchParams patientSearchParams) { return null; } - + + /** + * @param sourceIdentifier + * @param sourceIdentifierSystem + * @param extraTargetSystems + * @return + */ @Override public Patient getPatientByPIX(String sourceIdentifier, String sourceIdentifierSystem, List extraTargetSystems) { return null; } - + + /** + * @param patientSearchParams + * @return + */ @Override public List searchPatients(PatientSearchParams patientSearchParams) { return null; } - + + /** + * @param patient + * @return + */ @Override public Patient createOrUpdatePatient(Patient patient) { return null; } - + @Override public Patient purgePatient(Patient patient) { return null; } - + /** * Filter and parse out fhir patients from Client Registry Patient Search results */ diff --git a/api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java b/api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java new file mode 100644 index 0000000..c1dd459 --- /dev/null +++ b/api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java @@ -0,0 +1,79 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ + +package org.openmrs.module.clientregistry.api.impl; + +import org.junit.Before; +import org.junit.Test; + +import java.util.List; + +/** + * Tests All Crud Methods in @FhirCRPatientServiceImpl Service + * + * @see org.openmrs.module.clientregistry.api.impl.FhirCRPatientServiceImpl + */ +public class FhirCRPatientServiceImplTest { + + private static final Integer PATIENT_ID = 198; + + private static final String PATIENT_UUID = "34009h32-34h3j4-34pk34-0422y"; + + private static final String WRONG_PATIENT_UUID = "Wrong uuid"; + + private static final String PATIENT_GIVEN_NAME = "Mary"; + + private static final String PATIENT_GIVEN_NAME_NOT_MATCHED = "Kakooza"; + + private static final String PATIENT_FAMILY_NAME_NOT_MATCHED = "your fam"; + + private static final String PATIENT_PARTIAL_GIVEN_NAME = "Nansubuga"; + + private static final String PATIENT_FAMILY_NAME = "Kizza"; + + private static final String PATIENT_PARTIAL_FAMILY_NAME = "Patricia"; + + private static final String GENDER = "F"; + + private static final String WRONG_GENDER = "wrong-gender"; + + private static final String DATE = "1980-12-12"; + + private static final String UNKNOWN_DATE = "0001-10-10"; + + private static final String CITY = "Kampala"; + + private static final String STATE = "Central"; + + private static final String POSTAL_CODE = "256"; + + private static final String COUNTRY = "Uganda"; + + private static final String UNKNOWN_ADDRESS = "Kansanga"; + + private static final String LAST_UPDATED_DATE = "2021-09-03"; + + private static final String WRONG_LAST_UPDATED_DATE = "2020-09-09"; + + // private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); + + @Before + public void before() { + } + + /** + * @see FhirCRPatientServiceImpl#getCRPatients(String sourceIdentifier, String + * sourceIdentifierSystem, List targetSystems) + */ + @Test + public void createOrUpdatePatient_shouldSaveOrUpdatePatient() { + + } +} From a40b39d24ba139be097f24f7ed5a5804b5b0d0d7 Mon Sep 17 00:00:00 2001 From: Tendo Martin Date: Tue, 2 Apr 2024 01:55:42 +0300 Subject: [PATCH 4/5] Start test implementation for patient registration --- .../openmrs/module/clientregistry/api/CRPatientService.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java b/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java index be51b64..b7e3bb1 100644 --- a/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java +++ b/api/src/main/java/org/openmrs/module/clientregistry/api/CRPatientService.java @@ -11,16 +11,11 @@ public interface CRPatientService { List searchCRForPatients(PatientSearchParams patientSearchParams); - // Query a patient through a PIXm manager using native IDs - // Question: Should this return a patient bundle? Patient getPatientByPIX(String sourceIdentifier, String sourceIdentifierSystem, List extraTargetSystems); - // Method for patient search, including fuzzy search List searchPatients(PatientSearchParams patientSearchParams); - // Creates or updates a patient record Patient createOrUpdatePatient(Patient patient); - // Purges patient record from the registry Patient purgePatient(Patient patient); } From 041ddec57f453d23559349c37ede614e4e980370 Mon Sep 17 00:00:00 2001 From: Tendo Martin Date: Tue, 16 Apr 2024 12:02:30 +0300 Subject: [PATCH 5/5] Add patient service --- api/pom.xml | 5 ++ .../impl/FhirCRPatientServiceImplTest.java | 76 ++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/api/pom.xml b/api/pom.xml index e0d7bc6..eee79e0 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -41,5 +41,10 @@ event-api 2.10.0 + + junit + junit + test + diff --git a/api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java b/api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java index c1dd459..ce625a6 100644 --- a/api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/clientregistry/api/impl/FhirCRPatientServiceImplTest.java @@ -10,8 +10,22 @@ package org.openmrs.module.clientregistry.api.impl; +import org.hl7.fhir.r4.model.HumanName; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.openmrs.Patient; +import org.openmrs.PersonAddress; +import org.openmrs.PersonName; +import org.openmrs.module.fhir2.api.FhirGlobalPropertyService; +import org.openmrs.module.fhir2.api.dao.FhirPatientDao; +import org.openmrs.module.fhir2.api.dao.FhirPatientIdentifierSystemDao; +import org.openmrs.module.fhir2.api.impl.FhirPatientServiceImpl; +import org.openmrs.module.fhir2.api.search.SearchQuery; +import org.openmrs.module.fhir2.api.search.SearchQueryInclude; +import org.openmrs.module.fhir2.api.translators.PatientTranslator; import java.util.List; @@ -20,6 +34,7 @@ * * @see org.openmrs.module.clientregistry.api.impl.FhirCRPatientServiceImpl */ +@RunWith(MockitoJUnitRunner.class) public class FhirCRPatientServiceImplTest { private static final Integer PATIENT_ID = 198; @@ -64,8 +79,67 @@ public class FhirCRPatientServiceImplTest { // private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); + @Mock + private PatientTranslator patientTranslator; + + @Mock + private FhirPatientDao dao; + + @Mock + private FhirPatientIdentifierSystemDao systemDao; + + @Mock + private FhirGlobalPropertyService globalPropertyService; + + @Mock + private SearchQueryInclude searchQueryInclude; + + @Mock + private SearchQuery> searchQuery; + + private FhirPatientServiceImpl patientService; + + private org.hl7.fhir.r4.model.Patient fhirPatient; + + private Patient patient; + @Before - public void before() { + public void setUp() { + patientService = new FhirPatientServiceImpl() { + + @Override + protected void validateObject(org.openmrs.Patient object) { + } + }; + + patientService.setDao(dao); + patientService.setSystemDao(systemDao); + patientService.setTranslator(patientTranslator); + patientService.setSearchQuery(searchQuery); + patientService.setSearchQueryInclude(searchQueryInclude); + + PersonName name = new PersonName(); + name.setFamilyName(PATIENT_FAMILY_NAME); + name.setGivenName(PATIENT_GIVEN_NAME); + + patient = new Patient(); + patient.setUuid(PATIENT_UUID); + patient.setGender("M"); + patient.addName(name); + + PersonAddress address = new PersonAddress(); + address.setCityVillage(CITY); + address.setStateProvince(STATE); + address.setPostalCode(POSTAL_CODE); + address.setCountry(COUNTRY); + + HumanName humanName = new HumanName(); + humanName.addGiven(PATIENT_GIVEN_NAME); + humanName.setFamily(PATIENT_FAMILY_NAME); + + fhirPatient = new org.hl7.fhir.r4.model.Patient(); + fhirPatient.setId(PATIENT_UUID); + fhirPatient.addName(humanName); } /**