package com.jasamedika.medifirst2000.controller;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jasamedika.medifirst2000.constants.Constants;
import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.IBaseRestController;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.core.web.WebConstants;
import com.jasamedika.medifirst2000.dao.MapJabatanToUraianTugasDao;
import com.jasamedika.medifirst2000.dao.MapUraianTugasToRincianKegiatanDao;
import com.jasamedika.medifirst2000.dao.PegawaiDao;
import com.jasamedika.medifirst2000.dto.EditPegawaiDTO;
import com.jasamedika.medifirst2000.entities.LoginUser;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.security.model.AppPermission;
import com.jasamedika.medifirst2000.security.service.TokenAuthenticationService;
import com.jasamedika.medifirst2000.service.KeluargaPegawaiService;
import com.jasamedika.medifirst2000.service.LoginUserService;
import com.jasamedika.medifirst2000.service.PegawaiJadwalKerjaService;
import com.jasamedika.medifirst2000.service.PegawaiService;
import com.jasamedika.medifirst2000.service.RiwayatJabatanService;
import com.jasamedika.medifirst2000.service.RiwayatPekerjaanService;
import com.jasamedika.medifirst2000.service.RiwayatPelatihanService;
import com.jasamedika.medifirst2000.service.RiwayatPendidikanService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.DateUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;
import com.jasamedika.medifirst2000.util.PasswordUtil;
import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.jasamedika.medifirst2000.vo.PegawaiJadwalKerjaVO;
import com.jasamedika.medifirst2000.vo.PegawaiVO;
import com.jasamedika.medifirst2000.vo.RegistrasiPegawaiMobileVO;
import com.jasamedika.medifirst2000.vo.RekamDataPegawaiVO;
import com.jasamedika.medifirst2000.vo.RiwayatJabatanVO;
import com.jasamedika.medifirst2000.vo.RiwayatPekerjaanVO;
import com.jasamedika.medifirst2000.vo.RiwayatPelatihanVO;
import com.jasamedika.medifirst2000.vo.RiwayatPendidikanVO;

/**
 * Controller class for Pasien Business
 * 
 * @author Roberto
 */
@RestController
@RequestMapping("/pegawai")
public class PegawaiController extends LocaleController<PegawaiVO> implements IBaseRestController<PegawaiVO> {
	//Alter by Syamsu
	@Autowired
	private LoginUserService loginUserService;
	
	@Autowired
	private TokenAuthenticationService tokenAuthenticationService;
	
	//Alter by Syamsu
	

	@Autowired
	private RiwayatPekerjaanService riwayatPekerjaanService;
	@Autowired
	private MapJabatanToUraianTugasDao mapUraianToJabatanDao;

	@Autowired
	private PegawaiDao pegawaiDao;

	@Autowired
	private MapUraianTugasToRincianKegiatanDao mapUraianTugasToRincianKegiatanDao;

	@Autowired
	private PegawaiService pegawaiService;

	@Autowired
	private KeluargaPegawaiService keluargaPegawaiService;

	@Autowired
	private RiwayatPendidikanService riwayatPendidikanService;

	@Autowired
	private RiwayatPelatihanService riwayatPelatihanService;

	@Autowired
	private RiwayatJabatanService riwayatJabatanService;
	@Autowired
	private PegawaiJadwalKerjaService pegawaiJadwalKerjaServices;

	private static final Logger LOGGER = LoggerFactory.getLogger(PegawaiController.class);

	// for example
	/*
	 * @RequestMapping(value = "/test-list", method = RequestMethod.GET) public
	 * ResponseEntity<List<PasienVO>> testList() { List<PasienVO> listPasienVO =
	 * testService.getAllPasienForContoh(); return
	 * RestUtil.getJsonResponse(listPasienVO, HttpStatus.OK); }
	 */

	// for example
	/*
	 * @RequestMapping(value = "/test-list2", method = RequestMethod.GET) public
	 * ResponseEntity<List<PasienVO>> testList2() { try { LOGGER.info(
	 * "::Calling PasienController::"); List<PasienVO> listPasienVO =
	 * testService.getAllPasienForContoh(); // add http header messages //
	 * locale ENGLISH addHeaderMessage( Constants.MessageInfo.INFO_MESSAGE,
	 * getMessage(MessageResource.LABEL_SUCCESS, Constants.Locale.EN)); //
	 * locale INDONESIA (default)
	 * addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE,
	 * getMessage(MessageResource.LABEL_ERROR));
	 * 
	 * return RestUtil.getJsonResponse(listPasienVO, HttpStatus.OK,
	 * mapHeaderMessage);
	 * 
	 * } catch (Exception ex) { LOGGER.error("Got exception {}",
	 * ex.getMessage()); addHeaderMessage( Constants.MessageInfo.ERROR_MESSAGE,
	 * getMessage(MessageResource.LABEL_ERROR, Constants.Locale.EN)); return
	 * RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR,
	 * mapHeaderMessage); } }
	 */

	// for example using EM
	// @RequestMapping(value = "/test-em", method = RequestMethod.GET)
	// public ResponseEntity<List<PurchasedTest>> testPurchased() {
	// List<PurchasedTest> listVO = pasienService.getAllPurchasedContoh();
	// return RestUtil.getJsonResponse(listVO, HttpStatus.OK);
	// }
	//
	// // for example using EM
	// @RequestMapping(value = "/test-em/{customerId}", method =
	// RequestMethod.GET)
	// public ResponseEntity<List<PurchasedTest>> testPurchasedByCustomer(
	// @PathVariable("customerId") Long customerId) {
	// List<PurchasedTest> listVO = pasienService
	// .getAllPurchasedByCustomer(customerId);
	// return RestUtil.getJsonResponse(listVO, HttpStatus.OK);
	// }

	@RequestMapping(value = "/get-all-dokter2", method = RequestMethod.GET)
	public ResponseEntity<List<PegawaiVO>> getAllDokter2(HttpServletRequest request) {
		try {
			List<PegawaiVO> listPegawaiVo = pegawaiService.getAllDokter();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}
	
//	@RequestMapping(value = "/get-all-pegawai-mapping-jabatan", method = RequestMethod.GET)
//	public ResponseEntity<List<PegawaiVO>> getAllPegawaiForMapPegawaiJabatanToUnitKerja(HttpServletRequest request) {
//		try {
//			List<PegawaiVO> listPegawaiVo = pegawaiService.findAllPegawaiForMapPegawaiJabatanToUnitKerja();
//			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
//					getMessage(MessageResource.LABEL_SUCCESS, request));
//			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
//		} catch (ServiceVOException e) {
//			LOGGER.error("Got exception {} when get-all-pegawai-mapping-jabatan", e.getMessage());
//			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
//			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
//		} catch (JpaSystemException jse) {
//			LOGGER.error("Got exception {} when get-all-pegawai-mapping-jabatanr", jse.getMessage());
//			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
//			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
//		}
//
//	}

	@RequestMapping(value = "/get-all-dokter", method = RequestMethod.GET)
	public ResponseEntity<List<PegawaiVO>> getAllDokter(
			@RequestParam(value = "kodeRuangan", required = false) String kodeRuangan,
			@RequestParam(value = "tanggal", required = false) String tanggal, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			List<PegawaiVO> listPegawaiVo = pegawaiService.getAllDokterByRuanganAndTanggal(kodeRuangan,
					DateUtil.toDate(tanggal));
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@RequestMapping(value = "/get-all-pegawai", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity</* Map<String,Object> */Collection<Pegawai>> getAllPegawai(/*
																						 * HttpServletRequest
																						 * request
																						 */
			@RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
			@RequestParam(value = "take", required = false, defaultValue = "20") Integer take,
			@RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
			@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir,
			@RequestParam(value = "id", required = false) Integer id,
			@RequestParam(value = "namaLengkap", required = false) String namaLengkap) {
		Map<String, Object> result = new HashMap<String, Object>();
		result = pegawaiService.getAllPegawai(page, take, sort, dir, id, namaLengkap);
		return constructListPageResult(result);
	}

	@RequestMapping(value = "/get-by-satuan-kerja", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String, Object>>> getAllBySatuanKerja(
			@RequestParam(value = "satuankerjaId") Integer satuanKerjaId, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			List<Map<String, Object>> listPegawaiVo = pegawaiService.getAllBySatuanKerja(satuanKerjaId);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}

	@RequestMapping(value = "/get-all-pegawai", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String, Object>>> getAllPegawai(
			@RequestParam(value = "key", required = false) String key,
			@RequestParam(value = "tanggal", required = false) String tanggal, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			List<Map<String, Object>> listPegawaiVo = pegawaiService.getAll();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@RequestMapping(value = "/get-all-perawat", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String, Object>>> getAllPerawat(
			@RequestParam(value = "key", required = false) String key,
			@RequestParam(value = "tanggal", required = false) String tanggal, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			List<Map<String, Object>> listPegawaiVo = pegawaiService
					.getAllByJenisPegawai(GetSettingDataFixed("KdJenisPegawaiParamedis"), key);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@RequestMapping(value = "/save-riwayat-pekerjaan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveRiwayatPekerjaan(@Valid @RequestBody RiwayatPekerjaanVO vo,
			HttpServletRequest request) {
		try {
			RiwayatPekerjaanVO result = riwayatPekerjaanService.add(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			RestUtil.getJsonHttptatus(HttpStatus.CREATED);
			return RestUtil.getJsonResponse("Status Sukses", HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Riwayat Pekerjaan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Riwayat Pekerjaan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@RequestMapping(value = "/save-riwayat-pelatihan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveRiwayatPelatihan(@Valid @RequestBody RiwayatPelatihanVO vo,
			HttpServletRequest request) {
		try {
			RiwayatPelatihanVO result = riwayatPelatihanService.add(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			RestUtil.getJsonHttptatus(HttpStatus.CREATED);
			return RestUtil.getJsonResponse("Status Sukses", HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Riwayat Pelatihan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Riwayat Pelatihan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@RequestMapping(value = "/save-riwayat-pendidikan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveRiwayatPendidikan(@Valid @RequestBody RiwayatPendidikanVO vo,
			HttpServletRequest request) {
		try {
			RiwayatPendidikanVO result = riwayatPendidikanService.add(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			RestUtil.getJsonHttptatus(HttpStatus.CREATED);
			return RestUtil.getJsonResponse("Status Sukses", HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Riwayat Pendidikan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Riwayat Pendidikan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@RequestMapping(value = "/save-riwayat-jabatan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> saveRiwayatJabatan(@Valid @RequestBody RiwayatJabatanVO vo,
			HttpServletRequest request) {
		try {
			RiwayatJabatanVO result = riwayatJabatanService.add(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			RestUtil.getJsonHttptatus(HttpStatus.CREATED);
			return RestUtil.getJsonResponse("Status Sukses", HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Riwayat Jabatan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Riwayat Jabatan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@RequestMapping(value = "/save-pegawai", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> addVO(@Valid @RequestBody PegawaiVO vo) {
		try {
			PegawaiVO result = pegawaiService.add(vo);

			if (null != result)
				return RestUtil.getJsonResponse("", HttpStatus.CREATED);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add pegawai", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Pegawai", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

		return RestUtil.getJsonHttptatus(HttpStatus.NOT_ACCEPTABLE);
	}

	/// Alter by Syamsu untuk edit data pegawai
	@RequestMapping(value = "/update-pegawai", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	@AppPermission(AppPermission.SPECIALS)
	public ResponseEntity<String> editVOWithPassword(@Valid @RequestBody EditPegawaiDTO vo, HttpServletRequest request) {
		try{
			Authentication authentication = tokenAuthenticationService.getAuthentication(request);
			
			String namaUser = authentication.getName();
			List<LoginUser> loginUser = loginUserService.findByNamaUser(namaUser);
			
			if (!loginUser.isEmpty()) {
				
				LoginUser user = loginUser.get(0);
				
				PasswordUtil passwordUtil = new PasswordUtil();
				
				Boolean isValidPassword = passwordUtil.isPasswordEqual(vo.getPassword(), user.getKataSandi());

				if (isValidPassword) {
					PegawaiVO result = vo.getPegawaiVO();
					return editVO(result);					
				}else{
					LOGGER.error("Got exception {} when update Pegawai, password invalid");
					addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, "Invalid Password");
					return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
				}
			} else {
				LOGGER.error("Got exception {} when update Pegawai");
				addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, "User is unauthorized");
				return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
			}
		}catch(Exception e){
			e.printStackTrace();
			LOGGER.error("Got exception {} when update Pegawai", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		}

	}

	public ResponseEntity<String> editVO(@Valid @RequestBody PegawaiVO vo) {
		try {
			PegawaiVO result = pegawaiService.update(vo);

			if (null != result) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS));
				return RestUtil.getJsonResponse("", HttpStatus.OK, mapHeaderMessage);
			}
		} catch (ServiceVOException e) {
			e.printStackTrace();
			LOGGER.error("Got exception {} when update Pegawai", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			jse.printStackTrace();
			LOGGER.error("Got exception {} when update Pegawai", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

		return RestUtil.getJsonHttptatus(HttpStatus.NOT_ACCEPTABLE);
	}

	public ResponseEntity<PegawaiVO> getVO(@PathVariable("id") Integer id) {
		PegawaiVO pegawaiVO = pegawaiService.findById(id);

		return RestUtil.getJsonResponse(pegawaiVO, HttpStatus.OK);
	}

	@RequestMapping(value = "/get-pegawai-by-nik/{nik}", method = RequestMethod.GET)
	public ResponseEntity<List<PegawaiVO>> getAllVOWithQueryString(@PathVariable("nik") String nik,
			HttpServletRequest request) {
		try {
			List<PegawaiVO> listPegawaiVO = pegawaiService.findByNik(nik);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVO, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get Asal Rujukan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get Asal Rujukan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	@Override
	public ResponseEntity<String> deleteVO(Integer id) {
		return null;
	}

	@Override
	public ResponseEntity<List<PegawaiVO>> getAllVO() {
		return null;
	}

	@Override
	public ResponseEntity<Collection<PegawaiVO>> getAllVOWithQueryString(HttpServletRequest request, Integer page,
			Integer limit, String sort, String dir) {
		return null;
	}

	@RequestMapping(value = "/get-pegawai-by-id/{id}/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getKelasByRuangan(@PathVariable("id") Integer id,
			HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			result = pegawaiService.findPegawaiById(id);
			Boolean dataFound = new Boolean((boolean) result.get("dataFound"));

			if (dataFound) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR,
						getMessage(MessageResource.LABEL_ERROR, request));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}

	@RequestMapping(value = "/get-pegawai-by-customs/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<RekamDataPegawaiVO> getPegawaiById(@PathVariable("id") Integer id) {
		// PegawaiVO pegawaiVO = pegawaiService.getPegawaiById(id);
		RekamDataPegawaiVO rekamDataPegawaiVO = pegawaiService.findRekamDataPegawaiById(id);
		return RestUtil.getJsonResponse(rekamDataPegawaiVO, HttpStatus.OK);
	}

	@RequestMapping(value = "/get-pegawai-by-ruangan/{unitKerja}/{tahun}/{bulan}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getPegawaiByRuangan(@PathVariable("unitKerja") Integer unitKerja,
			@PathVariable("tahun") Integer tahun, @PathVariable("bulan") Integer bulan, HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			result = pegawaiService.findPegawaiByRuangan(unitKerja, tahun, bulan);

			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}

	@RequestMapping(value = "/get-pegawai-by-jadwal/{tahun}/{bulan}/{pegawai}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getPegawaiByJadwal(@PathVariable("tahun") Integer tahun,
			@PathVariable("bulan") Integer bulan, @PathVariable("pegawai") Integer pegawai,
			HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			result = pegawaiService.findPegawaiByRuangan(0, tahun, bulan, pegawai);

			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}

	// @RequestMapping(value = "/get-uraian/{jabatan}", method =
	// RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	// public ResponseEntity<Map<String, Object>>
	// getUraian(@PathVariable("jabatan") Integer jabatan,
	//
	// HttpServletRequest request) {
	// Map<String, Object> result = new HashMap<>();
	// try{
	// result.put("items", JsonUtil.ToMaps(
	// mapUraianToJabatanDao.findByJabatan(jabatan)));
	//
	// mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request
	// ));
	//
	//
	//
	//
	// }catch (Exception e){
	// e.printStackTrace();
	// }
	// return RestUtil.getJsonResponse(result, HttpStatus.OK);
	// }
	//
	@RequestMapping(value = "/get-uraian/{jabatan}/{pegawai}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getUraianPegawai(@PathVariable("jabatan") Integer jabatan,
			@PathVariable("pegawai") Integer pegawai,

			HttpServletRequest request) {
		Map<String, Object> result = new HashMap<>();
		try {
			Pegawai pegawaiModel = pegawaiDao.findOne(pegawai);
			result.put("items", JsonUtil.ToMaps(mapUraianTugasToRincianKegiatanDao
					.findByMapJabatanToUraianTugasId(mapUraianToJabatanDao.findByPegawaiId(pegawai).get(0).getId())));

			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}

	@RequestMapping(value = "/get-pegawai/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getDataPegawai(HttpServletRequest request) {
		Map<String, Object> result = new HashMap<>();
		try {
			result = pegawaiService.dataAllPegawai();

			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}

	@RequestMapping(value = "/get-pegawai-by-pelaksana", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getPegawaiByPelaksana(
			@RequestParam(value = "id", required = true) Integer id, HttpServletRequest request) {
		try {
			Map<String, Object> result = pegawaiService.getPegawaiByPelaksana(id);
			if (null != result) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
				return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage);
			} else {
				return RestUtil.getJsonResponse(result, HttpStatus.NOT_FOUND, mapHeaderMessage);
			}
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getPegawaiByPelaksana", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getPegawaiByPelaksana", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}

	@RequestMapping(value = "/get-all-pegawai-no-paging/", method = RequestMethod.GET)
	public ResponseEntity<Map<String, Object>> findAllPegwawaiNoPaging(
			@RequestParam(value = "key", required = false) String key, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			Map<String, Object> listPegawaiVo = pegawaiService.findAllPegawaiNoPaging();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-all-pegawai-lain-lain/", method = RequestMethod.GET)
	public ResponseEntity<Map<String, Object>> findAllPegwawaiLainLain(
			@RequestParam(value = "key", required = false) String key, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			Map<String, Object> listPegawaiVo = pegawaiService.findAllPegawaiLainLain();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}

	@RequestMapping(value = "/get-all-pegawai-no-paging-search", method = RequestMethod.GET)
	public ResponseEntity<Map<String, Object>> findAllPegawaiNoPagingSearch(
			@RequestParam(value = "namaPegawai") String namaPegawai,
			@RequestParam(value = "idJabatan") String idJabatan,
			@RequestParam(value = "idSubUnitKerja") Integer idSubUnitKerja,HttpServletRequest request) {
		try {

			Map<String, Object> listPegawaiVo = pegawaiService.findAllPegawaiNoPagingSearch(namaPegawai, idJabatan,idSubUnitKerja);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}

	@RequestMapping(value = "/get-keluarga-pegawai", method = RequestMethod.GET)
	public ResponseEntity<Map<String, Object>> getDataKeluargaPegawai(@RequestParam(value = "id") Integer id,
			HttpServletRequest request) {
		try {

			Map<String, Object> listPegawaiVo = keluargaPegawaiService.findAllDataKeluargaPegawai(id);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}

	@RequestMapping(value = "/find-pegawai-by-id-custom/{idPegawai}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> findpegawaiByIdCustom(@PathVariable("idPegawai") Integer idPegawai,
			HttpServletRequest request) {
		Map<String, Object> result = null;
		try {

			result = pegawaiService.findPegawaiByIdCustom(idPegawai);

			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}

	@RequestMapping(value = "/get-pegawai-by-ruangan/{ruangan}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getPegawaiByRuangan(@PathVariable("ruangan") Integer ruangan,

			HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			result = pegawaiService.findPegawaiByRuangan(ruangan);

			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}
	@RequestMapping(value = "/save-all-jadwal-pegawai-rev2/", method = RequestMethod.POST)
	public ResponseEntity<Map<String, Object>> addAllVOPegawai( @RequestBody List<PegawaiJadwalKerjaVO> vos,
			HttpServletRequest request) {

		try {
			Map<String, Object> result = pegawaiJadwalKerjaServices.saveListJadwalPegawai(vos, false,false);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Catatan Perkembangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add  Catatan Perkembangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	 

	@RequestMapping(value = "/get-pegawai-by-ruangan-rev2/{subUnitKerja}/{tahun}/{bulan}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getPegawaiByRuanganrev2(@PathVariable("subUnitKerja") Integer subUnitKerja,
			@PathVariable("tahun") Integer tahun, @PathVariable("bulan") Integer bulan, HttpServletRequest request) {
		Map<String, Object> result = null;
		try {
			result = pegawaiService.findPegawaiByRuanganRev2(subUnitKerja, tahun, bulan);

			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}
	@RequestMapping(value = "/get-all-pegawai-aktif-by-ruangan/", method = RequestMethod.GET)
	public ResponseEntity<List<PegawaiVO>> getAllPegawaiAktifByRuangan(
			@RequestParam(value = "idRuangan", required = false) Integer idRuangan,
			HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			List<PegawaiVO> listPegawaiVo = pegawaiService.findAllPegawaiAktifByRuangan(idRuangan);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}
	@RequestMapping(value = "/get-pegawai-by-id-mobile/{idPegawai}", method = RequestMethod.GET)
	public ResponseEntity<Map<String,Object>> getPegawaiByIdForMobile(
			@PathVariable("idPegawai")   Integer idPegawai,
			HttpServletRequest request) {
		try {
			
			Map<String,Object> pegawai = pegawaiService.getPegawaiByIdMobile(idPegawai);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawai, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}
	
	@RequestMapping(value = "/get-pegawai-with-username-by-id/{id}", method = RequestMethod.GET)
	public ResponseEntity<Map<String,Object>> getPegawaiWithNamaUserById(@PathVariable("id") Integer id, HttpServletRequest request) {
		
		try {
			Map<String,Object> pegawai = pegawaiService.getPegawaiWithNamaUserById(id);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawai, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getPegawaiWithNamaUserById", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getPegawaiWithNamaUserById", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/save-registrasi-pegawai-mobile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> SaveRegistrasiPegawaiMobile(@RequestBody RegistrasiPegawaiMobileVO vo,
			HttpServletRequest request) {
		try {
			SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");

			String result = pegawaiService.SaveRegistrasiPegawaiMobile(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Pasien", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Pasien", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}	
	
	@RequestMapping(value = "/get-tgl-pensiun/{tglLahir}/{idjabatan}", method = RequestMethod.GET)
	public ResponseEntity<Map<String,Object>> getPegawaiByIdForMobile(
			@PathVariable("idjabatan")   Integer idjabatan,@PathVariable("tglLahir")   String tglLahir,
			HttpServletRequest request) {
		try {
			
			Map<String,Object> tglpensiun = pegawaiService.getTglpensiun(tglLahir, idjabatan);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(tglpensiun, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}
	
	@RequestMapping(value = "/non-aktif-pegawai-by-id/{id}/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> deletePegawai(@PathVariable("id") Integer id,
			HttpServletRequest request) {
		Map<String,Object> result = null;
		try {
			result = pegawaiService.nonAktifPegawai(id);
			
			if (CommonUtil.isNotNullOrEmpty(result)) {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			} else {
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_ERROR,
						getMessage(MessageResource.LABEL_ERROR, request));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return RestUtil.getJsonResponse(result, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/get-pegawai-pensiun/{startPeriode}/{endPeriode}", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getPegawaiPensiun(
			@PathVariable("startPeriode")   String startPeriode,@PathVariable("endPeriode")   String endPeriode,
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> tglpensiun = pegawaiService.getPegawaiYgAkanPensiun(startPeriode, endPeriode);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(tglpensiun, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	@RequestMapping(value = "/get-pegawai-by-sub-Unit-kerja/{idSubUnitKerja}", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getPegawaiPensiun(
			@PathVariable("idSubUnitKerja")   Integer idSubUnitKerja,
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> tglpensiun = pegawaiService.getpegawaiByUnitkerja(idSubUnitKerja);
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(tglpensiun, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-pegawai-str-expired", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getPegawaiStrExpired(			
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> pegawais = pegawaiService.getpegawaiStrExpired();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawais, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-pegawai-sip-expired", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getPegawaiSipExpired(			
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> pegawais = pegawaiService.getpegawaiSipExpired();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawais, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-count-pegawai-by-unit-kerja", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getCountPegawaiByUnitKerja(			
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> pegawais = pegawaiService.getpegawaiByUnitKerja();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawais, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-count-pegawai-by-kelompok-jabatan", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getCountPegawaiByKelompokJabatan(			
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> pegawais = pegawaiService.getpegawaiByKelompokJabatan();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawais, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-count-pegawai-by-status-pegawai", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getCountPegawaiByStatusPegawai(			
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> pegawais = pegawaiService.getpegawaiByStatusPegawai();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawais, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-count-pegawai-by-jk", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String,Object>>> getCountPegawaiByJK(			
			HttpServletRequest request) {
		try {
			
			List<Map<String,Object>> pegawais = pegawaiService.getpegawaiByJenisKelamin();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(pegawais, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when getAllPegawaiAktifByRuangan", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-pegawai-meninggal-pindah-pensiun-no-paging/", method = RequestMethod.GET)
	public ResponseEntity<Map<String, Object>> findPegawaiMeninggalPindahPensiunNoPaging(
			@RequestParam(value = "key", required = false) String key, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			Map<String, Object> listPegawaiVo = pegawaiService.findPegawaiMeninggalPindahPensiunNoPaging();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-pegawai-outsourcing/", method = RequestMethod.GET)
	public ResponseEntity<Map<String, Object>> findPegawaiOutSourcingNoPaging(
			@RequestParam(value = "key", required = false) String key, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			Map<String, Object> listPegawaiVo = pegawaiService.findPegawaiOutSourcingNoPaging();
			
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-all-pegawai-custom/", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String, Object>>> findAllPegawaiCustom(
			@RequestParam(value = "key", required = false) String key, HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			List<Map<String, Object>> listPegawaiVo = pegawaiService.getAllPegawaiCustom();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawaiVo, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	@RequestMapping(value = "/get-all-pegawai-kepala-ruangan", method = RequestMethod.GET)
	public ResponseEntity<List<Map<String, Object>>> findAllPegawaiKepalaRuangan(
			 HttpServletRequest request) {
		try {

			// long tgl=Date.parse(tanggal);
			List<Map<String, Object>> listPegawai = pegawaiService.getAllKepalaRuangan();
			mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
					getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(listPegawai, HttpStatus.OK, mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when get all dokter", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when get all dokter", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
}
