Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate Client Registry Patient Service #13

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@
<artifactId>event-api</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -65,11 +65,11 @@ public String getClientRegistryDefaultPatientIdentifierSystem() {
public String getClientRegistryUserName() {
return username;
}

public String getClientRegistryPassword() {
return password;
}

public String getClientRegistryIdentifierRoot() {
return identifierRoot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public interface CRPatientService {
List<Patient> getCRPatients(String sourceIdentifier, String sourceIdentifierSystem, List<String> extraTargetSystems);

List<Patient> searchCRForPatients(PatientSearchParams patientSearchParams);

Patient getPatientByPIX(String sourceIdentifier, String sourceIdentifierSystem, List<String> extraTargetSystems);

List<Patient> searchPatients(PatientSearchParams patientSearchParams);

Patient createOrUpdatePatient(Patient patient);

Patient purgePatient(Patient patient);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +73,40 @@ public List<Patient> searchCRForPatients(PatientSearchParams patientSearchParams
return null;
}

/**
* @param sourceIdentifier
* @param sourceIdentifierSystem
* @param extraTargetSystems
* @return
*/
@Override
public Patient getPatientByPIX(String sourceIdentifier, String sourceIdentifierSystem, List<String> extraTargetSystems) {
return null;
}

/**
* @param patientSearchParams
* @return
*/
@Override
public List<Patient> 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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* 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.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;

/**
* Tests All Crud Methods in @FhirCRPatientServiceImpl Service
*
* @see org.openmrs.module.clientregistry.api.impl.FhirCRPatientServiceImpl
*/
@RunWith(MockitoJUnitRunner.class)
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");

@Mock
private PatientTranslator patientTranslator;

@Mock
private FhirPatientDao dao;

@Mock
private FhirPatientIdentifierSystemDao systemDao;

@Mock
private FhirGlobalPropertyService globalPropertyService;

@Mock
private SearchQueryInclude<org.hl7.fhir.r4.model.Patient> searchQueryInclude;

@Mock
private SearchQuery<Patient, org.hl7.fhir.r4.model.Patient, FhirPatientDao, PatientTranslator, SearchQueryInclude<org.hl7.fhir.r4.model.Patient>> searchQuery;

private FhirPatientServiceImpl patientService;

private org.hl7.fhir.r4.model.Patient fhirPatient;

private Patient patient;

@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);
}

/**
* @see FhirCRPatientServiceImpl#getCRPatients(String sourceIdentifier, String
* sourceIdentifierSystem, List <String> targetSystems)
*/
@Test
public void createOrUpdatePatient_shouldSaveOrUpdatePatient() {

}
}
Loading