Search in sources :

Example 66 with IntegerType

use of org.hl7.fhir.r4.model.IntegerType in project synthea by synthetichealth.

the class FhirPractitionerExporterStu3 method export.

/**
 * Export the practitioner in FHIR STU3 format.
 */
public static void export(long stop) {
    if (Config.getAsBoolean("exporter.practitioner.fhir_stu3.export")) {
        Bundle bundle = new Bundle();
        if (Config.getAsBoolean("exporter.fhir.transaction_bundle")) {
            bundle.setType(BundleType.BATCH);
        } else {
            bundle.setType(BundleType.COLLECTION);
        }
        for (Provider h : Provider.getProviderList()) {
            // filter - exports only those hospitals in use
            Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
            int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
            if (totalEncounters > 0) {
                Map<String, ArrayList<Clinician>> clinicians = h.clinicianMap;
                for (String specialty : clinicians.keySet()) {
                    ArrayList<Clinician> docs = clinicians.get(specialty);
                    for (Clinician doc : docs) {
                        if (doc.getEncounterCount() > 0) {
                            BundleEntryComponent entry = FhirStu3.practitioner(bundle, doc);
                            Practitioner practitioner = (Practitioner) entry.getResource();
                            practitioner.addExtension().setUrl(EXTENSION_URI).setValue(new IntegerType(doc.getEncounterCount()));
                        }
                    }
                }
            }
        }
        String bundleJson = FhirStu3.getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
        // get output folder
        List<String> folders = new ArrayList<>();
        folders.add("fhir_stu3");
        String baseDirectory = Config.get("exporter.baseDirectory");
        File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
        f.mkdirs();
        Path outFilePath = f.toPath().resolve("practitionerInformation" + stop + ".json");
        try {
            Files.write(outFilePath, Collections.singleton(bundleJson), StandardOpenOption.CREATE_NEW);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) Config(org.mitre.synthea.helpers.Config) Bundle(org.hl7.fhir.dstu3.model.Bundle) Files(java.nio.file.Files) Clinician(org.mitre.synthea.world.agents.Clinician) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) StandardOpenOption(java.nio.file.StandardOpenOption) BundleType(org.hl7.fhir.dstu3.model.Bundle.BundleType) IOException(java.io.IOException) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) File(java.io.File) ArrayList(java.util.ArrayList) Provider(org.mitre.synthea.world.agents.Provider) FhirContext(ca.uhn.fhir.context.FhirContext) List(java.util.List) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Table(com.google.common.collect.Table) Path(java.nio.file.Path) Collections(java.util.Collections) Path(java.nio.file.Path) Bundle(org.hl7.fhir.dstu3.model.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Provider(org.mitre.synthea.world.agents.Provider) Clinician(org.mitre.synthea.world.agents.Clinician) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File)

Example 67 with IntegerType

use of org.hl7.fhir.r4.model.IntegerType in project synthea by synthetichealth.

the class FhirStu3 method basicInfo.

/**
 * Map the given Person to a FHIR Patient resource, and add it to the given Bundle.
 *
 * @param person The Person
 * @param bundle The Bundle to add to
 * @param stopTime Time the simulation ended
 * @return The created Entry
 */
@SuppressWarnings("rawtypes")
private static BundleEntryComponent basicInfo(Person person, Bundle bundle, long stopTime) {
    Patient patientResource = new Patient();
    patientResource.addIdentifier().setSystem("https://github.com/synthetichealth/synthea").setValue((String) person.attributes.get(Person.ID));
    Code mrnCode = new Code("http://hl7.org/fhir/v2/0203", "MR", "Medical Record Number");
    patientResource.addIdentifier().setType(mapCodeToCodeableConcept(mrnCode, "http://hl7.org/fhir/v2/0203")).setSystem("http://hospital.smarthealthit.org").setValue((String) person.attributes.get(Person.ID));
    Code ssnCode = new Code("http://hl7.org/fhir/identifier-type", "SB", "Social Security Number");
    patientResource.addIdentifier().setType(mapCodeToCodeableConcept(ssnCode, "http://hl7.org/fhir/identifier-type")).setSystem("http://hl7.org/fhir/sid/us-ssn").setValue((String) person.attributes.get(Person.IDENTIFIER_SSN));
    if (person.attributes.get(Person.IDENTIFIER_DRIVERS) != null) {
        Code driversCode = new Code("http://hl7.org/fhir/v2/0203", "DL", "Driver's License");
        patientResource.addIdentifier().setType(mapCodeToCodeableConcept(driversCode, "http://hl7.org/fhir/v2/0203")).setSystem("urn:oid:2.16.840.1.113883.4.3.25").setValue((String) person.attributes.get(Person.IDENTIFIER_DRIVERS));
    }
    if (person.attributes.get(Person.IDENTIFIER_PASSPORT) != null) {
        Code passportCode = new Code("http://hl7.org/fhir/v2/0203", "PPN", "Passport Number");
        patientResource.addIdentifier().setType(mapCodeToCodeableConcept(passportCode, "http://hl7.org/fhir/v2/0203")).setSystem(SHR_EXT + "passportNumber").setValue((String) person.attributes.get(Person.IDENTIFIER_PASSPORT));
    }
    if (person.attributes.get(Person.CONTACT_EMAIL) != null) {
        ContactComponent contact = new ContactComponent();
        HumanName contactName = new HumanName();
        contactName.setUse(HumanName.NameUse.OFFICIAL);
        contactName.addGiven((String) person.attributes.get(Person.CONTACT_GIVEN_NAME));
        contactName.setFamily((String) person.attributes.get(Person.CONTACT_FAMILY_NAME));
        contact.setName(contactName);
        contact.addTelecom().setSystem(ContactPointSystem.EMAIL).setUse(ContactPointUse.HOME).setValue((String) person.attributes.get(Person.CONTACT_EMAIL));
        patientResource.addContact(contact);
    }
    // We do not yet account for mixed race
    Extension raceExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-race");
    String race = (String) person.attributes.get(Person.RACE);
    String raceDisplay;
    switch(race) {
        case "white":
            raceDisplay = "White";
            break;
        case "black":
            raceDisplay = "Black or African American";
            break;
        case "asian":
            raceDisplay = "Asian";
            break;
        case "native":
            raceDisplay = "American Indian or Alaska Native";
            break;
        case "hawaiian":
            raceDisplay = "Native Hawaiian or Other Pacific Islander";
            break;
        default:
            raceDisplay = "Other";
            break;
    }
    String raceNum = (String) raceEthnicityCodes.get(race);
    Extension raceCodingExtension = new Extension("ombCategory");
    Coding raceCoding = new Coding();
    if (raceDisplay.equals("Other")) {
        raceCoding.setSystem("http://hl7.org/fhir/v3/NullFlavor");
        raceCoding.setCode("UNK");
        raceCoding.setDisplay("Unknown");
    } else {
        raceCoding.setSystem("urn:oid:2.16.840.1.113883.6.238");
        raceCoding.setCode(raceNum);
        raceCoding.setDisplay(raceDisplay);
    }
    raceCodingExtension.setValue(raceCoding);
    raceExtension.addExtension(raceCodingExtension);
    Extension raceTextExtension = new Extension("text");
    raceTextExtension.setValue(new StringType(raceDisplay));
    raceExtension.addExtension(raceTextExtension);
    patientResource.addExtension(raceExtension);
    // We do not yet account for mixed ethnicity
    Extension ethnicityExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity");
    String ethnicity = (String) person.attributes.get(Person.ETHNICITY);
    String ethnicityDisplay;
    if (ethnicity.equals("hispanic")) {
        ethnicity = "hispanic";
        ethnicityDisplay = "Hispanic or Latino";
    } else {
        ethnicity = "nonhispanic";
        ethnicityDisplay = "Not Hispanic or Latino";
    }
    String ethnicityNum = (String) raceEthnicityCodes.get(ethnicity);
    Extension ethnicityCodingExtension = new Extension("ombCategory");
    Coding ethnicityCoding = new Coding();
    ethnicityCoding.setSystem("urn:oid:2.16.840.1.113883.6.238");
    ethnicityCoding.setCode(ethnicityNum);
    ethnicityCoding.setDisplay(ethnicityDisplay);
    ethnicityCodingExtension.setValue(ethnicityCoding);
    ethnicityExtension.addExtension(ethnicityCodingExtension);
    Extension ethnicityTextExtension = new Extension("text");
    ethnicityTextExtension.setValue(new StringType(ethnicityDisplay));
    ethnicityExtension.addExtension(ethnicityTextExtension);
    patientResource.addExtension(ethnicityExtension);
    String firstLanguage = (String) person.attributes.get(Person.FIRST_LANGUAGE);
    Map languageMap = (Map) languageLookup.get(firstLanguage);
    Code languageCode = new Code((String) languageMap.get("system"), (String) languageMap.get("code"), (String) languageMap.get("display"));
    List<PatientCommunicationComponent> communication = new ArrayList<PatientCommunicationComponent>();
    communication.add(new PatientCommunicationComponent(mapCodeToCodeableConcept(languageCode, (String) languageMap.get("system"))));
    patientResource.setCommunication(communication);
    HumanName name = patientResource.addName();
    name.setUse(HumanName.NameUse.OFFICIAL);
    name.addGiven((String) person.attributes.get(Person.FIRST_NAME));
    name.setFamily((String) person.attributes.get(Person.LAST_NAME));
    if (person.attributes.get(Person.NAME_PREFIX) != null) {
        name.addPrefix((String) person.attributes.get(Person.NAME_PREFIX));
    }
    if (person.attributes.get(Person.NAME_SUFFIX) != null) {
        name.addSuffix((String) person.attributes.get(Person.NAME_SUFFIX));
    }
    if (person.attributes.get(Person.MAIDEN_NAME) != null) {
        HumanName maidenName = patientResource.addName();
        maidenName.setUse(HumanName.NameUse.MAIDEN);
        maidenName.addGiven((String) person.attributes.get(Person.FIRST_NAME));
        maidenName.setFamily((String) person.attributes.get(Person.MAIDEN_NAME));
        if (person.attributes.get(Person.NAME_PREFIX) != null) {
            maidenName.addPrefix((String) person.attributes.get(Person.NAME_PREFIX));
        }
        if (person.attributes.get(Person.NAME_SUFFIX) != null) {
            maidenName.addSuffix((String) person.attributes.get(Person.NAME_SUFFIX));
        }
    }
    Extension mothersMaidenNameExtension = new Extension("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");
    String mothersMaidenName = (String) person.attributes.get(Person.NAME_MOTHER);
    mothersMaidenNameExtension.setValue(new StringType(mothersMaidenName));
    patientResource.addExtension(mothersMaidenNameExtension);
    long birthdate = (long) person.attributes.get(Person.BIRTHDATE);
    patientResource.setBirthDate(new Date(birthdate));
    Extension birthSexExtension = new Extension("http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex");
    if (person.attributes.get(Person.GENDER).equals("M")) {
        patientResource.setGender(AdministrativeGender.MALE);
        birthSexExtension.setValue(new CodeType("M"));
    } else if (person.attributes.get(Person.GENDER).equals("F")) {
        patientResource.setGender(AdministrativeGender.FEMALE);
        birthSexExtension.setValue(new CodeType("F"));
    }
    patientResource.addExtension(birthSexExtension);
    String state = (String) person.attributes.get(Person.STATE);
    Address addrResource = patientResource.addAddress();
    addrResource.addLine((String) person.attributes.get(Person.ADDRESS)).setCity((String) person.attributes.get(Person.CITY)).setPostalCode((String) person.attributes.get(Person.ZIP)).setState(state);
    if (COUNTRY_CODE != null) {
        addrResource.setCountry(COUNTRY_CODE);
    }
    Address birthplace = new Address();
    birthplace.setCity((String) person.attributes.get(Person.BIRTH_CITY)).setState((String) person.attributes.get(Person.BIRTH_STATE)).setCountry((String) person.attributes.get(Person.BIRTH_COUNTRY));
    Extension birthplaceExtension = new Extension("http://hl7.org/fhir/StructureDefinition/birthPlace");
    birthplaceExtension.setValue(birthplace);
    patientResource.addExtension(birthplaceExtension);
    if (person.attributes.get(Person.MULTIPLE_BIRTH_STATUS) != null) {
        patientResource.setMultipleBirth(new IntegerType((int) person.attributes.get(Person.MULTIPLE_BIRTH_STATUS)));
    } else {
        patientResource.setMultipleBirth(new BooleanType(false));
    }
    patientResource.addTelecom().setSystem(ContactPoint.ContactPointSystem.PHONE).setUse(ContactPoint.ContactPointUse.HOME).setValue((String) person.attributes.get(Person.TELECOM));
    String maritalStatus = ((String) person.attributes.get(Person.MARITAL_STATUS));
    if (maritalStatus != null) {
        Code maritalStatusCode = new Code("http://hl7.org/fhir/v3/MaritalStatus", maritalStatus, maritalStatus);
        patientResource.setMaritalStatus(mapCodeToCodeableConcept(maritalStatusCode, "http://hl7.org/fhir/v3/MaritalStatus"));
    } else {
        Code maritalStatusCode = new Code("http://hl7.org/fhir/v3/MaritalStatus", "S", "Never Married");
        patientResource.setMaritalStatus(mapCodeToCodeableConcept(maritalStatusCode, "http://hl7.org/fhir/v3/MaritalStatus"));
    }
    Point2D.Double coord = person.getLonLat();
    if (coord != null) {
        Extension geolocation = addrResource.addExtension();
        geolocation.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
        geolocation.addExtension("latitude", new DecimalType(coord.getY()));
        geolocation.addExtension("longitude", new DecimalType(coord.getX()));
    }
    if (!person.alive(stopTime)) {
        patientResource.setDeceased(convertFhirDateTime((Long) person.attributes.get(Person.DEATHDATE), true));
    }
    String generatedBySynthea = "Generated by <a href=\"https://github.com/synthetichealth/synthea\">Synthea</a>." + "Version identifier: " + Utilities.SYNTHEA_VERSION + " . " + "  Person seed: " + person.getSeed() + "  Population seed: " + person.populationSeed;
    patientResource.setText(new Narrative().setStatus(NarrativeStatus.GENERATED).setDiv(new XhtmlNode(NodeType.Element).setValue(generatedBySynthea)));
    if (USE_SHR_EXTENSIONS) {
        patientResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-entity-Patient"));
        // Patient profile requires race, ethnicity, birthsex,
        // MothersMaidenName, FathersName, Person-extension
        patientResource.addExtension().setUrl(SHR_EXT + "shr-actor-FictionalPerson-extension").setValue(new BooleanType(true));
        String fathersName = (String) person.attributes.get(Person.NAME_FATHER);
        Extension fathersNameExtension = new Extension(SHR_EXT + "shr-entity-FathersName-extension", new HumanName().setText(fathersName));
        patientResource.addExtension(fathersNameExtension);
        String ssn = (String) person.attributes.get(Person.IDENTIFIER_SSN);
        Extension ssnExtension = new Extension(SHR_EXT + "shr-demographics-SocialSecurityNumber-extension", new StringType(ssn));
        patientResource.addExtension(ssnExtension);
        Basic personResource = new Basic();
        // the only required field on this patient resource is code
        Coding fixedCode = new Coding("http://standardhealthrecord.org/fhir/basic-resource-type", "shr-entity-Person", "shr-entity-Person");
        personResource.setCode(new CodeableConcept().addCoding(fixedCode));
        Meta personMeta = new Meta();
        personMeta.addProfile(SHR_EXT + "shr-entity-Person");
        personResource.setMeta(personMeta);
        BundleEntryComponent personEntry = newEntry(person, bundle, personResource);
        patientResource.addExtension().setUrl(SHR_EXT + "shr-entity-Person-extension").setValue(new Reference(personEntry.getFullUrl()));
    }
    // DALY and QALY values
    // we only write the last(current) one to the patient record
    Double dalyValue = (Double) person.attributes.get("most-recent-daly");
    Double qalyValue = (Double) person.attributes.get("most-recent-qaly");
    if (dalyValue != null) {
        Extension dalyExtension = new Extension(SYNTHEA_EXT + "disability-adjusted-life-years");
        DecimalType daly = new DecimalType(dalyValue);
        dalyExtension.setValue(daly);
        patientResource.addExtension(dalyExtension);
        Extension qalyExtension = new Extension(SYNTHEA_EXT + "quality-adjusted-life-years");
        DecimalType qaly = new DecimalType(qalyValue);
        qalyExtension.setValue(qaly);
        patientResource.addExtension(qalyExtension);
    }
    return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Basic(org.hl7.fhir.dstu3.model.Basic) Address(org.hl7.fhir.dstu3.model.Address) StringType(org.hl7.fhir.dstu3.model.StringType) ArrayList(java.util.ArrayList) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu3.model.HumanName) Coding(org.hl7.fhir.dstu3.model.Coding) PatientCommunicationComponent(org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent) Point2D(java.awt.geom.Point2D) Narrative(org.hl7.fhir.dstu3.model.Narrative) ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Patient(org.hl7.fhir.dstu3.model.Patient) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.dstu3.model.Extension) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) CodeType(org.hl7.fhir.dstu3.model.CodeType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 68 with IntegerType

use of org.hl7.fhir.r4.model.IntegerType in project synthea by synthetichealth.

the class HospitalExporterR4 method addHospitalExtensions.

/**
 * Add FHIR extensions to capture additional information.
 */
public static void addHospitalExtensions(Provider h, Organization organizationResource) {
    Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
    // calculate totals for utilization
    int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
    Extension encountersExtension = new Extension(SYNTHEA_URI + "utilization-encounters-extension");
    IntegerType encountersValue = new IntegerType(totalEncounters);
    encountersExtension.setValue(encountersValue);
    organizationResource.addExtension(encountersExtension);
    int totalProcedures = utilization.column(Provider.PROCEDURES).values().stream().mapToInt(ai -> ai.get()).sum();
    Extension proceduresExtension = new Extension(SYNTHEA_URI + "utilization-procedures-extension");
    IntegerType proceduresValue = new IntegerType(totalProcedures);
    proceduresExtension.setValue(proceduresValue);
    organizationResource.addExtension(proceduresExtension);
    int totalLabs = utilization.column(Provider.LABS).values().stream().mapToInt(ai -> ai.get()).sum();
    Extension labsExtension = new Extension(SYNTHEA_URI + "utilization-labs-extension");
    IntegerType labsValue = new IntegerType(totalLabs);
    labsExtension.setValue(labsValue);
    organizationResource.addExtension(labsExtension);
    int totalPrescriptions = utilization.column(Provider.PRESCRIPTIONS).values().stream().mapToInt(ai -> ai.get()).sum();
    Extension prescriptionsExtension = new Extension(SYNTHEA_URI + "utilization-prescriptions-extension");
    IntegerType prescriptionsValue = new IntegerType(totalPrescriptions);
    prescriptionsExtension.setValue(prescriptionsValue);
    organizationResource.addExtension(prescriptionsExtension);
    Integer bedCount = h.getBedCount();
    if (bedCount != null) {
        Extension bedCountExtension = new Extension(SYNTHEA_URI + "bed-count-extension");
        IntegerType bedCountValue = new IntegerType(bedCount);
        bedCountExtension.setValue(bedCountValue);
        organizationResource.addExtension(bedCountExtension);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) Config(org.mitre.synthea.helpers.Config) Files(java.nio.file.Files) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) File(java.io.File) ArrayList(java.util.ArrayList) Provider(org.mitre.synthea.world.agents.Provider) Organization(org.hl7.fhir.r4.model.Organization) List(java.util.List) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Extension(org.hl7.fhir.r4.model.Extension) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) Table(com.google.common.collect.Table) Path(java.nio.file.Path) Collections(java.util.Collections) IntegerType(org.hl7.fhir.r4.model.IntegerType) Extension(org.hl7.fhir.r4.model.Extension) IntegerType(org.hl7.fhir.r4.model.IntegerType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 69 with IntegerType

use of org.hl7.fhir.r4.model.IntegerType in project synthea by synthetichealth.

the class FhirPractitionerExporterR4 method export.

/**
 * Export the practitioner in FHIR R4 format.
 */
public static void export(RandomNumberGenerator rand, long stop) {
    if (Config.getAsBoolean("exporter.practitioner.fhir.export")) {
        Bundle bundle = new Bundle();
        if (Config.getAsBoolean("exporter.fhir.transaction_bundle")) {
            bundle.setType(BundleType.BATCH);
        } else {
            bundle.setType(BundleType.COLLECTION);
        }
        for (Provider h : Provider.getProviderList()) {
            // filter - exports only those hospitals in use
            Table<Integer, String, AtomicInteger> utilization = h.getUtilization();
            int totalEncounters = utilization.column(Provider.ENCOUNTERS).values().stream().mapToInt(ai -> ai.get()).sum();
            if (totalEncounters > 0) {
                Map<String, ArrayList<Clinician>> clinicians = h.clinicianMap;
                for (String specialty : clinicians.keySet()) {
                    ArrayList<Clinician> docs = clinicians.get(specialty);
                    for (Clinician doc : docs) {
                        if (doc.getEncounterCount() > 0) {
                            BundleEntryComponent entry = FhirR4.practitioner(rand, bundle, doc);
                            Practitioner practitioner = (Practitioner) entry.getResource();
                            practitioner.addExtension().setUrl(EXTENSION_URI).setValue(new IntegerType(doc.getEncounterCount()));
                        }
                    }
                }
            }
        }
        String bundleJson = FhirR4.getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
        // get output folder
        List<String> folders = new ArrayList<>();
        folders.add("fhir");
        String baseDirectory = Config.get("exporter.baseDirectory");
        File f = Paths.get(baseDirectory, folders.toArray(new String[0])).toFile();
        f.mkdirs();
        Path outFilePath = f.toPath().resolve("practitionerInformation" + stop + ".json");
        try {
            Files.write(outFilePath, Collections.singleton(bundleJson), StandardOpenOption.CREATE_NEW);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) Config(org.mitre.synthea.helpers.Config) Files(java.nio.file.Files) Clinician(org.mitre.synthea.world.agents.Clinician) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) File(java.io.File) ArrayList(java.util.ArrayList) Provider(org.mitre.synthea.world.agents.Provider) FhirContext(ca.uhn.fhir.context.FhirContext) List(java.util.List) Paths(java.nio.file.Paths) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) Table(com.google.common.collect.Table) Path(java.nio.file.Path) Collections(java.util.Collections) IntegerType(org.hl7.fhir.r4.model.IntegerType) Practitioner(org.hl7.fhir.r4.model.Practitioner) Path(java.nio.file.Path) Bundle(org.hl7.fhir.r4.model.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Provider(org.mitre.synthea.world.agents.Provider) Clinician(org.mitre.synthea.world.agents.Clinician) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Practitioner(org.hl7.fhir.r4.model.Practitioner) IntegerType(org.hl7.fhir.r4.model.IntegerType) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File)

Example 70 with IntegerType

use of org.hl7.fhir.r4.model.IntegerType in project clinical_quality_language by cqframework.

the class DataRequirementsProcessor method toFhirValue.

private DataType toFhirValue(ElmRequirementsContext context, Expression value) {
    if (value == null) {
        return null;
    }
    if (value instanceof Interval) {
        // TODO: Handle lowclosed/highclosed
        return new Period().setStartElement(toFhirDateTimeValue(context, ((Interval) value).getLow())).setEndElement(toFhirDateTimeValue(context, ((Interval) value).getHigh()));
    } else if (value instanceof Literal) {
        if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
            return new DateTimeType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isDateType(value.getResultType())) {
            return new DateType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
            return new IntegerType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
            return new DecimalType(((Literal) value).getValue());
        } else if (context.getTypeResolver().isStringType(value.getResultType())) {
            return new StringType(((Literal) value).getValue());
        }
    } else if (value instanceof DateTime) {
        DateTime dateTime = (DateTime) value;
        return new DateTimeType(toDateTimeString(toFhirValue(context, dateTime.getYear()), toFhirValue(context, dateTime.getMonth()), toFhirValue(context, dateTime.getDay()), toFhirValue(context, dateTime.getHour()), toFhirValue(context, dateTime.getMinute()), toFhirValue(context, dateTime.getSecond()), toFhirValue(context, dateTime.getMillisecond()), toFhirValue(context, dateTime.getTimezoneOffset())));
    } else if (value instanceof org.hl7.elm.r1.Date) {
        org.hl7.elm.r1.Date date = (org.hl7.elm.r1.Date) value;
        return new DateType(toDateString(toFhirValue(context, date.getYear()), toFhirValue(context, date.getMonth()), toFhirValue(context, date.getDay())));
    } else if (value instanceof Start) {
        DataType operand = toFhirValue(context, ((Start) value).getOperand());
        if (operand != null) {
            Period period = (Period) operand;
            return period.getStartElement();
        }
    } else if (value instanceof End) {
        DataType operand = toFhirValue(context, ((End) value).getOperand());
        if (operand != null) {
            Period period = (Period) operand;
            return period.getEndElement();
        }
    } else if (value instanceof ParameterRef) {
        if (context.getTypeResolver().isIntervalType(value.getResultType())) {
            Extension e = toExpression(context, (ParameterRef) value);
            org.hl7.cql.model.DataType pointType = ((IntervalType) value.getResultType()).getPointType();
            if (context.getTypeResolver().isDateTimeType(pointType) || context.getTypeResolver().isDateType(pointType)) {
                Period period = new Period();
                period.addExtension(e);
                return period;
            } else if (context.getTypeResolver().isQuantityType(pointType) || context.getTypeResolver().isIntegerType(pointType) || context.getTypeResolver().isDecimalType(pointType)) {
                Range range = new Range();
                range.addExtension(e);
                return range;
            } else {
                throw new IllegalArgumentException(String.format("toFhirValue not implemented for interval of %s", pointType.toString()));
            }
        } else // Boolean, Integer, Decimal, String, Quantity, Date, DateTime, Time, Coding, CodeableConcept
        if (context.getTypeResolver().isBooleanType(value.getResultType())) {
            BooleanType result = new BooleanType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isIntegerType(value.getResultType())) {
            IntegerType result = new IntegerType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDecimalType(value.getResultType())) {
            DecimalType result = new DecimalType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isQuantityType(value.getResultType())) {
            Quantity result = new Quantity();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isCodeType(value.getResultType())) {
            Coding result = new Coding();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isConceptType(value.getResultType())) {
            CodeableConcept result = new CodeableConcept();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDateType(value.getResultType())) {
            DateType result = new DateType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isDateTimeType(value.getResultType())) {
            DateTimeType result = new DateTimeType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else if (context.getTypeResolver().isTimeType(value.getResultType())) {
            TimeType result = new TimeType();
            result.addExtension(toExpression(context, (ParameterRef) value));
            return result;
        } else {
            throw new IllegalArgumentException(String.format("toFhirValue not implemented for parameter of type %s", value.getResultType().toString()));
        }
    }
    throw new IllegalArgumentException(String.format("toFhirValue not implemented for %s", value.getClass().getSimpleName()));
}
Also used : IntervalType(org.hl7.cql.model.IntervalType) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) Quantity(org.hl7.fhir.r5.model.Quantity) org.hl7.elm.r1(org.hl7.elm.r1)

Aggregations

ArrayList (java.util.ArrayList)51 BigDecimal (java.math.BigDecimal)34 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)28 IntegerType (org.hl7.fhir.r5.model.IntegerType)26 IntegerType (org.hl7.fhir.r4.model.IntegerType)23 IntegerType (org.hl7.fhir.r4b.model.IntegerType)23 UcumException (org.fhir.ucum.UcumException)19 Test (org.junit.jupiter.api.Test)13 Decimal (org.fhir.ucum.Decimal)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 Base (org.hl7.fhir.r4b.model.Base)11 Base (org.hl7.fhir.r5.model.Base)11 IntegerType (org.hl7.fhir.dstu2.model.IntegerType)10 IntegerType (org.hl7.fhir.dstu2016may.model.IntegerType)10 StringType (org.hl7.fhir.r4.model.StringType)10 Patient (org.hl7.fhir.r4.model.Patient)9 Map (java.util.Map)7 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)7 DecimalType (org.hl7.fhir.r5.model.DecimalType)7 List (java.util.List)6