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());
        });
    }
}