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

Refactor search sync function from PatientExtProvider to EncounterExtProvider #18

Open
wants to merge 1 commit into
base: develop
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
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
package com.iemr.hwc.fhir.provider.encounter;

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.visitDetailsMain.visitDetails.BenVisitsDTO;
import com.iemr.hwc.fhir.model.encounter.EncounterExt;
import com.iemr.hwc.fhir.service.encounter.EncounterService;
import com.iemr.hwc.service.nurse.NurseServiceImpl;
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 EncounterExtProvider implements IResourceProvider {

@Autowired
private EncounterService encounterService;

@Autowired
private NurseServiceImpl nurseServiceImpl;

@Override
public Class<? extends IBaseResource> getResourceType() {
return EncounterExt.class;
Expand All @@ -33,4 +45,69 @@ public MethodOutcome createEncounter(HttpServletRequest theRequest, @ResourcePar
method.setResource(encounterService.createNewEncounter(theRequest,encounterExt));
return method;
}

@Search()
public List<EncounterExt> findVisitsByVillageAndLastModifDate(@RequiredParam(name = Patient.SP_ADDRESS) StringParam blockID, @RequiredParam(name = "lastModif") DateParam lastModifyDate) {
List<EncounterExt> listRes = new ArrayList<>();
List<BenVisitsDTO> listVisits = nurseServiceImpl.getVisitByLocationAndLastModifDate(Integer.parseInt(blockID.getValue()), new Timestamp(lastModifyDate.getValue().getTime()));
try {
for (int i = 0; i < listVisits.size(); i++) {
BenVisitsDTO benDetails = listVisits.get(i);
EncounterExt encounter = new EncounterExt();
encounter.setId(1L+"");
encounter.setProviderServiceMapId(new StringType(benDetails.getBenVisitDetails().getProviderServiceMapID()+""));
encounter.setVanID(new StringType(benDetails.getBenVisitDetails().getVanID()+""));
encounter.setParkingPlaceID(new StringType(benDetails.getBenVisitDetails().getParkingPlaceID()+""));
encounter.setCreatedBy(new StringType(benDetails.getBenVisitDetails().getCreatedBy()));
encounter.setSessionID(new StringType(benDetails.getSessionID()+""));
encounter.setBeneficiaryID(new StringType(benDetails.getBeneficiaryID()+""));
encounter.setBenFlowID(new StringType(benDetails.getBenFlowID()+""));
encounter.setBeneficiaryRegID(new StringType(benDetails.getBenVisitDetails().getBeneficiaryRegID()+""));

String status = benDetails.getBenVisitDetails().getVisitFlowStatusFlag();
if(status !=null && status.trim().equals("N")){
encounter.setStatus(Encounter.EncounterStatus.NULL);
}

List<CodeableConcept> listConcept = new ArrayList<>();
CodeableConcept concept2 = new CodeableConcept();
List<Coding> listCoding2 = new ArrayList<>();
Coding coding2 = new Coding();
coding2.setSystem("http://snomed.info/sct");
coding2.setDisplay(benDetails.getBenVisitDetails().getVisitCategory());
listCoding2.add(coding2);
concept2.setCoding(listCoding2);
listConcept.add(concept2);
encounter.setType(listConcept);

CodeableConcept concept = new CodeableConcept();
List<Coding> listCoding = new ArrayList<>();
Coding coding = new Coding();
coding.setSystem("http://snomed.info/sct");
coding.setDisplay("Management of Common Communicable Diseases and Outpatient Care for Acute Simple Illnesses & Minor Ailments");
listCoding.add(coding);
concept.setCoding(listCoding);
encounter.setServiceType(concept);

Coding coding3 = new Coding();
coding3.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
coding3.setCode("AMB");
coding3.setDisplay("ambulatory");
encounter.setClass_(coding3);

List<CodeableConcept> listConcept2 = new ArrayList<>();
CodeableConcept concept3 = new CodeableConcept();
concept3.setText(benDetails.getBenVisitDetails().getVisitReason());
listConcept2.add(concept3);
encounter.setReasonCode(listConcept2);

listRes.add(encounter);
}
}
catch (Exception e){
e.printStackTrace();
}

return listRes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.iemr.hwc.fhir.model.patient.PatientExt;
import com.iemr.hwc.fhir.service.patient.PatientService;
import com.iemr.hwc.service.registrar.RegistrarServiceImpl;
import io.swagger.models.Contact;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.*;
import org.json.JSONArray;
Expand All @@ -16,16 +15,12 @@
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import com.google.common.reflect.TypeToken;
import com.google.gson.*;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.StringParam;
import com.iemr.hwc.fhir.model.encounter.EncounterExt;
import com.iemr.hwc.fhir.dto.visitDetailsMain.visitDetails.BenVisitsDTO;
import com.iemr.hwc.service.nurse.NurseServiceImpl;

@Component
public class PatientExtProvider implements IResourceProvider {
Expand All @@ -41,9 +36,6 @@ public Class<? extends IBaseResource> getResourceType() {
@Autowired
private RegistrarServiceImpl registrarServiceImpl;

@Autowired
private NurseServiceImpl nurseServiceImpl;


@Create()
public MethodOutcome createPatient(HttpServletRequest theRequest, @ResourceParam PatientExt patientExt) {
Expand Down Expand Up @@ -164,69 +156,4 @@ public List<PatientExt> findPatientsByDistrictAndLastModifDate(HttpServletReques

return listRes;
}

@Search()
public List<EncounterExt> findVisitsByVillageAndLastModifDate(@RequiredParam(name = "type") StringParam type, @RequiredParam(name = Patient.SP_ADDRESS) StringParam blockID, @RequiredParam(name = "lastModif") DateParam lastModifyDate) {
List<EncounterExt> listRes = new ArrayList<>();
List<BenVisitsDTO> listVisits = nurseServiceImpl.getVisitByLocationAndLastModifDate(Integer.parseInt(blockID.getValue()), new Timestamp(lastModifyDate.getValue().getTime()));
try {
for (int i = 0; i < listVisits.size(); i++) {
BenVisitsDTO benDetails = listVisits.get(i);
EncounterExt encounter = new EncounterExt();
encounter.setId(1L+"");
encounter.setProviderServiceMapId(new StringType(benDetails.getBenVisitDetails().getProviderServiceMapID()+""));
encounter.setVanID(new StringType(benDetails.getBenVisitDetails().getVanID()+""));
encounter.setParkingPlaceID(new StringType(benDetails.getBenVisitDetails().getParkingPlaceID()+""));
encounter.setCreatedBy(new StringType(benDetails.getBenVisitDetails().getCreatedBy()));
encounter.setSessionID(new StringType(benDetails.getSessionID()+""));
encounter.setBeneficiaryID(new StringType(benDetails.getBeneficiaryID()+""));
encounter.setBenFlowID(new StringType(benDetails.getBenFlowID()+""));
encounter.setBeneficiaryRegID(new StringType(benDetails.getBenVisitDetails().getBeneficiaryRegID()+""));

String status = benDetails.getBenVisitDetails().getVisitFlowStatusFlag();
if(status !=null && status.trim().equals("N")){
encounter.setStatus(Encounter.EncounterStatus.NULL);
}

List<CodeableConcept> listConcept = new ArrayList<>();
CodeableConcept concept2 = new CodeableConcept();
List<Coding> listCoding2 = new ArrayList<>();
Coding coding2 = new Coding();
coding2.setSystem("http://snomed.info/sct");
coding2.setDisplay(benDetails.getBenVisitDetails().getVisitCategory());
listCoding2.add(coding2);
concept2.setCoding(listCoding2);
listConcept.add(concept2);
encounter.setType(listConcept);

CodeableConcept concept = new CodeableConcept();
List<Coding> listCoding = new ArrayList<>();
Coding coding = new Coding();
coding.setSystem("http://snomed.info/sct");
coding.setDisplay("Management of Common Communicable Diseases and Outpatient Care for Acute Simple Illnesses & Minor Ailments");
listCoding.add(coding);
concept.setCoding(listCoding);
encounter.setServiceType(concept);

Coding coding3 = new Coding();
coding3.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
coding3.setCode("AMB");
coding3.setDisplay("ambulatory");
encounter.setClass_(coding3);

List<CodeableConcept> listConcept2 = new ArrayList<>();
CodeableConcept concept3 = new CodeableConcept();
concept3.setText(benDetails.getBenVisitDetails().getVisitReason());
listConcept2.add(concept3);
encounter.setReasonCode(listConcept2);

listRes.add(encounter);
}
}
catch (Exception e){
e.printStackTrace();
}

return listRes;
}
}