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
36 changes: 35 additions & 1 deletion src/main/java/com/iemr/hwc/fhir/model/patient/PatientExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Class<? extends IBaseResource> 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);
Expand Down Expand Up @@ -85,6 +85,7 @@ public List<PatientExt> 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()+"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BeneficiaryFlowStatus> 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);
}