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));
}
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;
}
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;
}
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());
}
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()));
}
Aggregations