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;
051import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
052
053public class NUCCConvertor {
054
055  public static void main(String[] args) throws Exception {
056    new NUCCConvertor().execute();
057  }
058
059  public void execute() throws IOException, FHIRException {
060    CSVReader csv = new CSVReader(ManagedFileAccess.inStream(Utilities.path("[tmp]", "nucc.csv")));
061    CodeSystem cs = new CodeSystem();
062    cs.setId("nucc-provider-taxonomy");
063    cs.setUrl("http://nucc.org/provider-taxonomy");
064    cs.setName("NUCC Provider Taxonomy");
065    cs.setDateElement(new DateTimeType());
066    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");
067    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");
068    cs.setStatus(PublicationStatus.ACTIVE);
069    cs.setContent(CodeSystemContentMode.COMPLETE);
070    cs.setExperimental(false);
071    cs.setValueSet("http://hl7.org/fhir/ValueSet/nucc-provider-taxonomy");
072    cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.CLASSIFIEDWITH);
073    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");
074    cs.addProperty().setCode("classification").setType(PropertyType.STRING).setDescription("A more specific service or occupation related to the Provider Grouping.e");
075    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.");
076    csv.parseLine();
077    while (csv.ready()) {
078      String[] values = csv.parseLine();
079      processLine(cs, values);
080    }
081    csv.close();
082    cs.sort();
083    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(ManagedFileAccess.outStream(Utilities.path("[tmp]", "nucc.json")), cs);
084  }
085
086  private void processLine(CodeSystem cs, String[] values) throws FHIRFormatError {
087    ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
088    cs.getConcept().add(cc);
089    cc.setCode(values[0]);
090    cc.setDisplay(values[4]);
091    if (!Utilities.noString(values[1])) {
092      cc.addProperty().setCode("grouping").setValue(new StringType(values[1]));
093    }
094    if (!Utilities.noString(values[2])) {
095      cc.addProperty().setCode("classification").setValue(new StringType(values[2]));
096    }
097    if (!Utilities.noString(values[3])) {
098      cc.addProperty().setCode("specialization").setValue(new StringType(values[3]));
099    }
100    if (values.length > 5 && !Utilities.noString(values[5]))
101      cc.setDefinition(values[5]);
102  }
103
104}