Java tutorial
/* * Copyright (C) 2014 S&I Co.,Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * Copyright (C) 2001-2014 OpenDolphin Lab., Life Sciences Computing, Corp. * 825 Sylk BLDG., 1-Yamashita-Cho, Naka-Ku, Kanagawa-Ken, Yokohama-City, JAPAN. * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. * * (R)OpenDolphin version 2.4, Copyright (C) 2001-2014 OpenDolphin Lab., Life Sciences Computing, Corp. * (R)OpenDolphin comes with ABSOLUTELY NO WARRANTY; for details see the GNU General * Public License, version 3 (GPLv3) This is free software, and you are welcome to redistribute * it under certain conditions; see the GPLv3 for details. */ package open.dolphin.utilities.common; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.codec.binary.Base64; /** * ORCA API * * @author Life Sciences Computing Corporation. * @author modified Chikara Fujihira <fujihirach@sandi.co.jp>, S&I Co.,Ltd. */ public class OrcaApi extends AbstractCommonFunc { private static final String URL_HTTP = "http://"; public static final String KIND_01 = "?class=01"; public static final String KIND_02 = "?class=02"; public static final String KIND_03 = "?class=03"; // ? private static final String ORCAAPI47_ACCEPTLIST = "/api01rv2/acceptlstv2"; private String ACCEPTLIST; // private static final String ORCAAPI47_APPOINTLIST = "/api01rv2/appointlstv2"; private String APPOINTLIST; // ??? private static final String ORCAAPI47_GETDISEASE = "/api01rv2/diseasegetv2"; private String GETDISEASE; // private static final String ORCAAPI47_APPOINTLIST2 = "/api01rv2/appointlst2v2"; private String APPOINTLIST2; // ? private static final String ORCAAPI47_ACCEPTMOD = "/orca11/acceptmodv2"; private String ACCEPTMOD; protected String host; protected String port; protected String user; protected String pass; protected String ver; /** * */ protected OrcaApi() { super(); Init(); } /** * ? */ @Override final void Init() { host = null; port = null; user = null; pass = null; ver = null; } protected void setVerInfo() { if (ver.equals(ORCAAPI_VER_47)) { ACCEPTLIST = ORCAAPI47_ACCEPTLIST; APPOINTLIST = ORCAAPI47_APPOINTLIST; GETDISEASE = ORCAAPI47_GETDISEASE; APPOINTLIST2 = ORCAAPI47_APPOINTLIST2; ACCEPTMOD = ORCAAPI47_ACCEPTMOD; } } /** * ? * * @param date ?(YYYY-MM-DD) * @param dcode * @param pcode * @param medical * @param kind class=01:??,class=02:???,class=03:?? * @return */ protected String acceptlst(String date, String dcode, String pcode, String medical, String kind) { StringBuilder sbParam = new StringBuilder(); sbParam.append("<data>"); sbParam.append("<acceptlstreq type=\"record\">"); sbParam.append("<Acceptance_Date type=\"string\">"); sbParam.append(date); sbParam.append("</Acceptance_Date>"); sbParam.append("<Department_Code type=\"string\">"); sbParam.append(dcode); sbParam.append("</Department_Code>"); sbParam.append("<Physician_Code type=\"string\">"); sbParam.append(pcode); sbParam.append("</Physician_Code>"); sbParam.append("<Medical_Information type=\"string\">"); sbParam.append(medical); sbParam.append("</Medical_Information>"); sbParam.append("</acceptlstreq>"); sbParam.append("</data>"); return orcaSendRecv(ACCEPTLIST + kind, sbParam.toString()); /* 1 Information_Date 2011-03-13 2 Information_Time 10:50:00 3 Api_Result ? 00 4 Api_Result_Message ? 5 Reskey Patient Info 6 Acceptance_Date ? 2011-03-15 7 Acceptlst_Infomation ? (? 500) 7-1 Acceptance_Time ? 15:30:00 7-2 Department_Code (01:) 01 7-3 Department_WholeName ?? 7-4 Physician_Code 10001 7-5 Physician_WholeName ?? 7-6 Medical_Information (01:? 02:??? 03:??? 04:??? 05:?? 06:?? 07:? 99:??) 01 7-7 Claim_Infometion claim 0 7-8 Account_Time 15:50:00 7-9 Patient_Information 7-9-1 Patient_ID ? 00012 7-9-2 WholeName ??? 7-9-3 WholeName_inKana ??? ? 7-9-4 BirthDate 1975-01-01 7-9-5 Sex (1:?2:) 1 7-10 HealthInsurance_Information ??? 7-10-1 InsuranceProvider_Class ?? 060 7-10-2 InsuranceProvider_Number ?? 138057 7-10-3 InsuranceProvider_WholeName ???? ? 7-10-4 HealthInsuredPerson_Symbol ? ? 7-10-5 HealthInsuredPerson_Number ? 7-10-6 HealthInsuredPerson_Continuation (1:? 2:?) 7-10-7 HealthInsuredPerson_Assistance (????????????) 3 7-10-8 RelationToInsuredPerson ?(1:? 2:?) 1 7-10-9 HealthInsuredPerson_WholeName ??? 7-10-10 Certificate_StartDate ? 2010-05-01 7-10-11 Certificate_ExpiredDate ? 9999-12-31 7-10-12 PublicInsurance_Information ? 4 7-10-12-1 PublicInsurance_Class ? 010 7-10-12-2 PublicInsurance_Name ??? 37?2 7-10-12-3 PublicInsurer_Number ? 10131142 7-10-12-4 PublicInsuredPerson_Number ?? 1234566 7-10-12-5 Rate_Admission 0.05 7-10-12-6 Money_Admission ? 0 7-10-12-7 Rate_Outpatient ? 0.05 7-10-12-8 Money_Outpatient ?? 0 7-10-12-9 Certificate_IssuedDate ? 2010-05-01 7-10-12-10 Certificate_ExpiredDate ? 9999-12-31 */ } /** * * * @param date * @param medical * @param pcode * @param kind class=01:? * @return */ protected String appointlst(String date, String medical, String pcode, String kind) { StringBuilder sbParam = new StringBuilder(); sbParam.append("<data>"); sbParam.append("<appointlstreq type=\"record\">"); sbParam.append("<Appointment_Date type=\"string\">"); sbParam.append(date); sbParam.append("</Appointment_Date>"); sbParam.append("<Medical_Information type=\"string\">"); sbParam.append(medical); sbParam.append("</Medical_Information>"); sbParam.append("<Physician_Code type=\"string\">"); sbParam.append(pcode); sbParam.append("</Physician_Code>"); sbParam.append("</appointlstreq>"); sbParam.append("</data>"); return orcaSendRecv(APPOINTLIST + kind, sbParam.toString()); /* 1 Information_Date 2011-03-13 2 Information_Time 10:50:00 3 Api_Result ? 00 4 Api_Result_Message ? 5 Reskey Patient Info 6 Appointment_Date 2011-03-15 7 Appointlst_Infomation (?500) 7-1 Appointment_Time 15:30:00 7-2 Medical_Information (01:? 02:??? 03:??? 04:??? 05:?? 06:?? 07:? 99:??) 01 7-3 Department_Code (01:) 01 7-4 Department_WholeName ?? 7-5 Physician_Code 10001 7-6 Physician_WholeName ?? 7-7 Visit_Information ? (1:?) 8 Patient_Information 8-1 Patient_ID ? 00012 8-2 WholeName ??? 8-3 WholeName_inKana ??? ? 8-4 BirthDate 1975-01-01 8-5 Sex (1:?2:) 1 8-6 Home_Address_Information ? 8-6-1 PhoneNumber1 ? 03-8888-9999 */ } /** * ???? * * @param pid ID() * @param date (YYYY-MM)(????) * @param kind class=01:???? * @return */ protected String diseaseget(String pid, String date, String kind) { StringBuilder sbParam = new StringBuilder(); sbParam.append("<data>"); sbParam.append("<disease_inforeq type=\"record\">"); sbParam.append("<Patient_ID type=\"string\">"); sbParam.append(pid); sbParam.append("</Patient_ID>"); sbParam.append("<Base_Date type=\"string\">"); sbParam.append(date); sbParam.append("</Base_Date>"); sbParam.append("</disease_inforeq>"); sbParam.append("</data>"); return orcaSendRecv(GETDISEASE + kind, sbParam.toString()); /* 1 Information_Date 2011-09-07 2 Information_Time 17:30:30 3 Api_Result ?() 00 4 Api_Result_Message ? 5 Reskey Medical Info 6 Disease_Infores ?? 6-1 Patient_ID ? 00012 6-2 WholeName ??? 6-3 WholeName_inKana ??? ? 6-4 BirthDate 1975-01-01 6-5 Sex (1:?2:) 1 7 Base_Date 2011-09 8 Disease_Information ????? 8-1 InOut (1:?2:) 2 8-2 Department_Code (01:) 01 8-3 Insurance_Combination_Number ?????? 0002 8-4 Disease_Name ?? AC?? 8-5 Disease_Single ???? 8-5-1 Disease_Single_Code ?? 8830052 8-5-2 Disease_Single_Name ??? AC?? 8-5-3 Disease_Single_Condition ???(:?2:?3:(??)) 8-6 Disease_Category (PD:??) PD 8-7 Disease_SuspectedFlag ??(S:??A:?SA:???) S 8-8 Disease_StartDate ?? 2011-09-08 8-9 Disease_EndDate 2011-09-08 8-10 Disease_OutCome (F:?D:?C:?S:) F 8-11 Disease_Supplement_Name 8-12 Disease_Karte_Name ?? 8-13 Disease_Class (03:?()?04:?()?05:??07:???08:??????09:??) 03 4-14 Disease_Receipt_Print (1:????:?) 1 4-15 Disease_Receipt_Print_Period */ } /** * * * @param pid ID() * @param date (YYYY-MM-DD)(????) * @param kind class=01:? * @return */ protected String appointlst2(String pid, String date, String kind) { StringBuilder sbParam = new StringBuilder(); sbParam.append("<data>"); sbParam.append("<appointlstreq2 type=\"record\">"); sbParam.append("<Patient_ID type=\"string\">"); sbParam.append(pid); sbParam.append("</Patient_ID>"); sbParam.append("<Base_Date type=\"string\">"); sbParam.append(date); sbParam.append("</Base_Date>"); sbParam.append("</appointlstreq2>"); sbParam.append("</data>"); return orcaSendRecv(APPOINTLIST + kind, sbParam.toString()); /* 1 Information_Date 2012-12-17 2 Information_Time 14:09:44 3 Api_Result ? 00 4 Api_Result_Message ? 5 Reskey ? Patient Info 6 Base_Date 2012-12-18 7 Patient_Information 7-1 Patient_ID ? 00001 7-2 WholeName ??? 7-3 WholeName_inKana ??? 7-4 BirthDate 1970-01-01 7-5 Sex 1:?2: 1 8 Appointlst_Information ? ? 8-1 Appointment_Date 2012-12-22 8-2 Appointment_Time 11:00:00 8-3 Medical_Information 01:?02:???03:???04:???05:??06:??07:?99:?? 01 8-4 Medical_Information_WholeName ?? 8-5 Department_Code 01: 01 8-6 Department_WholeName ?? 8-7 Physician_Code 10001 8-8 Physician_WholeName ?? ?? 8-9 Visit_Information ?? 1 8-10 Appointment_Note */ } /** * ? * * @param pid ID * @param accept ?ID * @param depart * @param physician * @param kind * @return */ protected String acceptmod(String pid, String accept, String depart, String physician, String kind) { StringBuilder sbParam = new StringBuilder(); sbParam.append("<data>"); sbParam.append("<acceptreq type=\"record\">"); sbParam.append("<Patient_ID type=\"string\">"); sbParam.append(pid); sbParam.append("</Patient_ID>"); sbParam.append("<Acceptance_Id type=\"string\">"); sbParam.append(accept); sbParam.append("</Acceptance_Id>"); sbParam.append("<Department_Code type=\"string\">"); sbParam.append(depart); sbParam.append("</Department_Code>"); sbParam.append("<Physician_Code type=\"string\">"); sbParam.append(physician); sbParam.append("</Physician_Code>"); sbParam.append("</acceptrea>"); sbParam.append("</data>"); return orcaSendRecv(ACCEPTMOD + kind, sbParam.toString()); /* 1Patient_ID ? 00012 2 Acceptance_Date ? 2011-03-15 3 Acceptance_Time ? 15:30:00 4 Acceptance_Id ?ID (????) 5 Department_Code (01:) 01 (???) 6 Physician_Code 10001 (???) 7 Medical_Information (01:? 02:??? 03:??? 04:??? 05:?? 06:?? 07:? 99:??) 01 8 HealthInsurance_Information ??? 8-1 InsuranceProvider_Class ??(060:?) 060 8-2 InsuranceProvider_Number ?? 138057 8-3 InsuranceProvider_WholeName ???? ? 8-4 HealthInsuredPerson_Symbol ? ? 8-5 HealthInsuredPerson_Number ? 8-6 HealthInsuredPerson_Continuation (1:? 2:?) 8-7 HealthInsuredPerson_Assistance (????????????) 3 8-8 RelationToInsuredPerson ?(1:? 2:?) 1 8-9 HealthInsuredPerson_WholeName ??? 8-10 Certificate_StartDate ? 2010-05-01 8-11 Certificate_ExpiredDate ? 9999-12-31 8-12 PublicInsurance_Information ?4 8-12-1 PublicInsurance_Class ? 010 8-12-2 PublicInsurance_Name ??? 37?2 8-12-3 PublicInsurer_Number ? 10131142 8-12-4 PublicInsuredPerson_Number ?? 1234566 8-12-5 Certificate_IssuedDate ? 2010-05-01 8-12-6 Certificate_ExpiredDate ? 9999-12-31 */ } /** * ?? * * @param urlInfo URL * @param data ? * @return */ protected String orcaSendRecv(String urlInfo, String data) { StringBuilder ret = new StringBuilder(); try { StringBuilder urlStr = new StringBuilder(); urlStr.append(URL_HTTP); urlStr.append(host); urlStr.append(":"); urlStr.append(port); urlStr.append(urlInfo); URL url = new URL(urlStr.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestMethod(REQUESTMETHOD_POST); connection.setRequestProperty("Content-Type", "application/xml"); byte[] encoded = Base64.encodeBase64((user + ":" + pass).getBytes()); connection.setRequestProperty("Authorization", "Basic " + new String(encoded)); connection.setRequestProperty("Content-Length", "" + data.length()); try (PrintWriter printWriter = new PrintWriter(connection.getOutputStream())) { printWriter.printf(data); } InputStream is = connection.getInputStream(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"))) { String line = null; while ((line = reader.readLine()) != null) { ret.append(line);//.append("\n"); } } connection.disconnect(); } catch (MalformedURLException ex) { Logger.getLogger(OrcaApi.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(OrcaApi.class.getName()).log(Level.SEVERE, null, ex); } return ret.toString(); } }