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

Initial Checkin #20

Open
wants to merge 10 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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jpa-buddy.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/uiux-emr-middleware.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.emrmiddleware.action;

import com.emrmiddleware.api.APIClient;
import com.emrmiddleware.api.RestAPI;
import com.emrmiddleware.api.dto.AppointmentDTO;
import com.emrmiddleware.dto.CustomAppointmentDTO;
import com.google.gson.Gson;
import okhttp3.ResponseBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.ArrayList;

public class AppointmentAction {

String authString;

private final Logger logger = LoggerFactory.getLogger(EncounterAction.class);
APIClient apiclient;
RestAPI restapiintf;

//AppointmentDTO appointmentDTO;
public AppointmentAction(String authString) {
this.authString = authString;
apiclient = new APIClient(authString);
restapiintf = apiclient.getMMClient().create(RestAPI.class);
}
public boolean addAppointmentOpenMRS(ArrayList<CustomAppointmentDTO> appointmentdto) {
Gson gson = new Gson();
String val = "";


try {

for (CustomAppointmentDTO appointment: appointmentdto) {


logger.info("appointment value : " + gson.toJson(appointment));
if(appointment.getAppointmentId() == 0 ) {
Call<ResponseBody> addAppointment = restapiintf.addAppointment(appointment);
Response<ResponseBody> response = addAppointment.execute();
logger.info(response.message());
if (response.isSuccessful()) {
val = response.body().string();
appointment.setSyncd(true);
} else {
val = response.errorBody().string();
logger.error("REST failed : " + val);
return false;
}
logger.info("Response is : " + val);
}
else {
Call<ResponseBody> addAppointment = restapiintf.editAppointment(appointment);
Response<ResponseBody> response = addAppointment.execute();
logger.info(response.message());
if (response.isSuccessful()) {
val = response.body().string();
appointment.setSyncd(true);
} else {
val = response.errorBody().string();
logger.error("REST failed : " + val);
return false;
}
logger.info("Response is : " + val);
}
}
} catch (IOException | NullPointerException e) {
// TODO Auto-generated catch block
logger.error(e.getMessage(), e);
return false;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
return true;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.emrmiddleware.api.dto.EncounterAPIDTO;
import com.emrmiddleware.dao.EncounterDAO;
import com.emrmiddleware.dto.EncounterDTO;
import com.emrmiddleware.api.dto.ObsAPIDTO;
import com.emrmiddleware.exception.ActionException;
import com.emrmiddleware.exception.DAOException;
import com.google.gson.Gson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private String getOpenMrsId() {
UserCredentialDTO userCredentialdto = authenticationUtil.getAuthHeader(authString);
Call<ResponseBody> call = restIdapiintf.getOpenMrsId("1", userCredentialdto.getUsername(),
userCredentialdto.getPassword());

Response<ResponseBody> response = call.execute();
// IDGenAPIDTO idgenapidto = call.execute();
if (response.isSuccessful()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ public PullDataDTO getPullData(String lastpulldatatime, String locationuuid) thr
visitAttributesList = visitdao.getVisitAttributes(lastpulldatatime, locationuuid);
encounterlist = encounterdao.getEncounters(lastpulldatatime, locationuuid);
obslist = obsdao.getObsList(lastpulldatatime, locationuuid);

locationlist = locationdao.getLocations(lastpulldatatime);

providerlist = providerdao.getProviders(lastpulldatatime);
providerAttributeTypeList = providerdao.getProviderAttributeTypeMaster(lastpulldatatime);
providerAttributeList = providerdao.getProviderAttributes(lastpulldatatime);

pulldata.setLocationlist(locationlist);
pulldata.setPatientlist(patientlist);
pulldata.setPatientAttributeTypeListMaster(patientAttributeTypeList);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.emrmiddleware.action;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.emrmiddleware.api.dto.EncounterAPIDTO;
import com.emrmiddleware.api.dto.PatientAPIDTO;
import com.emrmiddleware.api.dto.PersonAPIDTO;
import com.emrmiddleware.api.dto.VisitAPIDTO;
import com.emrmiddleware.dto.EncounterDTO;
import com.emrmiddleware.dto.PatientDTO;
import com.emrmiddleware.dto.PersonDTO;
import com.emrmiddleware.dto.PullDataDTO;
import com.emrmiddleware.dto.PushDataDTO;
import com.emrmiddleware.dto.VisitDTO;
import com.emrmiddleware.api.dto.*;
import com.emrmiddleware.conf.DBconfig;
import com.emrmiddleware.dmo.ProviderDMO;
import com.emrmiddleware.dto.*;
import com.emrmiddleware.exception.DAOException;
import com.emrmiddleware.exception.ActionException;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;


public class PushDataAction {
Expand All @@ -30,16 +30,25 @@ public PullDataDTO pushData(PushDataDTO pushdatadto) throws DAOException, Action
ArrayList<PatientAPIDTO> patientList;
ArrayList<VisitAPIDTO> visitList;
ArrayList<EncounterAPIDTO> encounterList;

ArrayList<AppointmentDTO> appointmentDTOArrayList;

PullDataDTO pulldatadto = new PullDataDTO();
try {
personList = pushdatadto.getPersons();
patientList = pushdatadto.getPatients();
visitList = pushdatadto.getVisits();
encounterList = pushdatadto.getEncounters();
ArrayList<ProviderDTO> providerlist = pushdatadto.getProviders();
appointmentDTOArrayList = pushdatadto.getAppointments();

PersonAction personaction = new PersonAction(authString);
PatientAction patientaction = new PatientAction(authString);
VisitAction visitaction = new VisitAction(authString);
EncounterAction encounteraction = new EncounterAction(authString);

AppointmentAction appointmentAction = new AppointmentAction(authString);

// patientaction.setPatients(patientList);
if (personList != null) {
ArrayList<PersonDTO> persons = personaction.setPersons(personList);
Expand All @@ -57,6 +66,24 @@ public PullDataDTO pushData(PushDataDTO pushdatadto) throws DAOException, Action
ArrayList<EncounterDTO> encounters = encounteraction.setEncounters(encounterList);
pulldatadto.setEncounterlist(encounters);
}
if(providerlist != null)
{

for(ProviderDTO provider : providerlist) {
pulldatadto.setProviderlist(getProviders(new Integer(provider.providerId).intValue()));


}

}

if(appointmentDTOArrayList != null) {
ArrayList<CustomAppointmentDTO> customAppointmentDTOArrayList = updateAppointments(appointmentDTOArrayList);

boolean b = appointmentAction.addAppointmentOpenMRS(customAppointmentDTOArrayList);
pulldatadto.setAppointmentList(customAppointmentDTOArrayList);
}


} catch (Exception e) {
throw new ActionException(e.getMessage(), e);
Expand All @@ -65,4 +92,93 @@ public PullDataDTO pushData(PushDataDTO pushdatadto) throws DAOException, Action
return pulldatadto;
}

private ArrayList<CustomAppointmentDTO> updateAppointments(ArrayList<AppointmentDTO> appointmentDTOArrayList) {

ArrayList<CustomAppointmentDTO> customAppointmentDTOArrayList = new ArrayList<CustomAppointmentDTO>();
for(AppointmentDTO appointmentDTO: appointmentDTOArrayList) {
CustomAppointmentDTO customAppointmentDTO = new CustomAppointmentDTO();

customAppointmentDTO.setAppointmentId(appointmentDTO.getAppointmentId());

customAppointmentDTO.setSlotDay(appointmentDTO.getSlotDay());

customAppointmentDTO.setSlotDate(appointmentDTO.getSlotDate());

customAppointmentDTO.setSlotDuration(appointmentDTO.getSlotDuration());

customAppointmentDTO.setSlotDurationUnit(appointmentDTO.getSlotDurationUnit());

customAppointmentDTO.setSlotTime(appointmentDTO.getSlotTime());

customAppointmentDTO.setSpeciality(appointmentDTO.getSpeciality());

customAppointmentDTO.setUserUuid(appointmentDTO.getUserUuid());

customAppointmentDTO.setDrName(appointmentDTO.getDrName());

customAppointmentDTO.setVisitUuid(appointmentDTO.getVisitUuid());

customAppointmentDTO.setPatientName(appointmentDTO.getPatientName());

customAppointmentDTO.setOpenMrsId(appointmentDTO.getOpenMrsId());

customAppointmentDTO.setPatientId(appointmentDTO.getPatientId());

customAppointmentDTO.setLocationUuid(appointmentDTO.getLocationUuid());

customAppointmentDTO.setHwUUID(appointmentDTO.getHwUUID());

customAppointmentDTO.setReason(appointmentDTO.getReason());

customAppointmentDTO.setVoided(appointmentDTO.getVoided());
customAppointmentDTO.setSyncd(false);
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/openmrs", "root", "i10hi1c");
PreparedStatement pstmtPatient = con.prepareStatement("select gender, TIMESTAMPDIFF(YEAR, birthdate, now()) FROM person WHERE uuid = ? ");
PreparedStatement pstmtHealthWorker = con.prepareStatement("select a.gender, ifnull(TIMESTAMPDIFF(YEAR, a.birthdate, now()), 'NA'), concat_ws(' ', b.given_name, b.middle_name, b.family_name) FROM person a, person_name b WHERE a.person_id = b.person_id and a.person_id = (select person_id from provider where uuid = ?) ");
pstmtPatient.setString(1, appointmentDTO.getPatientId());
ResultSet rstPatient = pstmtPatient.executeQuery();
rstPatient.next();
customAppointmentDTO.setPatientGender(rstPatient.getString(1));
customAppointmentDTO.setPatientAge(rstPatient.getString(2));
pstmtHealthWorker.setString(1, appointmentDTO.getHwUUID());
ResultSet rstHW = pstmtHealthWorker.executeQuery();
rstHW.next();
customAppointmentDTO.setHwName(rstHW.getString(3));
customAppointmentDTO.setHwAge(rstHW.getString(2));
customAppointmentDTO.setHwGender(rstHW.getString(1));
customAppointmentDTOArrayList.add(customAppointmentDTO);
rstHW.close();
rstPatient.close();
pstmtHealthWorker.close();
pstmtPatient.close();
con.close();
}
catch(Exception e) {
System.out.println(e.getMessage());
}


}
return customAppointmentDTOArrayList;
}

private ArrayList<ProviderDTO> getProviders(int providerId) {
SqlSessionFactory sessionfactory = DBconfig.getSessionFactory();
SqlSession session = sessionfactory.openSession();
ArrayList<ProviderDTO> providerlist = new ArrayList<ProviderDTO>();

try {

ProviderDMO providerdmo = session.getMapper(ProviderDMO.class);
providerlist = providerdmo.getProviders2(providerId);
}
catch(Exception e){
System.out.println(e.getMessage());
}
return providerlist;

}

}
18 changes: 18 additions & 0 deletions EMR-Middleware/src/main/java/com/emrmiddleware/api/APIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,22 @@ public Retrofit getIdClient() {
return retrofit;
}

public Retrofit getMMClient() {

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
AuthenticationUtil authenticationUtil = new AuthenticationUtil();
UserCredentialDTO userCredentialdto = authenticationUtil.getAuthHeader(authString);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(
new BasicAuthInterceptor(userCredentialdto.getUsername(), userCredentialdto.getPassword()))
.build();
ResourcesEnvironment dbenv = new ResourcesEnvironment();
Gson gson = new GsonBuilder().setLenient().create();
retrofit = new Retrofit.Builder().baseUrl(dbenv.getMMBaseURL())
.addConverterFactory(retrofit2.converter.gson.GsonConverterFactory.create(gson)).client(client).build();

return retrofit;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.emrmiddleware.api.dto.PatientAPIDTO;
import com.emrmiddleware.api.dto.PersonAPIDTO;
import com.emrmiddleware.api.dto.VisitAPIDTO;
import com.emrmiddleware.dto.CustomAppointmentDTO;
import com.emrmiddleware.dto.PatientDTO;

import okhttp3.ResponseBody;
Expand Down Expand Up @@ -50,7 +51,10 @@ public interface RestAPI {
@DELETE("encounter/{uuid}")
Call<ResponseBody> deleteEncounter(@Path("uuid") String uuid);



@POST("appointment/bookAppointment")
Call<ResponseBody> addAppointment(@Body CustomAppointmentDTO appointmentdto);

@POST("appointment/rescheduleAppointment")
Call<ResponseBody> editAppointment(@Body CustomAppointmentDTO appointmentdto);

}
Loading