use of com.nedap.archie.rm.datatypes.CodePhrase in project ehrbase by ehrbase.
the class FhirTerminologyServerR4AdaptorImpl method expand.
@Override
public List<DvCodedText> expand(final String valueSetId) {
String responseBody;
try {
responseBody = internalGet(valueSetId);
} catch (IOException e) {
throw new InternalServerException("An error occurred while expanding ValueSet: " + valueSetId, e);
}
DocumentContext jsonContext = JsonPath.parse(responseBody);
List<String> codeList = jsonContext.read(props.getCodePath().replace("\\", ""));
List<String> systemList = jsonContext.read(props.getSystemPath());
List<String> displayList = jsonContext.read(props.getDisplayPath());
List<DvCodedText> expansionList = new ArrayList<>();
for (int i = 0; i < codeList.size(); i++) {
TerminologyId termId = new TerminologyId(systemList.get(i));
CodePhrase codePhrase = new CodePhrase(termId, codeList.get(i));
DvCodedText codedText = new DvCodedText(displayList.get(i), codePhrase);
expansionList.add(codedText);
}
return expansionList;
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project ehrbase by ehrbase.
the class EntryAccess method retrieveInstanceInCompositionVersion.
public static List<I_EntryAccess> retrieveInstanceInCompositionVersion(I_DomainAccess domainAccess, I_CompositionAccess compositionHistoryAccess, int version) {
Result<EntryHistoryRecord> entryHistoryRecords = domainAccess.getContext().selectFrom(ENTRY_HISTORY).where(ENTRY_HISTORY.COMPOSITION_ID.eq(compositionHistoryAccess.getId())).and(ENTRY_HISTORY.SYS_TRANSACTION.eq(compositionHistoryAccess.getSysTransaction())).fetch();
// build the list of parameters to recreate the composition
Map<SystemValue, Object> values = new HashMap<>();
values.put(SystemValue.COMPOSER, new PersistedPartyProxy(domainAccess).retrieve(compositionHistoryAccess.getComposerId()));
EventContext context = I_ContextAccess.retrieveHistoricalEventContext(domainAccess, compositionHistoryAccess.getId(), compositionHistoryAccess.getSysTransaction());
if (context == null) {
// unchanged context use the current one!
// also optional handling of context, because persistent compositions don't have a context
compositionHistoryAccess.getContextId().ifPresent(uuid -> I_ContextAccess.retrieveInstance(domainAccess, uuid).mapRmEventContext());
}
values.put(SystemValue.CONTEXT, context);
values.put(SystemValue.LANGUAGE, new CodePhrase(new TerminologyId("ISO_639-1"), compositionHistoryAccess.getLanguageCode()));
String territory2letters = domainAccess.getContext().fetchOne(TERRITORY, TERRITORY.CODE.eq(compositionHistoryAccess.getTerritoryCode())).getTwoletter();
values.put(SystemValue.TERRITORY, new CodePhrase(new TerminologyId("ISO_3166-1"), territory2letters));
values.put(SystemValue.FEEDER_AUDIT, new FeederAuditEncoding().fromDB(compositionHistoryAccess.getFeederAudit()));
List<I_EntryAccess> content = new ArrayList<>();
try {
EntryAccess entryAccess = new EntryAccess(domainAccess);
for (EntryHistoryRecord record : entryHistoryRecords) {
// set the record UID in the composition
UUID compositionId = compositionHistoryAccess.getId();
values.put(SystemValue.UID, new ObjectVersionId(compositionId.toString() + "::" + domainAccess.getServerConfig().getNodename() + "::" + version));
entryAccess.entryRecord = domainAccess.getContext().newRecord(ENTRY);
entryAccess.entryRecord.from(record);
entryAccess.composition = new RawJson().unmarshal(record.getEntry().data(), Composition.class);
setCompositionAttributes(entryAccess.composition, values);
buildArchetypeDetails(entryAccess);
content.add(entryAccess);
}
} catch (Exception e) {
throw new IllegalArgumentException(DB_INCONSISTENCY + e);
}
return content;
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project ehrbase by ehrbase.
the class AuditDetailsAccess method getAsAuditDetails.
@Override
public AuditDetails getAsAuditDetails() {
String systemId = getSystemId().toString();
PartyProxy party = new PersistedPartyProxy(this).retrieve(getCommitter());
DvDateTime time = new DvDateTime(getTimeCommitted().toLocalDateTime());
DvCodedText changeType = new DvCodedText(getChangeType().getLiteral(), new CodePhrase(new TerminologyId("openehr"), Integer.toString(I_ConceptAccess.ContributionChangeType.valueOf(getChangeType().getLiteral().toUpperCase()).getCode())));
DvText description = new DvText(getDescription());
return new AuditDetails(systemId, party, time, changeType, description);
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class UnflattenerTest method testUnflattenEhrbaseBloodPressureSimpleDeV0.
@Test
public void testUnflattenEhrbaseBloodPressureSimpleDeV0() {
Unflattener cut = new Unflattener(new TestDataTemplateProvider());
EhrbaseBloodPressureSimpleDeV0Composition dto = buildEhrbaseBloodPressureSimpleDeV0();
Composition rmObject = (Composition) cut.unflatten(dto);
assertThat(rmObject).isNotNull();
assertThat(rmObject.getContext().getParticipations()).extracting(p -> ((PartyIdentified) p.getPerformer()).getName(), p -> p.getFunction().getValue()).containsExactlyInAnyOrder(new Tuple("Test", "Pos1"), new Tuple("Test2", "Pos2"));
assertThat(rmObject.getLanguage()).extracting(CodePhrase::getCodeString, c -> c.getTerminologyId().getValue()).containsExactly("de", "ISO_639-1");
assertThat(rmObject.getArchetypeDetails().getTemplateId().getValue()).isEqualTo("ehrbase_blood_pressure_simple.de.v0");
assertThat(rmObject.itemAtPath("/context/start_time/value")).isEqualTo(dto.getStartTimeValue());
List<Object> observationList = rmObject.itemsAtPath("/content[openEHR-EHR-OBSERVATION.sample_blood_pressure.v1]");
assertThat(observationList).size().isEqualTo(1);
Observation observation = (Observation) observationList.get(0);
DvCodedText expected = new DvCodedText("Fifth sound", new CodePhrase(new TerminologyId("local"), "at1012"));
assertThat(observation.itemAtPath("/protocol[at0011]/items[at1010]/value")).isEqualTo(expected);
assertThat(observation.getSubject()).isNotNull().extracting(Object::getClass).isEqualTo(PartySelf.class);
}
use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.
the class DefaultRestAqlEndpoint method extractValue.
private Object extractValue(String valueAsString, Class<?> aClass) throws com.fasterxml.jackson.core.JsonProcessingException {
Object object;
if (StringUtils.isBlank(valueAsString) || "null".equals(valueAsString)) {
object = null;
} else if (aClass.isAnnotationPresent(Entity.class)) {
RMObject locatable = AQL_OBJECT_MAPPER.readValue(valueAsString, RMObject.class);
object = new Flattener(defaultRestClient.getTemplateProvider()).flatten(locatable, aClass);
if (locatable instanceof Composition) {
Flattener.addVersion(object, new VersionUid(((Composition) locatable).getUid().getValue()));
}
} else if (EnumValueSet.class.isAssignableFrom(aClass)) {
RMObject rmObject = AQL_OBJECT_MAPPER.readValue(valueAsString, RMObject.class);
final String codeString;
if (CodePhrase.class.isAssignableFrom(rmObject.getClass())) {
codeString = ((CodePhrase) rmObject).getCodeString();
} else {
codeString = ((DvCodedText) rmObject).getDefiningCode().getCodeString();
}
object = Arrays.stream(aClass.getEnumConstants()).map(e -> (EnumValueSet) e).filter(e -> e.getCode().equals(codeString)).findAny().orElseThrow(() -> new ClientException(String.format("Unknown code %s for %s", codeString, aClass.getSimpleName())));
} else {
object = AQL_OBJECT_MAPPER.readValue(valueAsString, aClass);
}
return object;
}
Aggregations