001package org.hl7.fhir.convertors.misc; 002 003import java.io.FileInputStream; 004import java.io.FileOutputStream; 005import java.io.IOException; 006 007/* 008 Copyright (c) 2011+, HL7, Inc. 009 All rights reserved. 010 011 Redistribution and use in source and binary forms, with or without modification, 012 are permitted provided that the following conditions are met: 013 014 * Redistributions of source code must retain the above copyright notice, this 015 list of conditions and the following disclaimer. 016 * Redistributions in binary form must reproduce the above copyright notice, 017 this list of conditions and the following disclaimer in the documentation 018 and/or other materials provided with the distribution. 019 * Neither the name of HL7 nor the names of its contributors may be used to 020 endorse or promote products derived from this software without specific 021 prior written permission. 022 023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 026 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 027 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 028 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 029 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 030 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 031 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 032 POSSIBILITY OF SUCH DAMAGE. 033 034 */ 035 036 037import org.hl7.fhir.exceptions.FHIRException; 038import org.hl7.fhir.exceptions.FHIRFormatError; 039import org.hl7.fhir.r4.formats.IParser.OutputStyle; 040import org.hl7.fhir.r4.formats.JsonParser; 041import org.hl7.fhir.r4.model.CodeSystem; 042import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode; 043import org.hl7.fhir.r4.model.CodeSystem.CodeSystemHierarchyMeaning; 044import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent; 045import org.hl7.fhir.r4.model.CodeSystem.PropertyType; 046import org.hl7.fhir.r4.model.DateTimeType; 047import org.hl7.fhir.r4.model.Enumerations.PublicationStatus; 048import org.hl7.fhir.r4.model.StringType; 049import org.hl7.fhir.utilities.CSVReader; 050import org.hl7.fhir.utilities.Utilities; 051 052public class NUCCConvertor { 053 054 public static void main(String[] args) throws Exception { 055 new NUCCConvertor().execute(); 056 } 057 058 public void execute() throws IOException, FHIRException { 059 CSVReader csv = new CSVReader(new FileInputStream(Utilities.path("[tmp]", "nucc.csv"))); 060 CodeSystem cs = new CodeSystem(); 061 cs.setId("nucc-provider-taxonomy"); 062 cs.setUrl("http://nucc.org/provider-taxonomy"); 063 cs.setName("NUCC Provider Taxonomy"); 064 cs.setDateElement(new DateTimeType()); 065 cs.setDescription("The Health Care Provider Taxonomy code is a unique alphanumeric code, ten characters in length. The code set is structured into three distinct 'Levels' including Provider Type, Classification, and Area of Specialization"); 066 cs.setCopyright("Vendors must request a license to include this in a product per the following: 'Vendors interested in incorporating the Health Care Provider Taxonomy code set into their commercial products must complete the license request form found on the CSV page.' Using the form at the url listed. The preamble is reproduced below: http://www.nucc.org/index.php?option=com_content&view=article&id=111&Itemid=110"); 067 cs.setStatus(PublicationStatus.ACTIVE); 068 cs.setContent(CodeSystemContentMode.COMPLETE); 069 cs.setExperimental(false); 070 cs.setValueSet("http://hl7.org/fhir/ValueSet/nucc-provider-taxonomy"); 071 cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.CLASSIFIEDWITH); 072 cs.addProperty().setCode("grouping").setType(PropertyType.STRING).setDescription("A major grouping of service(s) or occupation(s) of health care providers. For example: Allopathic & Osteopathic Physicians, Dental Providers, Hospitals, etc"); 073 cs.addProperty().setCode("classification").setType(PropertyType.STRING).setDescription("A more specific service or occupation related to the Provider Grouping.e"); 074 cs.addProperty().setCode("specialization").setType(PropertyType.STRING).setDescription("A more specialized area of the Classification in which a provider chooses to practice or make services available."); 075 csv.parseLine(); 076 while (csv.ready()) { 077 String[] values = csv.parseLine(); 078 processLine(cs, values); 079 } 080 csv.close(); 081 cs.sort(); 082 new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "nucc.json")), cs); 083 } 084 085 private void processLine(CodeSystem cs, String[] values) throws FHIRFormatError { 086 ConceptDefinitionComponent cc = new ConceptDefinitionComponent(); 087 cs.getConcept().add(cc); 088 cc.setCode(values[0]); 089 cc.setDisplay(values[4]); 090 if (!Utilities.noString(values[1])) { 091 cc.addProperty().setCode("grouping").setValue(new StringType(values[1])); 092 } 093 if (!Utilities.noString(values[2])) { 094 cc.addProperty().setCode("classification").setValue(new StringType(values[2])); 095 } 096 if (!Utilities.noString(values[3])) { 097 cc.addProperty().setCode("specialization").setValue(new StringType(values[3])); 098 } 099 if (values.length > 5 && !Utilities.noString(values[5])) 100 cc.setDefinition(values[5]); 101 } 102 103}