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

update with recent changes #36

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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 @@ -47,5 +47,10 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.openmrs.api.context.Context;
import org.openmrs.api.db.ContextDAO;
import org.openmrs.module.BaseModuleActivator;
import org.openmrs.module.ohricore.task.QueryLabResultsTask;
import org.openmrs.module.ohricore.task.UpdateLuceneIndexesTask;
import org.openmrs.scheduler.SchedulerService;
import org.openmrs.scheduler.TaskDefinition;

import org.springframework.core.task.TaskExecutor;

/**
* This class contains the logic that is run every time this module is either started or shutdown
*/
Expand All @@ -36,9 +34,6 @@ public OHRICoreActivator() {
* @see #started()
*/
public void started() {
ContextDAO contextDAO = (ContextDAO) Context.getRegisteredComponents(ContextDAO.class).get(0);
// Refresh Lucene indexes
contextDAO.updateSearchIndex();
log.info("Started OHRICore");
}

Expand All @@ -57,7 +52,14 @@ public void contextRefreshed() {
String taskClassName = QueryLabResultsTask.class.getName();
String description = "Query Lab Results Task - DISI";

String namibiaLuceneIndexUpdateTaskName = "Update Namibia Lucene Indexes";
Long namibiaLuceneRepeatInterval = 31536000L; //second
String namibiaLuceneTaskClassName = UpdateLuceneIndexesTask.class.getName();
String namibiaLuceneDescription = "Update Namibia Lucene Indexes task";

addTask(taskName, taskClassName, repeatInterval, description);
addTask(namibiaLuceneIndexUpdateTaskName, namibiaLuceneTaskClassName, namibiaLuceneRepeatInterval,
namibiaLuceneDescription);
}

@Override
Expand All @@ -67,7 +69,13 @@ public void stopped() {

@Override
public void willRefreshContext() {

super.willRefreshContext();
/*
System.out.println("Refresh Lucene indexes...");
ContextDAO contextDAO = Context.getRegisteredComponents(ContextDAO.class).get(0);
contextDAO.updateSearchIndex();// Refresh Lucene indexes
*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public final class OhriCoreConstant {

public static final String MUTEX_QUERY_LABRESULTS = "QUERY LAB RESULTS MUTEX";

public static final String MUTEX_UPDATE_LUCENE_INDEXES = "UPDATE LUCENE INDEXES MUTEX";

public static final String FHIR_SANDBOX_URL = "https://oh-route.gicsandbox.org/fhir";

public static final String FHIR_COMPLETED_OHRI_TASKS = "/Task?owner=Organization/101283&status=completed&_count=999";
Expand Down Expand Up @@ -67,10 +69,22 @@ public final class OhriCoreConstant {

public static final String OHRI_ENCOUNTER_SYSTEM = "OHRI_ENCOUNTER_UUID";

public static final String NATIONAL_ID_SYSTEM = "http://ohie.org/National_ID";

public static final String HEALTH_ID_SYSTEM = "http://ohie.org/Health_ID";

public static final String HEALTH_FACILITY_ID_SYSTEM = "http://ohie.org/Health_Facility";

public static final String GP_PARENT_SERVER_URL = "ohricore.fhir.sandbox.url";

public static final String GP_PARENT_SERVER_USERNAME = "";

public static final String GP_MPI_SERVER_URL = "ohricore.mpi.namibia.server.url";

public static final String GP_MPI_CLIENT_ID = "ohricore.mpi.namibia.server.clientid";

public static final String GP_MPI_CLIENT_SECRET = "ohricore.mpi.namibia.server.clientsecret";

public static final String CONCEPT_MAPPING_CIEL = "CIEL";

public static final String CONCEPT_MAPPING_LOINC = "LOINC";
Expand Down
70 changes: 70 additions & 0 deletions api/src/main/java/org/openmrs/module/ohricore/Token.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.openmrs.module.ohricore;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* @author smallGod date: 30/11/2022
*/

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Token {

@JsonProperty("access_token")
private String accessToken;

@JsonProperty("id_token")
private String idToken;

@JsonProperty("token_type")
private String tokenType;

@JsonProperty("expires_in")
private String expiresIn;

@JsonProperty("refresh_token")
private String refreshToken;

public Token() {
}

public String getAccessToken() {
return accessToken;
}

public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}

public String getIdToken() {
return idToken;
}

public void setIdToken(String idToken) {
this.idToken = idToken;
}

public String getTokenType() {
return tokenType;
}

public void setTokenType(String tokenType) {
this.tokenType = tokenType;
}

public String getExpiresIn() {
return expiresIn;
}

public void setExpiresIn(String expiresIn) {
this.expiresIn = expiresIn;
}

public String getRefreshToken() {
return refreshToken;
}

public void setRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void afterReturning(Object returnValue, Method methodInvoked, Object[] me

List<OHRIComputedConcept> ohriComputedConcepts = OHRIComputedConceptsFactory.getComputedConcepts(encounter);
for (OHRIComputedConcept computedConcept : ohriComputedConcepts) {
computedConcept.computeAndPersistObs(encounter);
//computedConcept.computeAndPersistObs(encounter); //Disable computed obs here: SG - Sept.11.2022
}

//TODO: Re-factor this code into a separate neat file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.openmrs.module.ohricore.aop;

import org.hl7.fhir.r4.model.Address;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.StringType;
import org.openmrs.Location;
import org.openmrs.PatientIdentifier;
import org.openmrs.PatientIdentifierType;
import org.openmrs.PersonAddress;
import org.openmrs.api.context.Context;
import org.openmrs.module.ohricore.engine.ConceptComputeTrigger;
import org.openmrs.module.ohricore.fhir.FhirClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.AfterReturningAdvice;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
* @author smallGod date: 30/11/2022
*/
public class PatientInterceptorAdvice implements AfterReturningAdvice {

private static final Logger log = LoggerFactory.getLogger(PatientInterceptorAdvice.class);

@Override
public void afterReturning(Object returnValue, Method methodInvoked, Object[] methodArgs, Object target)
throws Throwable {

System.out.println("After returning Patient Save in EMR");
try {
if (methodInvoked.getName().equals(ConceptComputeTrigger.SAVE_PATIENT)) {

System.out.println("Save Patient method()...");

for (Object arg : methodArgs) {
if (arg instanceof org.openmrs.Patient) {

org.openmrs.Patient patient = (org.openmrs.Patient) arg;
Patient newPatient = new Patient();

Enumerations.AdministrativeGender patientGender;
String gender = patient.getGender();
switch (gender) {
case "M":
patientGender = Enumerations.AdministrativeGender.MALE;
break;
case "F":
patientGender = Enumerations.AdministrativeGender.FEMALE;
break;
default:
patientGender = Enumerations.AdministrativeGender.UNKNOWN;
break;
}
//check if health id exists on MPI (send if doesn't exist) otherwise don't
// -> add global property for health ID
// expose endpoint for search
HumanName name = new HumanName();
name.setFamily(patient.getFamilyName());
name.setGiven(Collections.singletonList(new StringType(patient.getGivenName())));
name.setUse(HumanName.NameUse.USUAL);

Set<PersonAddress> personAddresses = patient.getAddresses();
List<Address> addresses = new ArrayList<>();
for (PersonAddress personAddress : personAddresses) {

Address address = new Address();
address.setUse(Address.AddressUse.HOME);
address.setCountry(personAddress.getCountry());
address.setCity(personAddress.getAddress1());
address.setState(personAddress.getCountry());
addresses.add(new Address());
}

List<PatientIdentifier> patientIds = patient.getActiveIdentifiers();
List<Identifier> identifiers = new ArrayList<>();
for (PatientIdentifier id : patientIds) {
Identifier identifier = new Identifier();
identifier.setSystem("urn:oid:3.9");//TODO: don't hardcode
identifier.setValue(id.getIdentifier());
identifiers.add(identifier);
}

newPatient.setIdentifier(identifiers);
newPatient.setGender(patientGender);
newPatient.setName(Collections.singletonList(name));
newPatient.setBirthDate(patient.getBirthdate());
newPatient.setAddress(addresses);

//String response = FhirClient.postMPIRequest(newPatient);
List<PatientIdentifier> newPatientIds = FhirClient.postPatient(newPatient);
for (PatientIdentifier patientId : newPatientIds) {
patientId.setPatient(patient);
Context.getPatientService().savePatientIdentifier(patientId);
}
}
}
}
} catch (Exception e) {
log.error("An un-expected Error occurred while registering a patient: " + e.getMessage());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.openmrs.module.ohricore.api;

import ca.uhn.fhir.model.api.annotation.ResourceDef;
import org.hl7.fhir.r4.model.Patient;

/**
* @author smallGod
*/

@ResourceDef(name = "MPIPatient", profile = "http://hl7.org/fhir/StructureDefinition/Patient")
public class MPIClientPatient extends Patient {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.openmrs.module.ohricore.api;

import org.hl7.fhir.r4.model.Patient;
import org.openmrs.module.fhir2.api.FhirService;

import javax.annotation.Nonnull;

/**
* @author smallGod
*/
public interface MPIClientService extends FhirService<MPIClientPatient> {

MPIClientPatient getByHealthId(@Nonnull String healthId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.openmrs.module.ohricore.api.impl;

import org.openmrs.module.fhir2.api.dao.FhirDao;
import org.openmrs.module.fhir2.api.impl.BaseFhirService;
import org.openmrs.module.ohricore.api.MPIClientPatient;
import org.openmrs.module.ohricore.api.MPIClientService;
import org.openmrs.module.ohricore.api.translator.MPIClientPatientTranslator;
import org.openmrs.module.ohricore.fhir.FhirClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Nonnull;

/**
* @author smallGod
*/

@Component
@Transactional
public class MPIClientServiceImpl extends BaseFhirService<MPIClientPatient, org.openmrs.Patient> implements MPIClientService {

@Autowired
private MPIClientPatientTranslator translator;

@Override
protected FhirDao<org.openmrs.Patient> getDao() {
return null;
}

@Override
public MPIClientPatient getByHealthId(@Nonnull String healthId) {
org.openmrs.Patient patient = FhirClient.getPatient(healthId);
return getTranslator().toFhirResource(patient);
}

@Override
public MPIClientPatientTranslator getTranslator() {
return translator;
}

public void setTranslator(MPIClientPatientTranslator translator) {
this.translator = translator;
}
}
Loading