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.convertors.advisors.impl.BaseAdvisor_10_30;
034import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30;
035import org.hl7.fhir.dstu3.formats.IParser.OutputStyle;
036import org.hl7.fhir.dstu3.model.Bundle;
037import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
038import org.hl7.fhir.dstu3.model.Bundle.BundleType;
039import org.hl7.fhir.dstu3.model.CodeSystem;
040import org.hl7.fhir.dstu3.model.ValueSet;
041import org.hl7.fhir.exceptions.FHIRException;
042import org.hl7.fhir.r5.model.FhirPublication;
043import org.hl7.fhir.utilities.Utilities;
044import javax.annotation.Nonnull;
045
046import java.io.File;
047import java.io.FileInputStream;
048import java.io.FileOutputStream;
049import java.io.IOException;
050import java.util.Date;
051
052public class IGPackConverter102 extends BaseAdvisor_10_30 {
053
054  private final Bundle cslist = new Bundle();
055
056  public static void main(String[] args) throws Exception {
057    new IGPackConverter102().process();
058  }
059
060  private void process() throws IOException, FHIRException {
061    initCSList();
062    for (String s : new File("C:\\temp\\igpack2").list()) {
063      if (s.endsWith(".xml") && !s.startsWith("z-") && !Utilities.existsInList(s, "expansions.xml", "v3-codesystems.xml", "v2-tables.xml")) {
064        System.out.println("process " + s);
065        org.hl7.fhir.dstu2.formats.XmlParser xp = new org.hl7.fhir.dstu2.formats.XmlParser();
066        org.hl7.fhir.dstu2.model.Resource r10 = xp.parse(new FileInputStream("C:\\temp\\igpack2\\" + s));
067        org.hl7.fhir.dstu3.model.Resource r17 = VersionConvertorFactory_10_30.convertResource(r10, this);
068        org.hl7.fhir.dstu3.formats.XmlParser xc = new org.hl7.fhir.dstu3.formats.XmlParser();
069        xc.setOutputStyle(OutputStyle.PRETTY);
070        xc.compose(new FileOutputStream("C:\\temp\\igpack2\\" + s), r17);
071      }
072    }
073    System.out.println("save codesystems");
074    org.hl7.fhir.dstu3.formats.XmlParser xc = new org.hl7.fhir.dstu3.formats.XmlParser();
075    xc.setOutputStyle(OutputStyle.PRETTY);
076    xc.compose(new FileOutputStream("C:\\temp\\igpack2\\codesystems.xml"), cslist);
077    System.out.println("done");
078  }
079
080  private void initCSList() {
081    cslist.setId("codesystems");
082    cslist.setType(BundleType.COLLECTION);
083    cslist.getMeta().setLastUpdated(new Date());
084  }
085
086  @Override
087  public boolean ignoreEntry(@Nonnull BundleEntryComponent src, @Nonnull FhirPublication publication) {
088    return false;
089  }
090
091
092  @Override
093  public void handleCodeSystem(@Nonnull CodeSystem tgtcs, @Nonnull ValueSet vs) {
094    cslist.addEntry().setFullUrl(tgtcs.getUrl()).setResource(tgtcs);
095  }
096
097  @Override
098  public CodeSystem getCodeSystem(@Nonnull ValueSet src) {
099    return null;
100  }
101
102}