Search in sources :

Example 1 with EhrStatus

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);
    }
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) GenericId(com.nedap.archie.rm.support.identification.GenericId) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) PartySelf(com.nedap.archie.rm.generic.PartySelf) DvText(com.nedap.archie.rm.datavalues.DvText) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with EhrStatus

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);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) DefaultRestClient(org.ehrbase.client.openehrclient.defaultrestclient.DefaultRestClient) URI(java.net.URI) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) PartySelf(com.nedap.archie.rm.generic.PartySelf) DvText(com.nedap.archie.rm.datavalues.DvText) PartyRef(com.nedap.archie.rm.support.identification.PartyRef) OpenEhrClientConfig(org.ehrbase.client.openehrclient.OpenEhrClientConfig) ResourceTemplateProvider(org.ehrbase.fhirbridge.ehr.ResourceTemplateProvider) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with 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);
    }
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) UUID(java.util.UUID) IdType(org.hl7.fhir.r4.model.IdType)

Example 4 with EhrStatus

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);
    }
}
Also used : VersionedEhrStatus(com.nedap.archie.rm.ehr.VersionedEhrStatus) EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)

Example 5 with EhrStatus

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;
}
Also used : EhrStatus(com.nedap.archie.rm.ehr.EhrStatus) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) RecordedDvCodedText(org.ehrbase.service.RecordedDvCodedText) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) UUID(java.util.UUID) HierObjectId(com.nedap.archie.rm.support.identification.HierObjectId) DvText(com.nedap.archie.rm.datavalues.DvText) RecordedDvText(org.ehrbase.service.RecordedDvText) PartySelf(com.nedap.archie.rm.generic.PartySelf) PersistedPartyProxy(org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)

Aggregations

EhrStatus (com.nedap.archie.rm.ehr.EhrStatus)23 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)12 UUID (java.util.UUID)11 PartySelf (com.nedap.archie.rm.generic.PartySelf)9 DvText (com.nedap.archie.rm.datavalues.DvText)8 PartyRef (com.nedap.archie.rm.support.identification.PartyRef)7 VersionedEhrStatus (com.nedap.archie.rm.ehr.VersionedEhrStatus)6 InvalidApiParameterException (org.ehrbase.api.exception.InvalidApiParameterException)5 ObjectNotFoundException (org.ehrbase.api.exception.ObjectNotFoundException)5 HttpHeaders (org.springframework.http.HttpHeaders)5 OriginalVersion (com.nedap.archie.rm.changecontrol.OriginalVersion)4 URI (java.net.URI)4 InternalServerException (org.ehrbase.api.exception.InternalServerException)4 Test (org.junit.Test)4 MediaType (org.springframework.http.MediaType)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Timestamp (java.sql.Timestamp)3 Optional (java.util.Optional)3 EhrService (org.ehrbase.api.service.EhrService)3 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)3