Loading specifications with SpecificationLoader

As of version 1.3.0, there is an alternative API to load specifications and obtain an IGrouperKernel. The SpecificationLoader class provides static methods to load an ISpecification from either a File or a URL:

// Load a specification from a directory on the file system
ISpecification specification = SpecificationLoader.from(new File("..."), Tariff.SWISSDRG);

// Load a specification from a URL
ISpecification specification = SpecificationLoader.from(new URL(...), Tariff.SWISSDRG);

// Get DRG Grouper and Supplement Grouper from specification
IGrouperKernel kernel = specification.getGrouper();
Optional<ISupplementGrouper> supplementGrouper = specification.getSupplementGrouper();
...

Loading from a File

You should use this API if you want to load a specification in the same way that was possible with the older SpecificationReader API. Use this API if you want to

  • load a specification from a directory on the file system
ISpecification specification = SpecificationLoader.from(new File("path/to/directory/root"), Tariff.SWISSDRG);
  • load a specification from a single-file specification from the file system
ISpecification specification = SpecificationLoader.from(new File("path/to/file.sgs"), Tariff.SWISSDRG);
  • load a specification from a ZIP compressed specification. You can now load the old SwissDRG provided specifications without decompressing first.
ISpecification specification = SpecificationLoader.from(new File("path/to/file.zip"), Tariff.SWISSDRG);

Loading from a URL

You can use this API to load a specification from a certain URL. This is necessary if you want to load specifications from the Java classpath, for example.

Use this API if you want to

  • load a directory based specification from a directory on the classpath
// Assuming your specification resides at 'specs/10.1' on the classpath
URL url = [yourClassHere].class.getResource("specs/10.1");
ISpecification specification = SpecificationLoader.from(url, Tariff.SWISSDRG);
  • load a single-file based specification on the classpath
// Assuming your specification resides at 'specs/spec10.1.sgs' on the classpath
URL url = [yourClassHere].class.getResource("specs/spec10.1.sgs");
ISpecification specification = SpecificationLoader.from(url, Tariff.SWISSDRG);
  • load a ZIP compressed specification from the classpath
// Assuming your specification resides at 'specs/spec10.1.zip' on the classpath
URL url = [yourClassHere].class.getResource("specs/spec10.1.zip");
ISpecification specification = SpecificationLoader.from(url, Tariff.SWISSDRG);

Note

Loading specifications from remote URLs is only supported for .sgs and .zip specifications.

Example

import org.swissdrg.grouper.*;
import org.swissdrg.zegrouper.api.ISupplementGroupResult;
import org.swissdrg.zegrouper.api.ISupplementGrouper;

import java.net.URL;
import java.util.Map;
import java.util.Optional;

public class Main {
    public static void main(String[] args) throws Exception {
        // Load a specification from a directory on the file system
        URL url = Main.class.getResource("specs/10.1");
        ISpecification specification = SpecificationLoader.from(
            url,
            IGrouperKernel.Tariff.SWISSDRG
        );

        // Get DRG Grouper and Supplement Grouper from specification
        IGrouperKernel kernel = specification.getGrouper();
        Optional<ISupplementGrouper> supplementGrouper = specification.getSupplementGrouper();

        // Create a parser for BATCH 2017 format
        IPatientCaseParser pcParser = PatientCaseParserFactory.getParserFor(
            PatientCaseParserFactory.InputFormat.BATCH_2017,
            IGrouperKernel.Tariff.SWISSDRG
        );

        // Parse patient case string
        String inputLine = "123456;;3;3100|293;W;20170101;01;20170105;00;4;0;D650|M0694|I1090;815421:L:20151026;B02BD02:Plas:IV:10000:U|J02AC04:Susp:O:500:mg";
        PatientCase patient = pcParser.parse(inputLine);

        // Group patient case
        kernel.groupByReference(patient);
        Optional<ISupplementGroupResult> supplementResult = supplementGrouper.map(
            grouper -> grouper.group(new SupplementPatientCase(patient))
        );

        // Access results
        GrouperResult drgResult = patient.getGrouperResult();

        System.out.println(drgResult.getDrg());
        System.out.println(drgResult.getMdc());
        System.out.println(drgResult.getGst());

        // Compute cost weight
        Map<String, WeightingRelation> catalog = Catalogue.createFrom(
            Main.class.getResource("specs/10.1/catalogue-acute.csv")
        );
        EffectiveCostWeight ecw = EffectiveCostWeight.calculateEffectiveCostWeight(
            patient,
            catalog.get(drgResult.getDrg())
        );

        System.out.println(ecw.getEffectiveCostWeight());

        supplementResult.ifPresent(result-> {
            System.out.println(result.getCharges().size());
            System.out.println(result.getTotalValue().floatValue());
        });
    }
}

Loading from Maven Specifications - BETA

Note

This feature is currently BETA and should NOT be used in production.

As of November 2021, specifications can be integrated into JVM language projects via Maven dependency. This greatly simplifies the handling of specifications since retrieving dependencies is as simple as selecting the appropriate specification from a Java Enum.

To use a Maven specification, go to https://download.swissdrg.org/bundled_specifications , select an available Maven specification (if you have access) and follow the setup instructions for your build tool. Currently, we have instructions for Maven (mvn), Gradle, Gradle with Kotlin Script and SBT (Scala).

Maven specifications contain all available specifications up to a certain point in time. You will only have access to Maven specifications connected to the billing years that you are eligible for. For example, if you have access to billing year 2021, you are eligible to download the Maven specification 2021.0.0, which contains every specification up to SwissDRG V11.0 AV, TARPSY T4.0 AV and ST Reha R1.0 AV.

Example

We illustrate using Maven specifications using Gradle.

Declare the SwissDRG Downloadportal as one of your Maven repositories in your build.gradle:

repositories {
    maven {
        url "https://download.swissdrg.org/artifacts"
        credentials {
            username("${swissDRGUser}")
            password("${swissDRGPassword}")
        }
        authentication {
            basic(BasicAuthentication)
        }
    }
}

Please refer to the “Maven Setup” guide in the SwissDRG Download Portal for further details such as authentication setup.

Once your repository is declared, you can declare the desired specification as a dependency (in this case grouper-specs:2021.0.0):

dependencies {
  implementation("org.swissdrg:grouper-specs:2021.0.0")
  implementation("org.swissdrg:java-grouper:1.4.3")
}

The grouper-specs artifact will always depend on a certain minimun version of the java-grouper artifact, (in this case java-grouper:1.4.3) which should be declared as a dependency as well.

You should then be able to retrieve the bundled specifications using the org.swissdrg.grouper.Specifications enum and load a grouper from the specification with the familiar SpecificationLoader API:

import org.swissdrg.grouper.Catalogue;
import org.swissdrg.grouper.PatientCase;
import org.swissdrg.grouper.SpecificationLoader;
import org.swissdrg.grouper.Specifications;

import java.io.IOException;

public class Main {
    public static void main(String[] args) throws SpecificationLoader.LoadException, IOException {
        var spec = Specifications.V11_3;
        var tariff = spec.getTariff();
        var loadedSpec = SpecificationLoader.from(spec.getUrl(), tariff);

        var grouper = loadedSpec.getGrouper();
        var supplementGrouper = loadedSpec.getSupplementGrouper();

        var pc = new PatientCase();
        grouper.groupByReference(pc);
        var catalog = Catalogue.createFrom(spec.getCatalogUrl());

        System.out.println(pc.getGrouperResult());
        System.out.println(catalog.get(pc.getGrouperResult().getDrg()));
    }
}