diff --git a/src/main/java/com/iemr/hwc/fhir/model/patient/PatientExt.java b/src/main/java/com/iemr/hwc/fhir/model/patient/PatientExt.java index 10cc2e44..1b2de31f 100644 --- a/src/main/java/com/iemr/hwc/fhir/model/patient/PatientExt.java +++ b/src/main/java/com/iemr/hwc/fhir/model/patient/PatientExt.java @@ -102,6 +102,16 @@ public class PatientExt extends Patient { @Child(name = "govtHealthProgramId") private StringType govtHealthProgramId; + @Description(shortDefinition = "Contains benFlowID ") + @Extension(url = "http://hl7.org/fhir/StructureDefinition/Patient#Patient.benFlowID", isModifier = false, definedLocally = true) + @Child(name = "benFlowID") + private StringType benFlowID; + + @Description(shortDefinition = "Contains beneficiaryRegID ") + @Extension(url = "http://hl7.org/fhir/StructureDefinition/Patient#Patient.beneficiaryRegID", isModifier = false, definedLocally = true) + @Child(name = "beneficiaryRegID") + private StringType beneficiaryRegID; + public StringType getFatherName() { if (fatherName == null) { @@ -301,12 +311,36 @@ public void setGovtHealthProgramId(StringType govtHealthProgram_Id) { govtHealthProgramId = govtHealthProgram_Id; } + public StringType getBenFlowID() { + if (benFlowID == null) { + benFlowID = new StringType(); + } + return benFlowID; + } + + public void setBenFlowID(StringType benFlow_ID) { + benFlowID = benFlow_ID; + } + + public StringType getBeneficiaryRegID() { + if (beneficiaryRegID == null) { + beneficiaryRegID = new StringType(); + } + return beneficiaryRegID; + } + + public void setBeneficiaryRegID(StringType beneficiary_RegID) { + beneficiaryRegID = beneficiary_RegID; + } + + @Override public boolean isEmpty() { return super.isEmpty() && ElementUtil.isEmpty(fatherName , spouseName , ageAtMarriage , abhaGenerationMode , providerServiceMapId , vanID , parkingPlaceID , createdBy , state , district , block , districtBranch , religion , community , - govtIdentityType , govtIdentityNo , govtHealthProgramType , govtHealthProgramId); + govtIdentityType , govtIdentityNo , govtHealthProgramType , + govtHealthProgramId, benFlowID ,beneficiaryRegID); } } diff --git a/src/main/java/com/iemr/hwc/fhir/provider/patient/PatientExtProvider.java b/src/main/java/com/iemr/hwc/fhir/provider/patient/PatientExtProvider.java index 2812d71d..fdb04def 100644 --- a/src/main/java/com/iemr/hwc/fhir/provider/patient/PatientExtProvider.java +++ b/src/main/java/com/iemr/hwc/fhir/provider/patient/PatientExtProvider.java @@ -46,7 +46,7 @@ public Class getResourceType() { @Create() - public MethodOutcome createPatient(HttpServletRequest theRequest, @ResourceParam PatientExt patientExt) { + public MethodOutcome createPatient(HttpServletRequest theRequest, @ResourceParam PatientExt patientExt) throws Exception{ MethodOutcome method = new MethodOutcome(); method.setCreated(true); @@ -85,6 +85,7 @@ public List findPatientsByDistrictAndLastModifDate(HttpServletReques patient.setVanID(new StringType(benef.getBeneficiaryDetails().getVanID()+"")); patient.setParkingPlaceID(new StringType(benef.getBeneficiaryDetails().getParkingPlaceID()+"")); + patient.setBeneficiaryRegID(new StringType(benef.getBeneficiaryDetails().getBeneficiaryRegID()+"")); patient.setCreatedBy(new StringType(benef.getCreatedBy())); Coding codingState = new Coding(); codingState.setCode(benef.getCurrentAddress().getStateId()+""); diff --git a/src/main/java/com/iemr/hwc/fhir/service/patient/PatientService.java b/src/main/java/com/iemr/hwc/fhir/service/patient/PatientService.java index 686acc53..856ed013 100644 --- a/src/main/java/com/iemr/hwc/fhir/service/patient/PatientService.java +++ b/src/main/java/com/iemr/hwc/fhir/service/patient/PatientService.java @@ -4,5 +4,5 @@ import javax.servlet.http.HttpServletRequest; public interface PatientService { - PatientExt createNewPatient(HttpServletRequest theRequest, PatientExt patientExt); + PatientExt createNewPatient(HttpServletRequest theRequest, PatientExt patientExt) throws Exception; } diff --git a/src/main/java/com/iemr/hwc/fhir/service/patient/PatientServiceImpl.java b/src/main/java/com/iemr/hwc/fhir/service/patient/PatientServiceImpl.java index 826db5e1..3c2d493d 100644 --- a/src/main/java/com/iemr/hwc/fhir/service/patient/PatientServiceImpl.java +++ b/src/main/java/com/iemr/hwc/fhir/service/patient/PatientServiceImpl.java @@ -4,11 +4,14 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.iemr.hwc.data.benFlowStatus.BeneficiaryFlowStatus; import com.iemr.hwc.fhir.dto.beneficiary.BeneficiaryDTO; import com.iemr.hwc.fhir.model.patient.PatientExt; import com.iemr.hwc.fhir.utils.mapper.MapperUtils; import com.iemr.hwc.fhir.utils.validation.PatientValidation; +import com.iemr.hwc.repo.benFlowStatus.BeneficiaryFlowStatusRepo; import com.iemr.hwc.service.registrar.RegistrarServiceImpl; +import org.hl7.fhir.r4.model.StringType; import org.mapstruct.factory.Mappers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,9 +32,12 @@ public class PatientServiceImpl implements PatientService{ @Autowired private PatientValidation validation; + @Autowired + private BeneficiaryFlowStatusRepo beneficiaryFlowStatusRepo; + @Override - public PatientExt createNewPatient(HttpServletRequest theRequest, PatientExt patientExt){ + public PatientExt createNewPatient(HttpServletRequest theRequest, PatientExt patientExt) throws Exception{ //Validating the resource for mandatory fields validation.patientResourceValidator(patientExt); @@ -47,7 +53,21 @@ public PatientExt createNewPatient(HttpServletRequest theRequest, PatientExt pat JsonObject registeredBenJson = new JsonParser().parse(registeredBeneficiary).getAsJsonObject(); String benID = registeredBenJson.getAsJsonObject("data").get("response").getAsString(); String[] arrOfResponse = benID.split(":"); - patientExt.setId(arrOfResponse[arrOfResponse.length - 1].trim()); + String beneficiaryID = arrOfResponse[arrOfResponse.length - 1].trim(); + patientExt.setId(beneficiaryID); + + BeneficiaryFlowStatus flowStatus = beneficiaryFlowStatusRepo.getFlowStatusForNewBeneficiary( + Integer.valueOf(patientExt.getProviderServiceMapId().toString()), + Integer.valueOf(patientExt.getVanID().toString()), + Long.valueOf(beneficiaryID)); + + if (flowStatus!=null){ + patientExt.setBeneficiaryRegID(new StringType(flowStatus.getBeneficiaryRegID().toString())); + patientExt.setBenFlowID(new StringType(flowStatus.getBenFlowID().toString())); + }else { + throw new InternalErrorException("Beneficiary saved successfully but encountered error while fetching beneficiary flow record"); + } + }catch (Exception e){ throw new InternalErrorException("Error occurred while saving the beneficiary."); } diff --git a/src/main/java/com/iemr/hwc/repo/benFlowStatus/BeneficiaryFlowStatusRepo.java b/src/main/java/com/iemr/hwc/repo/benFlowStatus/BeneficiaryFlowStatusRepo.java index 139126e2..39dff61a 100644 --- a/src/main/java/com/iemr/hwc/repo/benFlowStatus/BeneficiaryFlowStatusRepo.java +++ b/src/main/java/com/iemr/hwc/repo/benFlowStatus/BeneficiaryFlowStatusRepo.java @@ -451,4 +451,11 @@ 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 getVisitByLocationAndLastModifDate(@Param("villageID") Integer villageID, @Param("lastModDate") Timestamp lastModDate); + + @Query("SELECT t from BeneficiaryFlowStatus t WHERE (t.nurseFlag = 1 OR t.nurseFlag = 100) AND t.beneficiaryID = :beneficiaryID AND t.deleted = false " + + " AND t.benVisitNo = 1 AND t.providerServiceMapId = :providerServiceMapId " + + " AND t.vanID = :vanID") + public BeneficiaryFlowStatus getFlowStatusForNewBeneficiary( + @Param("providerServiceMapId") Integer providerServiceMapId, @Param("vanID") Integer vanID, + @Param("beneficiaryID") Long beneficiaryID); }