use of org.hl7.fhir.r5.model.IdType in project elexis-server by elexis.
the class FamilyMemberHistoryResourceProvider method createFamilyMemberHistory.
@Create
public MethodOutcome createFamilyMemberHistory(@ResourceParam FamilyMemberHistory familyMemberHistory) {
MethodOutcome outcome = new MethodOutcome();
Optional<IFamilyMemberHistory> exists = getTransformer().getLocalObject(familyMemberHistory);
if (exists.isPresent()) {
outcome.setCreated(false);
outcome.setId(new IdType(familyMemberHistory.getId()));
} else {
Optional<IFamilyMemberHistory> created = getTransformer().createLocalObject(familyMemberHistory);
if (created.isPresent()) {
outcome.setCreated(true);
outcome.setId(new IdType(created.get().getId()));
} else {
throw new InternalErrorException("Creation failed");
}
}
return outcome;
}
use of org.hl7.fhir.r5.model.IdType in project elexis-server by elexis.
the class MedicationRequestResourceProvider method findMedicationsByPatient.
@Search()
public List<MedicationRequest> findMedicationsByPatient(@RequiredParam(name = MedicationRequest.SP_PATIENT) IdType thePatientId) {
if (thePatientId != null && !thePatientId.isEmpty()) {
Optional<IPatient> patient = modelService.load(thePatientId.getIdPart(), IPatient.class);
if (patient.isPresent()) {
if (patient.get().isPatient()) {
IQuery<IPrescription> query = modelService.getQuery(IPrescription.class);
query.and(ModelPackage.Literals.IPRESCRIPTION__PATIENT, COMPARATOR.EQUALS, patient.get());
// TODO
// qbe.add(Prescription_.rezeptID, JPAQuery.QUERY.EQUALS, null);
List<IPrescription> prescriptions = query.execute();
if (prescriptions != null && !prescriptions.isEmpty()) {
List<MedicationRequest> ret = new ArrayList<MedicationRequest>();
for (IPrescription prescription : prescriptions) {
Optional<MedicationRequest> fhirMedicationOrder = getTransformer().getFhirObject(prescription);
fhirMedicationOrder.ifPresent(fmo -> ret.add(fmo));
}
return ret;
}
}
}
}
return null;
}
use of org.hl7.fhir.r5.model.IdType in project elexis-server by elexis.
the class EncounterTest method createEncounter.
@Test
public void createEncounter() {
Condition problem = new Condition();
problem.setCode(new CodeableConcept().addCoding(new Coding("http://hl7.org/fhir/sid/icpc-2", "A04", "Müdigkeit")));
problem.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
problem.addCategory().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay()));
MethodOutcome problemOutcome = client.create().resource(problem).execute();
Encounter encounter = new Encounter();
EncounterParticipantComponent participant = new EncounterParticipantComponent();
participant.setIndividual(new Reference("Practitioner/" + TestDatabaseInitializer.getMandant().getId()));
encounter.addParticipant(participant);
encounter.setPeriod(new Period().setStart(AllTests.getDate(LocalDate.now().atStartOfDay())).setEnd(AllTests.getDate(LocalDate.now().atTime(23, 59, 59))));
encounter.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
encounter.addDiagnosis().setCondition(new Reference(new IdType(problem.getResourceType().name(), problemOutcome.getId().getIdPart())));
encounter.addType(new CodeableConcept().addCoding(new Coding("www.elexis.info/encounter/type", "struct", "structured enconter")));
MethodOutcome outcome = client.create().resource(encounter).execute();
assertNotNull(outcome);
assertTrue(outcome.getCreated());
assertNotNull(outcome.getId());
// add subjective to the encounter
Observation subjective = new Observation();
Narrative narrative = new Narrative();
String divEncodedText = "Subjective\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
narrative.setDivAsString(divEncodedText);
subjective.setText(narrative);
subjective.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
subjective.addCategory().addCoding(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(), ObservationCategory.SOAP_SUBJECTIVE.getCode(), ObservationCategory.SOAP_SUBJECTIVE.getLocalized()));
subjective.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounter.getId())));
MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
assertTrue(subjectiveOutcome.getCreated());
Encounter readEncounter = client.read().resource(Encounter.class).withId(outcome.getId()).execute();
assertNotNull(readEncounter);
assertEquals(outcome.getId().getIdPart(), readEncounter.getIdElement().getIdPart());
assertEquals(encounter.getPeriod().getStart(), readEncounter.getPeriod().getStart());
}
use of org.hl7.fhir.r5.model.IdType in project elexis-server by elexis.
the class ServiceRequestTest method createServiceRequest.
@Test
public void createServiceRequest() {
Condition problem = new Condition();
problem.setCode(new CodeableConcept().addCoding(new Coding("http://hl7.org/fhir/sid/icpc-2", "A04", "Müdigkeit")));
problem.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
problem.addCategory().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay()));
MethodOutcome problemOutcome = client.create().resource(problem).execute();
Encounter encounter = new Encounter();
EncounterParticipantComponent participant = new EncounterParticipantComponent();
participant.setIndividual(new Reference("Practitioner/" + TestDatabaseInitializer.getMandant().getId()));
encounter.addParticipant(participant);
encounter.setPeriod(new Period().setStart(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay())).setEnd(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atTime(23, 59, 59))));
encounter.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
encounter.addDiagnosis().setCondition(new Reference(new IdType(problem.getResourceType().name(), problemOutcome.getId().getIdPart())));
encounter.addType(new CodeableConcept().addCoding(new Coding("www.elexis.info/encounter/type", "struct", "structured enconter")));
MethodOutcome encounterOutcome = client.create().resource(encounter).execute();
assertNotNull(encounterOutcome);
assertTrue(encounterOutcome.getCreated());
assertNotNull(encounterOutcome.getId());
// add subjective to the encounter
Observation subjective = new Observation();
Narrative narrative = new Narrative();
String divEncodedText = "Subjective\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
narrative.setDivAsString(divEncodedText);
subjective.setText(narrative);
subjective.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
subjective.addCategory().addCoding(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(), ObservationCategory.SOAP_SUBJECTIVE.getCode(), ObservationCategory.SOAP_SUBJECTIVE.getLocalized()));
subjective.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
assertTrue(subjectiveOutcome.getCreated());
// add procedure request to encounter
ServiceRequest serviceRequest = new ServiceRequest();
narrative = new Narrative();
divEncodedText = "Procedure\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
narrative.setDivAsString(divEncodedText);
serviceRequest.setText(narrative);
serviceRequest.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
serviceRequest.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
MethodOutcome outcome = client.create().resource(serviceRequest).execute();
assertNotNull(outcome);
assertTrue(outcome.getCreated());
assertNotNull(outcome.getId());
ServiceRequest readServiceRequest = client.read().resource(ServiceRequest.class).withId(outcome.getId()).execute();
assertNotNull(readServiceRequest);
assertEquals(outcome.getId().getIdPart(), readServiceRequest.getIdElement().getIdPart());
assertEquals(serviceRequest.getSubject().getReferenceElement().getIdPart(), readServiceRequest.getSubject().getReferenceElement().getIdPart());
assertEquals(serviceRequest.getEncounter().getReferenceElement().getIdPart(), readServiceRequest.getEncounter().getReferenceElement().getIdPart());
assertTrue(readServiceRequest.getText().getDivAsString().contains("Test"));
// check if the consultation text has been updated
// search by patient and date
Bundle results = client.search().forResource(Encounter.class).where(Encounter.PATIENT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Encounter.DATE.exactly().day(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay()))).returnBundle(Bundle.class).execute();
assertNotNull(results);
List<BundleEntryComponent> entries = results.getEntry();
assertFalse(entries.isEmpty());
Encounter readEncounter = (Encounter) entries.get(0).getResource();
assertNotNull(readEncounter);
assertEquals(readEncounter.getIdElement().getIdPart(), encounterOutcome.getId().getIdPart());
List<Identifier> identifier = readEncounter.getIdentifier();
String consultationId = null;
for (Identifier id : identifier) {
if (id.getSystem().equals(IdentifierSystem.ELEXIS_CONSID.getSystem())) {
consultationId = id.getValue();
}
}
assertNotNull(consultationId);
Optional<IEncounter> behandlung = AllTests.getModelService().load(consultationId, IEncounter.class);
assertTrue(behandlung.isPresent());
assertTrue(behandlung.get().getVersionedEntry().getHead().contains("Procedure"));
}
use of org.hl7.fhir.r5.model.IdType in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderTest method updateAllergyIntolerance_shouldUpdateRequestedAllergyIntolerance.
@Test
public void updateAllergyIntolerance_shouldUpdateRequestedAllergyIntolerance() {
when(service.update(ALLERGY_UUID, allergyIntolerance)).thenReturn(allergyIntolerance);
MethodOutcome result = resourceProvider.updateAllergy(new IdType().setValue(ALLERGY_UUID), allergyIntolerance);
assertThat(result, notNullValue());
assertThat(result.getResource(), equalTo(allergyIntolerance));
}
Aggregations