Skip to content

Commit

Permalink
Merge pull request #10010 from hmislk/9947-api_improvements
Browse files Browse the repository at this point in the history
9947 api improvements  Closes #9947
  • Loading branch information
Irani96 authored Jan 8, 2025
2 parents c2fbc60 + 6179886 commit c7051a0
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 75 deletions.
176 changes: 129 additions & 47 deletions src/main/java/com/divudi/service/ChannelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public class ChannelService {
@Inject
ConfigOptionApplicationController configOptionApplicationController;


@PermitAll //TODO: Fix this to appropriate roles .
public void retireNonSettledOnlineBills() {
String jpql = "select b "
Expand Down Expand Up @@ -153,8 +152,8 @@ public void retireNonSettledOnlineBills() {
b.getSingleBillItem().setRetired(true);
b.getSingleBillItem().setRetireComments("Online Agent Payment NOT completed");
billItemFacade.edit(b.getSingleBillItem());
if(b.getBillFees() != null){
for(BillFee bf : b.getBillFees()){
if (b.getBillFees() != null) {
for (BillFee bf : b.getBillFees()) {
bf.setRetired(true);
bf.setRetireComments("Online Agent Payment NOT completed");
billFeeFacade.edit(bf);
Expand Down Expand Up @@ -305,51 +304,135 @@ public void saveOrUpdatePatientDetails(Patient p) {
patientFacade.edit(p);
}
}

public Map getForeignFeesForDoctorAndInstitutionFromServiceSession(ServiceSession ss){


public Map nextAvailableAppoinmentNumberForSession(SessionInstance session) {
BillType[] billTypes = {
BillType.ChannelAgent,
BillType.ChannelCash,
BillType.ChannelOnCall,
BillType.ChannelStaff,
BillType.ChannelCredit,
BillType.ChannelResheduleWithPayment,
BillType.ChannelResheduleWithOutPayment,};

BillTypeAtomic[] billTypeAtomics = {
BillTypeAtomic.CHANNEL_BOOKING_FOR_PAYMENT_ONLINE_PENDING_PAYMENT,
BillTypeAtomic.CHANNEL_BOOKING_FOR_PAYMENT_ONLINE_COMPLETED_PAYMENT
};

List<BillType> bts = Arrays.asList(billTypes);
String sql = "Select bs "
+ " From BillSession bs "
+ " where bs.retired=false"
+ " and bs.bill.billType in :bts"
+ " and type(bs.bill)=:class "
+ " and bs.sessionInstance=:ss "
+ " order by bs.serialNo ";
HashMap<String, Object> hh = new HashMap<>();

Bill b = new Bill();
b.getBillTypeAtomic();
hh.put("bts", bts);
//hh.put("bta", Arrays.asList(billTypeAtomics));
hh.put("class", BilledBill.class);
hh.put("ss", session);
List<BillSession> billSessionList = getBillSessionFacade().findByJpql(sql, hh, TemporalType.DATE);

int nextNumber = 0;
int activePatientCount = 0;

if (billSessionList != null && !billSessionList.isEmpty()) {
for (BillSession bs : billSessionList) {
if (bs.getBill().getBillTypeAtomic() != BillTypeAtomic.CHANNEL_BOOKING_FOR_PAYMENT_ONLINE_PENDING_PAYMENT) {
if(!bs.getBill().isCancelled()){
activePatientCount++;
}
}
if(Integer.parseInt(bs.getBill().getSingleBillSession().getSerialNoStr()) > nextNumber){
nextNumber = Integer.parseInt(bs.getBill().getSingleBillSession().getSerialNoStr());
}
}
}

Map data = new HashMap();
data.put("nextNumber", ++nextNumber);
data.put("activePatients", activePatientCount);

return data;

}

public Map getForeignFeesForDoctorAndInstitutionFromServiceSession(ServiceSession ss) {

String sql = "Select fee From ItemFee fee "
+ " where fee.retired = false "
+ " and fee.serviceSession = :ss ";

Map params = new HashMap<>();
params.put("ss", ss);

List<ItemFee> itemFeeList = itemFeeFacade.findAggregates(sql, params);

double docForeignFee = 0;
double hosForeignFee = 0;
for(ItemFee f : itemFeeList){
if(f.getFeeType() == FeeType.OwnInstitution && f.getFee() > 0){

for (ItemFee f : itemFeeList) {
if (f.getFeeType() == FeeType.OwnInstitution && f.getFee() > 0) {
hosForeignFee = f.getFfee();
}else if(f.getFeeType() == FeeType.Staff && f.getFee() > 0){
} else if (f.getFeeType() == FeeType.Staff && f.getFee() > 0) {
docForeignFee = f.getFfee();
}
}

Map<String, Double> fees = new HashMap<>();

fees.put("docForeignFee", docForeignFee);
fees.put("hosForeignFee", hosForeignFee);

return fees;

// ItemFee fee = new ItemFee();
// fee.isRetired();
// fee.getServiceSession();
// fee.getFeeType();
// fee.getName();
}

public Map getLocalFeesForDoctorAndInstitutionFromServiceSession(ServiceSession ss) {

String sql = "Select fee From ItemFee fee "
+ " where fee.retired = false "
+ " and fee.serviceSession = :ss ";

Map params = new HashMap<>();
params.put("ss", ss);

List<ItemFee> itemFeeList = itemFeeFacade.findAggregates(sql, params);

double docFee = 0;
double hosFee = 0;

for (ItemFee f : itemFeeList) {
if (f.getFeeType() == FeeType.OwnInstitution && f.getFee() > 0) {
hosFee = f.getFee();
} else if (f.getFeeType() == FeeType.Staff && f.getFee() > 0) {
docFee = f.getFee();
}
}

Map<String, Double> fees = new HashMap<>();

fees.put("docFee", docFee);
fees.put("hosFee", hosFee);

return fees;

}
}



public Bill addToReserveAgentBookingThroughApi(boolean forReservedNumbers, Patient patient, SessionInstance session, String refNo, WebUser user, Institution creditCompany) {
saveOrUpdatePatientDetails(patient);
Bill savingTemporaryBill = createAgentInitialBookingBill(patient, session);
if(savingTemporaryBill == null){
if (savingTemporaryBill == null) {
return null;
}
BillItem savingBillItemForSession = createSessionItem(savingTemporaryBill, refNo, session);
Expand Down Expand Up @@ -429,7 +512,6 @@ public Bill addToReserveAgentBookingThroughApi(boolean forReservedNumbers, Patie
// }
// }
// }

calculateBillTotalsFromBillFees(savingTemporaryBill, savingBillFees);

getBillFacade().edit(savingTemporaryBill);
Expand Down Expand Up @@ -599,8 +681,8 @@ private BillItem createSessionItem(Bill bill, String refNo, SessionInstance sess
billItemFacade.create(bi);
return bi;
}
private List<BillSession> getAllBillSessionForSessionInstance(SessionInstance ss){

private List<BillSession> getAllBillSessionForSessionInstance(SessionInstance ss) {
List<BillSession> allBillSessions = new ArrayList<>();
BillType[] billTypes = {
BillType.ChannelAgent,
Expand Down Expand Up @@ -628,16 +710,16 @@ private List<BillSession> getAllBillSessionForSessionInstance(SessionInstance ss
hh.put("ss", ss);
return getBillSessionFacade().findByJpql(sql, hh, TemporalType.DATE);
}

public List getReleasedAppoinmentNumbersForApiBookings(SessionInstance ss) {
long nextNumber = 1L;
if(ss.getNextAvailableAppointmentNumber() != null){

if (ss.getNextAvailableAppointmentNumber() != null) {
nextNumber = ss.getNextAvailableAppointmentNumber();
}

List releasedNumberList = new ArrayList();

List<BillSession> allBillSessions = getAllBillSessionForSessionInstance(ss);

List<Integer> reservedSerialNumbers = allBillSessions.stream()
Expand All @@ -649,7 +731,7 @@ public List getReleasedAppoinmentNumbersForApiBookings(SessionInstance ss) {
for (Integer number : reservedSerialNumbers) {
if (i == number) {
isAssign = true;

}
}

Expand Down Expand Up @@ -684,13 +766,12 @@ private BillSession createBillSession(Bill bill, BillItem billItem, boolean forR

List<Integer> reservedNumbers = CommonFunctions.convertStringToIntegerList(session.getOriginatingSession().getReserveNumbers());
Integer count = null;
List<Integer> availableReleasedApoinmentNumbers = getReleasedAppoinmentNumbersForApiBookings(session);

List<Integer> availableReleasedApoinmentNumbers = getReleasedAppoinmentNumbersForApiBookings(session);
Random rand = new Random();
if(availableReleasedApoinmentNumbers != null && !availableReleasedApoinmentNumbers.isEmpty()){
if (availableReleasedApoinmentNumbers != null && !availableReleasedApoinmentNumbers.isEmpty()) {
count = availableReleasedApoinmentNumbers.get(rand.nextInt(availableReleasedApoinmentNumbers.size()));
}


if (forReservedNumbers) {
// // Pass the selectedReservedBookingNumber to the service method
Expand All @@ -699,7 +780,7 @@ private BillSession createBillSession(Bill bill, BillItem billItem, boolean forR
// count = serviceSessionBean.getNextNonReservedSerialNumber(session, reservedNumbers);
// JsfUtil.addErrorMessage("No reserved numbers available. Normal number is given");
// }
} else if(count == null){
} else if (count == null) {
count = serviceSessionBean.getNextNonReservedSerialNumber(session, reservedNumbers);
}

Expand Down Expand Up @@ -811,7 +892,7 @@ public BillSession cancelBookingBill(Bill bill) {

BillSession bs = bill.getSingleBillSession();
CancelledBill cb = createCancelBill1(bill);

BillItem cItem = cancelBillItems(bs.getBillItem(), cb);
BillSession cbs = cancelBillSession(bs, cb, cItem);
// bill.getSingleBillSession().getBill().setCancelled(true);
Expand Down Expand Up @@ -1008,7 +1089,8 @@ public List<Consultant> findConsultantFromName(String name, Long id) {

return consultantFacade.findByJpql(jpql.toString(), m);
}
public List<Speciality> findAllSpecilities(){

public List<Speciality> findAllSpecilities() {
String jpql;
Map params = new HashMap();
jpql = " select c "
Expand Down Expand Up @@ -1078,15 +1160,15 @@ public List<SessionInstance> findSessionInstance(List<Institution> institution,
// System.out.println(jpql.toString()+"\n"+sessionInstances.size()+"\n"+m.values());
return sessionInstances;
}

@EJB
WebUserFacade webUserFacade;
@Inject
SecurityController securityController;

public WebUser checkUserCredentialForApi(String temUserName, String temPassword) {
String temSQL;

String temSQL;
temSQL = "SELECT u FROM WebUser u WHERE u.retired = false and (u.name)=:n order by u.id desc";
Map m = new HashMap();

Expand All @@ -1101,13 +1183,13 @@ public WebUser checkUserCredentialForApi(String temUserName, String temPassword)

return u;
}

return null;
}

@EJB
ApiKeyFacade apiKeyFacade;

public List<ApiKey> listApiKeysForUser(WebUser user) {
String j;
j = "select a "
Expand All @@ -1121,8 +1203,8 @@ public List<ApiKey> listApiKeysForUser(WebUser user) {
m.put("ed", new Date());
return apiKeyFacade.findByJpql(j, m, TemporalType.DATE);
}
public ApiKey createNewApiKeyForApiResponse(WebUser user) {

public ApiKey createNewApiKeyForApiResponse(WebUser user) {
UUID uuid = UUID.randomUUID();
ApiKey newOne = new ApiKey();
newOne.setWebUser(user);
Expand All @@ -1145,7 +1227,7 @@ public SessionInstance findNextSessionInstance(List<Institution> institution, Li
if (sessionDate != null) {
jpql.append(" and i.sessionDate > :sd ");
m.put("sd", sessionDate);
// System.out.println(sessionDate);
// System.out.println(sessionDate);
}
//
// if(fromDate != null){
Expand Down
Loading

0 comments on commit c7051a0

Please sign in to comment.