Search in sources :

Example 91 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_allergyintolerance_example.

@Test
public void test_allergyintolerance_example() throws FileNotFoundException, IOException, Exception {
    System.out.println("allergyintolerance-example.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\allergyintolerance-example.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 92 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_allergyintolerance_medication.

@Test
public void test_allergyintolerance_medication() throws FileNotFoundException, IOException, Exception {
    System.out.println("allergyintolerance-medication.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\allergyintolerance-medication.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 93 with AllergyIntolerance

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

the class FhirStu3 method allergy.

/**
 * Map the Condition into a FHIR AllergyIntolerance 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 The Bundle to add to
 * @param encounterEntry The current Encounter entry
 * @param allergy The Allergy Entry
 * @return The added Entry
 */
private static BundleEntryComponent allergy(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, HealthRecord.Entry allergy) {
    AllergyIntolerance allergyResource = new AllergyIntolerance();
    allergyResource.setAssertedDate(new Date(allergy.start));
    if (allergy.stop == 0) {
        allergyResource.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
    } else {
        allergyResource.setClinicalStatus(AllergyIntoleranceClinicalStatus.INACTIVE);
    }
    allergyResource.setType(AllergyIntoleranceType.ALLERGY);
    AllergyIntoleranceCategory category = AllergyIntoleranceCategory.FOOD;
    // TODO: allergy categories in GMF
    allergyResource.addCategory(category);
    allergyResource.setCriticality(AllergyIntoleranceCriticality.LOW);
    allergyResource.setVerificationStatus(AllergyIntoleranceVerificationStatus.CONFIRMED);
    allergyResource.setPatient(new Reference(personEntry.getFullUrl()));
    Code code = allergy.codes.get(0);
    allergyResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
    if (USE_SHR_EXTENSIONS) {
        Meta meta = new Meta();
        meta.addProfile(SHR_EXT + "shr-allergy-AllergyIntolerance");
        // required fields for AllergyIntolerance profile are:
        // verificationStatus, code, patient, assertedDate
        allergyResource.setMeta(meta);
    }
    BundleEntryComponent allergyEntry = newEntry(rand, bundle, allergyResource);
    allergy.fullUrl = allergyEntry.getFullUrl();
    return allergyEntry;
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Reference(org.hl7.fhir.dstu3.model.Reference) AllergyIntoleranceCategory(org.hl7.fhir.dstu3.model.AllergyIntolerance.AllergyIntoleranceCategory) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date)

Example 94 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project gpconnect-demonstrator by nhsconnect.

the class StructuredAllergyIntoleranceBuilder method listResourceBuilder.

private void listResourceBuilder(ListResource buildingListResource, AllergyIntolerance allergyIntolerance, boolean isResolved) {
    ListEntryComponent comp = new ListEntryComponent();
    if (isResolved) {
        buildingListResource.addContained(allergyIntolerance);
        Reference allergyReference = new Reference("#" + allergyIntolerance.getId());
        comp.setItem(allergyReference);
    } else {
        Reference allergyReference = new Reference("AllergyIntolerance/" + allergyIntolerance.getId());
        comp.setItem(allergyReference);
    }
    buildingListResource.addEntry(comp);
}
Also used : ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 95 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project gpconnect-demonstrator by nhsconnect.

the class StructuredAllergyIntoleranceBuilder method buildStructuredAllergyIntolerence.

public Bundle buildStructuredAllergyIntolerence(String NHS, Set<String> practitionerIds, Bundle bundle, Boolean includedResolved) {
    List<StructuredAllergyIntoleranceEntity> allergyData = structuredAllergySearch.getAllergyIntollerence(NHS);
    ListResource activeList = initiateListResource(NHS, ACTIVE_ALLERGIES_DISPLAY, allergyData);
    ListResource resolvedList = initiateListResource(NHS, RESOLVED_ALLERGIES_DISPLAY, allergyData);
    // This is patient 5 example 2 only
    if (allergyData.size() == 1 && allergyData.get(0).getClinicalStatus().equals(SystemConstants.NO_KNOWN)) {
        StructuredAllergyIntoleranceEntity noKnownAllergy = allergyData.get(0);
        // #214 had incorrect code and value for no known allergies
        CodeableConcept noKnownAllergies = createCoding(SystemURL.VS_LIST_EMPTY_REASON_CODE, NO_CONTENT_RECORDED, NO_CONTENT_RECORDED_DISPLAY);
        noKnownAllergies.setText("No Known Allergies");
        // activeList.setEmptyReason(noKnownAllergies);
        // see spec example 2 no known allergies positively asserted
        Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyData.get(0).getPatientRef());
        String noKnownAllergyId = noKnownAllergy.getGuid();
        Reference allergyIntolerance = new Reference("AllergyIntolerance/" + noKnownAllergyId);
        Resource noKnownAllergyResource = createNoKnownAllergy(noKnownAllergy);
        activeList.setSubject(patient);
        // reference to AllergyIntolerance item
        activeList.addEntry().setItem(allergyIntolerance);
        activeList.setOrderedBy(createCoding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date"));
        bundle.addEntry().setResource(activeList);
        bundle.addEntry().setResource(noKnownAllergyResource);
        if (includedResolved) {
            resolvedList.setSubject(patient);
            resolvedList.setEmptyReason(noKnownAllergies);
            bundle.addEntry().setResource(resolvedList);
        }
        return bundle;
    }
    for (StructuredAllergyIntoleranceEntity allergyIntoleranceEntity : allergyData) {
        AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
        allergyIntolerance.setOnset(new DateTimeType(allergyIntoleranceEntity.getOnSetDateTime()));
        allergyIntolerance.setMeta(createMeta(SystemURL.SD_CC_ALLERGY_INTOLERANCE));
        allergyIntolerance.setId(allergyIntoleranceEntity.getId().toString());
        List<Identifier> identifiers = new ArrayList<>();
        Identifier identifier1 = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(allergyIntoleranceEntity.getGuid());
        identifiers.add(identifier1);
        allergyIntolerance.setIdentifier(identifiers);
        if (allergyIntoleranceEntity.getClinicalStatus().equals(SystemConstants.ACTIVE)) {
            allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
        } else {
            allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
        }
        if (allergyIntoleranceEntity.getCategory().equals(SystemConstants.MEDICATION)) {
            allergyIntolerance.addCategory(AllergyIntoleranceCategory.MEDICATION);
        } else {
            allergyIntolerance.addCategory(AllergyIntoleranceCategory.ENVIRONMENT);
        }
        allergyIntolerance.setVerificationStatus(AllergyIntoleranceVerificationStatus.UNCONFIRMED);
        // CODE
        codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getConceptCode(), allergyIntoleranceEntity.getConceptDisplay()).addDescription(allergyIntoleranceEntity.getDescCode(), allergyIntoleranceEntity.getDescDisplay()).addTranslation(allergyIntoleranceEntity.getCodeTranslationRef());
        allergyIntolerance.setCode(codeableConceptBuilder.build());
        codeableConceptBuilder.clear();
        allergyIntolerance.setAssertedDate(allergyIntoleranceEntity.getAssertedDate());
        Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
        allergyIntolerance.setPatient(patient);
        Annotation noteAnnotation = new Annotation(new StringType(allergyIntoleranceEntity.getNote()));
        allergyIntolerance.setNote(Collections.singletonList(noteAnnotation));
        AllergyIntoleranceReactionComponent reaction = new AllergyIntoleranceReactionComponent();
        // MANIFESTATION
        List<CodeableConcept> theManifestation = new ArrayList<>();
        codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getManifestationCoding(), allergyIntoleranceEntity.getManifestationDisplay()).addDescription(allergyIntoleranceEntity.getManifestationDescCoding(), allergyIntoleranceEntity.getManifestationDescDisplay()).addTranslation(allergyIntoleranceEntity.getManTranslationRef());
        theManifestation.add(codeableConceptBuilder.build());
        codeableConceptBuilder.clear();
        reaction.setManifestation(theManifestation);
        reaction.setDescription(allergyIntoleranceEntity.getNote());
        // SEVERITY
        try {
            reaction.setSeverity(AllergyIntoleranceSeverity.fromCode(allergyIntoleranceEntity.getSeverity()));
        } catch (FHIRException e) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Unknown severity: " + allergyIntoleranceEntity.getSeverity()), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
        }
        // EXPOSURE
        CodeableConcept exposureRoute = new CodeableConcept();
        reaction.setExposureRoute(exposureRoute);
        allergyIntolerance.addReaction(reaction);
        // RECORDER
        final Reference refValue = new Reference();
        final Identifier identifier = new Identifier();
        final String recorder = allergyIntoleranceEntity.getRecorder();
        // This is just an example to demonstrate using Reference element instead of Identifier element
        if (recorder.equals(patient2NhsNo.trim())) {
            Reference rec = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
            allergyIntolerance.setRecorder(rec);
        } else if (patientRepository.findByNhsNumber(recorder) != null) {
            identifier.setSystem(SystemURL.ID_NHS_NUMBER);
            identifier.setValue(recorder);
            refValue.setIdentifier(identifier);
            allergyIntolerance.setRecorder(refValue);
        } else if (practitionerSearch.findPractitionerByUserId(recorder) != null) {
            refValue.setReference("Practitioner/" + recorder);
            allergyIntolerance.setRecorder(refValue);
            practitionerIds.add(recorder);
        }
        // CLINICAL STATUS
        List<Extension> extensions = new ArrayList<>();
        if (allergyIntolerance.getClinicalStatus().getDisplay().contains("Active")) {
            listResourceBuilder(activeList, allergyIntolerance, false);
            bundle.addEntry().setResource(allergyIntolerance);
        } else if (allergyIntolerance.getClinicalStatus().getDisplay().equals("Resolved") && includedResolved.equals(true)) {
            listResourceBuilder(resolvedList, allergyIntolerance, true);
            allergyIntolerance.setLastOccurrence(allergyIntoleranceEntity.getEndDate());
            final Extension allergyEndExtension = createAllergyEndExtension(allergyIntoleranceEntity);
            extensions.add(allergyEndExtension);
        }
        if (!extensions.isEmpty()) {
            allergyIntolerance.setExtension(extensions);
        }
        // ASSERTER
        Reference asserter = allergyIntolerance.getAsserter();
        if (asserter != null && asserter.getReference() != null && asserter.getReference().startsWith("Practitioner")) {
            String[] split = asserter.getReference().split("/");
            practitionerIds.add(split[1]);
        }
    }
    if (!activeList.hasEntry()) {
        addEmptyListNote(activeList);
        addEmptyReasonCode(activeList);
    }
    bundle.addEntry().setResource(activeList);
    if (includedResolved && !resolvedList.hasEntry()) {
        addEmptyListNote(resolvedList);
        addEmptyReasonCode(resolvedList);
    }
    if (includedResolved) {
        bundle.addEntry().setResource(resolvedList);
    }
    return bundle;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) StructuredAllergyIntoleranceEntity(uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity) FHIRException(org.hl7.fhir.exceptions.FHIRException) AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance)

Aggregations

Test (org.junit.Test)158 AllergyIntolerance (org.hl7.fhir.r4.model.AllergyIntolerance)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)53 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)53 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)43 AllergyIntolerance (org.hl7.fhir.dstu3.model.AllergyIntolerance)42 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)29 TokenParam (ca.uhn.fhir.rest.param.TokenParam)29 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)26 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)25 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)25 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)23 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)14 InputStream (java.io.InputStream)12 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)12 Date (java.util.Date)10 IdType (org.hl7.fhir.r4.model.IdType)10