Update pasien task
Perbaikan scheduler update nik peserta bpjs
This commit is contained in:
parent
7c1011ff48
commit
d0a3b67d6c
@ -113,7 +113,6 @@ public interface PasienDao extends JpaRepository<Pasien, Integer> {
|
||||
@Query(value = "select ps.* " + "from pasien_m ps " + "where ps.statusenabled is true "
|
||||
+ "and (ps.nobpjs is not null " + "and trim(ps.nobpjs) <> '' " + "and ps.nobpjs <> '-' "
|
||||
+ "and ps.nobpjs ~ '[0-9]+' " + "and length(ps.nobpjs) = 13) " + "and (ps.noidentitas is null "
|
||||
+ "or length(ps.noidentitas) <> 16) "
|
||||
+ "order by ps.statusenabled, ps.tgldaftar desc limit 300", nativeQuery = true)
|
||||
+ "or length(ps.noidentitas) <> 16) " + "order by ps.statusenabled, ps.tgldaftar desc", nativeQuery = true)
|
||||
List<Pasien> findByValidBpjs();
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jasamedika.medifirst2000.dao.PasienDao;
|
||||
import com.jasamedika.medifirst2000.dto.PesertaBpjsDto;
|
||||
import com.jasamedika.medifirst2000.entities.Pasien;
|
||||
import com.jasamedika.medifirst2000.exception.ServiceVOException;
|
||||
import com.jasamedika.medifirst2000.util.CommonUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -18,6 +18,7 @@ import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -44,28 +45,31 @@ public class PasienTask {
|
||||
|
||||
@Scheduled(fixedRate = 1000 * 60 * 60 * 24)
|
||||
public void nikPesertaBpjs() {
|
||||
LOGGER.info("Start task PasienTask.nikPesertaBpjs {}", LocalDateTime.now());
|
||||
LOGGER.info("Task PasienTask.nikPesertaBpjs {}", LocalDateTime.now());
|
||||
|
||||
adjustNikPesertaBpjs();
|
||||
|
||||
LOGGER.info("End task PasienTask.nikPesertaBpjs {}", LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
private void adjustNikPesertaBpjs() {
|
||||
try {
|
||||
LOGGER.info("Start adjusting NIK Peserta BPJS {}", LocalDateTime.now());
|
||||
LOGGER.info("Adjusting NIK Peserta BPJS {}", LocalDateTime.now());
|
||||
|
||||
List<Pasien> listPasien = new ArrayList<>();
|
||||
List<Pasien> pasienValidBpjs = pasienDao.findByValidBpjs();
|
||||
for (Pasien pasien : pasienValidBpjs) {
|
||||
PesertaBpjsDto pesertaBpjsDto = cekKepesertaan(pasien.getNoBpjs());
|
||||
pasien.setNoIdentitas(pesertaBpjsDto.getNik());
|
||||
if (pesertaBpjsDto != null) {
|
||||
Pasien pasien_ = new Pasien();
|
||||
pasien_.setId(pasien.getId());
|
||||
pasien_.setNoIdentitas(pesertaBpjsDto.getNik());
|
||||
listPasien.add(pasien_);
|
||||
}
|
||||
|
||||
Thread.sleep((long) (Math.random() * 1000 * 60 * 5));
|
||||
Thread.sleep((long) (Math.random() * 1000 * 8));
|
||||
}
|
||||
pasienDao.save(pasienValidBpjs);
|
||||
|
||||
LOGGER.info("End adjusting NIK Peserta BPJS {}", LocalDateTime.now());
|
||||
if (CommonUtil.isNotNullOrEmpty(listPasien))
|
||||
pasienDao.save(listPasien);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error adjusting NIK Peserta BPJS {}", e.getMessage());
|
||||
}
|
||||
@ -73,7 +77,7 @@ public class PasienTask {
|
||||
|
||||
private PesertaBpjsDto cekKepesertaan(String noKartu) {
|
||||
try {
|
||||
LOGGER.info("Start cek kepesertaan BPJS {} {}", noKartu, LocalDateTime.now());
|
||||
LOGGER.info("Cek kepesertaan BPJS {} {}", noKartu, LocalDateTime.now());
|
||||
|
||||
URI uri = new URI("https://daftar.rsabhk.co.id/api/data/pasien/jaminan/bpjs/cek-kepesertaan/" + noKartu);
|
||||
HttpEntity<Object> request = new HttpEntity<>(null);
|
||||
@ -84,21 +88,14 @@ public class PasienTask {
|
||||
HashMap.class);
|
||||
Map<String, Object> responsePeserta = objectMapper.convertValue(responseMap.get("peserta"),
|
||||
HashMap.class);
|
||||
|
||||
LOGGER.info("End cek kepesertaan BPJS {} {}", noKartu, LocalDateTime.now());
|
||||
|
||||
return PesertaBpjsDto.builder().noKartu(responsePeserta.get("noKartu").toString())
|
||||
.nik(responsePeserta.get("nik").toString()).build();
|
||||
} else {
|
||||
LOGGER.error("Error handshake cek kepesertaan BPJS {}", response.getStatusCode().getReasonPhrase());
|
||||
|
||||
throw new ServiceVOException(
|
||||
"Error cek kepesertaan BPJS " + response.getStatusCode().getReasonPhrase());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error cek kepesertaan BPJS {}", e.getMessage());
|
||||
|
||||
throw new ServiceVOException("Error cek kepesertaan BPJS " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user