001package org.hl7.fhir.convertors.misc;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009    
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030 */
031
032
033import org.hl7.fhir.exceptions.FHIRException;
034import org.hl7.fhir.exceptions.FHIRFormatError;
035import org.hl7.fhir.r4.formats.IParser.OutputStyle;
036import org.hl7.fhir.r4.formats.JsonParser;
037import org.hl7.fhir.r4.model.CodeSystem;
038import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode;
039import org.hl7.fhir.r4.model.CodeSystem.CodeSystemHierarchyMeaning;
040import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
041import org.hl7.fhir.r4.model.CodeSystem.PropertyType;
042import org.hl7.fhir.r4.model.DateTimeType;
043import org.hl7.fhir.r4.model.Enumerations.PublicationStatus;
044import org.hl7.fhir.r4.model.StringType;
045import org.hl7.fhir.utilities.CSVReader;
046import org.hl7.fhir.utilities.Utilities;
047
048import java.io.FileInputStream;
049import java.io.FileOutputStream;
050import java.io.IOException;
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("c:\\temp\\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("c:\\temp\\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}