183 lines
6.7 KiB
Java
183 lines
6.7 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.qsoft.wmp.services.rest;
|
|
|
|
import com.qsoft.dao.exception.DaoException;
|
|
import com.qsoft.erp.dominio.AccionGenerica;
|
|
import com.qsoft.erp.dominio.ConsultaGenerica;
|
|
import com.qsoft.erp.dominio.exception.DominioExcepcion;
|
|
import com.qsoft.util.constantes.CodigoRespuesta;
|
|
import com.qsoft.util.constantes.ErrorTipo;
|
|
import com.qsoft.wmp.services.util.ServiceUtil;
|
|
import com.qsoft.wmp.services.xsd.EntradaRecetas;
|
|
import com.qsoft.wmp.services.xsd.SalidaConsulta;
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import javax.annotation.PostConstruct;
|
|
import javax.inject.Inject;
|
|
import javax.ws.rs.Consumes;
|
|
import javax.ws.rs.GET;
|
|
import javax.ws.rs.POST;
|
|
import javax.ws.rs.Path;
|
|
import javax.ws.rs.PathParam;
|
|
import javax.ws.rs.Produces;
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
/**
|
|
* REST Web Service
|
|
*
|
|
* @author james
|
|
*/
|
|
@Path("ServicioConvenioExterno")
|
|
public class FarmaenlaceResource {
|
|
|
|
@Inject
|
|
private ConsultaGenerica consulta;
|
|
|
|
@Inject
|
|
private AccionGenerica accion;
|
|
|
|
@PostConstruct
|
|
public void postConstructor() {
|
|
System.out.println("======> POST CONTRUCTOR " + consulta);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return an instance of java.lang.String
|
|
*/
|
|
@GET
|
|
@Path("/cedula={cedula}&diagnostico={diagnostico}")
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
public Map<String, Object> getJson(@PathParam("cedula") String cedula,
|
|
@PathParam("diagnostico") String diagnostico) {
|
|
Map<String, Object> mapFarmaenlace = new HashMap<String, Object>();
|
|
|
|
|
|
SalidaConsulta salida = null;
|
|
List resultado = null;
|
|
String message = "Mensaje OK";
|
|
Boolean status = true;
|
|
byte[] bytes = { 'c', 'd' };
|
|
String autorizacion = UUID.nameUUIDFromBytes(bytes).toString().replace("-", "");
|
|
Integer receta = 0;
|
|
if (cedula == null || cedula.trim().equals("")) {
|
|
salida = ServiceUtil.crearSalidaConsultaError(ErrorTipo.WARNING, CodigoRespuesta.CODIGO_IN_NULO, "La entrada no puede ser nula");
|
|
}else{
|
|
try {
|
|
resultado = this.consulta.consultaGet(cedula, diagnostico);
|
|
|
|
} catch (DominioExcepcion ex) {
|
|
Logger.getLogger(FarmaenlaceResource.class.getName()).log(Level.SEVERE, null, ex);
|
|
} catch (DaoException ex) {
|
|
Logger.getLogger(FarmaenlaceResource.class.getName()).log(Level.SEVERE, null, ex);
|
|
}
|
|
}
|
|
if(resultado.size()<=0){
|
|
message = "No se encontraron resultados correspondientes a la cedula ".concat(cedula);
|
|
status = false;
|
|
}
|
|
mapFarmaenlace.put("rec_titular", resultado);
|
|
Map<String, Object> mapResult = new HashMap<String, Object>();
|
|
mapResult.put("status", status);
|
|
mapResult.put("mensaje", message);
|
|
mapResult.put("autorizacion", autorizacion);
|
|
mapResult.put("receta", 0);
|
|
|
|
mapFarmaenlace.put("result", mapResult);
|
|
mapFarmaenlace.put("tipo_facturacion", "TOTAL");
|
|
|
|
return mapFarmaenlace;
|
|
/** SalidaConsulta salida = ServiceUtil.crearSalidaConsultaError(CodigoRespuesta.CODIGO_ERROR_GENERICO,
|
|
"Acción no soportada por favor ejecute la consulta via POST");*/
|
|
}
|
|
|
|
/**
|
|
* PUT method for updating or creating an instance of ConsultaResource
|
|
*
|
|
* @param entrada
|
|
* @return
|
|
*/
|
|
@POST
|
|
@Path("/Confirmacion_Datos")
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
public Map<String, Object> postJson(EntradaRecetas entrada) {
|
|
Map<String, Object> salida = null;
|
|
if (entrada == null) {
|
|
//salida = ServiceUtil.crearSalidaAccionError(ErrorTipo.WARNING, CodigoRespuesta.CODIGO_IN_NULO, "La entrada no puede ser nula");
|
|
} else {
|
|
//EntidadEnum entidad = Enum.valueOf(EntidadEnum.class, entrada.getBodyIn().getEntidad());
|
|
|
|
try {
|
|
|
|
salida = ejecutarAccionFarmaenlace(entrada);
|
|
|
|
} catch (DominioExcepcion ex) {
|
|
|
|
//salida = ServiceUtil.crearSalidaAccionError(ex.getTipo(), ex.getCodigo(), ex.getMensaje());
|
|
} catch (Exception ex) {
|
|
System.out.println("============ ERROR NO CONTROLADO ==============");
|
|
ex.printStackTrace(System.err);
|
|
String msg = getCauses(ex, new StringBuilder());
|
|
if (msg.contains("Duplicate entry")) {
|
|
//salida = ServiceUtil.crearSalidaAccionError(ErrorTipo.ERROR, CodigoRespuesta.CODIGO_ERROR_GUARDA_BDD, "Error el registro " + entrada.getBodyIn().getEntidad() + " ya existe en la Base de datos");
|
|
} else {
|
|
//salida = ServiceUtil.crearSalidaAccionError(ErrorTipo.ERROR, CodigoRespuesta.CODIGO_ERROR_GENERICO, "ERROR NO CONTROLADO: " + msg);
|
|
}
|
|
}
|
|
|
|
}
|
|
return salida;
|
|
}
|
|
/**
|
|
* @param e
|
|
* @param build
|
|
* @return
|
|
*/
|
|
private String getCauses(Throwable e, StringBuilder build) {
|
|
build.append("\n").append(e.toString());
|
|
for (Throwable t : e.getSuppressed()) {
|
|
System.out.println("SUPRESS =====> " + t);
|
|
build.append("\n").append(t.toString());
|
|
getCauses(t, build);
|
|
}
|
|
System.out.println("CAUSE =====> " + e);
|
|
if (e.getCause() != null) {
|
|
getCauses(e.getCause(), build);
|
|
}
|
|
return build.toString();
|
|
}
|
|
|
|
/**
|
|
* Ejecuta la accion
|
|
*
|
|
* @param entrada
|
|
* @param entidad
|
|
* @return
|
|
* @throws DominioExcepcion
|
|
*/
|
|
public Map<String, Object> ejecutarAccionFarmaenlace(EntradaRecetas entrada) throws DominioExcepcion {
|
|
//SalidaAccionFarmaEnlace salida = new SalidaAccionFarmaEnlace();
|
|
Map<String, Object> salida = new HashMap<String, Object>();
|
|
try {
|
|
Map<String, Object> resultado = accion.accionFarmaenlace(entrada.getReceta(), entrada.getRec_items(), entrada.getRec_facturacion(), entrada.getRec_credito(), entrada.getTipo_facturacion());
|
|
salida = ServiceUtil.crearSalidaAccionOkFarmaenlace(resultado);
|
|
|
|
} catch (Exception e) {
|
|
}
|
|
//String msg = "A continuacion se muestra el resultado de la accion.";
|
|
//HeaderMS header = entrada.getHeaderIn();
|
|
//header.setFechaHora(DominioConstantes.getDateTime());
|
|
return salida;
|
|
}
|
|
}
|