Search in sources :

Example 46 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project synthea by synthetichealth.

the class FhirDstu2 method provider.

/**
 * Map the Provider into a FHIR Organization resource, and add it to the given Bundle.
 *
 * @param bundle
 *          The Bundle to add to
 * @param provider
 *          The Provider
 * @return The added Entry
 */
protected static Entry provider(Bundle bundle, Provider provider) {
    ca.uhn.fhir.model.dstu2.resource.Organization organizationResource = new ca.uhn.fhir.model.dstu2.resource.Organization();
    CodeableConceptDt organizationType = mapCodeToCodeableConcept(new Code("http://hl7.org/fhir/ValueSet/organization-type", "prov", "Healthcare Provider"), "Healthcare Provider");
    organizationResource.addIdentifier().setSystem("https://github.com/synthetichealth/synthea").setValue((String) provider.getResourceID());
    organizationResource.setName(provider.name);
    organizationResource.setType(organizationType);
    AddressDt address = new AddressDt().addLine(provider.address).setCity(provider.city).setPostalCode(provider.zip).setState(provider.state);
    if (COUNTRY_CODE != null) {
        address.setCountry(COUNTRY_CODE);
    }
    organizationResource.addAddress(address);
    if (provider.phone != null && !provider.phone.isEmpty()) {
        ContactPointDt contactPoint = new ContactPointDt().setSystem(ContactPointSystemEnum.PHONE).setValue(provider.phone);
        organizationResource.addTelecom(contactPoint);
    }
    return newEntry(bundle, organizationResource, provider.getResourceID());
}
Also used : Organization(ca.uhn.fhir.model.dstu2.resource.Organization) Organization(ca.uhn.fhir.model.dstu2.resource.Organization) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) AddressDt(ca.uhn.fhir.model.dstu2.composite.AddressDt) ContactPointDt(ca.uhn.fhir.model.dstu2.composite.ContactPointDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code)

Example 47 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project synthea by synthetichealth.

the class FhirDstu2 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 Entry 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));
    patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.MR).setSystem("http://hospital.smarthealthit.org").setValue((String) person.attributes.get(Person.ID));
    patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.SOCIAL_BENEFICIARY_IDENTIFIER).setSystem("http://hl7.org/fhir/sid/us-ssn").setValue((String) person.attributes.get(Person.IDENTIFIER_SSN));
    if (person.attributes.get(Person.IDENTIFIER_DRIVERS) != null) {
        patientResource.addIdentifier().setType(IdentifierTypeCodesEnum.DL).setSystem("urn:oid:2.16.840.1.113883.4.3.25").setValue((String) person.attributes.get(Person.IDENTIFIER_DRIVERS));
    }
    ExtensionDt raceExtension = new ExtensionDt();
    raceExtension.setUrl("http://hl7.org/fhir/StructureDefinition/us-core-race");
    String race = (String) person.attributes.get(Person.RACE);
    ExtensionDt ethnicityExtension = new ExtensionDt();
    ethnicityExtension.setUrl("http://hl7.org/fhir/StructureDefinition/us-core-ethnicity");
    String ethnicity = (String) person.attributes.get(Person.ETHNICITY);
    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 ethnicityDisplay;
    if (ethnicity.equals("hispanic")) {
        ethnicityDisplay = "Hispanic or Latino";
    } else {
        ethnicityDisplay = "Not Hispanic or Latino";
    }
    Code raceCode = new Code("http://hl7.org/fhir/v3/Race", (String) raceEthnicityCodes.get(race), raceDisplay);
    Code ethnicityCode = new Code("http://hl7.org/fhir/v3/Ethnicity", (String) raceEthnicityCodes.get(ethnicity), ethnicityDisplay);
    raceExtension.setValue(mapCodeToCodeableConcept(raceCode, "http://hl7.org/fhir/v3/Race"));
    ethnicityExtension.setValue(mapCodeToCodeableConcept(ethnicityCode, "http://hl7.org/fhir/v3/Ethnicity"));
    patientResource.addUndeclaredExtension(raceExtension);
    patientResource.addUndeclaredExtension(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<Communication> communication = new ArrayList<Communication>();
    Communication language = new Communication();
    language.setLanguage(mapCodeToCodeableConcept(languageCode, (String) languageMap.get("system")));
    communication.add(language);
    patientResource.setCommunication(communication);
    HumanNameDt name = patientResource.addName();
    name.setUse(NameUseEnum.OFFICIAL);
    name.addGiven((String) person.attributes.get(Person.FIRST_NAME));
    List<StringDt> officialFamilyNames = new ArrayList<StringDt>();
    officialFamilyNames.add(new StringDt((String) person.attributes.get(Person.LAST_NAME)));
    name.setFamily(officialFamilyNames);
    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) {
        HumanNameDt maidenName = patientResource.addName();
        maidenName.setUse(NameUseEnum.MAIDEN);
        maidenName.addGiven((String) person.attributes.get(Person.FIRST_NAME));
        List<StringDt> maidenFamilyNames = new ArrayList<StringDt>();
        maidenFamilyNames.add(new StringDt((String) person.attributes.get(Person.MAIDEN_NAME)));
        maidenName.setFamily(maidenFamilyNames);
        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));
        }
    }
    ExtensionDt mothersMaidenNameExtension = new ExtensionDt();
    mothersMaidenNameExtension.setUrl("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");
    String mothersMaidenName = (String) person.attributes.get(Person.NAME_MOTHER);
    mothersMaidenNameExtension.setValue(new StringDt(mothersMaidenName));
    patientResource.addUndeclaredExtension(mothersMaidenNameExtension);
    long birthdate = (long) person.attributes.get(Person.BIRTHDATE);
    patientResource.setBirthDate(new DateDt(new Date(birthdate)));
    ExtensionDt birthSexExtension = new ExtensionDt();
    birthSexExtension.setUrl("http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex");
    if (person.attributes.get(Person.GENDER).equals("M")) {
        patientResource.setGender(AdministrativeGenderEnum.MALE);
        birthSexExtension.setValue(new CodeDt("M"));
    } else if (person.attributes.get(Person.GENDER).equals("F")) {
        patientResource.setGender(AdministrativeGenderEnum.FEMALE);
        birthSexExtension.setValue(new CodeDt("F"));
    }
    patientResource.addUndeclaredExtension(birthSexExtension);
    String state = (String) person.attributes.get(Person.STATE);
    AddressDt 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);
    }
    Point2D.Double coord = person.getLonLat();
    if (coord != null) {
        ExtensionDt geolocationExtension = new ExtensionDt();
        geolocationExtension.setUrl("http://hl7.org/fhir/StructureDefinition/geolocation");
        ExtensionDt latitudeExtension = new ExtensionDt();
        ExtensionDt longitudeExtension = new ExtensionDt();
        latitudeExtension.setUrl("latitude");
        longitudeExtension.setUrl("longitude");
        latitudeExtension.setValue(new DecimalDt(coord.getY()));
        longitudeExtension.setValue(new DecimalDt(coord.getX()));
        geolocationExtension.addUndeclaredExtension(latitudeExtension);
        geolocationExtension.addUndeclaredExtension(longitudeExtension);
        addrResource.addUndeclaredExtension(geolocationExtension);
    }
    AddressDt birthplace = new AddressDt();
    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));
    ExtensionDt birthplaceExtension = new ExtensionDt();
    birthplaceExtension.setUrl("http://hl7.org/fhir/StructureDefinition/birthPlace");
    birthplaceExtension.setValue(birthplace);
    patientResource.addUndeclaredExtension(birthplaceExtension);
    if (person.attributes.get(Person.MULTIPLE_BIRTH_STATUS) != null) {
        patientResource.setMultipleBirth(new IntegerDt((int) person.attributes.get(Person.MULTIPLE_BIRTH_STATUS)));
    } else {
        patientResource.setMultipleBirth(new BooleanDt(false));
    }
    patientResource.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setUse(ContactPointUseEnum.HOME).setValue((String) person.attributes.get(Person.TELECOM));
    String maritalStatus = ((String) person.attributes.get(Person.MARITAL_STATUS));
    if (maritalStatus != null) {
        patientResource.setMaritalStatus(MaritalStatusCodesEnum.forCode(maritalStatus.toUpperCase()));
    } else {
        patientResource.setMaritalStatus(MaritalStatusCodesEnum.S);
    }
    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 NarrativeDt(new XhtmlDt(generatedBySynthea), NarrativeStatusEnum.GENERATED));
    // 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) {
        ExtensionDt dalyExtension = new ExtensionDt();
        dalyExtension.setUrl(SYNTHEA_EXT + "disability-adjusted-life-years");
        DecimalDt daly = new DecimalDt(dalyValue);
        dalyExtension.setValue(daly);
        patientResource.addUndeclaredExtension(dalyExtension);
        ExtensionDt qalyExtension = new ExtensionDt();
        qalyExtension.setUrl(SYNTHEA_EXT + "quality-adjusted-life-years");
        DecimalDt qaly = new DecimalDt(qalyValue);
        qalyExtension.setValue(qaly);
        patientResource.addUndeclaredExtension(qalyExtension);
    }
    return newEntry(bundle, patientResource, (String) person.attributes.get(Person.ID));
}
Also used : HumanNameDt(ca.uhn.fhir.model.dstu2.composite.HumanNameDt) XhtmlDt(ca.uhn.fhir.model.primitive.XhtmlDt) IntegerDt(ca.uhn.fhir.model.primitive.IntegerDt) DecimalDt(ca.uhn.fhir.model.primitive.DecimalDt) ArrayList(java.util.ArrayList) Point2D(java.awt.geom.Point2D) AddressDt(ca.uhn.fhir.model.dstu2.composite.AddressDt) BooleanDt(ca.uhn.fhir.model.primitive.BooleanDt) ExtensionDt(ca.uhn.fhir.model.api.ExtensionDt) Communication(ca.uhn.fhir.model.dstu2.resource.Patient.Communication) CodeDt(ca.uhn.fhir.model.primitive.CodeDt) DateDt(ca.uhn.fhir.model.primitive.DateDt) Patient(ca.uhn.fhir.model.dstu2.resource.Patient) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) NarrativeDt(ca.uhn.fhir.model.dstu2.composite.NarrativeDt) Date(java.util.Date) StringDt(ca.uhn.fhir.model.primitive.StringDt) Map(java.util.Map) HashMap(java.util.HashMap)

Example 48 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project synthea by synthetichealth.

the class FhirDstu2 method supplyDelivery.

/**
 * Map the JsonObject for a Supply into a FHIR SupplyDelivery and add it to the Bundle.
 *
 * @param rand           Source of randomness to use when generating ids etc
 * @param personEntry    The Person entry.
 * @param bundle         Bundle to add to.
 * @param supply         The supplied object to add.
 * @param encounter      The encounter during which the supplies were delivered
 * @return The added Entry.
 */
private static Entry supplyDelivery(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, HealthRecord.Supply supply, Encounter encounter) {
    SupplyDelivery supplyResource = new SupplyDelivery();
    supplyResource.setStatus(SupplyDeliveryStatusEnum.DELIVERED);
    supplyResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    CodeableConceptDt type = new CodeableConceptDt();
    type.addCoding().setCode("device").setDisplay("Device").setSystem("http://hl7.org/fhir/supply-item-type");
    supplyResource.setType(type);
    // super hackish -- there's no "code" field available here, just a reference to a Device
    // so for now just put some text in the reference
    ResourceReferenceDt suppliedItem = new ResourceReferenceDt();
    Code code = supply.codes.get(0);
    suppliedItem.setDisplay("SNOMED[" + code.code + "]: " + code.display);
    supplyResource.setSuppliedItem(suppliedItem);
    supplyResource.setQuantity(new SimpleQuantityDt(supply.quantity));
    supplyResource.setTime((DateTimeDt) convertFhirDateTime(supply.start, true));
    return newEntry(rand, bundle, supplyResource);
}
Also used : ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) SupplyDelivery(ca.uhn.fhir.model.dstu2.resource.SupplyDelivery) SimpleQuantityDt(ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt) Code(org.mitre.synthea.world.concepts.HealthRecord.Code)

Example 49 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project synthea by synthetichealth.

the class FhirDstu2 method newEntry.

/**
 * Helper function to create an Entry for the given Resource within the given Bundle. Sets the
 * resourceID to a random UUID, sets the entry's fullURL to that resourceID, and adds the entry to
 * the bundle.
 *
 * @param bundle The Bundle to add the Entry to
 * @param resource Resource the new Entry should contain
 * @param resourceID The resourceID to use.
 * @return the created Entry
 */
private static Entry newEntry(Bundle bundle, BaseResource resource, String resourceID) {
    Entry entry = bundle.addEntry();
    resource.setId(resourceID);
    if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
        entry.setFullUrl(resource.getResourceName() + "/" + resourceID);
    } else {
        entry.setFullUrl("urn:uuid:" + resourceID);
    }
    entry.setResource(resource);
    if (TRANSACTION_BUNDLE) {
        EntryRequest request = entry.getRequest();
        request.setMethod(HTTPVerbEnum.POST);
        String resourceType = resource.getResourceName();
        request.setUrl(resourceType);
        if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
            IdentifierDt identifier = null;
            switch(resourceType) {
                case "Practitioner":
                    Practitioner practitioner = (Practitioner) resource;
                    identifier = practitioner.getIdentifierFirstRep();
                    break;
                case "Organization":
                    Organization organization = (Organization) resource;
                    identifier = organization.getIdentifierFirstRep();
                    break;
                default:
                    break;
            }
            if (identifier != null) {
                request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
            }
        }
        entry.setRequest(request);
    }
    return entry;
}
Also used : Practitioner(ca.uhn.fhir.model.dstu2.resource.Practitioner) EntryRequest(ca.uhn.fhir.model.dstu2.resource.Bundle.EntryRequest) Entry(ca.uhn.fhir.model.dstu2.resource.Bundle.Entry) IdentifierDt(ca.uhn.fhir.model.dstu2.composite.IdentifierDt) Organization(ca.uhn.fhir.model.dstu2.resource.Organization)

Example 50 with Bundle

use of ca.uhn.fhir.model.dstu2.resource.Bundle in project synthea by synthetichealth.

the class FhirDstu2 method imagingStudy.

/**
 * Map the given ImagingStudy to a FHIR ImagingStudy resource, and add it to the given Bundle.
 *
 * @param rand
 *          Source of randomness to use when generating ids etc
 * @param personEntry
 *          The Entry for the Person
 * @param bundle
 *          Bundle to add the ImagingStudy to
 * @param encounterEntry
 *          Current Encounter entry
 * @param imagingStudy
 *          The ImagingStudy to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static Entry imagingStudy(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, ImagingStudy imagingStudy) {
    ca.uhn.fhir.model.dstu2.resource.ImagingStudy imagingStudyResource = new ca.uhn.fhir.model.dstu2.resource.ImagingStudy();
    OidDt studyUid = new OidDt();
    studyUid.setValue("urn:oid:" + imagingStudy.dicomUid);
    imagingStudyResource.setUid(studyUid);
    imagingStudyResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
    DateTimeDt startDate = new DateTimeDt(new Date(imagingStudy.start));
    imagingStudyResource.setStarted(startDate);
    // Convert the series into their FHIR equivalents
    int numberOfSeries = imagingStudy.series.size();
    imagingStudyResource.setNumberOfSeries(new UnsignedIntDt(numberOfSeries));
    List<Series> seriesResourceList = new ArrayList<Series>();
    int totalNumberOfInstances = 0;
    int seriesNo = 1;
    for (ImagingStudy.Series series : imagingStudy.series) {
        Series seriesResource = new Series();
        OidDt seriesUid = new OidDt();
        seriesUid.setValue("urn:oid:" + series.dicomUid);
        seriesResource.setUid(seriesUid);
        seriesResource.setNumber(new UnsignedIntDt(seriesNo));
        seriesResource.setStarted(startDate);
        seriesResource.setAvailability(InstanceAvailabilityEnum.UNAVAILABLE);
        CodeableConceptDt modalityConcept = mapCodeToCodeableConcept(series.modality, DICOM_DCM_URI);
        seriesResource.setModality(modalityConcept.getCoding().get(0));
        CodeableConceptDt bodySiteConcept = mapCodeToCodeableConcept(series.bodySite, SNOMED_URI);
        seriesResource.setBodySite(bodySiteConcept.getCoding().get(0));
        // Convert the images in each series into their FHIR equivalents
        int numberOfInstances = series.instances.size();
        seriesResource.setNumberOfInstances(new UnsignedIntDt(numberOfInstances));
        totalNumberOfInstances += numberOfInstances;
        List<SeriesInstance> instanceResourceList = new ArrayList<SeriesInstance>();
        int instanceNo = 1;
        for (ImagingStudy.Instance instance : series.instances) {
            SeriesInstance instanceResource = new SeriesInstance();
            OidDt instanceUid = new OidDt();
            instanceUid.setValue("urn:oid:" + instance.dicomUid);
            instanceResource.setUid(instanceUid);
            instanceResource.setTitle(instance.title);
            OidDt sopOid = new OidDt();
            sopOid.setValue("urn:oid:" + instance.sopClass.code);
            instanceResource.setSopClass(sopOid);
            instanceResource.setNumber(new UnsignedIntDt(instanceNo));
            instanceResourceList.add(instanceResource);
            instanceNo += 1;
        }
        seriesResource.setInstance(instanceResourceList);
        seriesResourceList.add(seriesResource);
        seriesNo += 1;
    }
    imagingStudyResource.setSeries(seriesResourceList);
    imagingStudyResource.setNumberOfInstances(totalNumberOfInstances);
    return newEntry(rand, bundle, imagingStudyResource);
}
Also used : ResourceReferenceDt(ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt) CodeableConceptDt(ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt) UnsignedIntDt(ca.uhn.fhir.model.primitive.UnsignedIntDt) SeriesInstance(ca.uhn.fhir.model.dstu2.resource.ImagingStudy.SeriesInstance) ArrayList(java.util.ArrayList) Series(ca.uhn.fhir.model.dstu2.resource.ImagingStudy.Series) ImagingStudy(org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy) Date(java.util.Date) OidDt(ca.uhn.fhir.model.primitive.OidDt) Series(ca.uhn.fhir.model.dstu2.resource.ImagingStudy.Series) DateTimeDt(ca.uhn.fhir.model.primitive.DateTimeDt)

Aggregations

Bundle (ca.uhn.fhir.model.dstu2.resource.Bundle)37 Entry (ca.uhn.fhir.model.dstu2.resource.Bundle.Entry)34 Date (java.util.Date)20 ResourceReferenceDt (ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt)18 ArrayList (java.util.ArrayList)16 CodeableConceptDt (ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt)15 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)15 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)15 HashMap (java.util.HashMap)11 GET (javax.ws.rs.GET)11 Path (javax.ws.rs.Path)11 Produces (javax.ws.rs.Produces)11 Condition (ca.uhn.fhir.model.dstu2.resource.Condition)10 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)9 CodingDt (ca.uhn.fhir.model.dstu2.composite.CodingDt)8 JsonObject (javax.json.JsonObject)8 Provider (org.mitre.synthea.world.agents.Provider)8 Observation (ca.uhn.fhir.model.dstu2.resource.Observation)7 Patient (ca.uhn.fhir.model.dstu2.resource.Patient)7 DateTimeDt (ca.uhn.fhir.model.primitive.DateTimeDt)7