Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

@Data
public class PastHistoryDTO {
private Long id;
private String beneficiaryRegID;
private Integer providerServiceMapID;
private String benVisitID;
private String visitCode;
private String createdBy;
private Integer vanID;
private Integer parkingPlaceID;
private Long benFlowID;
private Long beneficiaryID;
private List<PastIllnessDTO> pastIllness;
private List<PastSurgeryDTO> pastSurgery;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package com.iemr.hwc.fhir.provider.observation;

import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastHistoryDTO;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastIllnessDTO;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastSurgeryDTO;
import com.iemr.hwc.fhir.model.observation.ObservationExt;
import com.iemr.hwc.fhir.service.observation.ObservationService;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Component
public class ObservationExtProvider implements IResourceProvider {
Expand All @@ -33,4 +43,105 @@ public MethodOutcome createObservation(HttpServletRequest theRequest, @ResourceP
method.setResource(observationService.createObservation(theRequest,observationExt));
return method;
}

@Search()
public List<ObservationExt> findHistoryByLocationAndLastModifDate(@RequiredParam(name = "providerServiceMapId") StringParam providerServiceMapId, @RequiredParam(name = "vanID") StringParam vanID,
@RequiredParam(name = "lastModif") DateParam lastModifyDate) {
List<ObservationExt> listRes = new ArrayList<>();
List<PastHistoryDTO> ListHistoryDTO = observationService.getBenMedHistoryByLocationAndLastModifDate(Integer.parseInt(providerServiceMapId.getValue()), Integer.parseInt(vanID.getValue()),
new Timestamp(lastModifyDate.getValue().getTime()));
try {
for (int i = 0; i < ListHistoryDTO.size(); i++) {
PastHistoryDTO historyDTO = ListHistoryDTO.get(i);
ObservationExt historyObservation = new ObservationExt();
historyObservation.setId(historyDTO.getId()+"");
historyObservation.setVanID(new StringType(historyDTO.getVanID()+""));
historyObservation.setParkingPlaceID(new StringType(historyDTO.getParkingPlaceID()+""));
historyObservation.setCreatedBy(new StringType(historyDTO.getCreatedBy()));
historyObservation.setProviderServiceMapId(new StringType(historyDTO.getProviderServiceMapID()+""));
historyObservation.setBeneficiaryRegID(new StringType(historyDTO.getBeneficiaryRegID()+""));
historyObservation.setBeneficiaryID(new StringType(historyDTO.getBeneficiaryID()+""));
historyObservation.setBenFlowID(new StringType(historyDTO.getBenFlowID()+""));

List<CodeableConcept> codeableConceptList1 = new ArrayList<>();
CodeableConcept codeableConcept1 = new CodeableConcept();
codeableConcept1.setText("History");
List<Coding> codingList1 = new ArrayList<>();
Coding coding1 = new Coding();
coding1.setSystem("http://terminology.hl7.org/CodeSystem/observation-category");
coding1.setCode("social-history");
coding1.setDisplay("Social History");
codingList1.add(coding1);
codeableConcept1.setCoding(codingList1);
codeableConceptList1.add(codeableConcept1);
historyObservation.setCategory(codeableConceptList1);

CodeableConcept codeableConcept2 = new CodeableConcept();
codeableConcept2.setText("Past medical history");
List<Coding> codingList2 = new ArrayList<>();
Coding coding2 = new Coding();
coding2.setSystem("http://loinc.org/");
coding2.setCode("11348-0");
coding2.setDisplay("Past medical history");
codingList2.add(coding2);
codeableConcept2.setCoding(codingList2);
historyObservation.setCode(codeableConcept2);


List<Observation.ObservationComponentComponent> listComponent = new ArrayList<>();
List<PastIllnessDTO> pastIllnessDTOList = historyDTO.getPastIllness();
List<PastSurgeryDTO> pastSurgeryDTOList = historyDTO.getPastSurgery();
if(pastIllnessDTOList!=null && !pastIllnessDTOList.isEmpty()){
for (int j = 0; j < pastIllnessDTOList.size(); j++) {
Observation.ObservationComponentComponent observation1 = new Observation.ObservationComponentComponent();
CodeableConcept codeableConcept3 = new CodeableConcept();
List<Coding> codingList3 = new ArrayList<>();
Coding coding3 = new Coding();
coding3.setCode(pastIllnessDTOList.get(j).getIllnessTypeID());
coding3.setDisplay(pastIllnessDTOList.get(j).getIllnessType());
codingList3.add(coding3);
codeableConcept3.setCoding(codingList3);
codeableConcept3.setText("pastIllness");
observation1.setCode(codeableConcept3);
Type type = new Quantity();
if(pastIllnessDTOList.get(j).getTimePeriodAgo() !=null && !pastIllnessDTOList.get(j).getTimePeriodAgo().equals("null")){
type = new Quantity(Quantity.QuantityComparator.NULL, 0L, "", pastIllnessDTOList.get(j).getTimePeriodAgo(), pastIllnessDTOList.get(j).getTimePeriodUnit());
}
observation1.setValue(type);
listComponent.add(observation1);
}
}

if(pastSurgeryDTOList!=null && !pastSurgeryDTOList.isEmpty()){
for (int j = 0; j < pastSurgeryDTOList.size(); j++) {
Observation.ObservationComponentComponent observation2 = new Observation.ObservationComponentComponent();
CodeableConcept codeableConcept3 = new CodeableConcept();
List<Coding> codingList3 = new ArrayList<>();
Coding coding3 = new Coding();
coding3.setCode(pastSurgeryDTOList.get(j).getSurgeryID());
coding3.setDisplay(pastSurgeryDTOList.get(j).getSurgeryType());
codingList3.add(coding3);
codeableConcept3.setCoding(codingList3);
codeableConcept3.setText("pastSurgery");
observation2.setCode(codeableConcept3);
Type type = new Quantity();
if(pastSurgeryDTOList.get(j).getTimePeriodAgo() !=null && !pastSurgeryDTOList.get(j).getTimePeriodAgo().equals("null")){
type = new Quantity(Quantity.QuantityComparator.NULL, 0L, "", pastSurgeryDTOList.get(j).getTimePeriodAgo(), pastSurgeryDTOList.get(j).getTimePeriodUnit());
}
observation2.setValue(type);
listComponent.add(observation2);
}
}

historyObservation.setComponent(listComponent);

listRes.add(historyObservation);
}
}
catch (Exception e){

}

return listRes;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.iemr.hwc.fhir.service.observation;

import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastHistoryDTO;
import com.iemr.hwc.fhir.model.observation.ObservationExt;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.List;

public interface ObservationService {
ObservationExt createObservation(HttpServletRequest theRequest, ObservationExt observationExt) throws Exception;
public List<PastHistoryDTO> getBenMedHistoryByLocationAndLastModifDate(Integer providerServiceMapId, Integer vanID, Timestamp lastModifDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import com.iemr.hwc.data.anc.BenMedHistory;
import com.iemr.hwc.data.benFlowStatus.BeneficiaryFlowStatus;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastHistoryDTO;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastIllnessDTO;
import com.iemr.hwc.fhir.dto.historyDetails.pastHistory.PastSurgeryDTO;
import com.iemr.hwc.fhir.dto.mandatoryFieldsDTO.MandatoryFieldsDTO;
import com.iemr.hwc.fhir.dto.vitalDetails.VitalDetailsDTO;
import com.iemr.hwc.fhir.model.observation.ObservationExt;
import com.iemr.hwc.fhir.utils.mapper.MapperMethods;
import com.iemr.hwc.fhir.utils.mapper.MapperUtils;
import com.iemr.hwc.fhir.utils.validation.ObservationValidation;
import com.iemr.hwc.repo.benFlowStatus.BeneficiaryFlowStatusRepo;
import com.iemr.hwc.repo.nurse.anc.BenMedHistoryRepo;
import com.iemr.hwc.service.anc.Utility;
import com.iemr.hwc.service.common.transaction.CommonNurseServiceImpl;
import com.iemr.hwc.service.generalOPD.GeneralOPDServiceImpl;
import com.iemr.hwc.utils.exception.IEMRException;
Expand All @@ -26,6 +30,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ObservationServiceImpl implements ObservationService{
Expand All @@ -46,6 +54,9 @@ public class ObservationServiceImpl implements ObservationService{
@Autowired
private CommonNurseServiceImpl commonNurseService;

@Autowired
private BenMedHistoryRepo benMedHistoryRepo;

@Override
public ObservationExt createObservation(HttpServletRequest theRequest, ObservationExt observationExt) throws Exception{

Expand Down Expand Up @@ -150,4 +161,58 @@ private ObservationExt createOrUpdateHistoryFromObservation(HttpServletRequest t

return observationExt;
}

@Override
public List<PastHistoryDTO> getBenMedHistoryByLocationAndLastModifDate(Integer providerServiceMapId, Integer vanID, Timestamp lastModifDate){
List<PastHistoryDTO> pastHistoryDTOList = new ArrayList<>();
List<BenMedHistory> listHistory = benMedHistoryRepo.getBenMedHistoryByLocationAndLastModDate(providerServiceMapId, vanID, lastModifDate);
System.out.println("listHistory size "+listHistory.size());
if(listHistory != null && !listHistory.isEmpty()){
for (int i = 0; i < listHistory.size(); i++) {
PastHistoryDTO pastHistoryDTO = new PastHistoryDTO();
BenMedHistory benMedHistory = listHistory.get(i);
BeneficiaryFlowStatus beneficiaryFlowStatus = beneficiaryFlowStatusRepo.getBenFlowByVisitIDAndVisitCode(benMedHistory.getBenVisitID(), benMedHistory.getVisitCode());
if(beneficiaryFlowStatus !=null){
pastHistoryDTO.setBenFlowID(beneficiaryFlowStatus.getBenFlowID());
pastHistoryDTO.setBeneficiaryID(beneficiaryFlowStatus.getBeneficiaryID());
}
pastHistoryDTO.setId(benMedHistory.getBenMedHistoryID());
pastHistoryDTO.setVanID(benMedHistory.getVanID());
pastHistoryDTO.setParkingPlaceID(benMedHistory.getParkingPlaceID());
pastHistoryDTO.setProviderServiceMapID(benMedHistory.getProviderServiceMapID());
pastHistoryDTO.setCreatedBy(benMedHistory.getCreatedBy());
pastHistoryDTO.setBeneficiaryRegID(benMedHistory.getBeneficiaryRegID()+"");

List<PastIllnessDTO> pastIllnessDTOList = new ArrayList<>();
PastIllnessDTO illnessDTO = new PastIllnessDTO();
illnessDTO.setIllnessTypeID(benMedHistory.getIllnessTypeID()+"");
illnessDTO.setIllnessType(benMedHistory.getIllnessType());
illnessDTO.setOtherIllnessType(benMedHistory.getOtherIllnessType());
Map<String, Object> timePeriodIllness = Utility.convertTimeToWords(benMedHistory.getYearofIllness(), benMedHistory.getCreatedDate());
if(timePeriodIllness !=null){
illnessDTO.setTimePeriodAgo(timePeriodIllness.get("timePeriodAgo") +"");
illnessDTO.setTimePeriodUnit(timePeriodIllness.get("timePeriodUnit")+"");
}
pastIllnessDTOList.add(illnessDTO);
pastHistoryDTO.setPastIllness(pastIllnessDTOList);

List<PastSurgeryDTO> pastSurgeryDTOList = new ArrayList<>();
PastSurgeryDTO surgeryDTO = new PastSurgeryDTO();
surgeryDTO.setSurgeryID(benMedHistory.getSurgeryID()+"");
surgeryDTO.setSurgeryType(benMedHistory.getSurgeryType());
surgeryDTO.setOtherSurgeryType(benMedHistory.getOtherSurgeryType());
Map<String, Object> timePeriodSurgery = Utility.convertTimeToWords(benMedHistory.getYearofSurgery(), benMedHistory.getCreatedDate());
if(timePeriodSurgery!=null){
surgeryDTO.setTimePeriodAgo(timePeriodSurgery.get("timePeriodAgo")+"");
surgeryDTO.setTimePeriodUnit(timePeriodSurgery.get("timePeriodUnit")+"");
}
pastSurgeryDTOList.add(surgeryDTO);
pastHistoryDTO.setPastSurgery(pastSurgeryDTOList);

pastHistoryDTOList.add(pastHistoryDTO);
}
}

return pastHistoryDTOList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,7 @@ public int updateLabTechnicianFlag(@Param("lab_technician_flag") Short lab_techn
// get visit by location and modify_date
@Query("SELECT t from BeneficiaryFlowStatus t WHERE t.villageID = :villageID AND t.modified_date > :lastModDate ORDER BY t.visitDate DESC ")
public ArrayList<BeneficiaryFlowStatus> getVisitByLocationAndLastModifDate(@Param("villageID") Integer villageID, @Param("lastModDate") Timestamp lastModDate);

@Query("SELECT t FROM BeneficiaryFlowStatus t Where t.benVisitID = :benVisitID AND t.visitCode = :visitCode")
public BeneficiaryFlowStatus getBenFlowByVisitIDAndVisitCode(@Param("benVisitID") Long benVisitID, @Param("visitCode") Long visitCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*/
package com.iemr.hwc.repo.nurse.anc;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

Expand Down Expand Up @@ -62,4 +64,6 @@ public ArrayList<Object[]> getBenMedHistoryStatus(@Param("benRegID") Long benReg
+ " (illnessTypeID IN (11, 13, 15, 16, 17) OR surgeryID IN (5, 15, 16 )) AND deleted is false ")
public ArrayList<Long> getHRPStatus(@Param("benRegID") Long benRegID);

@Query("select v from BenMedHistory v where (v.providerServiceMapID = :providerServiceMapId OR v.vanID = :vanID) AND v.lastModDate> :lastModDate ORDER BY v.lastModDate DESC")
public List<BenMedHistory> getBenMedHistoryByLocationAndLastModDate(@Param("providerServiceMapId") Integer providerServiceMapId, @Param("vanID") Integer vanID, @Param("lastModDate") Timestamp lastModDate);
}