001/* ***** BEGIN LICENSE BLOCK *****
002 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
003 *
004 * The contents of this file are subject to the Mozilla Public License Version
005 * 1.1 (the "License"); you may not use this file except in compliance with
006 * the License. You may obtain a copy of the License at
007 * http://www.mozilla.org/MPL/
008 *
009 * Software distributed under the License is distributed on an "AS IS" basis,
010 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
011 * for the specific language governing rights and limitations under the
012 * License.
013 *
014 * The Original Code is part of dcm4che, an implementation of DICOM(TM) in
015 * Java(TM), hosted at https://github.com/gunterze/dcm4che.
016 *
017 * The Initial Developer of the Original Code is
018 * Agfa Healthcare.
019 * Portions created by the Initial Developer are Copyright (C) 2012
020 * the Initial Developer. All Rights Reserved.
021 *
022 * Contributor(s):
023 * See @authors listed below
024 *
025 * Alternatively, the contents of this file may be used under the terms of
026 * either the GNU General Public License Version 2 or later (the "GPL"), or
027 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
028 * in which case the provisions of the GPL or the LGPL are applicable instead
029 * of those above. If you wish to allow use of your version of this file only
030 * under the terms of either the GPL or the LGPL, and not to allow others to
031 * use your version of this file under the terms of the MPL, indicate your
032 * decision by deleting the provisions above and replace them with the notice
033 * and other provisions required by the GPL or the LGPL. If you do not delete
034 * the provisions above, a recipient may use your version of this file under
035 * the terms of any one of the MPL, the GPL or the LGPL.
036 *
037 * ***** END LICENSE BLOCK ***** */
038
039package org.dcm4che3.hl7;
040
041/**
042 * @author Gunter Zeilinger <gunterze@gmail.com>
043 *
044 */
045public abstract class HL7Charset {
046
047    public static String toCharsetName(String code) {
048        if (code != null && !code.isEmpty())
049            switch (code.charAt(code.length()-1)) {
050            case '0':
051                if (code.equals("GB 18030-2000"))
052                    return "GB18030";
053                break;
054            case '1':
055                if (code.equals("8859/1"))
056                    return "ISO-8859-1";
057                if (code.equals("KS X 1001"))
058                    return "EUC-KR";
059                break;
060            case '2':
061                if (code.equals("8859/2"))
062                    return "ISO-8859-2";
063                if (code.equals("CNS 11643-1992"))
064                    return "TIS-620";
065                break;
066            case '3':
067                if (code.equals("8859/3"))
068                    return "ISO-8859-3";
069                break;
070            case '4':
071                if (code.equals("8859/4"))
072                    return "ISO-8859-4";
073                if (code.equals("ISO IR14"))
074                    return "JIS_X0201";
075                break;
076            case '5':
077                if (code.equals("8859/5"))
078                    return "ISO-8859-5";
079                break;
080            case '6':
081                if (code.equals("8859/6"))
082                    return "ISO-8859-6";
083                break;
084            case '7':
085                if (code.equals("8859/7"))
086                    return "ISO-8859-7";
087                if (code.equals("ISO IR87"))
088                    return "x-JIS0208";
089                break;
090            case '8':
091                if (code.equals("8859/8"))
092                    return "ISO-8859-8";
093                if (code.equals("UNICODE UTF-8"))
094                    return "UTF-8";
095                break;
096            case '9':
097                if (code.equals("8859/9"))
098                    return "ISO-8859-9";
099                if (code.equals("ISO IR159"))
100                    return "JIS_X0212-1990";
101                break;
102            case 'E':
103                if (code.equals("UNICODE"))
104                    return "UTF-8";
105                break;
106            }
107        return "US-ASCII";
108    }
109
110    public static String toDicomCharacterSetCode(String code) {
111        if (code != null && !code.isEmpty())
112            switch (code.charAt(code.length()-1)) {
113            case '0':
114                if (code.equals("GB 18030-2000"))
115                    return "GB18030";
116                break;
117            case '1':
118                if (code.equals("8859/1"))
119                    return "ISO_IR 100";
120                if (code.equals("KS X 1001"))
121                    return "ISO 2022 IR 149";
122                break;
123            case '2':
124                if (code.equals("8859/2"))
125                    return "ISO_IR 101";
126                if (code.equals("CNS 11643-1992"))
127                    return "ISO_IR 166";
128                break;
129            case '3':
130                if (code.equals("8859/3"))
131                    return "ISO_IR 109";
132                break;
133            case '4':
134                if (code.equals("8859/4"))
135                    return "ISO_IR 110";
136                if (code.equals("ISO IR14"))
137                    return "ISO_IR 13";
138                break;
139            case '5':
140                if (code.equals("8859/5"))
141                    return "ISO_IR 144";
142                break;
143            case '6':
144                if (code.equals("8859/6"))
145                    return "ISO_IR 127";
146                break;
147            case '7':
148                if (code.equals("8859/7"))
149                    return "ISO_IR 126";
150                if (code.equals("ISO IR87"))
151                    return "ISO 2022 IR 87";
152                break;
153            case '8':
154                if (code.equals("8859/8"))
155                    return "ISO_IR 138";
156                if (code.equals("UNICODE UTF-8"))
157                    return "ISO_IR 192";
158                break;
159            case '9':
160                if (code.equals("8859/9"))
161                    return "ISO_IR 148";
162                if (code.equals("ISO IR159"))
163                    return "ISO 2022 IR 159";
164                break;
165            case 'E':
166                if (code.equals("UNICODE"))
167                    return "ISO_IR 192";
168                break;
169            }
170        return null;
171    }
172
173}