use of com.nedap.archie.rm.ehr.EhrStatus in project fhir-bridge by ehrbase.
the class EhrController method createEHR.
@PostMapping
public ResponseEntity<String> createEHR(@RequestParam String pPatientId) {
try {
// taken from EhrBase tests
PartySelf subject = new PartySelf();
PartyRef externalRef = new PartyRef();
externalRef.setType("PARTY_REF");
externalRef.setNamespace("patients");
GenericId genericId = new GenericId();
genericId.setScheme("id_scheme");
genericId.setValue(pPatientId);
externalRef.setId(genericId);
subject.setExternalRef(externalRef);
DvText dvText = new DvText("any EHR status");
EhrStatus ehrStatus = new EhrStatus("openEHR-EHR-ITEM_TREE.generic.v1", dvText, subject, true, true, null);
return ResponseEntity.ok(openEhrClient.ehrEndpoint().createEhr(ehrStatus).toString());
} catch (Exception ex) {
return new ResponseEntity<>("Error while creating an EHR for patient id " + pPatientId, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of com.nedap.archie.rm.ehr.EhrStatus in project fhir-bridge by ehrbase.
the class AbstractSetupIT method setup.
@BeforeAll
static void setup() throws URISyntaxException {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("myuser", "myPassword432"));
CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
DefaultRestClient client = new DefaultRestClient(new OpenEhrClientConfig(new URI("http://localhost:8080/ehrbase/")), new ResourceTemplateProvider("classpath:/opt/*.opt"), httpClient);
PATIENT_ID = UUID.randomUUID().toString();
EhrStatus ehrStatus = new EhrStatus();
ehrStatus.setSubject(new PartySelf(new PartyRef(new HierObjectId(PATIENT_ID), "demographic", "PERSON")));
ehrStatus.setArchetypeNodeId("openEHR-EHR-EHR_STATUS.generic.v1");
ehrStatus.setName(new DvText("Integration tests status"));
client.ehrEndpoint().createEhr(ehrStatus);
}
use of com.nedap.archie.rm.ehr.EhrStatus in project fhir-bridge by ehrbase.
the class EhrStatusService method handlePatient.
private void handlePatient(PatientEhr patientEhr) {
var patient = patientDao.read(new IdType("Patient", patientEhr.getPatientId()));
UUID ehrId = patientEhr.getEhrId();
Optional<EhrStatus> existing = ehrEndpoint.getEhrStatus(ehrId);
if (existing.isEmpty()) {
log.warn("Patient[id={}, ehr_id={}]", patientEhr.getPatientId(), patientEhr.getEhrId());
} else {
EhrStatus status = existing.get();
Identifier pseudonym = PatientUtils.getPseudonym(patient);
status.getSubject().getExternalRef().getId().setValue(pseudonym.getValue());
ehrEndpoint.updateEhrStatus(ehrId, status);
}
}
use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.
the class EhrServiceImp method create.
@Override
public UUID create(EhrStatus status, UUID ehrId) {
try {
validationService.check(status);
} catch (Exception e) {
// rethrow if this class, but wrap all others in InternalServerException
if (e.getClass().equals(UnprocessableEntityException.class))
throw (UnprocessableEntityException) e;
if (e.getClass().equals(IllegalArgumentException.class))
throw new ValidationException(e);
if (e.getClass().equals(ValidationException.class))
throw e;
else
throw new InternalServerException(e);
}
if (status == null) {
// in case of new status with default values
status = new EhrStatus();
status.setSubject(new PartySelf(null));
status.setModifiable(true);
status.setQueryable(true);
}
// server sets own new UUID in both cases (new or given status)
status.setUid(new HierObjectId(UUID.randomUUID().toString()));
UUID subjectUuid;
if (PartyUtils.isEmpty(status.getSubject())) {
subjectUuid = emptyParty;
} else {
subjectUuid = new PersistedPartyProxy(getDataAccess()).getOrCreate(status.getSubject());
if (I_EhrAccess.checkExist(getDataAccess(), subjectUuid)) {
throw new StateConflictException("Specified party has already an EHR set (partyId=" + subjectUuid + ")");
}
}
UUID systemId = getSystemUuid();
UUID committerId = getUserUuid();
try {
// this try block sums up a bunch of operations that can throw errors in the following
I_EhrAccess ehrAccess = I_EhrAccess.getInstance(getDataAccess(), subjectUuid, systemId, null, null, ehrId);
ehrAccess.setStatus(status);
return ehrAccess.commit(committerId, systemId, DESCRIPTION);
} catch (Exception e) {
throw new InternalServerException("Could not create an EHR with given parameters.", e);
}
}
use of com.nedap.archie.rm.ehr.EhrStatus in project ehrbase by ehrbase.
the class EhrAccess method getStatus.
// get latest status
@Override
public EhrStatus getStatus() {
EhrStatus status = new EhrStatus();
status.setModifiable(isModifiable());
status.setQueryable(isQueryable());
// set otherDetails if available
if (getStatusAccess().getStatusRecord().getOtherDetails() != null) {
status.setOtherDetails(getStatusAccess().getStatusRecord().getOtherDetails());
}
// Locatable attribute
status.setArchetypeNodeId(getArchetypeNodeId());
Object name = new RecordedDvCodedText().fromDB(getStatusAccess().getStatusRecord(), STATUS.NAME);
status.setName(name instanceof DvText ? (DvText) name : (DvCodedText) name);
UUID statusId = getStatusAccess().getStatusRecord().getId();
status.setUid(new HierObjectId(statusId.toString() + "::" + getServerConfig().getNodename() + "::" + I_StatusAccess.getLatestVersionNumber(this, statusId)));
PartySelf partySelf = (PartySelf) new PersistedPartyProxy(this).retrieve(getParty());
status.setSubject(partySelf);
return status;
}
Aggregations