Search in sources :

Example 56 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceFhirResourceProviderTest method searchForAllergies_shouldReturnMatchingBundleOfAllergiesWhenPatientGivenNameIsSpecifiedAsSubject.

@Test
public void searchForAllergies_shouldReturnMatchingBundleOfAllergiesWhenPatientGivenNameIsSpecifiedAsSubject() {
    ReferenceAndListParam subject = new ReferenceAndListParam();
    subject.addValue(new ReferenceOrListParam().add(new ReferenceParam().setValue("John").setChain(Patient.SP_GIVEN)));
    when(service.searchForAllergies(argThat(is(subject)), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(allergyIntolerance), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchForAllergies(null, subject, null, null, null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList.get(0).fhirType(), is(FhirConstants.ALLERGY_INTOLERANCE));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(((AllergyIntolerance) resultList.iterator().next()).getId(), equalTo(ALLERGY_UUID));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 57 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceTranslatorImpl method toOpenmrsType.

@Override
public Allergy toOpenmrsType(@Nonnull Allergy allergy, @Nonnull AllergyIntolerance fhirAllergy) {
    notNull(allergy, "The existing Allergy should not be null");
    notNull(fhirAllergy, "The AllergyIntolerance object should not be null");
    if (fhirAllergy.getId() != null) {
        allergy.setUuid(fhirAllergy.getId());
    }
    if (fhirAllergy.hasCode()) {
        if (allergy.getAllergen() == null) {
            Allergen allergen = new Allergen();
            allergen.setCodedAllergen(conceptTranslator.toOpenmrsType(fhirAllergy.getCode()));
            allergy.setAllergen(allergen);
        }
    }
    if (fhirAllergy.hasCategory() && allergy.getAllergen() != null) {
        allergy.getAllergen().setAllergenType(categoryTranslator.toOpenmrsType(fhirAllergy.getCategory().get(0).getValue()));
    }
    allergy.setVoided(isAllergyInactive(fhirAllergy.getClinicalStatus()));
    allergy.setPatient(patientReferenceTranslator.toOpenmrsType(fhirAllergy.getPatient()));
    allergy.setCreator(practitionerReferenceTranslator.toOpenmrsType(fhirAllergy.getRecorder()));
    if (fhirAllergy.hasReaction()) {
        for (AllergyIntolerance.AllergyIntoleranceReactionComponent reaction : fhirAllergy.getReaction()) {
            reactionComponentTranslator.toOpenmrsType(allergy, reaction);
        }
    }
    if (!CollectionUtils.isEmpty(fhirAllergy.getNote())) {
        allergy.setComment(fhirAllergy.getNote().get(0).getText());
    }
    return allergy;
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Allergen(org.openmrs.Allergen)

Example 58 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceTranslatorImpl method toFhirResource.

@Override
public AllergyIntolerance toFhirResource(@Nonnull Allergy omrsAllergy) {
    notNull(omrsAllergy, "The Allergy object should not be null");
    AllergyIntolerance allergy = new AllergyIntolerance();
    allergy.setId(omrsAllergy.getUuid());
    if (omrsAllergy.getAllergen() != null) {
        allergy.addCategory(categoryTranslator.toFhirResource(omrsAllergy.getAllergen().getAllergenType()));
    }
    allergy.setClinicalStatus(setClinicalStatus(omrsAllergy.getVoided()));
    allergy.setVerificationStatus(new CodeableConcept().setText("Confirmed").addCoding(new Coding(FhirConstants.ALLERGY_INTOLERANCE_VERIFICATION_STATUS_SYSTEM_URI, "confirmed", "Confirmed")));
    allergy.setPatient(patientReferenceTranslator.toFhirResource(omrsAllergy.getPatient()));
    allergy.setRecorder(practitionerReferenceTranslator.toFhirResource(omrsAllergy.getCreator()));
    allergy.setRecordedDate(omrsAllergy.getDateCreated());
    allergy.getMeta().setLastUpdated(omrsAllergy.getDateChanged());
    allergy.setType(AllergyIntolerance.AllergyIntoleranceType.ALLERGY);
    allergy.addNote(new Annotation().setText(omrsAllergy.getComment()));
    allergy.setCriticality(criticalityTranslator.toFhirResource(severityTranslator.toFhirResource(omrsAllergy.getSeverity())));
    allergy.addReaction(reactionComponentTranslator.toFhirResource(omrsAllergy));
    allergy.setCode(allergy.getReactionFirstRep().getSubstance());
    allergy.addContained(provenanceTranslator.getCreateProvenance(omrsAllergy));
    allergy.addContained(provenanceTranslator.getUpdateProvenance(omrsAllergy));
    return allergy;
}
Also used : AllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance) Coding(org.hl7.fhir.r4.model.Coding) Annotation(org.hl7.fhir.r4.model.Annotation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 59 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceFhirR3ResourceProviderWebTest method updateAllergyIntolerance_shouldUpdateRequestedAllergyIntolerance.

@Test
public void updateAllergyIntolerance_shouldUpdateRequestedAllergyIntolerance() throws Exception {
    org.hl7.fhir.r4.model.AllergyIntolerance allergyIntolerance = new org.hl7.fhir.r4.model.AllergyIntolerance();
    allergyIntolerance.setId(ALLERGY_UUID);
    String allergyJson;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_ALLERGY_PATH)) {
        Objects.requireNonNull(is);
        allergyJson = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    when(allergyService.update(any(String.class), any(org.hl7.fhir.r4.model.AllergyIntolerance.class))).thenReturn(allergyIntolerance);
    MockHttpServletResponse response = put("/AllergyIntolerance/" + ALLERGY_UUID).jsonContent(allergyJson).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 60 with AllergyIntolerance

use of org.hl7.fhir.r4.model.AllergyIntolerance in project openmrs-module-fhir2 by openmrs.

the class AllergyIntoleranceFhirR3ResourceProviderWebTest method shouldGetAllergyIntoleranceHistoryById.

@Test
public void shouldGetAllergyIntoleranceHistoryById() throws IOException, ServletException {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    provenance.setRecorded(new Date());
    provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
    provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(FhirConstants.AUT).setDisplay(FhirConstants.AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
    org.hl7.fhir.r4.model.AllergyIntolerance allergyIntolerance = new org.hl7.fhir.r4.model.AllergyIntolerance();
    allergyIntolerance.setId(ALLERGY_UUID);
    allergyIntolerance.addContained(provenance);
    when(allergyService.get(ALLERGY_UUID)).thenReturn(allergyIntolerance);
    MockHttpServletResponse response = getAllergyIntoleranceHistoryRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), notNullValue());
    assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) IdType(org.hl7.fhir.dstu3.model.IdType) AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Coding(org.hl7.fhir.r4.model.Coding) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

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