use of com.nedap.archie.rm.datavalues.DvCodedText in project ehrbase by ehrbase.
the class EhrServiceImp method getEhrStatusAtVersion.
@Override
public Optional<OriginalVersion<EhrStatus>> getEhrStatusAtVersion(UUID ehrUuid, UUID versionedObjectUid, int version) {
// pre-step: check for valid ehrId
if (!hasEhr(ehrUuid)) {
throw new ObjectNotFoundException("ehr", "No EHR found with given ID: " + ehrUuid.toString());
}
if ((version == 0) || (I_StatusAccess.getLatestVersionNumber(getDataAccess(), versionedObjectUid) < version)) {
throw new ObjectNotFoundException("versioned_ehr_status", "No VERSIONED_EHR_STATUS with given version: " + version);
}
I_StatusAccess statusAccess = I_StatusAccess.getVersionMapOfStatus(getDataAccess(), versionedObjectUid).get(version);
ObjectVersionId versionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + version);
// TODO: once lifecycle state is supported, get it here dynamically
DvCodedText lifecycleState = new DvCodedText("complete", new CodePhrase("532"));
AuditDetails commitAudit = statusAccess.getAuditDetailsAccess().getAsAuditDetails();
ObjectRef<HierObjectId> contribution = new ObjectRef<>(new HierObjectId(statusAccess.getStatusRecord().getInContribution().toString()), "openehr", "contribution");
List<UUID> attestationIdList = I_AttestationAccess.retrieveListOfAttestationsByRef(getDataAccess(), statusAccess.getStatusRecord().getAttestationRef());
// as default, gets content if available in the following lines
List<Attestation> attestations = null;
if (!attestationIdList.isEmpty()) {
attestations = new ArrayList<>();
for (UUID id : attestationIdList) {
I_AttestationAccess a = new AttestationAccess(getDataAccess()).retrieveInstance(id);
attestations.add(a.getAsAttestation());
}
}
ObjectVersionId precedingVersionId = null;
// check if there is a preceding version and set it, if available
if (version > 1) {
// in the current scope version is an int and therefore: preceding = current - 1
precedingVersionId = new ObjectVersionId(versionedObjectUid + "::" + getServerConfig().getNodename() + "::" + (version - 1));
}
OriginalVersion<EhrStatus> versionStatus = new OriginalVersion<>(versionId, precedingVersionId, statusAccess.getStatus(), lifecycleState, commitAudit, contribution, null, null, attestations);
return Optional.of(versionStatus);
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project ehrbase by ehrbase.
the class RecordedDvCodedText method fromDB.
public Object fromDB(Record record, Field<DvCodedTextRecord> fromField) {
Object retObject;
DvCodedTextRecord dvCodedTextRecord = record.get(fromField);
CodePhraseRecord codePhraseDefiningCode = dvCodedTextRecord.getDefiningCode();
CodePhraseRecord codePhraseLanguage = dvCodedTextRecord.getLanguage();
CodePhraseRecord codePhraseEncoding = dvCodedTextRecord.getEncoding();
if (codePhraseDefiningCode != null)
retObject = new DvCodedText(dvCodedTextRecord.getValue(), codePhraseLanguage == null ? null : new CodePhrase(new TerminologyId(codePhraseLanguage.getTerminologyIdValue()), codePhraseLanguage.getCodeString()), codePhraseEncoding == null ? null : new CodePhrase(new TerminologyId(codePhraseEncoding.getTerminologyIdValue()), codePhraseEncoding.getCodeString()), new CodePhrase(new TerminologyId(codePhraseDefiningCode.getTerminologyIdValue()), codePhraseDefiningCode.getCodeString()));
else
// assume DvText
retObject = new DvText(dvCodedTextRecord.getValue(), codePhraseLanguage == null ? null : new CodePhrase(new TerminologyId(codePhraseLanguage.getTerminologyIdValue()), codePhraseLanguage.getCodeString()), codePhraseEncoding == null ? null : new CodePhrase(new TerminologyId(codePhraseEncoding.getTerminologyIdValue()), codePhraseEncoding.getCodeString()));
if (dvCodedTextRecord.getTermMapping() != null && dvCodedTextRecord.getTermMapping().length > 0) {
for (String dvCodedTextTermMappingRecord : dvCodedTextRecord.getTermMapping()) {
((DvText) retObject).addMapping(new PersistentTermMapping().decode(dvCodedTextTermMappingRecord));
}
}
return retObject;
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project ehrbase by ehrbase.
the class InvokeVisitorTest method shouldVisitInvokeExpressionExpandOperation.
@Test
public void shouldVisitInvokeExpressionExpandOperation() {
// postman request for expansion is: GET https://r4.ontoserver.csiro.au/fhir/ValueSet/$expand?url=http://hl7.org/fhir/ValueSet/surface
FhirTerminologyServerR4AdaptorImpl mock = mock(FhirTerminologyServerR4AdaptorImpl.class);
when(mock.expandWithParameters(any(), any())).thenReturn(List.of(new DvCodedText("Occlusal", new CodePhrase("O")), new DvCodedText("Mesial", new CodePhrase("M")), new DvCodedText("Distoclusal", new CodePhrase("DO")), new DvCodedText("Lingual", new CodePhrase("L")), new DvCodedText("Incisal", new CodePhrase("I")), new DvCodedText("Ventral", new CodePhrase("V")), new DvCodedText("Mesioclusodistal", new CodePhrase("MOD")), new DvCodedText("Mesioclusal", new CodePhrase("MO")), new DvCodedText("Distal", new CodePhrase("D")), new DvCodedText("Distoincisal", new CodePhrase("DI")), new DvCodedText("Buccal", new CodePhrase("B"))));
WhereVisitor cut = new WhereVisitor(mock);
String aql = "SELECT o/data[at0002]/events[at0003] AS systolic " + "FROM EHR [ehr_id/value='1234'] " + "CONTAINS COMPOSITION c " + "CONTAINS OBSERVATION o [openEHR-EHR-OBSERVATION.blood_pressure.v1] " + "WHERE c/archetype_details/template_id/value matches {'Flormidal', TERMINOLOGY('expand','http://hl7.org/fhir/4.0','url=http://hl7.org/fhir/ValueSet/surface'), 'Kloralhidrat'}";
ParseTree tree = QueryHelper.setupParseTree(aql);
cut.visit(tree);
List<Object> whereExpression = cut.getWhereExpression();
assertThat(whereExpression).size().isEqualTo(29);
I_VariableDefinition where1 = (I_VariableDefinition) whereExpression.get(0);
I_VariableDefinition expected1 = I_VariableDefinitionHelper.build("archetype_details/template_id/value", null, "c", false, false, false);
I_VariableDefinitionHelper.checkEqualWithoutFuncParameters(where1, expected1);
assertThat(whereExpression.get(1)).isEqualTo(" IN ");
assertThat(whereExpression.get(2)).isEqualTo("(");
assertThat(whereExpression.get(3)).isEqualTo("'Flormidal'");
assertThat(whereExpression.get(4)).isEqualTo(",");
assertThat(whereExpression.get(5)).isEqualTo("'O'");
assertThat(whereExpression.get(6)).isEqualTo(",");
assertThat(whereExpression.get(7)).isEqualTo("'M'");
assertThat(whereExpression.get(8)).isEqualTo(",");
assertThat(whereExpression.get(9)).isEqualTo("'DO'");
assertThat(whereExpression.get(10)).isEqualTo(",");
assertThat(whereExpression.get(11)).isEqualTo("'L'");
assertThat(whereExpression.get(12)).isEqualTo(",");
assertThat(whereExpression.get(13)).isEqualTo("'I'");
assertThat(whereExpression.get(14)).isEqualTo(",");
assertThat(whereExpression.get(15)).isEqualTo("'V'");
assertThat(whereExpression.get(16)).isEqualTo(",");
assertThat(whereExpression.get(17)).isEqualTo("'MOD'");
assertThat(whereExpression.get(18)).isEqualTo(",");
assertThat(whereExpression.get(19)).isEqualTo("'MO'");
assertThat(whereExpression.get(20)).isEqualTo(",");
assertThat(whereExpression.get(21)).isEqualTo("'D'");
assertThat(whereExpression.get(22)).isEqualTo(",");
assertThat(whereExpression.get(23)).isEqualTo("'DI'");
assertThat(whereExpression.get(24)).isEqualTo(",");
assertThat(whereExpression.get(25)).isEqualTo("'B'");
assertThat(whereExpression.get(26)).isEqualTo(",");
assertThat(whereExpression.get(27)).isEqualTo("'Kloralhidrat'");
assertThat(whereExpression.get(28)).isEqualTo(")");
}
use of com.nedap.archie.rm.datavalues.DvCodedText in project ehrbase by ehrbase.
the class ContextAccess method retrieveHistoricalEventContext.
/**
* @throws InternalServerException on failure of decoding DvText or DvDateTime
*/
public static EventContext retrieveHistoricalEventContext(I_DomainAccess domainAccess, UUID compositionId, Timestamp transactionTime) {
// use fetch any since duplicates are possible during tests...
EventContextHistoryRecord eventContextHistoryRecord = domainAccess.getContext().fetchAny(EVENT_CONTEXT_HISTORY, EVENT_CONTEXT_HISTORY.COMPOSITION_ID.eq(compositionId).and(EVENT_CONTEXT_HISTORY.SYS_TRANSACTION.eq(transactionTime)));
// no matching version for this composition
if (eventContextHistoryRecord == null)
return null;
// get the facility entry
PartyIdentified healthCareFacility = null;
if (eventContextHistoryRecord.getFacility() != null) {
PartyIdentifiedRecord partyIdentifiedRecord = domainAccess.getContext().fetchOne(PARTY_IDENTIFIED, PARTY_IDENTIFIED.ID.eq(eventContextHistoryRecord.getFacility()));
if (partyIdentifiedRecord != null) {
List<DvIdentifier> identifiers = new ArrayList<>();
domainAccess.getContext().fetch(IDENTIFIER, IDENTIFIER.PARTY.eq(partyIdentifiedRecord.getId())).forEach(record -> {
DvIdentifier dvIdentifier = new DvIdentifier();
dvIdentifier.setIssuer(record.getIssuer());
dvIdentifier.setAssigner(record.getAssigner());
dvIdentifier.setId(record.getIdValue());
dvIdentifier.setType(record.getTypeName());
identifiers.add(dvIdentifier);
});
// get PartyRef values from record
healthCareFacility = getPartyIdentifiedFromRecord(partyIdentifiedRecord, identifiers);
}
}
List<Participation> participationList = new ArrayList<>();
// get the participations
domainAccess.getContext().fetch(PARTICIPATION_HISTORY, PARTICIPATION_HISTORY.EVENT_CONTEXT.eq(eventContextHistoryRecord.getId()).and(PARTICIPATION_HISTORY.SYS_TRANSACTION.eq(transactionTime))).forEach(record -> {
// retrieve performer
PartyProxy performer = new PersistedPartyProxy(domainAccess).retrieve(record.getPerformer());
DvInterval<DvDateTime> startTime = convertDvIntervalDvDateTimeFromRecord(eventContextHistoryRecord);
DvCodedText mode = convertModeFromRecord(eventContextHistoryRecord);
Participation participation = new Participation(performer, (DvText) new RecordedDvCodedText().fromDB(record, PARTICIPATION.FUNCTION), mode, startTime);
participationList.add(participation);
});
DvCodedText setting = (DvCodedText) new RecordedDvCodedText().fromDB(eventContextHistoryRecord, EVENT_CONTEXT_HISTORY.SETTING);
return new EventContext(healthCareFacility, new RecordedDvDateTime().decodeDvDateTime(eventContextHistoryRecord.getStartTime(), eventContextHistoryRecord.getStartTimeTzid()), new RecordedDvDateTime().decodeDvDateTime(eventContextHistoryRecord.getEndTime(), eventContextHistoryRecord.getEndTimeTzid()), participationList.isEmpty() ? null : participationList, eventContextHistoryRecord.getLocation(), setting, null);
}
Aggregations