/******************************************************************************* | |
* Copyright (c) 2009, 2011 IBM Corporation and others. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* IBM Corporation - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.mdht.uml.cda.operations; | |
import java.util.Collection; | |
import java.util.Map; | |
import org.eclipse.emf.common.util.BasicDiagnostic; | |
import org.eclipse.emf.common.util.BasicEList; | |
import org.eclipse.emf.common.util.Diagnostic; | |
import org.eclipse.emf.common.util.DiagnosticChain; | |
import org.eclipse.emf.common.util.EList; | |
import org.eclipse.emf.ecore.EClassifier; | |
import org.eclipse.mdht.uml.cda.CDAPackage; | |
import org.eclipse.mdht.uml.cda.Patient; | |
import org.eclipse.mdht.uml.cda.util.CDAValidator; | |
import org.eclipse.mdht.uml.hl7.datatypes.II; | |
import org.eclipse.mdht.uml.hl7.datatypes.util.DatatypesUtil; | |
import org.eclipse.mdht.uml.hl7.rim.operations.EntityOperations; | |
import org.eclipse.ocl.ParserException; | |
import org.eclipse.ocl.ecore.Constraint; | |
import org.eclipse.ocl.ecore.OCL; | |
import org.eclipse.ocl.expressions.OCLExpression; | |
/** | |
* <!-- begin-user-doc --> | |
* A static utility class that provides operations related to '<em><b>Patient</b></em>' model objects. | |
* <!-- end-user-doc --> | |
* | |
* <p> | |
* The following operations are supported: | |
* </p> | |
* <ul> | |
* <li>{@link org.eclipse.mdht.uml.cda.Patient#validateClassCode(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>Validate Class Code</em>}</li> | |
* <li>{@link org.eclipse.mdht.uml.cda.Patient#validateDeterminerCode(org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>Validate Determiner Code</em>}</li> | |
* <li>{@link org.eclipse.mdht.uml.cda.Patient#getIds() <em>Get Ids</em>}</li> | |
* </ul> | |
* | |
* @generated | |
*/ | |
public class PatientOperations extends EntityOperations { | |
/** | |
* The cached environment for evaluating OCL expressions. | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @generated | |
* @ordered | |
*/ | |
protected static final ThreadLocal<OCL> EOCL_ENV = new ThreadLocal<OCL>() { | |
@Override | |
public OCL initialValue() { | |
return OCL.newInstance(); | |
} | |
}; | |
/** | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @generated | |
*/ | |
protected PatientOperations() { | |
super(); | |
} | |
/** | |
* The cached OCL expression body for the '{@link #validateClassCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>Validate Class Code</em>}' operation. | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @see #validateClassCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) | |
* @generated | |
* @ordered | |
*/ | |
protected static final String VALIDATE_CLASS_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP = "self.isClassCodeDefined() implies self.classCode=vocab::EntityClass::PSN"; | |
/** | |
* The cached OCL invariant for the '{@link #validateClassCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>Validate Class Code</em>}' invariant operation. | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @see #validateClassCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) | |
* @generated | |
* @ordered | |
*/ | |
protected static ThreadLocal<Constraint> VALIDATE_CLASS_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV = new ThreadLocal<Constraint>(); | |
/** | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* <!-- begin-model-doc --> | |
* @param patient The receiving '<em><b>Patient</b></em>' model object. | |
* @param diagnostics The chain of diagnostics to which problems are to be appended. | |
* @param context The cache of context-specific information. | |
* <!-- end-model-doc --> | |
* @generated | |
*/ | |
public static boolean validateClassCode(Patient patient, DiagnosticChain diagnostics, Map<Object, Object> context) { | |
DatatypesUtil.increment(context, "PatientClassCode", "ERROR"); | |
if (VALIDATE_CLASS_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV.get() == null) { | |
synchronized (EOCL_ENV) { | |
OCL.Helper helper = EOCL_ENV.get().createOCLHelper(); | |
helper.setContext(CDAPackage.Literals.PATIENT); | |
try { | |
VALIDATE_CLASS_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV.set( | |
helper.createInvariant(VALIDATE_CLASS_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP)); | |
} catch (ParserException pe) { | |
throw new UnsupportedOperationException(pe.getLocalizedMessage()); | |
} | |
} | |
} | |
if (!EOCL_ENV.get().createQuery(VALIDATE_CLASS_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV.get()).check(patient)) { | |
if (diagnostics != null) { | |
diagnostics.add( | |
new BasicDiagnostic( | |
Diagnostic.ERROR, CDAValidator.DIAGNOSTIC_SOURCE, CDAValidator.PATIENT__CLASS_CODE, | |
org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE.getString( | |
"_UI_GenericInvariant_diagnostic", | |
new Object[] { | |
"validateClassCode", | |
org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(patient, context) }), | |
new Object[] { patient })); | |
} | |
return false; | |
} | |
return true; | |
} | |
/** | |
* The cached OCL expression body for the '{@link #validateDeterminerCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>Validate Determiner Code</em>}' operation. | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @see #validateDeterminerCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) | |
* @generated | |
* @ordered | |
*/ | |
protected static final String VALIDATE_DETERMINER_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP = "self.isDeterminerCodeDefined() implies self.determinerCode=vocab::EntityDeterminer::INSTANCE"; | |
/** | |
* The cached OCL invariant for the '{@link #validateDeterminerCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) <em>Validate Determiner Code</em>}' invariant operation. | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @see #validateDeterminerCode(Patient, org.eclipse.emf.common.util.DiagnosticChain, java.util.Map) | |
* @generated | |
* @ordered | |
*/ | |
protected static ThreadLocal<Constraint> VALIDATE_DETERMINER_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV = new ThreadLocal<Constraint>(); | |
/** | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* <!-- begin-model-doc --> | |
* @param patient The receiving '<em><b>Patient</b></em>' model object. | |
* @param diagnostics The chain of diagnostics to which problems are to be appended. | |
* @param context The cache of context-specific information. | |
* <!-- end-model-doc --> | |
* @generated | |
*/ | |
public static boolean validateDeterminerCode(Patient patient, DiagnosticChain diagnostics, | |
Map<Object, Object> context) { | |
DatatypesUtil.increment(context, "PatientDeterminerCode", "ERROR"); | |
if (VALIDATE_DETERMINER_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV.get() == null) { | |
synchronized (EOCL_ENV) { | |
OCL.Helper helper = EOCL_ENV.get().createOCLHelper(); | |
helper.setContext(CDAPackage.Literals.PATIENT); | |
try { | |
VALIDATE_DETERMINER_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV.set( | |
helper.createInvariant(VALIDATE_DETERMINER_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_EXP)); | |
} catch (ParserException pe) { | |
throw new UnsupportedOperationException(pe.getLocalizedMessage()); | |
} | |
} | |
} | |
if (!EOCL_ENV.get().createQuery(VALIDATE_DETERMINER_CODE__DIAGNOSTIC_CHAIN_MAP__EOCL_INV.get()).check( | |
patient)) { | |
if (diagnostics != null) { | |
diagnostics.add( | |
new BasicDiagnostic( | |
Diagnostic.ERROR, CDAValidator.DIAGNOSTIC_SOURCE, CDAValidator.PATIENT__DETERMINER_CODE, | |
org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE.getString( | |
"_UI_GenericInvariant_diagnostic", | |
new Object[] { | |
"validateDeterminerCode", | |
org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(patient, context) }), | |
new Object[] { patient })); | |
} | |
return false; | |
} | |
return true; | |
} | |
/** | |
* The cached OCL expression body for the '{@link #getIds(Patient) <em>Get Ids</em>}' operation. | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @see #getIds(Patient) | |
* @generated | |
* @ordered | |
*/ | |
protected static final String GET_IDS__EOCL_EXP = "Bag { self.id }"; | |
/** | |
* The cached OCL query for the '{@link #getIds(Patient) <em>Get Ids</em>}' query operation. | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @see #getIds(Patient) | |
* @generated | |
* @ordered | |
*/ | |
protected static ThreadLocal<OCLExpression<EClassifier>> GET_IDS__EOCL_QRY = new ThreadLocal<OCLExpression<EClassifier>>(); | |
/** | |
* <!-- begin-user-doc --> | |
* <!-- end-user-doc --> | |
* @generated | |
*/ | |
public static EList<II> getIds(Patient patient) { | |
if (GET_IDS__EOCL_QRY.get() == null) { | |
synchronized (EOCL_ENV) { | |
OCL.Helper helper = EOCL_ENV.get().createOCLHelper(); | |
helper.setOperationContext( | |
CDAPackage.Literals.PATIENT, CDAPackage.Literals.PATIENT.getEAllOperations().get(16)); | |
try { | |
GET_IDS__EOCL_QRY.set(helper.createQuery(GET_IDS__EOCL_EXP)); | |
} catch (ParserException pe) { | |
throw new UnsupportedOperationException(pe.getLocalizedMessage()); | |
} | |
} | |
} | |
OCL.Query query = EOCL_ENV.get().createQuery(GET_IDS__EOCL_QRY.get()); | |
@SuppressWarnings("unchecked") | |
Collection<II> result = (Collection<II>) query.evaluate(patient); | |
return new BasicEList.UnmodifiableEList<II>(result.size(), result.toArray()); | |
} | |
} // PatientOperations |