Search in sources :

Example 96 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirR4 method encounterClaim.

/**
 * Create an entry for the given Claim, associated to an Encounter.
 *
 * @param person         The patient having the encounter.
 * @param personEntry    Entry for the person
 * @param bundle         The Bundle to add to
 * @param encounterEntry The current Encounter
 * @param claim          the Claim object
 * @return the added Entry
 */
private static BundleEntryComponent encounterClaim(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Claim claim) {
    org.hl7.fhir.r4.model.Claim claimResource = new org.hl7.fhir.r4.model.Claim();
    org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
    claimResource.setStatus(ClaimStatus.ACTIVE);
    CodeableConcept type = new CodeableConcept();
    type.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/claim-type").setCode("institutional");
    claimResource.setType(type);
    claimResource.setUse(org.hl7.fhir.r4.model.Claim.Use.CLAIM);
    InsuranceComponent insuranceComponent = new InsuranceComponent();
    insuranceComponent.setSequence(1);
    insuranceComponent.setFocal(true);
    insuranceComponent.setCoverage(new Reference().setDisplay(claim.payer.getName()));
    claimResource.addInsurance(insuranceComponent);
    // duration of encounter
    claimResource.setBillablePeriod(encounterResource.getPeriod());
    claimResource.setCreated(encounterResource.getPeriod().getEnd());
    claimResource.setPatient(new Reference().setReference(personEntry.getFullUrl()).setDisplay((String) person.attributes.get(Person.NAME)));
    claimResource.setProvider(encounterResource.getServiceProvider());
    if (USE_US_CORE_IG) {
        claimResource.setFacility(encounterResource.getLocationFirstRep().getLocation());
    }
    // set the required priority
    CodeableConcept priority = new CodeableConcept();
    priority.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/processpriority").setCode("normal");
    claimResource.setPriority(priority);
    // add item for encounter
    claimResource.addItem(new ItemComponent(new PositiveIntType(1), encounterResource.getTypeFirstRep()).addEncounter(new Reference(encounterEntry.getFullUrl())));
    int itemSequence = 2;
    int conditionSequence = 1;
    int procedureSequence = 1;
    int informationSequence = 1;
    for (Claim.ClaimEntry claimEntry : claim.items) {
        HealthRecord.Entry item = claimEntry.entry;
        if (Costs.hasCost(item)) {
            // update claimItems list
            Code primaryCode = item.codes.get(0);
            String system = ExportHelper.getSystemURI(primaryCode.system);
            ItemComponent claimItem = new ItemComponent(new PositiveIntType(itemSequence), mapCodeToCodeableConcept(primaryCode, system));
            // calculate the cost of the procedure
            Money moneyResource = new Money();
            moneyResource.setCurrency("USD");
            moneyResource.setValue(item.getCost());
            claimItem.setNet(moneyResource);
            claimResource.addItem(claimItem);
            if (item instanceof Procedure) {
                Type procedureReference = new Reference(item.fullUrl);
                ProcedureComponent claimProcedure = new ProcedureComponent(new PositiveIntType(procedureSequence), procedureReference);
                claimResource.addProcedure(claimProcedure);
                claimItem.addProcedureSequence(procedureSequence);
                procedureSequence++;
            } else {
                Reference informationReference = new Reference(item.fullUrl);
                SupportingInformationComponent informationComponent = new SupportingInformationComponent();
                informationComponent.setSequence(informationSequence);
                informationComponent.setValue(informationReference);
                CodeableConcept category = new CodeableConcept();
                category.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/claiminformationcategory").setCode("info");
                informationComponent.setCategory(category);
                claimResource.addSupportingInfo(informationComponent);
                claimItem.addInformationSequence(informationSequence);
                informationSequence++;
            }
        } else {
            // assume it's a Condition, we don't have a Condition class specifically
            // add diagnosisComponent to claim
            Reference diagnosisReference = new Reference(item.fullUrl);
            DiagnosisComponent diagnosisComponent = new DiagnosisComponent(new PositiveIntType(conditionSequence), diagnosisReference);
            claimResource.addDiagnosis(diagnosisComponent);
            // update claimItems with diagnosis
            ItemComponent diagnosisItem = new ItemComponent(new PositiveIntType(itemSequence), mapCodeToCodeableConcept(item.codes.get(0), SNOMED_URI));
            diagnosisItem.addDiagnosisSequence(conditionSequence);
            claimResource.addItem(diagnosisItem);
            conditionSequence++;
        }
        itemSequence++;
    }
    Money moneyResource = new Money();
    moneyResource.setCurrency("USD");
    moneyResource.setValue(claim.getTotalClaimCost());
    claimResource.setTotal(moneyResource);
    return newEntry(person, bundle, claimResource);
}
Also used : DiagnosisComponent(org.hl7.fhir.r4.model.Claim.DiagnosisComponent) ProcedureComponent(org.hl7.fhir.r4.model.Claim.ProcedureComponent) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) Money(org.hl7.fhir.r4.model.Money) SupportingInformationComponent(org.hl7.fhir.r4.model.Claim.SupportingInformationComponent) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) ItemComponent(org.hl7.fhir.r4.model.Claim.ItemComponent) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) InsuranceComponent(org.hl7.fhir.r4.model.Claim.InsuranceComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) IntegerType(org.hl7.fhir.r4.model.IntegerType) BooleanType(org.hl7.fhir.r4.model.BooleanType) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) DeviceNameType(org.hl7.fhir.r4.model.Device.DeviceNameType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) AllergyIntoleranceType(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType) DecimalType(org.hl7.fhir.r4.model.DecimalType) CodeType(org.hl7.fhir.r4.model.CodeType) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) StringType(org.hl7.fhir.r4.model.StringType) DateType(org.hl7.fhir.r4.model.DateType) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) Type(org.hl7.fhir.r4.model.Type) DoseRateType(org.hl7.fhir.r4.model.codesystems.DoseRateType) Claim(org.mitre.synthea.world.concepts.Claim) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 97 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirR4 method provider.

/**
 * Map the Provider into a FHIR Organization resource, and add it to the given Bundle.
 *
 * @param rand     Source of randomness to use when generating ids etc
 * @param bundle   The Bundle to add to
 * @param provider The Provider
 * @return The added Entry
 */
protected static BundleEntryComponent provider(RandomNumberGenerator rand, Bundle bundle, Provider provider) {
    Organization organizationResource = new Organization();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-organization");
        organizationResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        organizationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-entity-Organization"));
        organizationResource.addIdentifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid" + provider.getResourceID());
        organizationResource.addContact().setName(new HumanName().setText("Synthetic Provider"));
    }
    List<CodeableConcept> organizationType = new ArrayList<CodeableConcept>();
    organizationType.add(mapCodeToCodeableConcept(new Code("http://terminology.hl7.org/CodeSystem/organization-type", "prov", "Healthcare Provider"), "http://terminology.hl7.org/CodeSystem/organization-type"));
    organizationResource.addIdentifier().setSystem(SYNTHEA_IDENTIFIER).setValue((String) provider.getResourceID());
    organizationResource.setActive(true);
    organizationResource.setId(provider.getResourceID());
    organizationResource.setName(provider.name);
    organizationResource.setType(organizationType);
    Address address = new Address().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()) {
        ContactPoint contactPoint = new ContactPoint().setSystem(ContactPointSystem.PHONE).setValue(provider.phone);
        organizationResource.addTelecom(contactPoint);
    } else if (USE_US_CORE_IG) {
        ContactPoint contactPoint = new ContactPoint().setSystem(ContactPointSystem.PHONE).setValue("(555) 555-5555");
        organizationResource.addTelecom(contactPoint);
    }
    org.hl7.fhir.r4.model.Location location = null;
    if (USE_US_CORE_IG) {
        location = providerLocation(rand, bundle, provider);
    }
    BundleEntryComponent entry = newEntry(bundle, organizationResource, provider.getResourceID());
    // add location to bundle *after* organization to ensure no forward reference
    if (location != null) {
        newEntry(bundle, location, provider.getResourceLocationID());
    }
    return entry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Organization(org.hl7.fhir.r4.model.Organization) Address(org.hl7.fhir.r4.model.Address) ArrayList(java.util.ArrayList) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) HumanName(org.hl7.fhir.r4.model.HumanName) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 98 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirR4 method encounter.

/**
 * Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
 *
 * @param personEntry Entry for the Person
 * @param bundle      The Bundle to add to
 * @param encounter   The current Encounter
 * @return The added Entry
 */
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
    org.hl7.fhir.r4.model.Encounter encounterResource = new org.hl7.fhir.r4.model.Encounter();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter");
        encounterResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
        Extension performedContext = new Extension();
        performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
        performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
        encounterResource.addExtension(performedContext);
    }
    Patient patient = (Patient) personEntry.getResource();
    encounterResource.setSubject(new Reference().setReference(personEntry.getFullUrl()).setDisplay(patient.getNameFirstRep().getNameAsSingleString()));
    encounterResource.setStatus(EncounterStatus.FINISHED);
    if (encounter.codes.isEmpty()) {
        // wellness encounter
        encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
    } else {
        Code code = encounter.codes.get(0);
        encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
    }
    Coding classCode = new Coding();
    classCode.setCode(EncounterType.fromString(encounter.type).code());
    classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
    encounterResource.setClass_(classCode);
    encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(new Date(encounter.stop)));
    if (encounter.reason != null) {
        encounterResource.addReasonCode().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
    }
    Provider provider = encounter.provider;
    if (provider == null) {
        // no associated provider, patient goes to wellness provider
        provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
    }
    if (TRANSACTION_BUNDLE) {
        encounterResource.setServiceProvider(new Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
    } else {
        String providerFullUrl = findProviderUrl(provider, bundle);
        if (providerFullUrl != null) {
            encounterResource.setServiceProvider(new Reference(providerFullUrl));
        } else {
            BundleEntryComponent providerOrganization = provider(person, bundle, provider);
            encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
        }
    }
    encounterResource.getServiceProvider().setDisplay(provider.name);
    if (USE_US_CORE_IG) {
        String referenceUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirSearchUrl("Location", provider.getResourceLocationID()) : findLocationUrl(provider, bundle);
        encounterResource.addLocation().setLocation(new Reference().setReference(referenceUrl).setDisplay(provider.name));
    }
    if (encounter.clinician != null) {
        if (TRANSACTION_BUNDLE) {
            encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
        } else {
            String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
            if (practitionerFullUrl != null) {
                encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
            } else {
                BundleEntryComponent practitioner = practitioner(person, bundle, encounter.clinician);
                encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
            }
        }
        encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
        encounterResource.getParticipantFirstRep().addType(mapCodeToCodeableConcept(new Code("http://terminology.hl7.org/CodeSystem/v3-ParticipationType", "PPRF", "primary performer"), null));
        encounterResource.getParticipantFirstRep().setPeriod(encounterResource.getPeriod());
    }
    if (encounter.discharge != null) {
        EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
        Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
        hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
        encounterResource.setHospitalization(hospitalization);
    }
    BundleEntryComponent entry = newEntry(person, bundle, encounterResource);
    if (USE_US_CORE_IG) {
        // US Core Encounters should have an identifier to support the required
        // Encounter.identifier search parameter
        encounterResource.addIdentifier().setUse(IdentifierUse.OFFICIAL).setSystem(SYNTHEA_IDENTIFIER).setValue(encounterResource.getId());
    }
    return entry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) EncounterHospitalizationComponent(org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Provider(org.mitre.synthea.world.agents.Provider) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) CodeType(org.hl7.fhir.r4.model.CodeType)

Example 99 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirR4 method media.

/**
 * Map the given Observation with attachment element to a FHIR Media 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 Media to
 * @param encounterEntry Current Encounter entry
 * @param obs   The Observation to map to FHIR and add to the bundle
 * @return The added Entry
 */
private static BundleEntryComponent media(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) {
    org.hl7.fhir.r4.model.Media mediaResource = new org.hl7.fhir.r4.model.Media();
    // Hard code as Image since we don't anticipate using video or audio any time soon
    Code mediaType = new Code("http://terminology.hl7.org/CodeSystem/media-type", "image", "Image");
    if (obs.codes != null && obs.codes.size() > 0) {
        List<CodeableConcept> reasonList = obs.codes.stream().map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
        mediaResource.setReasonCode(reasonList);
    }
    mediaResource.setType(mapCodeToCodeableConcept(mediaType, MEDIA_TYPE_URI));
    mediaResource.setStatus(MediaStatus.COMPLETED);
    mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
    mediaResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    Attachment content = (Attachment) obs.value;
    org.hl7.fhir.r4.model.Attachment contentResource = new org.hl7.fhir.r4.model.Attachment();
    contentResource.setContentType(content.contentType);
    contentResource.setLanguage(content.language);
    if (content.data != null) {
        contentResource.setDataElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.data));
    } else {
        contentResource.setSize(content.size);
    }
    contentResource.setUrl(content.url);
    contentResource.setTitle(content.title);
    if (content.hash != null) {
        contentResource.setHashElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.hash));
    }
    mediaResource.setWidth(content.width);
    mediaResource.setHeight(content.height);
    mediaResource.setContent(contentResource);
    return newEntry(rand, bundle, mediaResource);
}
Also used : Location(org.mitre.synthea.world.geography.Location) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) SupplyDeliveryStatus(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus) Identifier(org.hl7.fhir.r4.model.Identifier) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HashBasedTable(com.google.common.collect.HashBasedTable) Condition(org.hl7.fhir.r4.model.Condition) CarePlanActivityComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent) Reference(org.hl7.fhir.r4.model.Reference) SupplyDeliverySuppliedItemComponent(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliverySuppliedItemComponent) HTTPVerb(org.hl7.fhir.r4.model.Bundle.HTTPVerb) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) FhirContext(ca.uhn.fhir.context.FhirContext) Device(org.hl7.fhir.r4.model.Device) Person(org.mitre.synthea.world.agents.Person) ImmunizationStatus(org.hl7.fhir.r4.model.Immunization.ImmunizationStatus) Map(java.util.Map) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) Coverage(org.hl7.fhir.r4.model.Coverage) IntegerType(org.hl7.fhir.r4.model.IntegerType) Meta(org.hl7.fhir.r4.model.Meta) Practitioner(org.hl7.fhir.r4.model.Practitioner) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) ProcedureStatus(org.hl7.fhir.r4.model.Procedure.ProcedureStatus) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) CarePlanActivityStatus(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus) Goal(org.hl7.fhir.r4.model.Goal) EncounterHospitalizationComponent(org.hl7.fhir.r4.model.Encounter.EncounterHospitalizationComponent) Period(org.hl7.fhir.r4.model.Period) HealthRecord(org.mitre.synthea.world.concepts.HealthRecord) Provenance(org.hl7.fhir.r4.model.Provenance) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) Utilities(org.mitre.synthea.helpers.Utilities) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) BooleanType(org.hl7.fhir.r4.model.BooleanType) ObservationComponentComponent(org.hl7.fhir.r4.model.Observation.ObservationComponentComponent) Coding(org.hl7.fhir.r4.model.Coding) EncounterStatus(org.hl7.fhir.r4.model.Encounter.EncounterStatus) ImagingStudySeriesInstanceComponent(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesInstanceComponent) BundleType(org.hl7.fhir.r4.model.Bundle.BundleType) EncounterType(org.mitre.synthea.world.concepts.HealthRecord.EncounterType) DeviceNameType(org.hl7.fhir.r4.model.Device.DeviceNameType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) AllergyIntoleranceType(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType) DocumentReferenceContextComponent(org.hl7.fhir.r4.model.DocumentReference.DocumentReferenceContextComponent) Use(org.hl7.fhir.r4.model.ExplanationOfBenefit.Use) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) DosageDoseAndRateComponent(org.hl7.fhir.r4.model.Dosage.DosageDoseAndRateComponent) ProvenanceAgentComponent(org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent) Money(org.hl7.fhir.r4.model.Money) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Calendar(java.util.Calendar) ContactPointUse(org.hl7.fhir.r4.model.ContactPoint.ContactPointUse) DiagnosisComponent(org.hl7.fhir.r4.model.Claim.DiagnosisComponent) Quantity(org.hl7.fhir.r4.model.Quantity) DecimalType(org.hl7.fhir.r4.model.DecimalType) Procedure(org.mitre.synthea.world.concepts.HealthRecord.Procedure) ImagingStudySeriesComponent(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudySeriesComponent) ImagingStudy(org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy) IOException(java.io.IOException) NarrativeStatus(org.hl7.fhir.r4.model.Narrative.NarrativeStatus) FHIRDeviceStatus(org.hl7.fhir.r4.model.Device.FHIRDeviceStatus) Claim(org.mitre.synthea.world.concepts.Claim) ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit) Bundle(org.hl7.fhir.r4.model.Bundle) CodeType(org.hl7.fhir.r4.model.CodeType) CarePlanIntent(org.hl7.fhir.r4.model.CarePlan.CarePlanIntent) DocumentReferenceStatus(org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus) LocationStatus(org.hl7.fhir.r4.model.Location.LocationStatus) TotalComponent(org.hl7.fhir.r4.model.ExplanationOfBenefit.TotalComponent) ContactComponent(org.hl7.fhir.r4.model.Patient.ContactComponent) JsonObject(com.google.gson.JsonObject) Attachment(org.mitre.synthea.engine.Components.Attachment) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) Point2D(java.awt.geom.Point2D) Date(java.util.Date) CoverageStatus(org.hl7.fhir.r4.model.Coverage.CoverageStatus) Costs(org.mitre.synthea.world.concepts.Costs) AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) LocationPositionComponent(org.hl7.fhir.r4.model.Location.LocationPositionComponent) ContactPointSystem(org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem) HumanName(org.hl7.fhir.r4.model.HumanName) Gson(com.google.gson.Gson) StringType(org.hl7.fhir.r4.model.StringType) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Components(org.mitre.synthea.engine.Components) Patient(org.hl7.fhir.r4.model.Patient) Timing(org.hl7.fhir.r4.model.Timing) GoalLifecycleStatus(org.hl7.fhir.r4.model.Goal.GoalLifecycleStatus) DateType(org.hl7.fhir.r4.model.DateType) CarePlanStatus(org.hl7.fhir.r4.model.CarePlan.CarePlanStatus) SupplyDelivery(org.hl7.fhir.r4.model.SupplyDelivery) Report(org.mitre.synthea.world.concepts.HealthRecord.Report) CareTeamStatus(org.hl7.fhir.r4.model.CareTeam.CareTeamStatus) MedicationAdministration(org.hl7.fhir.r4.model.MedicationAdministration) Resource(org.hl7.fhir.r4.model.Resource) MedicationRequestStatus(org.hl7.fhir.r4.model.MedicationRequest.MedicationRequestStatus) Collectors(java.util.stream.Collectors) SupportingInformationComponent(org.hl7.fhir.r4.model.Claim.SupportingInformationComponent) CarePlanActivityDetailComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityDetailComponent) InsuranceComponent(org.hl7.fhir.r4.model.Claim.InsuranceComponent) ProcedureComponent(org.hl7.fhir.r4.model.Claim.ProcedureComponent) Narrative(org.hl7.fhir.r4.model.Narrative) List(java.util.List) Immunization(org.hl7.fhir.r4.model.Immunization) Extension(org.hl7.fhir.r4.model.Extension) PositiveIntType(org.hl7.fhir.r4.model.PositiveIntType) ClaimStatus(org.hl7.fhir.r4.model.Claim.ClaimStatus) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) SimpleCSV(org.mitre.synthea.helpers.SimpleCSV) Property(org.hl7.fhir.r4.model.Property) TimingRepeatComponent(org.hl7.fhir.r4.model.Timing.TimingRepeatComponent) Type(org.hl7.fhir.r4.model.Type) Clinician(org.mitre.synthea.world.agents.Clinician) AllergyIntoleranceCategory(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) AllergyIntoleranceCriticality(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality) Dosage(org.hl7.fhir.r4.model.Dosage) CareTeam(org.hl7.fhir.r4.model.CareTeam) JsonElement(com.google.gson.JsonElement) Address(org.hl7.fhir.r4.model.Address) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) ItemComponent(org.hl7.fhir.r4.model.Claim.ItemComponent) PatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent) ImagingStudyStatus(org.hl7.fhir.r4.model.ImagingStudy.ImagingStudyStatus) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) UnitsOfTime(org.hl7.fhir.r4.model.Timing.UnitsOfTime) ObservationStatus(org.hl7.fhir.r4.model.Observation.ObservationStatus) Config(org.mitre.synthea.helpers.Config) DoseRateType(org.hl7.fhir.r4.model.codesystems.DoseRateType) MedicationRequestIntent(org.hl7.fhir.r4.model.MedicationRequest.MedicationRequestIntent) MedicationStatus(org.hl7.fhir.r4.model.Medication.MedicationStatus) MedicationAdministrationDosageComponent(org.hl7.fhir.r4.model.MedicationAdministration.MedicationAdministrationDosageComponent) Payer(org.mitre.synthea.world.agents.Payer) MediaStatus(org.hl7.fhir.r4.model.Media.MediaStatus) Provider(org.mitre.synthea.world.agents.Provider) CareTeamParticipantComponent(org.hl7.fhir.r4.model.CareTeam.CareTeamParticipantComponent) Organization(org.hl7.fhir.r4.model.Organization) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) RemittanceOutcome(org.hl7.fhir.r4.model.ExplanationOfBenefit.RemittanceOutcome) Observation(org.mitre.synthea.world.concepts.HealthRecord.Observation) IdentifierUse(org.hl7.fhir.r4.model.Identifier.IdentifierUse) DiagnosticReportStatus(org.hl7.fhir.r4.model.DiagnosticReport.DiagnosticReportStatus) Table(com.google.common.collect.Table) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Attachment(org.mitre.synthea.engine.Components.Attachment) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 100 with Code

use of org.mitre.synthea.world.concepts.HealthRecord.Code in project synthea by synthetichealth.

the class FhirR4 method medicationRequest.

/**
 * Map the given Medication to a FHIR MedicationRequest resource, and add it to the given Bundle.
 *
 * @param person         The person being prescribed medication
 * @param personEntry    The Entry for the Person
 * @param bundle         Bundle to add the Medication to
 * @param encounterEntry Current Encounter entry
 * @param medication     The Medication
 * @return The added Entry
 */
private static BundleEntryComponent medicationRequest(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication) {
    MedicationRequest medicationResource = new MedicationRequest();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest");
        medicationResource.setMeta(meta);
    } else if (USE_SHR_EXTENSIONS) {
        medicationResource.addExtension().setUrl(SHR_EXT + "shr-base-ActionCode-extension").setValue(PRESCRIPTION_OF_DRUG_CC);
        medicationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-medication-MedicationRequested"));
        Extension requestedContext = new Extension();
        requestedContext.setUrl(SHR_EXT + "shr-action-RequestedContext-extension");
        requestedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
        requestedContext.addExtension(SHR_EXT + "shr-action-RequestIntent-extension", new CodeType("original-order"));
        medicationResource.addExtension(requestedContext);
    }
    medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
    medicationResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
    Code code = medication.codes.get(0);
    String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
    medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
    if (USE_US_CORE_IG && medication.administration) {
        // Occasionally, rather than use medication codes, we want to use a Medication
        // Resource. We only want to do this when we use US Core, to make sure we
        // sometimes produce a resource for the us-core-medication profile, and the
        // 'administration' flag is an arbitrary way to decide without flipping a coin.
        org.hl7.fhir.r4.model.Medication drugResource = new org.hl7.fhir.r4.model.Medication();
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication");
        drugResource.setMeta(meta);
        drugResource.setCode(mapCodeToCodeableConcept(code, system));
        drugResource.setStatus(MedicationStatus.ACTIVE);
        BundleEntryComponent drugEntry = newEntry(person, bundle, drugResource);
        medicationResource.setMedication(new Reference(drugEntry.getFullUrl()));
    }
    medicationResource.setAuthoredOn(new Date(medication.start));
    medicationResource.setIntent(MedicationRequestIntent.ORDER);
    org.hl7.fhir.r4.model.Encounter encounter = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
    medicationResource.setRequester(encounter.getParticipantFirstRep().getIndividual());
    if (medication.stop != 0L) {
        medicationResource.setStatus(MedicationRequestStatus.STOPPED);
    } else {
        medicationResource.setStatus(MedicationRequestStatus.ACTIVE);
    }
    if (!medication.reasons.isEmpty()) {
        // Only one element in list
        Code reason = medication.reasons.get(0);
        for (BundleEntryComponent entry : bundle.getEntry()) {
            if (entry.getResource().fhirType().equals("Condition")) {
                Condition condition = (Condition) entry.getResource();
                // Only one element in list
                Coding coding = condition.getCode().getCoding().get(0);
                if (reason.code.equals(coding.getCode())) {
                    medicationResource.addReasonReference().setReference(entry.getFullUrl());
                }
            }
        }
    }
    if (medication.prescriptionDetails != null) {
        JsonObject rxInfo = medication.prescriptionDetails;
        Dosage dosage = new Dosage();
        dosage.setSequence(1);
        // as_needed is true if present
        dosage.setAsNeeded(new BooleanType(rxInfo.has("as_needed")));
        if (rxInfo.has("as_needed")) {
            dosage.setText("Take as needed.");
        }
        // as_needed is false
        if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
            Timing timing = new Timing();
            TimingRepeatComponent timingRepeatComponent = new TimingRepeatComponent();
            timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
            timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
            timingRepeatComponent.setPeriodUnit(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
            timing.setRepeat(timingRepeatComponent);
            dosage.setTiming(timing);
            Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
            DosageDoseAndRateComponent dosageDetails = new DosageDoseAndRateComponent();
            dosageDetails.setType(new CodeableConcept().addCoding(new Coding().setCode(DoseRateType.ORDERED.toCode()).setSystem(DoseRateType.ORDERED.getSystem()).setDisplay(DoseRateType.ORDERED.getDisplay())));
            dosageDetails.setDose(dose);
            List<DosageDoseAndRateComponent> details = new ArrayList<DosageDoseAndRateComponent>();
            details.add(dosageDetails);
            dosage.setDoseAndRate(details);
            if (rxInfo.has("instructions")) {
                String text = "";
                for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
                    JsonObject instruction = instructionElement.getAsJsonObject();
                    Code instructionCode = new Code(SNOMED_URI, instruction.get("code").getAsString(), instruction.get("display").getAsString());
                    text += instructionCode.display + "\n";
                    dosage.addAdditionalInstruction(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
                }
                dosage.setText(text);
            }
        }
        List<Dosage> dosageInstruction = new ArrayList<Dosage>();
        dosageInstruction.add(dosage);
        medicationResource.setDosageInstruction(dosageInstruction);
    }
    BundleEntryComponent medicationEntry = newEntry(person, bundle, medicationResource);
    // create new claim for medication
    medicationClaim(person, personEntry, bundle, encounterEntry, medication.claim, medicationEntry);
    // Create new administration for medication, if needed
    if (medication.administration) {
        medicationAdministration(person, personEntry, bundle, encounterEntry, medication, medicationResource);
    }
    return medicationEntry;
}
Also used : Meta(org.hl7.fhir.r4.model.Meta) DosageDoseAndRateComponent(org.hl7.fhir.r4.model.Dosage.DosageDoseAndRateComponent) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Dosage(org.hl7.fhir.r4.model.Dosage) Coding(org.hl7.fhir.r4.model.Coding) Medication(org.mitre.synthea.world.concepts.HealthRecord.Medication) Encounter(org.mitre.synthea.world.concepts.HealthRecord.Encounter) TimingRepeatComponent(org.hl7.fhir.r4.model.Timing.TimingRepeatComponent) Condition(org.hl7.fhir.r4.model.Condition) MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) BooleanType(org.hl7.fhir.r4.model.BooleanType) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) SimpleQuantity(org.hl7.fhir.r4.model.SimpleQuantity) Quantity(org.hl7.fhir.r4.model.Quantity) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) Extension(org.hl7.fhir.r4.model.Extension) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) JsonElement(com.google.gson.JsonElement) CodeType(org.hl7.fhir.r4.model.CodeType) Timing(org.hl7.fhir.r4.model.Timing) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

Code (org.mitre.synthea.world.concepts.HealthRecord.Code)152 Test (org.junit.Test)64 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)49 HealthRecord (org.mitre.synthea.world.concepts.HealthRecord)48 Date (java.util.Date)30 CardiovascularDiseaseModule (org.mitre.synthea.modules.CardiovascularDiseaseModule)30 DeathModule (org.mitre.synthea.modules.DeathModule)30 EncounterModule (org.mitre.synthea.modules.EncounterModule)30 LifecycleModule (org.mitre.synthea.modules.LifecycleModule)30 QualityOfLifeModule (org.mitre.synthea.modules.QualityOfLifeModule)30 WeightLossModule (org.mitre.synthea.modules.WeightLossModule)29 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)20 JsonObject (com.google.gson.JsonObject)19 Person (org.mitre.synthea.world.agents.Person)19 Medication (org.mitre.synthea.world.concepts.HealthRecord.Medication)15 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)14 Reference (org.hl7.fhir.r4.model.Reference)14 Provider (org.mitre.synthea.world.agents.Provider)14 Meta (org.hl7.fhir.r4.model.Meta)13