171 lines
6.1 KiB
JavaScript
171 lines
6.1 KiB
JavaScript
/// <reference types="cypress" />
|
|
|
|
describe("it test the api", () => {
|
|
let jsonWebToken = "";
|
|
const apiUrl = "https://fhir-api.public.post-prod.lifen.fr";
|
|
let documentReferenceId, communicationRequestId = "";
|
|
|
|
it("I have a JWT", () => {
|
|
|
|
cy.request({
|
|
url: "https://lifen-post-prod.eu.auth0.com/oauth/token",
|
|
method: "POST",
|
|
body: {
|
|
client_id: 'szVsMPaDPUdwqngGiLoHfXFT5XCYPFcy',
|
|
client_secret: 'sMp2PB-QWBZupCB4IXJrWDJ-7tlpUl09vQ2tMKdy049He7-g93ofbXz7ESlAc82B',
|
|
audience: 'post-prod-apis',
|
|
grant_type: 'client_credentials',
|
|
}
|
|
}).its('body').then((body) => {
|
|
jsonWebToken = body.access_token;
|
|
//cy.log(json_web_token);
|
|
expect(jsonWebToken).to.not.be.empty;
|
|
});
|
|
|
|
});
|
|
|
|
it.skip("I have a the document #1615660", () => {
|
|
cy.request({
|
|
url:`${apiUrl}/fhir/Binary/1615660`,
|
|
method:'GET',
|
|
headers: {
|
|
"authorization" : `Bearer ${jsonWebToken}`,
|
|
"content-type": "application/json",
|
|
"Prefer": "return=representation"
|
|
}
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.headers["content-type"]).to.eq("application/pdf");
|
|
})
|
|
});
|
|
|
|
it("I prepare the DocumentReference", () => {
|
|
cy.request({
|
|
url:`${apiUrl}/fhir/DocumentReference`,
|
|
method:'POST',
|
|
headers: {
|
|
authorization : `Bearer ${jsonWebToken}`,
|
|
'content-type': 'application/json',
|
|
"Prefer": "return=representation"
|
|
},
|
|
json: true,
|
|
body: {
|
|
"status": "current",
|
|
"docStatus": "final",
|
|
"type": {
|
|
"coding": [
|
|
{
|
|
"system": "http://loinc.org",
|
|
"code": "34109-9",
|
|
"display": "Document médical"
|
|
}
|
|
]
|
|
},
|
|
"indexed": "2021-02-11T09:25:39Z",
|
|
"description": "aelgain-copiepatient.pdf",
|
|
"content": [
|
|
{
|
|
"attachment": {
|
|
"contentType": "application/pdf",
|
|
"url": "Binary/1615660",
|
|
"title": "aelgain-copiepatient.pdf"
|
|
}
|
|
}
|
|
],
|
|
"resourceType": "DocumentReference"
|
|
}
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(201);
|
|
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
|
|
expect(response.body).to.have.property("resourceType", "DocumentReference");
|
|
expect(response.body).to.have.property('id');
|
|
documentReferenceId = response.body.id
|
|
});
|
|
//cy.log(documentReferenceId);
|
|
});
|
|
|
|
it("I prepare the CommunicationRequest", () => {
|
|
cy.request({
|
|
url: `${apiUrl}/fhir/CommunicationRequest`,
|
|
method: 'POST',
|
|
headers: {
|
|
authorization: `Bearer ${jsonWebToken}`,
|
|
'content-type': 'application/json',
|
|
"Prefer": "return=representation"
|
|
},
|
|
json: true,
|
|
body: {
|
|
"meta": {
|
|
"tag": [
|
|
{
|
|
"system": "http://lifen.fr/fhir/tag/verified/sender",
|
|
"code": "SENDER_VERIFIED",
|
|
"display": "Sender is verified and should not be changed."
|
|
},
|
|
{
|
|
"system": "http://lifen.fr/fhir/tag/processing/mode",
|
|
"code": "IMMEDIATE_MODE",
|
|
"display": "request should be treated in immediate mode"
|
|
},
|
|
{
|
|
"system": "http://lifen.fr/fhir/CodeSystem/Resource/Tag/PatientAutomaticResending",
|
|
"code": "NONE",
|
|
"display": "Patient communication should not be resent"
|
|
}
|
|
]
|
|
},
|
|
"status": "draft",
|
|
"category": [
|
|
{
|
|
"coding": [
|
|
{
|
|
"system": "http://lifen.fr/fhir/CodeSystem/communication-category",
|
|
"code": "MEDICAL_REPORT"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"priority": "routine",
|
|
"payload": [
|
|
{
|
|
"contentReference": {
|
|
"reference": `DocumentReference/${documentReferenceId}`
|
|
}
|
|
}
|
|
],
|
|
"sender": {
|
|
"extension": [
|
|
{
|
|
"url": "http://lifen.fr/fhir/StructureDefinition/Resource/Extension/Source",
|
|
"valueCode": "USER"
|
|
}
|
|
],
|
|
"reference": "Organization/2"
|
|
},
|
|
"requester": {
|
|
"agent": {
|
|
"extension": [
|
|
{
|
|
"url": "http://lifen.fr/fhir/StructureDefinition/communicationrequest-requester-user-uuid",
|
|
"valueString": "ea07d7c6-ff4b-43fc-9765-e4235886d30c"
|
|
}
|
|
],
|
|
"reference": "Organization/2"
|
|
}
|
|
},
|
|
"resourceType": "CommunicationRequest"
|
|
}
|
|
}).then((response) => {
|
|
expect(response.status).to.eq(201);
|
|
expect(response.headers["content-type"]).to.eq("application/fhir+json;charset=UTF-8");
|
|
expect(response.body).to.have.property("resourceType", "CommunicationRequest");
|
|
expect(response.body).to.have.property('id');
|
|
expect(response.body).to.have.property('status', 'draft');
|
|
communicationRequestId = response.body.id
|
|
});
|
|
});
|
|
|
|
|
|
|
|
});
|