Created
February 1, 2019 20:03
-
-
Save daniel7byte/2d5b6aa8b54786e01adbdeb37ff052cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class pdf417 { | |
decoder(String barCode){ | |
var infoTarjeta = null; | |
if (barCode != null) { | |
var primerApellido = "", segundoApellido = "", primerNombre = "", segundoNombre = "",cedula = "",rh = "" ,fechaNacimiento = "",sexo = ""; | |
var alphaAndDigits = barCode.replaceAll("[^\\p{Alpha}\\p{Digit}\\+\\_]+", " "); | |
List<String> splitStr = alphaAndDigits.split("\\s+"); | |
if(!alphaAndDigits.contains("PubDSK")) { | |
int corrimiento = 0; | |
/*####*/ | |
Pattern pat = Pattern.compile("[A-Z]"); | |
Matcher match = pat.matcher(splitStr[2+corrimiento]); | |
int lastCapitalIndex = -1; | |
if (match.find()) { | |
lastCapitalIndex = match.start(); | |
print("match.start: " + match.start()); | |
print("match.end: " + match.end()); | |
print("splitStr: " + splitStr[2+corrimiento]); | |
print("splitStr length: " + splitStr[2+corrimiento].length; | |
print("lastCapitalIndex: " + lastCapitalIndex); | |
} | |
cedula = splitStr[2+corrimiento].substring(lastCapitalIndex-10,lastCapitalIndex); | |
primerApellido = splitStr[2+corrimiento].substring(lastCapitalIndex); | |
segundoApellido = splitStr[3+corrimiento]; | |
primerNombre = splitStr[4+corrimiento]; | |
/* Se verifica que contenga segundo nombre */ | |
if (Character.isDigit(splitStr[5+corrimiento].charAt(0))) { | |
corrimiento--; | |
} else { | |
segundoNombre=splitStr[5+corrimiento]; | |
} | |
sexo = splitStr[6+corrimiento].contains("M") ? "Masculino":"Femenino"; | |
rh = splitStr[6+corrimiento].substring(splitStr[6+corrimiento].length() - 2); | |
fechaNacimiento = splitStr[6+corrimiento].substring(2, 10); | |
} else { | |
int corrimiento=0; | |
Pattern pat = Pattern.compile("[A-Z]"); | |
if (splitStr[2+corrimiento].length()>7){ | |
corrimiento--; | |
} | |
Matcher match = pat.matcher(splitStr[3+corrimiento]); | |
int lastCapitalIndex = -1; | |
if(match.find()) { | |
lastCapitalIndex = match.start(); | |
} | |
cedula = splitStr[3+corrimiento].substring(lastCapitalIndex-10, lastCapitalIndex); | |
primerApellido = splitStr[3+corrimiento].substring(lastCapitalIndex); | |
segundoApellido = splitStr[4+corrimiento]; | |
primerNombre = splitStr[5+corrimiento]; | |
segundoNombre = splitStr[6+corrimiento]; | |
sexo = splitStr[7+corrimiento].contains("M") ? "Masculino":"Femenino"; | |
rh = splitStr[7+corrimiento].substring(splitStr[7+corrimiento].length - 2); | |
fechaNacimiento = splitStr[7+corrimiento].substring(2, 10); | |
} | |
/* Se setea el objeto con los datos */ | |
infoTarjeta['PrimerNombre'] = (primerNombre); | |
infoTarjeta['SegundoNombre'] = (segundoNombre); | |
infoTarjeta['PrimerApellido'] = (primerApellido); | |
infoTarjeta['SegundoApellido'] = (segundoApellido); | |
infoTarjeta['Cedula'] = (cedula); | |
infoTarjeta['Sexo'] = (sexo); | |
infoTarjeta['FechaNacimiento'] = (fechaNacimiento); | |
infoTarjeta['Rh'] = (rh); | |
} else { | |
print("No barcode capturado"); | |
return infoTarjeta; | |
} | |
return infoTarjeta; | |
/*####*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know what the character after the blood type is?