use of org.hl7.fhir.dstu2.model.DateTimeType in project summary-care-record-api by NHSDigital.
the class FindingMapper method mapAuthor.
private void mapAuthor(List<Resource> resources, Encounter encounter, Node author) {
DateTimeType time = parseDate(xmlUtils.getValueByXPath(author, FINDING_PARTICIPANT_TIME_XPATH), DateTimeType.class);
participantMapper.map(author).stream().peek(it -> resources.add(it)).filter(it -> it instanceof PractitionerRole).map(Reference::new).forEach(it -> encounter.addParticipant(new EncounterParticipantComponent().setPeriod(new Period().setStartElement(time)).addType(getParticipationType("AUT", "author")).setIndividual(it)));
}
use of org.hl7.fhir.dstu2.model.DateTimeType in project summary-care-record-api by NHSDigital.
the class ObservationMapper method mapFinding.
private static Finding mapFinding(Observation observation, Bundle bundle) {
var finding = new Finding();
finding.setIdRoot(observation.getIdentifierFirstRep().getValue());
finding.setCodeCode(observation.getCode().getCodingFirstRep().getCode());
finding.setCodeDisplayName(observation.getCode().getCodingFirstRep().getDisplay());
finding.setStatusCodeCode(mapStatus(observation.getStatus()));
if (observation.getEffective() instanceof DateTimeType) {
finding.setEffectiveTimeCenter(formatDateToHl7(observation.getEffectiveDateTimeType()));
} else if (observation.getEffective() instanceof Period) {
var period = observation.getEffectivePeriod();
if (period.hasStart()) {
finding.setEffectiveTimeLow(formatDateToHl7(period.getStartElement()));
}
if (period.hasEnd()) {
finding.setEffectiveTimeHigh(formatDateToHl7(period.getEndElement()));
}
} else {
throw new FhirValidationException("Observation.effective must be of type DateTimeType or Period");
}
var encounterReference = observation.getEncounter().getReference();
if (StringUtils.isNotBlank(encounterReference)) {
var encounter = getResourceByReference(bundle, encounterReference, Encounter.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is Missing Encounter %s that is linked to Condition %s", observation.getEncounter().getReference(), observation.getId())));
for (var encounterParticipant : encounter.getParticipant()) {
Coding coding = encounterParticipant.getTypeFirstRep().getCodingFirstRep();
if (!PARTICIPATION_TYPE_SYSTEM.equals(coding.getSystem())) {
throw new FhirValidationException("Unsupported encounter participant system: " + coding.getSystem());
}
var code = coding.getCode();
if ("AUT".equals(code)) {
var author = mapAuthor1(bundle, encounterParticipant);
finding.setAuthor(author);
} else if ("INF".equals(code)) {
var informant = mapInformant(bundle, encounterParticipant);
finding.setInformant(informant);
} else if ("PRF".equals(code)) {
var performer = mapPerformer(bundle, encounterParticipant);
finding.setPerformer(performer);
} else {
throw new FhirValidationException(String.format("Invalid encounter %s participant code %s", encounter.getId(), code));
}
}
}
return finding;
}
use of org.hl7.fhir.dstu2.model.DateTimeType in project openmrs-module-fhir2 by openmrs.
the class FhirImmunizationServiceImplTest method updateImmunization_shouldUpdateImmunizationAccordingly.
@Test
public void updateImmunization_shouldUpdateImmunizationAccordingly() {
// setup
FhirContext ctx = FhirContext.forR4();
IParser parser = ctx.newJsonParser();
Immunization updatedImmunization = parser.parseResource(Immunization.class, "{\n" + " \"resourceType\": \"Immunization\",\n" + " \"id\": \"9353776b-dead-4588-8723-d687197d8438\",\n" + " \"status\": \"completed\",\n" + " \"vaccineCode\": {\n" + " \"coding\": [\n" + " {\n" + " \"code\": \"d144d24f-6913-4b63-9660-a9108c2bebef\",\n" + " \"display\": \"STAVUDINE LAMIVUDINE AND NEVIRAPINE\"\n" + " }\n" + " ]\n" + " },\n" + " \"patient\": {\n" + " \"reference\": \"Patient/a7e04421-525f-442f-8138-05b619d16def\",\n" + " \"type\": \"Patient\"\n" + " },\n" + " \"encounter\": {\n" + " \"reference\": \"Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc\",\n" + " \"type\": \"Encounter\"\n" + " },\n" + " \"occurrenceDateTime\": \"2020-07-08T20:30:00+02:00\",\n" + " \"manufacturer\": {\n" + " \"display\": \"Pharma Inc.\"\n" + " },\n" + " \"lotNumber\": \"YU765YT-1\",\n" + " \"expirationDate\": \"2020-10-08\",\n" + " \"performer\": [\n" + " {\n" + " \"actor\": {\n" + " \"reference\": \"Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66\",\n" + " \"type\": \"Practitioner\"\n" + " }\n" + " }\n" + " ],\n" + " \"protocolApplied\": [\n" + " {\n" + " \"doseNumberPositiveInt\": 4\n" + " }\n" + " ]\n" + "}");
// replay
Immunization savedImmunization = service.update("9353776b-dead-4588-8723-d687197d8438", updatedImmunization);
Obs obs = obsService.getObsByUuid(savedImmunization.getId());
// verify
helper.validateImmunizationObsGroup(obs);
assertObsCommons(obs, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
obs.getGroupMembers().forEach(o -> {
assertObsCommons(o, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
});
Map<String, Obs> members = helper.getObsMembersMap(obs);
assertThat(members.get(CIEL_984).getValueCoded().getUuid(), is("d144d24f-6913-4b63-9660-a9108c2bebef"));
assertThat(members.get(CIEL_1410).getValueDatetime(), equalTo(new DateTimeType("2020-07-08T20:30:00+02:00").getValue()));
assertThat(members.get(CIEL_1418).getValueNumeric(), equalTo(4.0));
assertThat(members.get(CIEL_1419).getValueText(), is("Pharma Inc."));
assertThat(members.get(CIEL_1420).getValueText(), is("YU765YT-1"));
assertThat(members.get(CIEL_165907).getValueDate(), equalTo(new DateType("2020-10-08").getValue()));
}
use of org.hl7.fhir.dstu2.model.DateTimeType in project openmrs-module-fhir2 by openmrs.
the class ObservationTranslatorImplTest method toFhirResource_shouldTranslateOpenMrsObsDatetimeToEffectiveDatetime.
@Test
public void toFhirResource_shouldTranslateOpenMrsObsDatetimeToEffectiveDatetime() {
Obs observation = new Obs();
observation.setObsDatetime(new Date());
when(datetimeTranslator.toFhirResource(observation)).thenReturn(new DateTimeType(new Date()));
Observation result = observationTranslator.toFhirResource(observation);
assertThat(result, notNullValue());
assertThat(result.getEffectiveDateTimeType(), notNullValue());
assertThat(result.getEffectiveDateTimeType().getValue(), DateMatchers.sameDay(new Date()));
}
use of org.hl7.fhir.dstu2.model.DateTimeType in project openmrs-module-fhir2 by openmrs.
the class ObservationValueTranslatorImplTest method toOpenmrsType_shouldConvertDateTimeToDateValue.
@Test
public void toOpenmrsType_shouldConvertDateTimeToDateValue() {
Date expectedValue = new Date();
DateTimeType dateTimeType = new DateTimeType();
dateTimeType.setValue(expectedValue);
Obs result = obsValueTranslator.toOpenmrsType(obs, dateTimeType);
assertThat(result, notNullValue());
assertThat(result.getValueDatetime(), equalTo(expectedValue));
}
Aggregations