LifeCenterFunction.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. package com.lemon.lifecenter.common;
  2. import java.io.BufferedReader;
  3. import java.io.BufferedWriter;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.io.OutputStreamWriter;
  9. import java.io.PrintWriter;
  10. import java.io.UnsupportedEncodingException;
  11. import java.net.HttpURLConnection;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.net.URLDecoder;
  15. import java.net.URLEncoder;
  16. import java.security.MessageDigest;
  17. import java.security.NoSuchAlgorithmException;
  18. import java.security.spec.AlgorithmParameterSpec;
  19. import java.text.DateFormat;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.ArrayList;
  23. import java.util.Base64;
  24. import java.util.Calendar;
  25. import java.util.Date;
  26. import java.util.GregorianCalendar;
  27. import java.util.HashMap;
  28. import java.util.Iterator;
  29. import java.util.Map;
  30. import java.util.Random;
  31. import java.util.UUID;
  32. import java.util.regex.Matcher;
  33. import java.util.regex.Pattern;
  34. import javax.crypto.Cipher;
  35. import javax.crypto.Mac;
  36. import javax.crypto.spec.IvParameterSpec;
  37. import javax.crypto.spec.SecretKeySpec;
  38. import javax.servlet.http.HttpServletRequest;
  39. import javax.servlet.http.HttpServletResponse;
  40. import org.json.JSONArray;
  41. import org.json.JSONException;
  42. import org.json.JSONObject;
  43. import org.slf4j.Logger;
  44. import org.slf4j.LoggerFactory;
  45. import com.lemon.lifecenter.dto.PatientDTO;
  46. public class LifeCenterFunction {
  47. public static String setURLEncode(String content, String lngType) throws UnsupportedEncodingException {
  48. return URLEncoder.encode(content, lngType);
  49. }
  50. public static String setURLDecode(String content, String lngType) throws UnsupportedEncodingException {
  51. return URLDecoder.decode(content, lngType);
  52. }
  53. public static String aesEncrypt(String encKey, byte[] iv, String paramInput) throws Exception {
  54. Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
  55. SecretKeySpec key = new SecretKeySpec(encKey.getBytes("UTF-8"), "AES");
  56. cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
  57. byte[] cipherText = cipher.doFinal(paramInput.getBytes("UTF-8"));
  58. return Base64.getEncoder().encodeToString(cipherText);
  59. }
  60. /**
  61. * sha256 passwd encrypt
  62. * @author jksong
  63. * @Param
  64. **/
  65. public static String sha256Encrypt(String str) {
  66. String SHA = "";
  67. try {
  68. MessageDigest sh = MessageDigest.getInstance("SHA-256");
  69. sh.update(str.getBytes());
  70. byte byteData[] = sh.digest();
  71. StringBuffer sb = new StringBuffer();
  72. for (int i = 0; i < byteData.length; i++) {
  73. sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
  74. }
  75. SHA = sb.toString();
  76. } catch (NoSuchAlgorithmException e) {
  77. e.printStackTrace();
  78. SHA = null;
  79. }
  80. return SHA;
  81. }
  82. public static String aesDecrypt(String encKey, byte[] iv, String paramInput) throws Exception {
  83. byte[] textBytes = Base64.getDecoder().decode(paramInput);
  84. AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv);
  85. SecretKeySpec newKey = new SecretKeySpec(encKey.getBytes("UTF-8"), "AES");
  86. Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
  87. cipher.init(Cipher.DECRYPT_MODE, newKey, ivSpec);
  88. return new String(cipher.doFinal(textBytes), "UTF-8");
  89. }
  90. public static ArrayList<HashMap<String, String>> parseJSON(String jsonString) {
  91. ArrayList<HashMap<String, String>> rtn = new ArrayList<HashMap<String, String>>();
  92. try {
  93. JSONArray array = new JSONArray(jsonString);
  94. for (int i = 0; i < array.length(); i++) {
  95. HashMap<String, String> map = new HashMap<String, String>();
  96. JSONObject object = array.getJSONObject(i);
  97. Iterator<?> keys = object.keys();
  98. while (keys.hasNext()) {
  99. String key = (String) keys.next();
  100. String val = "";
  101. if (object.isNull(key)) {
  102. val = "";
  103. } else {
  104. if (object.get(key) instanceof Integer) {
  105. val = String.valueOf(object.getInt(key));
  106. } else if (object.get(key) instanceof Long) {
  107. val = String.valueOf(object.getLong(key));
  108. } else if (object.get(key) instanceof Double) {
  109. val = String.valueOf(object.getDouble(key));
  110. } else {
  111. val = object.getString(key).equals(null) ? "" : object.getString(key);
  112. }
  113. }
  114. map.put(key, val);
  115. }
  116. rtn.add(i, map);
  117. map = null;
  118. }
  119. } catch (JSONException e) {
  120. e.printStackTrace();
  121. }
  122. return rtn;
  123. }
  124. public static int getAgeFromBirthday(String jumin) throws ParseException {
  125. SimpleDateFormat transFormat = new SimpleDateFormat("yyyyMMdd");
  126. Date birthday = transFormat.parse(jumin);
  127. Calendar birth = new GregorianCalendar();
  128. Calendar today = new GregorianCalendar();
  129. birth.setTime(birthday);
  130. today.setTime(new Date());
  131. int factor = 0;
  132. if (today.get(Calendar.DAY_OF_YEAR) < birth.get(Calendar.DAY_OF_YEAR)) {
  133. factor = -1;
  134. }
  135. return today.get(Calendar.YEAR) - birth.get(Calendar.YEAR) + factor;
  136. }
  137. public static String getRandomUUID() {
  138. return UUID.randomUUID().toString().replaceAll("-", "");
  139. }
  140. public static String exportOnlyNumber(String input) {
  141. return input.replaceAll("[^0-9?!\\.]", "");
  142. }
  143. public static String getNow() {
  144. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  145. Date date = new Date();
  146. return dateFormat.format(date);
  147. }
  148. public static String getPrevMonth( String ym ) throws ParseException {
  149. DateFormat df = new SimpleDateFormat( "yyyy-MM" );
  150. Date date = df.parse( ym );
  151. Calendar cal = Calendar.getInstance();
  152. cal.setTime( date );
  153. cal.add( Calendar.MONTH, -1 );
  154. return df.format( cal.getTime() );
  155. }
  156. public static String getNextMonth( String ym ) throws ParseException {
  157. DateFormat df = new SimpleDateFormat( "yyyy-MM" );
  158. Date date = df.parse( ym );
  159. Calendar cal = Calendar.getInstance();
  160. cal.setTime( date );
  161. cal.add( Calendar.MONTH, +1 );
  162. return df.format( cal.getTime() );
  163. }
  164. public static String getPrevNextDate( String ymd, int val ) throws ParseException {
  165. DateFormat df = new SimpleDateFormat( "yyyy-MM-dd" );
  166. Date date = df.parse( ymd );
  167. Calendar cal = Calendar.getInstance();
  168. cal.setTime( date );
  169. cal.add( Calendar.DATE, val );
  170. return df.format( cal.getTime() );
  171. }
  172. public static String getPrevDate( String ymd ) throws ParseException {
  173. DateFormat df = new SimpleDateFormat( "yyyy-MM-dd" );
  174. Date date = df.parse( ymd );
  175. Calendar cal = Calendar.getInstance();
  176. cal.setTime( date );
  177. cal.add( Calendar.DATE, -1 );
  178. return df.format( cal.getTime() );
  179. }
  180. public static String getNextDate( String ymd ) throws ParseException {
  181. DateFormat df = new SimpleDateFormat( "yyyy-MM-dd" );
  182. Date date = df.parse( ymd );
  183. Calendar cal = Calendar.getInstance();
  184. cal.setTime( date );
  185. cal.add( Calendar.DATE, +1 );
  186. return df.format( cal.getTime() );
  187. }
  188. public static String getNow(String format) {
  189. DateFormat dateFormat = new SimpleDateFormat(format);
  190. Date date = new Date();
  191. return dateFormat.format(date);
  192. }
  193. /**
  194. * 시간 더하기 빼기
  195. * @author jksong
  196. * @Param
  197. **/
  198. public static String addDate(String fromDate, String format, int addYear, int addMonth, int addDate, int addHour, int addMinute) {
  199. SimpleDateFormat sdf = new SimpleDateFormat(format);
  200. Date date = null;
  201. try {
  202. date = sdf.parse(fromDate);
  203. Calendar cal = new GregorianCalendar();
  204. cal.setTime(date);
  205. cal.add(Calendar.YEAR, +addYear);
  206. cal.add(Calendar.MONTH, +addMonth);
  207. cal.add(Calendar.DATE, +addDate);
  208. cal.add(Calendar.HOUR, +addHour);
  209. cal.add(Calendar.MINUTE, +addMinute);
  210. // cal.add(Calendar.SECOND, +addSecond);
  211. SimpleDateFormat sdf2 = new SimpleDateFormat(format);
  212. String toDate = sdf2.format(cal.getTime());
  213. return toDate;
  214. } catch (ParseException e) {
  215. e.printStackTrace();
  216. }
  217. return "";
  218. }
  219. public static String getFullURL(HttpServletRequest request) {
  220. StringBuilder requestURL = new StringBuilder(request.getRequestURL().toString());
  221. String queryString = request.getQueryString();
  222. if (queryString == null) {
  223. return requestURL.toString();
  224. } else {
  225. return requestURL.append('?').append(queryString).toString();
  226. }
  227. }
  228. public static String changeJuminToBirthday(String dateStr) {
  229. String resDate = "";
  230. try {
  231. SimpleDateFormat df = new SimpleDateFormat("yyyymmdd");
  232. Date date = date = df.parse(dateStr);
  233. SimpleDateFormat df1 = new SimpleDateFormat("yyyy-mm-dd");
  234. resDate = df1.format(date);
  235. } catch (ParseException e) {
  236. e.printStackTrace();
  237. }
  238. return resDate;
  239. }
  240. public static String removeStringChar(String str, String c) {
  241. str = str.replace(c, "");
  242. return str;
  243. }
  244. public static boolean validationDate(String checkDate){
  245. try{
  246. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  247. dateFormat.setLenient(false);
  248. dateFormat.parse(checkDate);
  249. return true;
  250. }catch (ParseException e){
  251. return false;
  252. }
  253. }
  254. public static long getNowUnixTimeStamp() {
  255. return System.currentTimeMillis() / 1000;
  256. }
  257. public static long setFormatUnixTimeStamp(String data) {
  258. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  259. long timeStamp = 0;
  260. try {
  261. long time = dateFormat.parse(data).getTime();
  262. timeStamp = time / 1000;
  263. } catch (ParseException e) {
  264. e.printStackTrace();
  265. }
  266. return timeStamp;
  267. }
  268. public static String setFormatDateFromUnixTimeStamp(Date data) {
  269. SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  270. return transFormat.format(data);
  271. }
  272. public static String getRandomNumber(int maxSize) {
  273. Random rand = new Random();
  274. String code = "";
  275. for (int i = 0; i < maxSize; i++) {
  276. code += rand.nextInt(9);
  277. }
  278. return code;
  279. }
  280. public static void scriptMessage(HttpServletResponse response, String script) {
  281. response.setContentType("text/html; charset=UTF-8");
  282. PrintWriter out;
  283. try {
  284. out = response.getWriter();
  285. out.println("<script>window.onload = function(){" + script + "}</script>");
  286. out.flush();
  287. } catch (IOException e) {
  288. e.printStackTrace();
  289. }
  290. }
  291. public static String getRemoteAddr(HttpServletRequest request) {
  292. String ip = request.getHeader("X-Forwarded-For");
  293. if (ip == null) {
  294. ip = request.getHeader("Proxy-Client-IP");
  295. }
  296. if (ip == null) {
  297. ip = request.getHeader("WL-Proxy-Client-IP");
  298. }
  299. if (ip == null) {
  300. ip = request.getHeader("HTTP_CLIENT_IP");
  301. }
  302. if (ip == null) {
  303. ip = request.getHeader("HTTP_X_FORWARDED_FOR");
  304. }
  305. if (ip == null) {
  306. ip = request.getRemoteAddr();
  307. }
  308. return ip;
  309. }
  310. /**
  311. * 숫자만 입력되었는지 체크
  312. * @param s
  313. * @return
  314. */
  315. public static boolean isIntegerNumeric(String s) {
  316. try {
  317. Integer.parseInt(s);
  318. return true;
  319. } catch(NumberFormatException e) {
  320. return false;
  321. }
  322. }
  323. public static String setPhoneFormat(String number) {
  324. StringBuilder sb = new StringBuilder(15);
  325. StringBuilder temp = new StringBuilder(number);
  326. int tempLength = temp.length();
  327. if (tempLength == 3) {
  328. sb.append(number);
  329. } else {
  330. while (tempLength < 10) {
  331. temp.insert(0, "0");
  332. }
  333. char[] chars = temp.toString().toCharArray();
  334. int size = chars.length;
  335. if (size < 11) {
  336. for (int i = 0; i < size; i++) {
  337. if (i == 3) {
  338. sb.append("-");
  339. } else if (i == 6) {
  340. sb.append("-");
  341. }
  342. sb.append(chars[i]);
  343. }
  344. } else {
  345. for (int i = 0; i < size; i++) {
  346. if (i == 3) {
  347. sb.append("-");
  348. } else if (i == 7) {
  349. sb.append("-");
  350. }
  351. sb.append(chars[i]);
  352. }
  353. }
  354. }
  355. return sb.toString();
  356. }
  357. public static String removeTag(String html) throws Exception {
  358. return html.replaceAll("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>", "");
  359. }
  360. public static String getSalt() {
  361. String uniqId = "";
  362. Random randomGenerator = new Random();
  363. // length - set the unique Id length
  364. for (int length = 1; length <= 10; ++length) {
  365. int randomInt = randomGenerator.nextInt(10); // digit range from 0 - 9
  366. uniqId += randomInt + "";
  367. }
  368. return uniqId;
  369. }
  370. public static String getTimestamp() {
  371. long timestamp_long = System.currentTimeMillis() / 1000;
  372. String timestamp = Long.toString(timestamp_long);
  373. return timestamp;
  374. }
  375. private static final Logger logger = LoggerFactory.getLogger(LifeCenterFunction.class);
  376. public static String getSignature(String apiSecret, String salt, String timestamp) throws Exception {
  377. String signature = "";
  378. try {
  379. String temp = timestamp + salt;
  380. SecretKeySpec keySpec = new SecretKeySpec(apiSecret.getBytes(), "HmacSHA256");
  381. Mac mac = Mac.getInstance("HmacSHA256");
  382. mac.init(keySpec);
  383. // 바이너리를 hex로 변환
  384. byte[] result = mac.doFinal(temp.getBytes());
  385. char[] hexArray = "0123456789ABCDEF".toCharArray();
  386. char[] hexChars = new char[result.length * 2];
  387. for (int i = 0; i < result.length; i++) {
  388. int positive = result[i] & 0xff;
  389. hexChars[i * 2] = hexArray[positive >>> 4];
  390. hexChars[i * 2 + 1] = hexArray[positive & 0x0F];
  391. }
  392. signature = new String(hexChars);
  393. } catch (Exception e) {
  394. e.printStackTrace();
  395. }
  396. return signature.toLowerCase();
  397. }
  398. public static String httpUrlConnection(String apiUrl, HashMap<String, String> hash) {
  399. String result = "";
  400. URL url;
  401. try {
  402. url = new URL(apiUrl);
  403. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  404. conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  405. conn.setRequestProperty("Accept", "application/json");
  406. conn.setRequestMethod("POST"); // post방식 통신
  407. conn.setDoOutput(true); // 쓰기모드 지정
  408. conn.setDoInput(true); // 읽기모드 지정
  409. conn.setUseCaches(false); // 캐싱데이터를 받을지 안받을지
  410. conn.setDefaultUseCaches(false); // 캐싱데이터 디폴트 값 설정
  411. conn.setReadTimeout(10000); // 타임아웃 10초
  412. OutputStream os = conn.getOutputStream(); // 서버로 보내기 위한 출력 스트림
  413. BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); // UTF-8로 전송
  414. bw.write(getPostString(hash)); // 매개변수 전송
  415. bw.flush();
  416. bw.close();
  417. os.close();
  418. InputStream is = conn.getInputStream(); //데이타를 받기위 구멍을 열어준다
  419. StringBuilder builder = new StringBuilder(); //문자열을 담기 위한 객체
  420. BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8")); //문자열 셋 세팅
  421. String line;
  422. while ((line = reader.readLine()) != null) {
  423. builder.append(line+ "\n");
  424. }
  425. // logger.error("httpUrlConnection Result -- > " + builder.toString());
  426. result = builder.toString();
  427. conn.disconnect();
  428. } catch (MalformedURLException e) {
  429. // TODO Auto-generated catch block
  430. e.printStackTrace();
  431. } catch (IOException e) {
  432. // TODO Auto-generated catch block
  433. e.printStackTrace();
  434. }
  435. return result;
  436. }
  437. public static String httpUrlCon(String apiUrl, String param) {
  438. String result = "";
  439. URL url;
  440. try {
  441. url = new URL(apiUrl);
  442. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  443. // conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  444. conn.setRequestProperty("Content-Type", "application/json;utf-8");
  445. conn.setRequestProperty("Accept", "application/json");
  446. conn.setRequestMethod("POST"); // post방식 통신
  447. conn.setDoOutput(true); // 쓰기모드 지정
  448. conn.setDoInput(true); // 읽기모드 지정
  449. conn.setUseCaches(false); // 캐싱데이터를 받을지 안받을지
  450. conn.setDefaultUseCaches(false); // 캐싱데이터 디폴트 값 설정
  451. conn.setReadTimeout(10000); // 타임아웃 10초
  452. OutputStream os = conn.getOutputStream(); // 서버로 보내기 위한 출력 스트림
  453. byte[] input = param.getBytes("utf-8");
  454. os.write(input, 0, input.length);
  455. os.close();
  456. InputStream is = conn.getInputStream(); //데이타를 받기위 구멍을 열어준다
  457. StringBuilder builder = new StringBuilder(); //문자열을 담기 위한 객체
  458. BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8")); //문자열 셋 세팅
  459. String line;
  460. while ((line = reader.readLine()) != null) {
  461. builder.append(line+ "\n");
  462. }
  463. // logger.error("httpUrlConnection Result -- > " + builder.toString());
  464. result = builder.toString();
  465. conn.disconnect();
  466. } catch (MalformedURLException e) {
  467. // TODO Auto-generated catch block
  468. e.printStackTrace();
  469. } catch (IOException e) {
  470. // TODO Auto-generated catch block
  471. e.printStackTrace();
  472. }
  473. return result;
  474. }
  475. private static String getPostString(HashMap<String, String> map) {
  476. StringBuilder result = new StringBuilder();
  477. boolean first = true; // 첫 번째 매개변수 여부
  478. for (Map.Entry<String, String> entry : map.entrySet()) {
  479. if (first)
  480. first = false;
  481. else // 첫 번째 매개변수가 아닌 경우엔 앞에 &를 붙임
  482. result.append("&");
  483. try { // UTF-8로 주소에 키와 값을 붙임
  484. result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
  485. result.append("=");
  486. result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
  487. } catch (UnsupportedEncodingException ue) {
  488. ue.printStackTrace();
  489. } catch (Exception e) {
  490. e.printStackTrace();
  491. }
  492. }
  493. return result.toString();
  494. }
  495. public static String phone(String src) {
  496. if (src == null) {
  497. return "";
  498. }
  499. if (src.length() == 8) {
  500. return src.replaceFirst("^([0-9]{4})([0-9]{4})$", "$1-$2");
  501. } else if (src.length() == 12) {
  502. return src.replaceFirst("(^[0-9]{4})([0-9]{4})([0-9]{4})$", "$1-$2-$3");
  503. }
  504. return src.replaceFirst("(^02|[0-9]{3})([0-9]{3,4})([0-9]{4})$", "$1-$2-$3");
  505. }
  506. public static String getDisease(PatientDTO dto) {
  507. String highBloodPressureCheck = dto.getHighBloodPressureCheck().equals("Y") ? "고혈압" : "";
  508. String lowBloodPressureCheck = dto.getLowBloodPressureCheck().equals("Y") ? "저혈압" : "";
  509. String organTransplantCheck = dto.getOrganTransplantCheck().equals("Y") ? "장기이식(신장, 간 등)" : "";
  510. String diabetesCheck = dto.getDiabetesCheck().equals("Y") ? "당뇨" : "";
  511. String respiratoryDiseaseCheck = dto.getRespiratoryDiseaseCheck().equals("Y") ? "호흡기질환" : "";
  512. String immunologicalDiseaseCheck = dto.getImmunologicalDiseaseCheck().equals("Y") ? "면역질환(류마티스 등)" : "";
  513. String heartDisease = dto.getHeartDisease().equals("Y") ? "심장질환" : "";
  514. String liverDisease = dto.getLiverDisease().equals("Y") ? "간질환" : "";
  515. String operation = dto.getOperation().equals("Y") ? "수술(" + dto.getOperationContent() + ")" : "";
  516. String allergyCheck = dto.getAllergyCheck().equals("Y") ? "알레르기" : "";
  517. String kidneyDisease = dto.getKidneyDisease().equals("Y") ? "신장질환" : "";
  518. String cancerName = dto.getCancerName() == null ? "" : "(" + dto.getCancerName() + ")";
  519. String cancerCheck = dto.getCancerCheck().equals("Y") ? "암" + cancerName : "";
  520. String etcContent = dto.getEtcContentDisease() == null ? "" : dto.getEtcContentDisease();
  521. String ectCheckDisease = dto.getEtcCheckDisease().equals("Y") ? "기타(" + etcContent + ")" : "";
  522. ArrayList<String> disease = new ArrayList<String>();
  523. disease.add(highBloodPressureCheck);
  524. disease.add(lowBloodPressureCheck);
  525. disease.add(organTransplantCheck);
  526. disease.add(diabetesCheck);
  527. disease.add(respiratoryDiseaseCheck);
  528. disease.add(immunologicalDiseaseCheck);
  529. disease.add(heartDisease);
  530. disease.add(liverDisease);
  531. disease.add(operation);
  532. disease.add(allergyCheck);
  533. disease.add(kidneyDisease);
  534. disease.add(cancerCheck);
  535. disease.add(ectCheckDisease);
  536. String strDisease = "";
  537. for (int i = 0; i < disease.size(); i++) {
  538. String str = disease.get(i);
  539. if (!str.equals("")) {
  540. strDisease += str;
  541. strDisease += ", ";
  542. }
  543. }
  544. strDisease = strDisease.trim();
  545. if (!strDisease.equals("")) {
  546. strDisease = strDisease.substring(0, strDisease.length()-1);
  547. }
  548. return strDisease;
  549. }
  550. public static String getSymptom(PatientDTO dto) {
  551. String feverCheck = dto.getFeverCheck().equals("Y") ? "열감(열나는 느낌)" : "";
  552. String coughCheck = dto.getCoughCheck().equals("Y") ? "기침" : "";
  553. String colic = dto.getColic().equals("Y") ? "복통(배아픔)" : "";
  554. String coldFitCheck = dto.getColdFitCheck().equals("Y") ? "오한(추운 느낌)" : "";
  555. String sputumCheck = dto.getSputumCheck().equals("Y") ? "가래" : "";
  556. String ocinCheck = dto.getOcinCheck().equals("Y") ? "오심(구역질)" : "";
  557. String chestPain = dto.getChestPain().equals("Y") ? "흉통" : "";
  558. String noseCheck = dto.getNoseCheck().equals("Y") ? "콧물 또는 코 막힘" : "";
  559. String vomitingCheck = dto.getVomitingCheck().equals("Y") ? "구토" : "";
  560. String musclePainCheck = dto.getMusclePainCheck().equals("Y") ? "근육통(몸살)" : "";
  561. String soreThroatCheck = dto.getSoreThroatCheck().equals("Y") ? "인후통(목 아픔)" : "";
  562. String diarrheaCheck = dto.getDiarrheaCheck().equals("Y") ? "설사" : "";
  563. String headacheCheck = dto.getHeadacheCheck().equals("Y") ? "두통(머리아픔)" : "";
  564. String dyspneaCheck = dto.getDyspneaCheck().equals("Y") ? "호흡곤란(숨가쁨)" : "";
  565. String fatigueCheck = dto.getFatigueCheck().equals("Y") ? "권태감(피로감)" : "";
  566. String etcContent = dto.getEtcContentSymptom() == null ? "" : dto.getEtcContentSymptom();
  567. String ectCheckSymptom = dto.getEtcCheckSymptom().equals("Y") ? "기타(" + etcContent + ")" : "";
  568. String strSymptom = "";
  569. ArrayList<String> symptom = new ArrayList<String>();
  570. symptom.add(feverCheck);
  571. symptom.add(coughCheck);
  572. symptom.add(colic);
  573. symptom.add(coldFitCheck);
  574. symptom.add(sputumCheck);
  575. symptom.add(ocinCheck);
  576. symptom.add(chestPain);
  577. symptom.add(noseCheck);
  578. symptom.add(vomitingCheck);
  579. symptom.add(musclePainCheck);
  580. symptom.add(soreThroatCheck);
  581. symptom.add(diarrheaCheck);
  582. symptom.add(headacheCheck);
  583. symptom.add(dyspneaCheck);
  584. symptom.add(fatigueCheck);
  585. symptom.add(ectCheckSymptom);
  586. for (int i = 0; i < symptom.size(); i++) {
  587. String str = symptom.get(i);
  588. if (!str.equals("")) {
  589. strSymptom += str;
  590. strSymptom += ", ";
  591. }
  592. }
  593. strSymptom = strSymptom.trim();
  594. if (!strSymptom.equals("")) {
  595. strSymptom = strSymptom.substring(0, strSymptom.length() - 1);
  596. }
  597. return strSymptom;
  598. }
  599. /**
  600. * 패스워드를 규칙에 맞게 체크한다.
  601. * [사용방법]
  602. * LifeCenterFunction.checkPw(String inputPw);
  603. * Return
  604. * 0: OK (규칙에 부합됨)
  605. * 1: 입력된 패스워드가 null이거나 없음.
  606. * 2: 입력된 패스워드가 16자 이상임 15자리까지 입력가능.
  607. * 3: 입력된 패스워드가 2조합 미만이고 10자리 미만.
  608. * 4: 입력된 패스워드가 2조합인데, 8자리 미만임.
  609. * 5:
  610. * 6: 입력된 패스워드가 3자리 이상 연속된 값이 포함됨. (예, abc, def, 123)
  611. * 7: 입력된 패스워드가 키보드 조합으로 3자리 이상 연속된 값이 포함됨. (예, asd, qwe, jkl)
  612. * 8: 입력된 패스워드가 3자리 이상 같은 값이 포함됨. (예, aaa, 222)
  613. * 99: 에러
  614. */
  615. public static String checkPw(String inputPw) {
  616. String strResult = "";
  617. if( inputPw == null || inputPw.equals("") ) return "1";
  618. if( inputPw.length() > 15 ) return "2";
  619. try {
  620. Pattern pAlphabetLow = null;
  621. Pattern pAlphabetUp = null;
  622. Pattern pNumber = null;
  623. Pattern pSpecialChar = null;
  624. Pattern pThreeChar = null;
  625. Matcher match;
  626. int nCharType = 0;
  627. pAlphabetLow = Pattern.compile("[a-z]"); // 영소문자
  628. pAlphabetUp = Pattern.compile("[A-Z]"); // 영대문자
  629. pNumber = Pattern.compile("[0-9]"); // 숫자
  630. pSpecialChar = Pattern.compile("\\p{Punct}"); // 특수문자 -_=+\\|()*&^%$#@!~`?></;,.:'
  631. pThreeChar = Pattern.compile("(\\p{Alnum})\\1{2,}");// 3자리 이상 같은 문자 또는 숫자
  632. // 영소문자가 포함되어 있는가?
  633. match = pAlphabetLow.matcher(inputPw);
  634. if(match.find()) nCharType++;
  635. // 영대문자가 포함되어 있는가?
  636. match = pAlphabetUp.matcher(inputPw);
  637. if(match.find()) nCharType++;
  638. // 숫자가 포함되어 있는가?
  639. match = pNumber.matcher(inputPw);
  640. if(match.find()) nCharType++;
  641. // 특수문자가 포함되어 있는가?
  642. match = pSpecialChar.matcher(inputPw);
  643. if(match.find()) nCharType++;
  644. // 3자리 이상 같은 문자 또는 숫자가 포함되어 있는가?
  645. match = pThreeChar.matcher(inputPw);
  646. if(match.find()) return "8"; //입력된 패스워드가 3자리 이상 같은 값이 포함됨. (예, aaa, 222)
  647. // 2가지 이상 조합인가?
  648. if(nCharType >= 2) {
  649. // 8자리 미만인경우
  650. if(inputPw.length() < 8) return "4";
  651. else strResult = "0";
  652. } else {
  653. //10자리 미만인 경우
  654. if(inputPw.length() < 10) return "3";
  655. else strResult = "0";
  656. }
  657. // 연속된 3자리 이상의 문자나 숫자가 포함되어 있는가?
  658. String listThreeChar = "abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789|890";
  659. String[] arrThreeChar = listThreeChar.split("\\|");
  660. for (int i=0; i<arrThreeChar.length; i++) {
  661. if(inputPw.toLowerCase().matches(".*" + arrThreeChar[i] + ".*")) {
  662. return "6";
  663. }
  664. }
  665. // 연속된 3자리 이상의 키보드 문자가 포함되어 있는가?
  666. String listKeyboardThreeChar = "qwe|wer|ert|rty|tyu|yui|uio|iop|asd|sdf|dfg|fgh|ghj|hjk|jkl|zxc|xcv|cvb|vbn|bnm";
  667. String[] arrKeyboardThreeChar = listKeyboardThreeChar.split("\\|");
  668. for (int j=0; j<arrKeyboardThreeChar.length; j++) {
  669. if(inputPw.toLowerCase().matches(".*" + arrKeyboardThreeChar[j] + ".*")) {
  670. return "7";
  671. }
  672. }
  673. } catch (Exception ex) {
  674. strResult = "99";
  675. }
  676. return strResult;
  677. }
  678. }