public static boolean containsAll(ArchetypeReference ar1, ArchetypeReference ar2) { return ar1.getElementInstancesMap().keySet().containsAll(ar2.getElementInstancesMap().keySet()); }
private List<PredicateGeneratedElementInstance> getPredicates(ArchetypeReference archetypeReference) { List<PredicateGeneratedElementInstance> predicates = new ArrayList<>(); for (ElementInstance elementInstance : archetypeReference.getElementInstancesMap().values()) { if (elementInstance instanceof PredicateGeneratedElementInstance) { PredicateGeneratedElementInstance pgei = (PredicateGeneratedElementInstance) elementInstance; predicates.add(pgei); } } return predicates; }
public static boolean isEmpty(ArchetypeReference ar) { for (String idElement : ar.getElementInstancesMap().keySet()) { ElementInstance ei = ar.getElementInstancesMap().get(idElement); if (ei.getDataValue() != null) { return false; } } return true; }
public Set<ElementInstance> getAllElementInstancesByDomain(String idDomain) { Set<ElementInstance> elementInstances = new HashSet<>(); for (ArchetypeReference archetypeReference : getAllArchetypeReferencesByDomain(idDomain)) { elementInstances.addAll(archetypeReference.getElementInstancesMap().values()); } return elementInstances; }
@Override public ArchetypeReference deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { ArchetypeReference archetypeReference = gson.fromJson(json, ArchetypeReference.class); for (ElementInstance elementInstance : archetypeReference.getElementInstancesMap().values()) { elementInstance.setArchetypeReference(archetypeReference); } return archetypeReference; } }
private int getNumPredicates(ArchetypeReference archetypeReference) { int count = 0; for (ElementInstance elementInstance : archetypeReference.getElementInstancesMap().values()) { if (elementInstance instanceof PredicateGeneratedElementInstance && elementInstance.getDataValue() != null) { count++; } } return count; } }
public Collection<ElementInstance> getAllElementInstances() { Collection<ElementInstance> elementInstances = new ArrayList<>(); for (ArchetypeReference ar : getAllArchetypeReferences()) { elementInstances.addAll(ar.getElementInstancesMap().values()); } return elementInstances; }
private static void checkForMissingPathsInEHR( ElementInstanceCollection ehrEIC, ElementInstanceCollection generatedEIC) { Map<String, ArchetypeReference> compressedARsMap = getCompressedQueryArchetypeReferencesMap(generatedEIC.getAllArchetypeReferences()); for (ArchetypeReference ar : ehrEIC.getAllArchetypeReferences()) { ArchetypeReference compressedAR = compressedARsMap.get(ar.getIdArchetype()); if (compressedAR != null) { for (String elementId : compressedAR.getElementInstancesMap().keySet()) { if (!ar.getElementInstancesMap().containsKey(elementId)) { new ElementInstance(elementId, null, ar, null, OpenEHRConstUI.NULL_FLAVOUR_CODE_NO_INFO); } } } } }
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("-----\n"); for (String idArchetype : getArchetypeReferenceMap().keySet()) { sb.append(idArchetype).append("\n"); for (String idDomain : getArchetypeReferenceMap(idArchetype).keySet()) { sb.append("-Domain=").append(idDomain).append("\n"); for (String idAux : getArchetypeReferenceMap(idArchetype, idDomain).keySet()) { sb.append("--idAux=").append(idAux).append("\n"); int index = 1; for (ArchetypeReference ar : getArchetypeReferences(idArchetype, idDomain, idAux)) { sb.append("---[").append(index).append("]\n"); for (String idElement : ar.getElementInstancesMap().keySet()) { sb.append("----").append(idElement).append(""); ElementInstance ei = ar.getElementInstancesMap().get(idElement); if (ei.getDataValue() != null) { sb.append(" (").append(ei.getDataValue().toString()).append(")"); } sb.append("\n"); } } } } } sb.append("-----\n"); return sb.toString(); } }
private void filterEquals( PredicateGeneratedElementInstance predicate, Collection<ArchetypeReference> ehrArchetypeReferences, boolean negation) { final Set<ArchetypeReference> archetypeReferencesToRemove = new HashSet<>(); for (ArchetypeReference archetypeReference : ehrArchetypeReferences) { ElementInstance elementInstance = archetypeReference.getElementInstancesMap().get(predicate.getId()); if (elementInstance != null) { DataValue dataValue = elementInstance.getDataValue(); if (dataValue != null) { boolean equals = dataValue.equals(predicate.getDataValue()); if ((!equals && !negation) || (equals && negation)) { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); } } else { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); } } } ehrArchetypeReferences.removeAll(archetypeReferencesToRemove); }
private void filterMaxMin(String elementId, Collection<ArchetypeReference> ehrArchetypeReferences, boolean max) { final Set<ArchetypeReference> archetypeReferencesToRemove = new HashSet<>(); ElementInstance maxElementInstance = null; for (ArchetypeReference archetypeReference : ehrArchetypeReferences) { ElementInstance elementInstance = archetypeReference.getElementInstancesMap().get(elementId); if (elementInstance != null) { if (elementInstance.getDataValue() != null) { if (maxElementInstance == null || isMaxMin(elementInstance, maxElementInstance, max)) { if (maxElementInstance != null) { archetypeReferencesToRemove.add(maxElementInstance.getArchetypeReference()); } maxElementInstance = elementInstance; } else { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); } } else { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); } } } ehrArchetypeReferences.removeAll(archetypeReferencesToRemove); }
public DateTime getDateTime(ArchetypeReference ar) { String dvDateTimePath = getEventTimePath(ar.getIdArchetype()); if (dvDateTimePath != null) { ElementInstance ei = ar.getElementInstancesMap().get(ar.getIdArchetype() + dvDateTimePath); return getDateTime(ei); } else { return null; } }
private Map<RuleReference, ElementInstance> generateElementInstanceByRuleReferenceMap() { Map<RuleReference, ElementInstance> allElementInstancesByRuleReference = new HashMap<>(); for (Guide guide : guideMap.values()) { if (guide.getDefinition() != null) { for (ArchetypeBinding archetypeBinding : guide.getDefinition().getArchetypeBindings().values()) { ArchetypeReference archetypeReference = GuideUtil.getGeneratedArchetypeReference(archetypeBinding, guide.getId()); for (ElementInstance elementInstance : archetypeReference.getElementInstancesMap().values()) { if (elementInstance instanceof GeneratedElementInstance) { GeneratedElementInstance generatedElementInstance = (GeneratedElementInstance) elementInstance; for (RuleReference ruleReference : generatedElementInstance.getRuleReferences()) { allElementInstancesByRuleReference.put(ruleReference, elementInstance); } } } } } } return allElementInstancesByRuleReference; }
private void addEventTimeElements(Collection<ArchetypeReference> queryARs) { for (ArchetypeReference archetypeReference : queryARs) { String eventTimePath = dateTimeARFinder.getEventTimePath(archetypeReference.getIdArchetype()); if (eventTimePath != null) { String eventTimeElementId = archetypeReference.getIdArchetype() + eventTimePath; if (!archetypeReference.getElementInstancesMap().containsKey(eventTimeElementId)) { log.info("Adding event path '" + eventTimeElementId + "' for archetype '" + archetypeReference.getIdArchetype() + "'!"); new GeneratedElementInstance(eventTimeElementId, null, archetypeReference, null, OpenEHRConstUI.NULL_FLAVOUR_CODE_NO_INFO); } } else { log.warn("Could not find event path for archetype '" + archetypeReference.getIdArchetype() + "'!"); } } }
private void filterGreaterLessThanPredicate( String elementId, DataValue dv, Collection<ArchetypeReference> ehrArchetypeReferences, boolean greaterThan, Calendar date) { if (dv instanceof CurrentTimeExpressionDataValue) { OperatorKind operatorKind = greaterThan ? OperatorKind.GREATER_THAN_OR_EQUAL : OperatorKind.LESS_THAN_OR_EQUAL; dv = ElementInstanceCollectionManager.resolvePredicate(dv, operatorKind, null, date); if (dv == null) { LoggerFactory.getLogger(PredicateFilterManager.class).warn("No Data Value returned after resolving predicate!"); } } final Set<ArchetypeReference> archetypeReferencesToRemove = new HashSet<>(); for (ArchetypeReference archetypeReference : ehrArchetypeReferences) { ElementInstance elementInstance = archetypeReference.getElementInstancesMap().get(elementId); if (elementInstance != null) { if (elementInstance.getDataValue() != null) { int compare = DVUtil.compareDVs(dv, elementInstance.getDataValue()); if (compare != 0 && ((greaterThan && compare > 0) || (!greaterThan && compare < 0))) { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); } } else { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); } } } ehrArchetypeReferences.removeAll(archetypeReferencesToRemove); }
boolean matchAndFill(GeneratedArchetypeReference ar1, ArchetypeReference ar2, Map<String, Guide> guideMap, Calendar date) { Collection<ElementInstance> emptyElementInstances = new ArrayList<ElementInstance>(); boolean matches = matches(ar1, ar2, guideMap, date); if (!matches) { return false; } else { if (ar2 instanceof GeneratedArchetypeReference) { for (String idElement : ar1.getElementInstancesMap().keySet()) { ElementInstance ei1 = ar1.getElementInstancesMap().get(idElement); ElementInstance ei2 = ar2.getElementInstancesMap().get(idElement); if (!(ei1 instanceof PredicateGeneratedElementInstance) && ei2 == null) { ei2 = ei1.clone(); emptyElementInstances.add(ei2); } if (ei1 instanceof GeneratedElementInstance && ei2 instanceof GeneratedElementInstance) { ((GeneratedElementInstance) ei2).getRuleReferences().addAll(((GeneratedElementInstance) ei1).getRuleReferences()); } } for (ElementInstance elementInstance : emptyElementInstances) { elementInstance.setArchetypeReference(ar2); } } } return true; }
private void filterIsA( PredicateGeneratedElementInstance predicate, Collection<ArchetypeReference> ehrArchetypeReferences, boolean negation) { final Set<ArchetypeReference> archetypeReferencesToRemove = new HashSet<>(); final Set<CodePhrase> codePhrases = getCodePhrases(predicate); ElementInstance elementInstance; for (ArchetypeReference archetypeReference : ehrArchetypeReferences) { elementInstance = archetypeReference.getElementInstancesMap().get(predicate.getId()); if (elementInstance != null && codePhrases != null) { CodePhrase codePhrase = getCodePhrase(elementInstance); try { if (codePhrase != null) { if ("local".equalsIgnoreCase(codePhrase.getTerminologyId().name())) { filterIsALocalTerminology(negation, archetypeReferencesToRemove, codePhrases, elementInstance, codePhrase); } else { filterIsAExternalTerminology(negation, archetypeReferencesToRemove, codePhrases, elementInstance, codePhrase); } } else { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); } } catch (Exception exception) { archetypeReferencesToRemove.add(elementInstance.getArchetypeReference()); logger.warn("Filter isA ", exception); } } } ehrArchetypeReferences.removeAll(archetypeReferencesToRemove); }
private static PredicateGeneratedElementInstance generateElementInstanceForPredicate( ArchetypeReference ar, OperatorKind op, String idElement, DataValue dv, Guide guide, DateTime dateTime, boolean resolvePredicates) { Collection<RuleReference> previousRuleReferences = new ArrayList<>(); ElementInstance elementInstance = ar.getElementInstancesMap().get(idElement); if (elementInstance instanceof GeneratedElementInstance) { GeneratedElementInstance generatedElementInstance = (GeneratedElementInstance) elementInstance; previousRuleReferences.addAll(generatedElementInstance.getRuleReferences()); } if (dv != null && guide != null && dateTime != null && resolvePredicates) { dv = ElementInstanceCollectionManager.resolvePredicate(dv, op, Collections.singleton(guide), dateTime.toCalendar(Locale.getDefault())); } PredicateGeneratedElementInstance predicateGeneratedElementInstance = new PredicateGeneratedElementInstanceBuilder() .setId(idElement) .setDataValue(dv) .setArchetypeReference(ar) .setOperatorKind(op) .createPredicateGeneratedElementInstance(); predicateGeneratedElementInstance.getRuleReferences().addAll(previousRuleReferences); return predicateGeneratedElementInstance; }
public boolean matches(GeneratedArchetypeReference ar1, ArchetypeReference ar2, Map<String, Guide> guideMap, Calendar date) { if (!ar1.getIdArchetype().equals(ar2.getIdArchetype())) { return false; } else { for (String idElement : ar1.getElementInstancesMap().keySet()) { ElementInstance ei1 = ar1.getElementInstancesMap().get(idElement); ElementInstance ei2 = ar2.getElementInstancesMap().get(idElement); if (ei1 instanceof PredicateGeneratedElementInstance) { if (ei2 != null) { OperatorKind operatorKind = ((PredicateGeneratedElementInstance) ei1).getOperatorKind(); Set<String> guideIds = new HashSet<>(); DataValue dv = getResolveDataValueIfNeeded(guideMap, date, ei1, guideIds); DataValue dv2 = getResolveDataValueIfNeeded(guideMap, date, ei2, guideIds); Collection<Guide> guides = getGuides(guideMap, guideIds); if (!matches(dv, dv2, operatorKind, guides)) { return false; } } else { return false; } } } return true; } }
private static void compressQueryArchetypeReference(ArchetypeReference arPrev, ArchetypeReference arNew) { for (ElementInstance newEI : arNew.getElementInstancesMap().values()) { ElementInstance eiAux = arPrev.getElementInstancesMap().get(newEI.getId()); if (eiAux == null) { cloneElementInstanceWithGTCodes(newEI, arPrev, false); if (newEI instanceof PredicateGeneratedElementInstance) { PredicateGeneratedElementInstance pgeiNew = (PredicateGeneratedElementInstance) newEI; ElementInstance prevEI = arPrev.getElementInstancesMap().get(pgeiNew.getId()); if (prevEI instanceof PredicateGeneratedElementInstance) { PredicateGeneratedElementInstance pgeiPrev = (PredicateGeneratedElementInstance) prevEI;